Search in sources :

Example 1 with ViewFrame

use of easik.ui.ViewFrame in project fql by CategoricalData.

the class OverviewHandler method startElement.

/**
 * Overloaded method that is called any time the start of an element is
 * found
 *
 * @param namespace
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param localName
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param qName
 * 			@see org.xml.sax.helpers.DefaultHandler
 * @param atts
 * 			@see org.xml.sax.helpers.DefaultHandler
 */
@Override
public void startElement(String namespace, String localName, String qName, Attributes atts) {
    _currNode = qName;
    // call
    if (_sketchParser != null) {
        _sketchParser.startElement(namespace, localName, qName, atts);
    } else // Initialize a sketch handler, and note this sketch's attributes
    if (qName.equals("easketch")) {
        String sketchName = atts.getValue("name");
        int sketchX = Integer.parseInt(atts.getValue("x"));
        int sketchY = Integer.parseInt(atts.getValue("y"));
        String cascade = atts.getValue("cascade"), pCascade = atts.getValue("partial-cascade");
        if (cascade == null) {
            cascade = Easik.getInstance().getSettings().getProperty("sql_cascade", "restrict");
        }
        if (pCascade == null) {
            pCascade = Easik.getInstance().getSettings().getProperty("sql_cascade_partial", "set_null");
        }
        Cascade c = cascade.equals("cascade") ? Cascade.CASCADE : Cascade.RESTRICT;
        Cascade cp = pCascade.equals("cascade") ? Cascade.CASCADE : pCascade.equals("restrict") ? Cascade.RESTRICT : Cascade.SET_NULL;
        _sketchParser = SketchFileIO.getNewSketchHandler(_theFrame.getOverview());
        SketchFrame frame = _sketchParser.getFrame();
        Sketch sketch = frame.getMModel();
        sketch.setDefaultCascading(c);
        sketch.setDefaultPartialCascading(cp);
        _newSketchNode = new SketchNode(sketchName, sketchX, sketchY, frame);
        _sketchNodes.put(sketchName, _newSketchNode);
    } else // know not to override the overview's
    if (qName.equals("view")) {
        _parsingView = true;
        _queryNodes = new HashMap<>();
        String viewName = atts.getValue("name");
        int x = Integer.parseInt(atts.getValue("x"));
        int y = Integer.parseInt(atts.getValue("y"));
        String edgeLabel = atts.getValue("viewDefinitionEdge");
        String sketchName = atts.getValue("on_sketch");
        ViewFrame viewFrame = new ViewFrame(_theFrame.getOverview(), _sketchNodes.get(sketchName).getFrame().getMModel());
        _newViewNode = new ViewNode(viewName, x, y, viewFrame);
        _viewDefEdge.put(edgeLabel, new ViewDefinitionEdge(_newViewNode, _sketchNodes.get(sketchName), edgeLabel));
        _viewDocInfo = new DocumentInfo(viewFrame);
        _viewNodes.put(viewName, _newViewNode);
        _sketchNodes.get(sketchName).getFrame().getMModel().addView(_newViewNode);
    } else if (qName.equals("queryNode")) {
        String name = atts.getValue("name");
        int x = Integer.parseInt(atts.getValue("x"));
        int y = Integer.parseInt(atts.getValue("y"));
        String query = atts.getValue("query");
        // exception so they can't be saved
        try {
            _queryNodes.put(name, new QueryNode(name, x, y, _newViewNode.getFrame().getMModel(), query));
        } catch (QueryException e) {
            e.printStackTrace();
        }
    } else if (qName.equals("View_Edge")) {
        View_Edge newEdge;
        String edgeType = atts.getValue("type");
        QueryNode source = _queryNodes.get(atts.getValue("source"));
        QueryNode target = _queryNodes.get(atts.getValue("target"));
        String id = atts.getValue("id");
        String cascadeAtt = atts.getValue("cascade");
        if (cascadeAtt == null) {
            // This is from an export before Easik had per-edge cascading
            // (in other words, before r583)
            // We use the global preferences for cascading
            String key = "sql_cascade", def = "restrict";
            if (edgeType.equals("partial")) {
                key = "sql_cascade_partial";
                def = "set_null";
            }
            cascadeAtt = Easik.getInstance().getSettings().getProperty(key, def);
        }
        @SuppressWarnings("unused") SketchEdge.Cascade cascade = cascadeAtt.equals("set_null") ? SketchEdge.Cascade.SET_NULL : cascadeAtt.equals("cascade") ? SketchEdge.Cascade.CASCADE : SketchEdge.Cascade.RESTRICT;
        if (edgeType.equals("injective")) {
            newEdge = new InjectiveViewEdge(source, target, id);
        } else if (edgeType.equals("partial")) {
            newEdge = new PartialViewEdge(source, target, id);
        } else {
            newEdge = new NormalViewEdge(source, target, id);
        }
        _viewEdges.put(id, newEdge);
    }
}
Also used : NormalViewEdge(easik.view.edge.NormalViewEdge) ViewFrame(easik.ui.ViewFrame) SketchNode(easik.overview.vertex.SketchNode) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge) View_Edge(easik.view.edge.View_Edge) InjectiveViewEdge(easik.view.edge.InjectiveViewEdge) PartialViewEdge(easik.view.edge.PartialViewEdge) SketchFrame(easik.ui.SketchFrame) QueryException(easik.view.util.QueryException) SketchEdge(easik.sketch.edge.SketchEdge) QueryNode(easik.view.vertex.QueryNode) Sketch(easik.sketch.Sketch) ViewNode(easik.overview.vertex.ViewNode) Cascade(easik.model.edge.ModelEdge.Cascade) DocumentInfo(easik.DocumentInfo)

Example 2 with ViewFrame

use of easik.ui.ViewFrame in project fql by CategoricalData.

the class Overview method addNewView.

/**
 * Add a view to a given sketch node
 *
 * @param sketch
 * @param viewName
 *            The name of the new view. Assumes no naming naming conflict
 * @return The new view node
 */
public ViewNode addNewView(SketchNode sketch, String viewName) {
    Point newP = getNewViewPosition(sketch.getX(), sketch.getY(), 10);
    ViewFrame newFrame = new ViewFrame(this, sketch.getFrame().getMModel());
    ViewNode newNode = new ViewNode(viewName, (int) newP.getX(), (int) newP.getY(), newFrame);
    sketch.getFrame().getMModel().addView(newNode);
    // Add our ViewNode
    addVertex(newNode);
    // Add edge to out connected sketch
    addViewEdge(new ViewDefinitionEdge(newNode, sketch, getNewEdgeName()));
    return newNode;
}
Also used : ViewFrame(easik.ui.ViewFrame) ViewNode(easik.overview.vertex.ViewNode) Point(java.awt.Point) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge)

Example 3 with ViewFrame

use of easik.ui.ViewFrame in project fql by CategoricalData.

the class DocumentInfo method setAllInfo.

/**
 * Sets all editable information, with the parameters determined by the
 * user. If any parameters have been changed, the sketch is set to dirty so
 * user will be prompted for a save if an attempt to discard the current
 * sketch is made before a save. If a name change results in a conflict, we
 * add numbers. If no name is specified, we keep the old name.
 *
 * @param name
 *            The name of the sketch
 * @param author
 *            The string of all authors of the sketch
 * @param desc
 *            The description of the sketch
 */
public void setAllInfo(String name, String author, String desc) {
    name = name.trim();
    if (!_name.equals(name) || !getAuthorString().equals(author) || !_desc.equals(desc)) {
        Overview overview = _theFrame.getOverview();
        if (_theFrame instanceof SketchFrame) {
            ((SketchFrame) _theFrame).getNode().setName(name);
            ((SketchFrame) _theFrame).getMModel().setDirty();
        } else if (_theFrame instanceof ViewFrame) {
            ((ViewFrame) _theFrame).getNode().setName(name);
            ((ViewFrame) _theFrame).getMModel().setDirty();
        } else {
            // The Sketch and View setDirty()'s
            overview.setDirty(true);
        // will make this happen anyway
        }
        if (!name.equals("")) {
            setName(name);
        }
        _authors = new ArrayList<>();
        for (String aut : author.split(",")) {
            aut = aut.trim();
            if (!aut.equals("")) {
                _authors.add(aut);
            }
        }
        _desc = desc;
    }
}
Also used : SketchFrame(easik.ui.SketchFrame) ViewFrame(easik.ui.ViewFrame) Overview(easik.overview.Overview)

Example 4 with ViewFrame

use of easik.ui.ViewFrame 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 5 with ViewFrame

use of easik.ui.ViewFrame in project fql by CategoricalData.

the class View method removeNode.

/**
 * Removes an entity, and also cascades to remove all the arrows involved
 * with it.
 *
 * @param toRemove
 *            The entity about to be removed
 */
@Override
public void removeNode(final QueryNode toRemove) {
    // So we don't get a ConcurrentModificationException
    final ArrayList<View_Edge> removeEdges = new ArrayList<>();
    for (final View_Edge edge : _edges.values()) {
        if (edge.getSourceQueryNode().equals(toRemove) || edge.getTargetQueryNode().equals(toRemove)) {
            // add the edge to a list of edges to remove
            removeEdges.add(edge);
        }
    }
    model.beginUpdate();
    // Remove the edges
    for (final View_Edge e : removeEdges) {
        removeEdge(e);
    }
    // remove the constraints this queryNode is a part of
    for (ModelConstraint<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge> c : toRemove.getConstraints()) {
        if (_constraints.containsKey(c.getID())) {
            this.removeConstraint(c);
        }
    }
    _nodes.remove(toRemove.toString());
    getGraphLayoutCache().remove(new Object[] { toRemove });
    // Remove Entity from tree
    _Frame.getInfoTreeUI().removeNode(toRemove);
    model.endUpdate();
}
Also used : ViewGraphModel(easik.view.util.graph.ViewGraphModel) ViewFrame(easik.ui.ViewFrame) QueryNode(easik.view.vertex.QueryNode) ArrayList(java.util.ArrayList) View_Edge(easik.view.edge.View_Edge)

Aggregations

ViewFrame (easik.ui.ViewFrame)8 View_Edge (easik.view.edge.View_Edge)4 QueryNode (easik.view.vertex.QueryNode)4 View (easik.view.View)3 QueryException (easik.view.util.QueryException)3 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)2 ViewNode (easik.overview.vertex.ViewNode)2 DefineQueryNodeDialog (easik.ui.DefineQueryNodeDialog)2 SketchFrame (easik.ui.SketchFrame)2 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)2 PartialViewEdge (easik.view.edge.PartialViewEdge)2 ViewGraphModel (easik.view.util.graph.ViewGraphModel)2 DocumentInfo (easik.DocumentInfo)1 ModelConstraint (easik.model.constraint.ModelConstraint)1 GuideEdge (easik.model.edge.GuideEdge)1 Cascade (easik.model.edge.ModelEdge.Cascade)1 TriangleEdge (easik.model.edge.TriangleEdge)1 GetPathState (easik.model.states.GetPathState)1 Overview (easik.overview.Overview)1 SketchNode (easik.overview.vertex.SketchNode)1