use of org.apache.airavata.workflow.model.graph.Port.Kind in project airavata by apache.
the class GraphCanvas method paintComponent.
private void paintComponent(Graphics2D g) {
NodeController.getGUI(this.graph).paint(g);
// Draws a creating edge.
if (this.draggedPort != null) {
Point p1, p2;
Kind kind = this.draggedPort.getKind();
if (kind == Kind.DATA_OUT || kind == Kind.CONTROL_OUT || kind == Kind.EPR) {
p1 = NodeController.getGUI(this.draggedPort).getPosition();
p2 = this.mousePoint;
} else if (kind == Kind.DATA_IN || kind == Kind.CONTROL_IN) {
p1 = this.mousePoint;
p2 = NodeController.getGUI(this.draggedPort).getPosition();
} else {
// This should not happen.
throw new WorkflowRuntimeException();
}
g.setColor(Color.RED);
Stroke originalStroke = g.getStroke();
if (kind == Kind.CONTROL_IN || kind == Kind.CONTROL_OUT) {
g.setStroke(EdgeGUI.CONTROL_EDGE_STROKE);
}
EdgeGUI.paintLine(p1, p2, g);
g.setStroke(originalStroke);
}
// Draw rectangular for selection
if (this.mousePointForSelection != null) {
double width = Math.abs(this.mousePoint.getX() - this.mousePointForSelection.getX());
double height = Math.abs(this.mousePoint.getY() - this.mousePointForSelection.getY());
int x = (int) (this.mousePoint.getX() > this.mousePointForSelection.getX() ? this.mousePointForSelection.getX() : this.mousePoint.getX());
int y = (int) (this.mousePoint.getY() > this.mousePointForSelection.getY() ? this.mousePointForSelection.getY() : this.mousePoint.getY());
g.setColor(Color.RED);
g.setStroke(new // End cap
BasicStroke(// End cap
1.0f, // End cap
BasicStroke.CAP_ROUND, // Join style
BasicStroke.JOIN_MITER, // Miter limit
15.0f, // Dash pattern
new float[] { 5.0f, 5.0f }, // Dash phase
3.0f));
g.drawRect(x, y, (int) width, (int) height);
}
}
use of org.apache.airavata.workflow.model.graph.Port.Kind in project airavata by apache.
the class EndBlockNode method portTypeChanged.
/**
* @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
*/
@Override
protected void portTypeChanged(SystemDataPort port) throws GraphException {
super.portTypeChanged(port);
List<DataPort> inputPorts = getInputPorts();
List<DataPort> outputPorts = getOutputPorts();
int size = outputPorts.size();
Kind kind = port.getKind();
int index;
if (kind == Kind.DATA_IN) {
index = inputPorts.indexOf(port) % size;
} else if (kind == Kind.DATA_OUT) {
index = outputPorts.indexOf(port);
} else {
throw new WorkflowRuntimeException();
}
DataPort inputPort1 = inputPorts.get(index);
DataPort inputPort2 = inputPorts.get(size + index);
DataPort outputPort = outputPorts.get(index);
DataType inputType1 = inputPort1.getType();
DataType inputType2 = inputPort2.getType();
DataType outputType = outputPort.getType();
DataType portType = port.getType();
if (portType == null || portType.equals(WSConstants.XSD_ANY_TYPE)) {
// Do nothing
return;
}
if (port == inputPort1) {
// input1 -> input2
if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort2.copyType(port);
} else if (inputType2.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
throw new GraphException(message);
}
// input1 -> output
if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
outputPort.copyType(port);
} else if (outputType.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else if (port == inputPort2) {
// input2 -> input1
if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort1.copyType(port);
} else if (inputType1.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
throw new GraphException(message);
}
// input2 -> output
if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
outputPort.copyType(port);
} else if (outputType.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else if (port == outputPort) {
// output -> input1
if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort1.copyType(port);
} else if (inputType1.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + index + " (" + inputType1 + ") of " + getID() + " must be same as the type of output " + index + " (" + outputType + ").";
throw new GraphException(message);
}
// output -> input2
if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort2.copyType(port);
} else if (inputType2.equals(portType)) {
// Do nothing.
} else {
String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID() + " must be same as the type of input " + index + " (" + outputType + ").";
throw new GraphException(message);
}
} else {
throw new WorkflowRuntimeException();
}
}
use of org.apache.airavata.workflow.model.graph.Port.Kind in project airavata by apache.
the class EndDoWhileNode method portTypeChanged.
/**
* @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
*/
@Override
protected void portTypeChanged(SystemDataPort port) throws GraphException {
super.portTypeChanged(port);
List<DataPort> inputPorts = getInputPorts();
List<DataPort> outputPorts = getOutputPorts();
Kind kind = port.getKind();
int index;
if (kind == Kind.DATA_IN) {
index = inputPorts.indexOf(port);
} else if (kind == Kind.DATA_OUT) {
index = outputPorts.indexOf(port);
} else {
throw new WorkflowRuntimeException();
}
SystemDataPort inputPort = (SystemDataPort) inputPorts.get(index);
SystemDataPort outputPort = (SystemDataPort) outputPorts.get(index);
DataType inputType = inputPort.getType();
DataType outputType = outputPort.getType();
DataType portType = port.getType();
if (portType == null || portType.equals(WSConstants.XSD_ANY_TYPE)) {
// Do nothing
return;
}
if (port == inputPort) {
// input -> output
if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
outputPort.copyType(port, 1);
} else if (outputType.equals(portType)) {
// Do nothing.
} else {
// XXX cannot parse array from WSDL.
// String message = "The type of input " + index + " ("
// + inputType + ") of " + getID()
// + " must be same as the type of output " + index + " ("
// + outputType + ").";
// throw new GraphException(message);
}
} else if (port == outputPort) {
// output -> input1
if (inputType.equals(WSConstants.XSD_ANY_TYPE)) {
inputPort.copyType(port, -1);
} else if (inputType.equals(portType)) {
// Do nothing.
} else {
// XXX cannot parse array from WSDL.
// String message = "The type of input " + index + " ("
// + inputType + ") of " + getID()
// + " must be same as the type of output " + index + " ("
// + outputType + ").";
// throw new GraphException(message);
}
} else {
throw new WorkflowRuntimeException();
}
}
use of org.apache.airavata.workflow.model.graph.Port.Kind in project airavata by apache.
the class ForEachNode method portTypeChanged.
/**
* @param port
* @throws GraphException
*/
@Override
protected void portTypeChanged(SystemDataPort port) throws GraphException {
super.portTypeChanged(port);
List<DataPort> inputPorts = getInputPorts();
List<DataPort> outputPorts = getOutputPorts();
Kind kind = port.getKind();
int index;
if (kind == Kind.DATA_IN) {
index = inputPorts.indexOf(port);
} else if (kind == Kind.DATA_OUT) {
index = outputPorts.indexOf(port);
} else {
throw new WorkflowRuntimeException();
}
SystemDataPort inputPort = (SystemDataPort) inputPorts.get(index);
SystemDataPort outputPort = (SystemDataPort) outputPorts.get(index);
DataType inputType = inputPort.getType();
DataType outputType = outputPort.getType();
DataType portType = port.getType();
if (portType == null || portType.equals(WSConstants.XSD_ANY_TYPE)) {
// Do nothing
return;
}
if (port == inputPort) {
// input -> output
if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
// outputPort.copyType(port, -1);
} else if (outputType.equals(portType)) {
// Do nothing.
} else {
// XXX cannot parse array from WSDL.
// String message = "The type of input " + index + " ("
// + inputType + ") of " + getID()
// + " must be same as the type of output " + index + " ("
// + outputType + ").";
// throw new GraphException(message);
}
} else if (port == outputPort) {
// output -> input1
if (inputType.equals(WSConstants.XSD_ANY_TYPE)) {
// inputPort.copyType(port, 1);
} else if (inputType.equals(portType)) {
// Do nothing.
} else {
// XXX cannot parse array from WSDL.
// String message = "The type of input " + index + " ("
// + inputType + ") of " + getID()
// + " must be same as the type of output " + index + " ("
// + outputType + ").";
// throw new GraphException(message);
}
} else {
throw new WorkflowRuntimeException();
}
}
use of org.apache.airavata.workflow.model.graph.Port.Kind in project airavata by apache.
the class PortGUI method paint.
/**
* @param g
*/
public void paint(Graphics2D g) {
Kind kind = this.port.getKind();
Color color = null;
switch(kind) {
case DATA_IN:
color = this.selected ? SELECTED_COLOR : DATA_IN_COLOR;
break;
case DATA_OUT:
color = this.selected ? SELECTED_COLOR : DATA_OUT_COLOR;
break;
case CONTROL_IN:
color = this.selected ? SELECTED_COLOR : CONTROL_IN_COLOR;
break;
case CONTROL_OUT:
color = this.selected ? SELECTED_COLOR : CONTROL_OUT_COLOR;
break;
case EPR:
color = this.selected ? SELECTED_COLOR : EPR_COLOR;
break;
}
Point point = getPosition();
Shape shape = null;
switch(kind) {
case DATA_IN:
shape = drawPortArrow(point);
int count = 0;
String[] tokenArray = new String[this.tokens.size()];
this.tokens.toArray(tokenArray);
for (String token : tokenArray) {
g.setColor(TOKEN_COLOR);
g.fill(new Ellipse2D.Double(point.x + TOKEN_SIZE, /* +count*5 */
point.y + TOKEN_SIZE * count, TOKEN_SIZE, TOKEN_SIZE / 2));
g.setColor(TEXT_COLOR);
g.drawString(token, point.x + TOKEN_SIZE * 3, /* +count*5 */
point.y + TOKEN_SIZE * count);
++count;
}
break;
case DATA_OUT:
shape = drawPortArrow(point);
count = 0;
tokenArray = new String[this.tokens.size()];
this.tokens.toArray(tokenArray);
for (String token : tokenArray) {
g.setColor(TOKEN_COLOR);
g.fill(new Ellipse2D.Double(point.x + 5, /* +count*5 */
point.y + TOKEN_SIZE * count, TOKEN_SIZE, TOKEN_SIZE / 2));
g.setColor(TEXT_COLOR);
g.drawString(token, point.x + TOKEN_SIZE + 10, /* +count*0 */
point.y + TOKEN_SIZE * count);
++count;
}
break;
case CONTROL_IN:
case CONTROL_OUT:
shape = new Ellipse2D.Double(point.x - CONTROL_PORT_SIZE / 2, point.y - CONTROL_PORT_SIZE / 2, CONTROL_PORT_SIZE, CONTROL_PORT_SIZE);
break;
case EPR:
shape = new Ellipse2D.Double(point.x - CONTROL_PORT_SIZE / 2, point.y - CONTROL_PORT_SIZE / 2, CONTROL_PORT_SIZE, CONTROL_PORT_SIZE);
break;
}
DrawUtils.gradientFillShape(g, color.brighter().brighter().brighter().brighter(), color.darker(), shape);
if (getPortText() != null) {
g.setColor(Color.WHITE);
Font oldFont = g.getFont();
g.setFont(new Font(oldFont.getFontName(), Font.BOLD, 7));
Rectangle2D bounds = g.getFontMetrics().getStringBounds(getPortText(), g);
g.drawString(getPortText(), (int) (shape.getBounds().getX() + (shape.getBounds().getWidth() - bounds.getWidth()) * 2 / 4), (int) (shape.getBounds().getY() + (shape.getBounds().getHeight() + bounds.getHeight()) * 4 / 8));
g.setFont(oldFont);
}
}
Aggregations