Search in sources :

Example 31 with Sketch

use of easik.sketch.Sketch 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 32 with Sketch

use of easik.sketch.Sketch in project fql by CategoricalData.

the class EntityNode method getShadowEdges.

/**
 * This method returns the edges that will be "shadowed" in this entity for
 * allowing various types of constraints. The problem arises when we have
 * something like: A -&gt; B -&gt; C, where A is the summand of B, but B has
 * to be specified. In this case, the B to C edge will be returned as a
 * "shadow" edge. We handle this for other constraint types, too. For a
 * good, working, technical example, see the shadowEdges.easik sample
 * sketch.
 *
 * @return a set of edges that will be shadowed by this entity node.
 *
 *         Removing shadow edges completely. Started by Sarah Van der Laan
 *         continued by Federico Mora because a partial solution is worse
 *         than all or nothing
 *
 *         public LinkedHashSet<SketchEdge> getShadowEdges() { return
 *         getShadowEdges(new LinkedHashSet<EntityNode>(5), new
 *         LinkedHashSet<SketchEdge>(5)); }
 */
// Package-only implementation of the above that breaks recursion by
// ignoring
// shadowed nodes that we already know about.
/**
 * @param ignore
 * @param constraintEdges
 *
 * @return
 */
LinkedHashSet<SketchEdge> getShadowEdges(final Collection<EntityNode> ignore, final LinkedHashSet<SketchEdge> constraintEdges) {
    // These are the other entity node that we (potentially) need to shadow:
    final Collection<EntityNode> shadow = new LinkedHashSet<>(10);
    CONSTRAINT: for (final ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> c : getMModel().getConstraints().values()) {
        if (c instanceof SumConstraint) {
            final SumConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> s = (SumConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c;
            for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : s.getPaths()) {
                // for this entity, of course):
                if (path.getDomain() == this) {
                    shadow.addAll(path.getEntities());
                    constraintEdges.addAll(path.getEdges());
                    continue CONSTRAINT;
                }
            }
        } else if (c instanceof ProductConstraint) {
            final ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> p = (ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c;
            for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : p.getPaths()) {
                // codomains), along each product path
                if (path.getCoDomain() == this) {
                    for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> prodPath : p.getPaths()) {
                        // But we ignore all of the product path edges,
                        // since they will be automatically generated:
                        constraintEdges.addAll(prodPath.getEdges());
                        final Deque<EntityNode> pathNodes = new LinkedList<>();
                        pathNodes.addAll(prodPath.getEntities());
                        pathNodes.removeLast();
                        shadow.addAll(pathNodes);
                    }
                    continue CONSTRAINT;
                }
            }
        } else if (c instanceof EqualizerConstraint) {
            final EqualizerConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> e = (EqualizerConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c;
            // injective *edge* doesn't cause that problem).
            if (e.getSourceEntity() == this) {
                final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> projection = e.getProjection();
                shadow.addAll(projection.getEntities());
                // Ignore the projection edge itself:
                constraintEdges.addAll(projection.getEdges());
                continue CONSTRAINT;
            }
        } else if (c instanceof PullbackConstraint) {
            final PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> pb = (PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c;
            // WPBEDIT CF2012
            for (int i = 0; i < pb.getWidth(); i++) {
                ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> proj = pb.getProjectionPath(i);
                if (this == proj.getCoDomain()) {
                    for (int j = 0; j < pb.getWidth(); j++) {
                        proj = pb.getProjectionPath(j);
                        Deque<EntityNode> projNodes = new LinkedList<>(proj.getEntities());
                        projNodes.removeLast();
                        shadow.addAll(projNodes);
                        constraintEdges.addAll(proj.getEdges());
                    }
                    continue CONSTRAINT;
                }
            }
        } else if (c instanceof LimitConstraint) {
        // TRIANGLES TODO CF2012 incomplete
        }
    }
    final LinkedHashSet<SketchEdge> shadowEdges = new LinkedHashSet<>(20);
    // All of the ignore entities, plus everything we just found should be
    // ignored by any recursion:
    final Collection<EntityNode> toIgnore = new LinkedHashSet<>(3);
    toIgnore.add(this);
    toIgnore.addAll(ignore);
    toIgnore.addAll(shadow);
    for (final EntityNode node : shadow) {
        // it:
        if ((node == this) || ignore.contains(node)) {
            continue;
        }
        // Otherwise, shadow its non-partial edges, and all of its shadow
        // edges:
        shadowEdges.addAll(node.getShadowEdges(toIgnore, constraintEdges));
        shadowEdges.addAll(node.getNonPartialEdges());
        // Remove edges already
        shadowEdges.removeAll(constraintEdges);
    // involved in the sum
    }
    return shadowEdges;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LimitConstraint(easik.model.constraint.LimitConstraint) ModelConstraint(easik.model.constraint.ModelConstraint) PullbackConstraint(easik.model.constraint.PullbackConstraint) SumConstraint(easik.model.constraint.SumConstraint) LinkedList(java.util.LinkedList) LimitConstraint(easik.model.constraint.LimitConstraint) EqualizerConstraint(easik.model.constraint.EqualizerConstraint) ProductConstraint(easik.model.constraint.ProductConstraint) SumConstraint(easik.model.constraint.SumConstraint) PullbackConstraint(easik.model.constraint.PullbackConstraint) ModelConstraint(easik.model.constraint.ModelConstraint) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) SketchFrame(easik.ui.SketchFrame) ProductConstraint(easik.model.constraint.ProductConstraint) SketchEdge(easik.sketch.edge.SketchEdge) ModelPath(easik.model.path.ModelPath) EqualizerConstraint(easik.model.constraint.EqualizerConstraint) Sketch(easik.sketch.Sketch)

Example 33 with Sketch

use of easik.sketch.Sketch in project fql by CategoricalData.

the class EditSketchEdgeAction method actionPerformed.

/**
 * Called when clicked upon, will popup the edge UI and, if accepted, update
 * the name and cascade option.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Sketch _ourSketch = _theFrame.getMModel();
    Object[] currentSelection = _ourSketch.getSelectionCells();
    // non-edges which might be selected
    if ((currentSelection.length == 1) && (currentSelection[0] instanceof SketchEdge)) {
        // cancel operation
        if (_ourSketch.isSynced()) {
            if (JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; delete and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
                return;
            }
        }
        SketchEdge edge = (SketchEdge) currentSelection[0];
        EdgeOptions opts = new EdgeOptions(_theFrame, edge);
        if (opts.isAccepted()) {
            if (!opts.getName().equals(edge.getName())) {
                edge.setName(opts.getName());
            }
            edge.setCascading(opts.getCascadeMode());
            _theFrame.getInfoTreeUI().refreshTree();
            _ourSketch.getGraphLayoutCache().reload();
            _ourSketch.clearSelection();
            _ourSketch.repaint();
            _ourSketch.setDirty();
            _ourSketch.setSynced(false);
        }
    }
}
Also used : SketchEdge(easik.sketch.edge.SketchEdge) Sketch(easik.sketch.Sketch)

Example 34 with Sketch

use of easik.sketch.Sketch 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)

Example 35 with Sketch

use of easik.sketch.Sketch in project fql by CategoricalData.

the class DocInfoUI method accepted.

/**
 * Called when the user clicks OK
 *
 * @param ok
 */
@Override
public void accepted(boolean ok) {
    if (!ok) {
        return;
    }
    // This call will setDirty() if anything has changed:
    docInfo.setAllInfo(name.getText(), author.getText(), JUtils.taText(description));
    if (context == InfoContext.SKETCH) {
        Sketch sketch = ((SketchFrame) _theFrame).getMModel();
        int cascadeIndex = edgeCascading.getSelectedIndex(), partialIndex = edgeCascadingPartial.getSelectedIndex();
        sketch.setDefaultCascading((cascadeIndex == 0) ? Cascade.RESTRICT : Cascade.CASCADE);
        sketch.setDefaultPartialCascading((partialIndex == 0) ? Cascade.SET_NULL : (partialIndex == 1) ? Cascade.RESTRICT : Cascade.CASCADE);
        // Might already have happened above, but no big
        sketch.setDirty();
    // deal.
    }
}
Also used : Sketch(easik.sketch.Sketch)

Aggregations

Sketch (easik.sketch.Sketch)40 SketchEdge (easik.sketch.edge.SketchEdge)32 EntityNode (easik.sketch.vertex.EntityNode)30 SketchFrame (easik.ui.SketchFrame)30 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)27 LimitConstraint (easik.model.constraint.LimitConstraint)16 ProductConstraint (easik.model.constraint.ProductConstraint)16 SumConstraint (easik.model.constraint.SumConstraint)16 PullbackConstraint (easik.model.constraint.PullbackConstraint)15 LinkedList (java.util.LinkedList)15 ModelConstraint (easik.model.constraint.ModelConstraint)13 EqualizerConstraint (easik.model.constraint.EqualizerConstraint)12 ModelPath (easik.model.path.ModelPath)9 ArrayList (java.util.ArrayList)7 LinkedHashSet (java.util.LinkedHashSet)7 InjectiveEdge (easik.sketch.edge.InjectiveEdge)5 XSDAnnotation (easik.xml.xsd.nodes.XSDAnnotation)5 XSDType (easik.xml.xsd.nodes.types.XSDType)5 EasikType (easik.database.types.EasikType)4 EntityAttribute (easik.model.attribute.EntityAttribute)4