Search in sources :

Example 1 with GuideEdge

use of easik.model.edge.GuideEdge in project fql by CategoricalData.

the class ViewGraphModel 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 = (_view.getSketch().getFrame().getMode() == Mode.EDIT) ? "edit_" : "manip_";
    if (o instanceof GraphCell) {
        GraphCell cell = (GraphCell) o;
        AttributeMap attribs = cell.getAttributes();
        AttributeMap easikAttribs = null;
        if (cell instanceof View_Edge) {
            easikAttribs = (cell instanceof InjectiveViewEdge) ? injectiveEdgeAttributes() : (cell instanceof PartialViewEdge) ? partialEdgeAttributes() : normalEdgeAttributes();
        } else if (cell instanceof TriangleEdge) {
            easikAttribs = triangleEdgeAttributes((TriangleEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>) cell);
        } else if (cell instanceof GuideEdge) {
            easikAttribs = ((GuideEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>) cell).isHighlighted() ? virtualHighlightedEdgeAttributes() : virtualEdgeAttributes();
        } else if (cell instanceof ModelConstraint) {
            easikAttribs = virtualVertexAttributes();
        } else if (cell instanceof QueryNode) {
            easikAttribs = vertexAttributes();
        }
        if (easikAttribs != null) {
            if (_view.isCellSelected(cell)) {
                Color selColor;
                float lineWidth;
                if (_view.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) ViewFrame(easik.ui.ViewFrame) Color(java.awt.Color) TriangleEdge(easik.model.edge.TriangleEdge) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) View(easik.view.View) PartialViewEdge(easik.view.edge.PartialViewEdge) ModelConstraint(easik.model.constraint.ModelConstraint) AttributeMap(org.jgraph.graph.AttributeMap) QueryNode(easik.view.vertex.QueryNode) GetPathState(easik.model.states.GetPathState) GuideEdge(easik.model.edge.GuideEdge)

Example 2 with GuideEdge

use of easik.model.edge.GuideEdge in project fql by CategoricalData.

the class ModelConstraint method addVisualsToModel.

/**
 * Adds the visual aids to the sketch
 */
private void addVisualsToModel() {
    // Push loading state
    _theModel.getStateManager().pushState(new LoadingState<>(_theModel));
    _theModel.getGraphModel().beginInsignificantUpdate();
    _visuals.clear();
    // Get Nodes involved in constraint
    LinkedHashSet<N> entitiesInvolved = new LinkedHashSet<>();
    for (E edge : _edges) {
        entitiesInvolved.add(edge.getSourceEntity());
        entitiesInvolved.add(edge.getTargetEntity());
    }
    int avgX = 0, avgY = 0;
    if ("limitconstraint".equals(getType())) {
        // slightly differently
        for (N node : entitiesInvolved) {
            avgX += node.getX();
            avgY += node.getY();
        }
        LimitConstraint<F, GM, M, N, E> thisConstraintAsLC = ((LimitConstraint<F, GM, M, N, E>) this);
        N constraintRoot = thisConstraintAsLC.getLimitNode();
        final float BIG_EDGE_WIDTH = (float) 3.0;
        final float LITTLE_EDGE_WIDTH = (float) 2.0;
        final int TRANSPARENCY = 230;
        // a hopefully
        Color col = EasikTools.getUnusedColor(TRANSPARENCY);
        // unique
        // color,
        // 230 is
        // transparency
        _visuals.add(new TriangleEdge<>(this, constraintRoot, col, BIG_EDGE_WIDTH, GraphConstants.ARROW_NONE, GraphConstants.ARROW_NONE));
        _visuals.add(new TriangleEdge<>(this, thisConstraintAsLC.getCone().getA(), col, LITTLE_EDGE_WIDTH, GraphConstants.ARROW_NONE, GraphConstants.ARROW_NONE));
        _visuals.add(new TriangleEdge<>(this, thisConstraintAsLC.getCone().getB(), col, LITTLE_EDGE_WIDTH, GraphConstants.ARROW_NONE, GraphConstants.ARROW_NONE));
        _visuals.add(new TriangleEdge<>(this, thisConstraintAsLC.getCone().getC(), col, LITTLE_EDGE_WIDTH, GraphConstants.ARROW_NONE, GraphConstants.ARROW_NONE));
    } else {
        // edges going to each entity involved
        for (N node : entitiesInvolved) {
            GuideEdge<F, GM, M, N, E> myEdge = new GuideEdge<>(this, node);
            _visuals.add(myEdge);
            avgX += node.getX();
            avgY += node.getY();
        }
    }
    // If only one entity is involved add some vertical space
    if (entitiesInvolved.size() == 1) {
        avgY += 20;
    }
    int posX = getX();
    int posY = getY();
    // If visual does not already have a position then position it
    if ((posX == 0) && (posY == 0)) {
        posX = avgX / entitiesInvolved.size();
        posY = avgY / entitiesInvolved.size();
    }
    // Set the on-screen position of our entity to the attributes of the
    // entity
    AttributeMap attribs = getAttributes();
    GraphConstants.setAutoSize(attribs, true);
    GraphConstants.setBounds(attribs, new Rectangle2D.Double(posX, posY, 0, 0));
    GraphConstants.setSelectable(attribs, false);
    // Actually add them to the sketch display:
    GraphLayoutCache glc = _theModel.getGraphLayoutCache();
    if (!_nodeVisualized) {
        glc.insert(this);
        _nodeVisualized = true;
    }
    glc.insert(_visuals.toArray(new GuideEdge[0]));
    _edgesVisualized = true;
    _theModel.getGraphModel().endInsignificantUpdate();
    _theModel.refresh();
    // Pop state
    _theModel.getStateManager().popState();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) AttributeMap(org.jgraph.graph.AttributeMap) GuideEdge(easik.model.edge.GuideEdge)

Example 3 with GuideEdge

use of easik.model.edge.GuideEdge in project fql by CategoricalData.

the class ModelConstraint method removeVisualsFromModel.

/**
 * Removes the visuals from the sketch (when hiding)
 */
private void removeVisualsFromModel() {
    // Push loading state
    _theModel.getStateManager().pushState(new LoadingState<>(_theModel));
    _theModel.getGraphModel().beginInsignificantUpdate();
    GraphLayoutCache glc = _theModel.getGraphLayoutCache();
    glc.remove(_visuals.toArray(new GuideEdge[0]));
    _visuals.clear();
    _edgesVisualized = false;
    GraphConstants.setSelectable(getAttributes(), false);
    _theModel.refresh();
    _theModel.getGraphModel().cancelInsignificantUpdate();
    // Pop state
    _theModel.getStateManager().popState();
}
Also used : GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) GuideEdge(easik.model.edge.GuideEdge)

Example 4 with GuideEdge

use of easik.model.edge.GuideEdge in project fql by CategoricalData.

the class ModelConstraint method setVisible.

/**
 * Sets if the constraint should be visible or not
 *
 * @param inIsVisible
 *            If the constraint should be visible or not.
 */
public void setVisible(boolean inIsVisible) {
    if (inIsVisible != _isVisible) {
        _isVisible = inIsVisible;
        _theModel.setDirty();
    }
    @SuppressWarnings({ "unused", "unchecked" }) GuideEdge<F, GM, M, N, E>[] visuals = _visuals.toArray(new GuideEdge[0]);
    @SuppressWarnings("unused") GraphLayoutCache glc = _theModel.getGraphLayoutCache();
    if (_isVisible && !_edgesVisualized) {
        addVisualsToModel();
    } else if (!_isVisible && _edgesVisualized) {
        removeVisualsFromModel();
    }
    _theModel.clearSelection();
}
Also used : GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) GuideEdge(easik.model.edge.GuideEdge)

Example 5 with GuideEdge

use of easik.model.edge.GuideEdge in project fql by CategoricalData.

the class Model method removeConstraint.

/**
 * Removes a constraint and guide arrows
 *
 * @param toRemove
 *            The constraint about to be removed
 */
public void removeConstraint(final ModelConstraint<F, GM, M, N, E> toRemove) {
    model.beginUpdate();
    getGraphLayoutCache().remove(toRemove.getGuideEdges().toArray(new GuideEdge[toRemove.getGuideEdges().size()]));
    getGraphLayoutCache().remove(new Object[] { toRemove });
    final int position = toRemove.getID();
    _constraints.remove(toRemove.getID());
    for (N n : toRemove.getEntities()) {
        n.removeConstraint(toRemove);
    }
    model.postEdit(new AbstractUndoableEdit() {

        /**
         */
        private static final long serialVersionUID = 6431577416127308496L;

        @Override
        public void undo() {
            super.undo();
            _constraints.put(position, toRemove);
            for (N n : toRemove.getEntities()) {
                n.addConstraint(toRemove);
            }
        }

        @Override
        public void redo() {
            super.redo();
            _constraints.remove(position);
            for (N n : toRemove.getEntities()) {
                n.removeConstraint(toRemove);
            }
        }
    });
    // Remove Entity from tree
    _Frame.getInfoTreeUI().removeConstraint(toRemove);
    model.endUpdate();
}
Also used : AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit) GuideEdge(easik.model.edge.GuideEdge) Point(java.awt.Point) ModelConstraint(easik.model.constraint.ModelConstraint)

Aggregations

GuideEdge (easik.model.edge.GuideEdge)6 ModelConstraint (easik.model.constraint.ModelConstraint)3 Color (java.awt.Color)3 AttributeMap (org.jgraph.graph.AttributeMap)3 GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)3 TriangleEdge (easik.model.edge.TriangleEdge)2 GetPathState (easik.model.states.GetPathState)2 GraphCell (org.jgraph.graph.GraphCell)2 Sketch (easik.sketch.Sketch)1 InjectiveEdge (easik.sketch.edge.InjectiveEdge)1 PartialEdge (easik.sketch.edge.PartialEdge)1 SketchEdge (easik.sketch.edge.SketchEdge)1 EntityNode (easik.sketch.vertex.EntityNode)1 SketchFrame (easik.ui.SketchFrame)1 ViewFrame (easik.ui.ViewFrame)1 View (easik.view.View)1 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)1 PartialViewEdge (easik.view.edge.PartialViewEdge)1 View_Edge (easik.view.edge.View_Edge)1 QueryNode (easik.view.vertex.QueryNode)1