Search in sources :

Example 6 with InjectiveEdge

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);
}
Also used : ModelConstraint(easik.model.constraint.ModelConstraint) GraphCell(org.jgraph.graph.GraphCell) Color(java.awt.Color) TriangleEdge(easik.model.edge.TriangleEdge) PartialEdge(easik.sketch.edge.PartialEdge) ModelConstraint(easik.model.constraint.ModelConstraint) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) AttributeMap(org.jgraph.graph.AttributeMap) InjectiveEdge(easik.sketch.edge.InjectiveEdge) SketchEdge(easik.sketch.edge.SketchEdge) GetPathState(easik.model.states.GetPathState) Sketch(easik.sketch.Sketch) GuideEdge(easik.model.edge.GuideEdge)

Example 7 with InjectiveEdge

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);
        }
    }
}
Also used : InjectiveEdge(easik.sketch.edge.InjectiveEdge) SketchEdge(easik.sketch.edge.SketchEdge) NormalEdge(easik.sketch.edge.NormalEdge) Sketch(easik.sketch.Sketch) PartialEdge(easik.sketch.edge.PartialEdge) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

InjectiveEdge (easik.sketch.edge.InjectiveEdge)7 SketchEdge (easik.sketch.edge.SketchEdge)7 EntityNode (easik.sketch.vertex.EntityNode)7 Sketch (easik.sketch.Sketch)5 NormalEdge (easik.sketch.edge.NormalEdge)4 PartialEdge (easik.sketch.edge.PartialEdge)4 SketchFrame (easik.ui.SketchFrame)4 LimitConstraint (easik.model.constraint.LimitConstraint)3 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)3 EasikType (easik.database.types.EasikType)2 EntityAttribute (easik.model.attribute.EntityAttribute)2 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)2 ModelConstraint (easik.model.constraint.ModelConstraint)2 ProductConstraint (easik.model.constraint.ProductConstraint)2 PullbackConstraint (easik.model.constraint.PullbackConstraint)2 SumConstraint (easik.model.constraint.SumConstraint)2 UniqueIndexable (easik.model.keys.UniqueIndexable)2 DocumentInfo (easik.DocumentInfo)1 GuideEdge (easik.model.edge.GuideEdge)1 TriangleEdge (easik.model.edge.TriangleEdge)1