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;
}
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;
}
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);
}
Aggregations