Search in sources :

Example 6 with GraphLayoutCache

use of org.jgraph.graph.GraphLayoutCache in project fql by CategoricalData.

the class View method initialiseModel.

/**
 * When we initialize the sketch, we flush out all the data concerning the
 * sketch itself. Even the modelAdapter is reinitialized.
 *
 * This methods serves as a "new sketch" function.
 */
@Override
public void initialiseModel() {
    clearSelection();
    model = new ViewGraphModel(this);
    final GraphLayoutCache glc = new GraphLayoutCache(model, new ModelViewFactory<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>());
    setModel(model);
    setGraphLayoutCache(glc);
    _nodes = new LinkedHashMap<>();
    _edges = new LinkedHashMap<>();
    if (_Frame.getInfoTreeUI() != null) {
        // Wipe
        _Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame));
        // Tree
        _Frame.getInfoTreeUI().refreshTree();
    }
    _docInfo.reset();
    model.discardUndo();
}
Also used : ViewGraphModel(easik.view.util.graph.ViewGraphModel) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) ViewFrame(easik.ui.ViewFrame) QueryNode(easik.view.vertex.QueryNode) View_Edge(easik.view.edge.View_Edge)

Example 7 with GraphLayoutCache

use of org.jgraph.graph.GraphLayoutCache 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 8 with GraphLayoutCache

use of org.jgraph.graph.GraphLayoutCache 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 9 with GraphLayoutCache

use of org.jgraph.graph.GraphLayoutCache 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 10 with GraphLayoutCache

use of org.jgraph.graph.GraphLayoutCache in project fql by CategoricalData.

the class Sketch method initialiseModel.

/**
 * When we initialise the sketch, we flush out all the data concerning the
 * sketch itself.
 *
 * This methods serves as a "new sketch" function.
 */
@Override
public void initialiseModel() {
    clearSelection();
    model = new SketchGraphModel(this);
    final GraphLayoutCache glc = new GraphLayoutCache(model, new ModelViewFactory<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>());
    setModel(model);
    setGraphLayoutCache(glc);
    _nodes = new LinkedHashMap<>();
    _edges = new LinkedHashMap<>();
    if (_Frame.getInfoTreeUI() != null) {
        // Wipe
        _Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame));
        // Tree
        _Frame.getInfoTreeUI().refreshTree();
    }
    _docInfo.reset();
    _views = new HashMap<>();
    _connParams = new HashMap<>();
    model.discardUndo();
}
Also used : SketchFrame(easik.ui.SketchFrame) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) SketchEdge(easik.sketch.edge.SketchEdge) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode)

Aggregations

GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)11 Rectangle2D (java.awt.geom.Rectangle2D)4 GuideEdge (easik.model.edge.GuideEdge)3 AbstractUndoableEdit (javax.swing.undo.AbstractUndoableEdit)3 AttributeMap (org.jgraph.graph.AttributeMap)3 SketchEdge (easik.sketch.edge.SketchEdge)2 EntityNode (easik.sketch.vertex.EntityNode)2 QueryNode (easik.view.vertex.QueryNode)2 JGraph (org.jgraph.JGraph)2 DefaultCellViewFactory (org.jgraph.graph.DefaultCellViewFactory)2 DefaultGraphCell (org.jgraph.graph.DefaultGraphCell)2 DefaultGraphModel (org.jgraph.graph.DefaultGraphModel)2 GraphModel (org.jgraph.graph.GraphModel)2 DocumentInfo (easik.DocumentInfo)1 KosarajuSCC (easik.model.util.graph.KosarajuSCC)1 OverviewGraphModel (easik.overview.util.graph.OverviewGraphModel)1 SketchNode (easik.overview.vertex.SketchNode)1 ViewNode (easik.overview.vertex.ViewNode)1 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)1 SketchFrame (easik.ui.SketchFrame)1