Skip to content

Instantly share code, notes, and snippets.

@ghostandthemachine
Created December 22, 2009 20:17
Show Gist options
  • Save ghostandthemachine/262008 to your computer and use it in GitHub Desktop.
Save ghostandthemachine/262008 to your computer and use it in GitHub Desktop.
import java.lang.Object.*;
class BaseNode{
int cx;
int cy;
int px;
int py;
int x;
int y;
int xOffset = 0;
int yOffset = 0;
int w;
int bw;
int h;
int r;
int value;
int outputs;
int inputs;
int outLockedID;
int inOrOut;
int currentConnectionIDout = -1;
int currentConnectionIDin = -1;
//for interaction
boolean press = false;
boolean scaleable = true;
boolean rollover;
boolean locked;
boolean over;
boolean highLight = false;
boolean selected = false;
boolean connecting = false;
boolean scaleLocked = false;
boolean wideSelectionOnly = true;
boolean currentObject = false;
//for connections
int[][] outLocation;
int[][] inLocation;
color fillColor = color(0xFFFFFF);
color borderColor = color(0xA5A5A5);
color highlightColor = color(205,255,240);
color cfillColor = color(0xFFFFFF);
color cborderColor = color(0xA5A5A5);
color cHighlightColor = color(0xB9FFEB);
String titleString;
ArrayList outputShapes;
ArrayList inputShapes;
SGText title = new SGText();
SGGroup group = new SGGroup();
BaseNode(String tTitle, int ins, int outs, int tx, int ty){
inputs = ins;
outputs = outs;
titleString = tTitle;
rollover = false;
locked = false;
over = false;
x = tx;
y = ty;
h = 23;
r = 8;
bw = titleString.length() * 6;
w = constrain(titleString.length() * 7 + 5, bw, 1000);
inputShapes = new ArrayList();
outputShapes = new ArrayList();
FXShape baseRect = new FXShape();
baseRect.setShape(new RoundRectangle2D.Float(float(x), float(y), float(w), float(h), float(r), float(r) ));
baseRect.setFillPaint(new Color(255, 255, 255));
baseRect.setMode(SGShape.Mode.STROKE_FILL);
baseRect.setDrawStroke(new BasicStroke(2.0f));
baseRect.setDrawPaint(Color.GRAY);
baseRect.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
title.setText(titleString);
title.setFont(new Font("SansSerif", Font.BOLD, 14));
title.setLocation(new Point(x + 5, y + 17));
title.setAntialiasingHint(RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
title.setFillPaint(Color.BLACK);
for(int i = 0; i < inputs; i++){
inputShapes.add(new FXShape());
FXShape shape = (FXShape)inputShapes.get(i);
shape.setShape(new Line2D.Float(x + (i * (w / inputs)) + r, y, x + r + (i * (w / inputs)) + constrain((w / inputs + 2), 2, 6), y));
shape.setDrawPaint(Color.BLACK);
shape.setMode(SGShape.Mode.STROKE_FILL);
shape.setDrawStroke(new BasicStroke(2));
shape.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
}
for(int i = 0; i < outputs; i++){
outputShapes.add(new FXShape());
FXShape shape = (FXShape)outputShapes.get(i);
shape.setShape(new Line2D.Float(x + (i * (w / outputs)) + r, y + h, x + r + (i * (w / outputs)) + constrain((w / outputs + 3), 2, 4), y + h));
shape.setDrawPaint(Color.BLACK);
shape.setMode(SGShape.Mode.STROKE_FILL);
shape.setDrawStroke(new BasicStroke(2));
shape.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
}
group.add(baseRect);
group.add(title);
for(int i = 0; i < inputs; i++){
FXShape shape = (FXShape)inputShapes.get(i);
group.add(shape);
}
for(int i = 0; i < outputs; i++){
FXShape shape = (FXShape)outputShapes.get(i);
group.add(shape);
}
}
void update(int mx, int my){
xOffset = pmouseX - mouseX;
yOffset = pmouseY - mouseY;
x += xOffset;
y += yOffset;
}
SGGroup returnGroup(){
return group;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment