package models.controlFlowModel;
import models.NodeAttribute;
/**
* {@link ObjectNodeAttribute} represents an attribute that the linked object node in a control-flow graph has.
*/
public class ObjectNodeAttribute extends NodeAttribute {
private final ObjectNode objectNode;
private String shapeStyle = "";
public ObjectNodeAttribute(final ObjectNode objectNode) {
this.objectNode = objectNode;
this.objectNode.setAttribute(this);
// Setting a shape style of cell
if (objectNode instanceof StatefulObjectNode) {
shapeStyle = "shape=ellipse;perimeter=ellipsePerimeter;";
} else if (objectNode instanceof EventChannelObjectNode) {
shapeStyle = "shape=rectangle;perimeter=rectanglePerimeter;";
} else {
shapeStyle = "shape=hexagon;perimeter=hexagonPerimeter;";
}
// Setting a name of a cell
if (objectNode.name != null) return;
// if (objectNode.name.isEmpty()) return;
if (objectNode instanceof StatefulObjectNode) {
objectNode.name = objectNode.getName();
} else if (objectNode instanceof EventChannelObjectNode) {
objectNode.name = "entryPoint";
}
}
/**
* Get an object node that the attribute is linked to.
*
* @return an object node that the attribute is linked to.
*/
public ObjectNode getObjectNode() {
return objectNode;
}
public String getDefaultStyle() {
String style = ";";
return shapeStyle + style;
}
/**
* Get the color of a selected cell.
*/
public String getEnableStyle() {
String style = "fillColor=#7fffd4;";
style += "strokeColor=#66cdaa;";
style += "strokeWidth=2;";
return shapeStyle + style;
}
/**
* Get the color of an unselected cell.
*/
public String getDisableStyle() {
String style = "fillColor=#999999";
return shapeStyle + style;
}
/**
* Get the color of a cell that can be delegated.
*/
public String getDelegatingStyle() {
String style = "strokeWidth=4;";
style += "strokeColor=#4169e;";
return shapeStyle + style;
}
/**
* Get the cell's name that displayed on GUI
*/
@Override
public String toString() {
return objectNode instanceof StatefulObjectNode
? ((StatefulObjectNode) objectNode).getResource().getResourceName()
: objectNode.getName();
}
}