use of easik.sketch.edge.InjectiveEdge in project fql by CategoricalData.
the class SketchGraphModel method getAttributes.
/**
* Overridden method to get cell attributes; we make sure the appropriate
* attributes are applied to the Easik objects before returning them.
*
* @see DefaultGraphModel.getAttributes(Object)
*
* @param o
*
* @return
*/
@Override
@SuppressWarnings("unchecked")
public AttributeMap getAttributes(Object o) {
_mode = (_sketch.getFrame().getMode() == Mode.EDIT) ? "edit_" : "manip_";
if (o instanceof GraphCell) {
GraphCell cell = (GraphCell) o;
AttributeMap attribs = cell.getAttributes();
AttributeMap easikAttribs = null;
if (cell instanceof SketchEdge) {
easikAttribs = (cell instanceof InjectiveEdge) ? injectiveEdgeAttributes() : (cell instanceof PartialEdge) ? partialEdgeAttributes() : normalEdgeAttributes();
} else if (cell instanceof TriangleEdge) {
easikAttribs = triangleEdgeAttributes((TriangleEdge<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) cell);
} else if (cell instanceof GuideEdge) {
easikAttribs = ((GuideEdge<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) cell).isHighlighted() ? virtualHighlightedEdgeAttributes() : virtualEdgeAttributes();
} else if (cell instanceof ModelConstraint) {
easikAttribs = virtualVertexAttributes();
} else if (cell instanceof EntityNode) {
easikAttribs = vertexAttributes();
}
if (easikAttribs != null) {
if (_sketch.isCellSelected(cell)) {
Color selColor;
float lineWidth;
if (_sketch.getStateManager().peekState() instanceof GetPathState) {
selColor = getColor("path_selection");
lineWidth = getWidth("path_selection", 2);
} else {
selColor = getColor("selection");
lineWidth = getWidth("selection", 3);
}
int borderWidth = getIntWidth(_mode + ((cell instanceof ModelConstraint) ? "constraint" : "entity") + "_border", 1);
GraphConstants.setBorder(easikAttribs, BorderFactory.createLineBorder(selColor, borderWidth));
GraphConstants.setForeground(easikAttribs, selColor);
GraphConstants.setLineColor(easikAttribs, selColor);
GraphConstants.setLineWidth(easikAttribs, lineWidth);
}
if (attribs == null) {
cell.setAttributes(easikAttribs);
attribs = easikAttribs;
} else {
attribs.applyMap(easikAttribs);
}
return attribs;
}
}
return super.getAttributes(o);
}
use of easik.sketch.edge.InjectiveEdge in project fql by CategoricalData.
the class NewSketchEdgeAction method actionPerformed.
/**
* The action for creating a new edge. Make sure the selection is alright,
* and then create the edge.
*
* @param e
* The action event
*/
@Override
public void actionPerformed(ActionEvent e) {
Sketch _ourSketch = _theFrame.getMModel();
// cancel operation
if (_ourSketch.isSynced()) {
if (JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
return;
}
}
Object[] currentSelection = _ourSketch.getSelectionCells();
EntityNode[] node = new EntityNode[(_edgeType == Edge.SELF) ? 1 : 2];
if (currentSelection.length == node.length) {
for (int i = 0; i < node.length; i++) {
node[i] = null;
if (currentSelection[i] instanceof EntityNode) {
node[i] = (EntityNode) currentSelection[i];
}
}
}
if ((_edgeType == Edge.SELF) && (node[0] == null)) {
JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with one entity selected", "Error", JOptionPane.ERROR_MESSAGE);
} else if ((_edgeType != Edge.SELF) && ((node[0] == null) || (node[1] == null))) {
JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with two entities selected", "Error", JOptionPane.ERROR_MESSAGE);
} else {
EdgeOptions opts = new EdgeOptions(_theFrame, _edgeType, node[0], (_edgeType == Edge.SELF) ? null : node[1]);
if (opts.isAccepted()) {
SketchEdge edge;
if (_edgeType == Edge.SELF) {
edge = new PartialEdge(node[0], node[0], opts.getName(), opts.getCascadeMode());
} else {
// UI:
if (opts.isReversed()) {
node = new EntityNode[] { node[1], node[0] };
}
if (_edgeType == Edge.PARTIAL) {
edge = new PartialEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
} else if (_edgeType == Edge.INJECTIVE) {
edge = new InjectiveEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
} else {
edge = new NormalEdge(node[0], node[1], opts.getName(), opts.getCascadeMode());
}
}
_ourSketch.addEdge(edge);
_ourSketch.setDirty();
_ourSketch.setSynced(false);
}
}
}
Aggregations