Search in sources :

Example 16 with SketchNode

use of easik.overview.vertex.SketchNode in project fql by CategoricalData.

the class OverviewFileIO method overviewToXML.

/**
 * Converts an overview to an XML file. Returns the success of the save.
 *
 * @param outputFile
 *            The file we will output to
 * @param overview
 *            The sketch we're reading to
 * @return True if successful, false otherwise
 */
public static boolean overviewToXML(File outputFile, Overview overview) {
    Document overviewAsXML;
    try {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = docBuilderFactory.newDocumentBuilder();
        overviewAsXML = db.newDocument();
        Element rootElement = overviewAsXML.createElement("easketch_overview");
        Element header = overviewAsXML.createElement("header");
        Element sketches = overviewAsXML.createElement("sketches");
        Element views = overviewAsXML.createElement("views");
        // Add Header info to document
        DocumentInfo d = overview.getDocInfo();
        Element name = overviewAsXML.createElement("title");
        name.appendChild(overviewAsXML.createTextNode(d.getName()));
        header.appendChild(name);
        for (String aut : d.getAuthors()) {
            Element author = overviewAsXML.createElement("author");
            author.appendChild(overviewAsXML.createTextNode(aut));
            header.appendChild(author);
        }
        Element desc = overviewAsXML.createElement("description");
        desc.appendChild(overviewAsXML.createTextNode(d.getDesc()));
        header.appendChild(desc);
        Element creationDate = overviewAsXML.createElement("creationDate");
        creationDate.appendChild(overviewAsXML.createTextNode(EasikConstants.XML_DATETIME.format(d.getCreationDate())));
        header.appendChild(creationDate);
        Element modDate = overviewAsXML.createElement("lastModificationDate");
        modDate.appendChild(overviewAsXML.createTextNode(EasikConstants.XML_DATETIME.format(d.getModificationDate())));
        header.appendChild(modDate);
        // Loop through sketches, add them to the document
        for (SketchNode currentSketch : overview.getSketches()) {
            if (currentSketch != null) {
                Element thisSketch = SketchFileIO.sketchToElement(overviewAsXML, currentSketch.getFrame().getMModel());
                thisSketch.setAttribute("name", currentSketch.toString());
                thisSketch.setAttribute("x", currentSketch.getX() + "");
                thisSketch.setAttribute("y", currentSketch.getY() + "");
                Cascade c = currentSketch.getFrame().getMModel().getDefaultCascading();
                Cascade cp = currentSketch.getFrame().getMModel().getDefaultPartialCascading();
                thisSketch.setAttribute("cascade", (c == Cascade.CASCADE) ? "cascade" : "restrict");
                thisSketch.setAttribute("partial-cascade", (cp == Cascade.CASCADE) ? "cascade" : (cp == Cascade.RESTRICT) ? "restrict" : "set_null");
                sketches.appendChild(thisSketch);
            }
        }
        for (ViewNode currentView : overview.getViews()) {
            if (currentView != null) {
                Element thisView = viewToElement(overviewAsXML, currentView.getFrame().getMModel());
                thisView.setAttribute("name", currentView.toString());
                thisView.setAttribute("x", currentView.getX() + "");
                thisView.setAttribute("y", currentView.getY() + "");
                ViewDefinitionEdge thisViewEdge = overview.getViewEdge(currentView.getFrame().getMModel());
                thisView.setAttribute("viewDefinitionEdge", thisViewEdge.getName());
                thisView.setAttribute("on_sketch", thisViewEdge.getTargetNode().getName());
                views.appendChild(thisView);
            }
        }
        // Add root elements to document
        overviewAsXML.appendChild(rootElement);
        rootElement.appendChild(header);
        rootElement.appendChild(sketches);
        rootElement.appendChild(views);
    } catch (Exception e) {
        e.printStackTrace();
        overviewAsXML = null;
    }
    outputXMLtoFile(outputFile, overviewAsXML);
    return true;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) ViewNode(easik.overview.vertex.ViewNode) Document(org.w3c.dom.Document) SketchNode(easik.overview.vertex.SketchNode) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge) Cascade(easik.model.edge.ModelEdge.Cascade) DocumentInfo(easik.DocumentInfo)

Example 17 with SketchNode

use of easik.overview.vertex.SketchNode in project fql by CategoricalData.

the class OverviewFileIO method graphicalOverviewFromXML.

/**
 * Load an overview from XML.
 *
 * @param inputFile
 *            the file from which the XML will be read
 * @param outputOverview
 * @return Returns the success or failure of the reading.
 */
public static boolean graphicalOverviewFromXML(File inputFile, Overview outputOverview) {
    OverviewHandler overviewHandler = new OverviewHandler(outputOverview.getFrame());
    if (!initializeOverviewHandlerFromXML(inputFile, overviewHandler)) {
        return false;
    }
    outputOverview.initializeFromData(overviewHandler.getSketches(), overviewHandler.getViews(), overviewHandler.getViewEdges(), overviewHandler.getDocumentInfo());
    outputOverview.getFrame().getInfoTreeUI().refreshTree();
    outputOverview.getFrame().setTreeName(overviewHandler.getDocumentInfo().getName());
    String warning = overviewHandler.get_warnings();
    SketchNode sk = overviewHandler.getSketches().values().iterator().next();
    if (warning != null && !warning.isEmpty()) {
        JOptionPane.showMessageDialog(sk.getFrame().getOverview(), warning, "Warning", JOptionPane.ERROR_MESSAGE);
    }
    return true;
}
Also used : SketchNode(easik.overview.vertex.SketchNode)

Example 18 with SketchNode

use of easik.overview.vertex.SketchNode in project fql by CategoricalData.

the class OverviewGraphModel 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
public AttributeMap getAttributes(Object o) {
    if (o instanceof GraphCell) {
        GraphCell cell = (GraphCell) o;
        AttributeMap attribs = cell.getAttributes();
        AttributeMap easikAttribs = null;
        if (cell instanceof SketchNode) {
            easikAttribs = sketchAttributes((SketchNode) cell);
        } else if (cell instanceof ViewNode) {
            easikAttribs = viewAttributes((ViewNode) cell);
        } else if (cell instanceof ViewDefinitionEdge) {
            easikAttribs = viewEdgeAttributes((ViewDefinitionEdge) cell);
        // easikAttribs =
        // easik.sketch.util.graph.SketchGraphModel.normalEdgeAttributes();
        }
        if (easikAttribs != null) {
            if (_overview.isCellSelected(cell)) {
                Color selColor = getColor("selection");
                float lineWidth = getWidth("selection", 3);
                int borderWidth = 1;
                Border currentBorder = GraphConstants.getBorder(easikAttribs);
                if (currentBorder instanceof LineBorder) {
                    borderWidth = ((LineBorder) currentBorder).getThickness();
                }
                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 : AttributeMap(org.jgraph.graph.AttributeMap) GraphCell(org.jgraph.graph.GraphCell) Color(java.awt.Color) LineBorder(javax.swing.border.LineBorder) ViewNode(easik.overview.vertex.ViewNode) SketchNode(easik.overview.vertex.SketchNode) ViewDefinitionEdge(easik.overview.edge.ViewDefinitionEdge) LineBorder(javax.swing.border.LineBorder) Border(javax.swing.border.Border)

Aggregations

SketchNode (easik.overview.vertex.SketchNode)18 ViewNode (easik.overview.vertex.ViewNode)11 ViewDefinitionEdge (easik.overview.edge.ViewDefinitionEdge)4 Sketch (easik.sketch.Sketch)4 SketchFrame (easik.ui.SketchFrame)4 DocumentInfo (easik.DocumentInfo)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Cascade (easik.model.edge.ModelEdge.Cascade)2 OverviewVertex (easik.overview.vertex.OverviewVertex)2 Component (java.awt.Component)2 Point (java.awt.Point)2 JMenuItem (javax.swing.JMenuItem)2 AttributeMap (org.jgraph.graph.AttributeMap)2 OverviewGraphModel (easik.overview.util.graph.OverviewGraphModel)1 SketchEdge (easik.sketch.edge.SketchEdge)1 ViewFrame (easik.ui.ViewFrame)1 AboutAction (easik.ui.menu.AboutAction)1 ExportDatabaseAction (easik.ui.menu.ExportDatabaseAction)1 FileNewOverviewAction (easik.ui.menu.FileNewOverviewAction)1 FileOpenAction (easik.ui.menu.FileOpenAction)1