use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class PositionablePolygonXml method store.
/**
* Default implementation for storing the contents of a PositionableShape
*
* @param o Object to store, of type PositionableShape
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
PositionablePolygon p = (PositionablePolygon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("positionablePolygon");
storeCommonAttributes(p, element);
element.addContent(storePath(p));
element.setAttribute("class", "jmri.jmrit.display.controlPanelEditor.shape.configurexml.PositionablePolygonXml");
return element;
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class PositionablePolygonXml method storePath.
protected Element storePath(PositionablePolygon p) {
Element elem = new Element("path");
PathIterator iter = p.getPathIterator(null);
float[] coord = new float[6];
while (!iter.isDone()) {
int type = iter.currentSegment(coord);
elem.addContent(storeVertex(type, coord));
iter.next();
}
return elem;
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class LocoLabelXml method load.
/**
* Create a PositionableShape, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor ed = (Editor) o;
LocoLabel ll = new LocoLabel(ed);
Element elem = element.getChild("size");
ll.setWidth(getInt(elem, "width"));
ll.setHeight(getInt(elem, "height"));
if (elem != null && elem.getAttribute("systemName") != null) {
String name = elem.getAttribute("systemName").getValue();
OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
OBlock block = manager.getBySystemName(name);
ll.setBlock(block);
if (elem.getAttribute("trainName") != null && block != null) {
block.setValue(elem.getAttribute("trainName").getValue());
}
} else {
// don't put into editor's content list without
return;
}
ed.putItem(ll);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(ll, Editor.MARKERS, element);
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class PositionableEllipseXml method store.
/**
* Default implementation for storing the contents of a PositionableShape
*
* @param o Object to store, of type PositionableShape
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
PositionableEllipse p = (PositionableEllipse) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("positionableEllipse");
storeCommonAttributes(p, element);
Element elem = new Element("size");
elem.setAttribute("width", "" + p.getWidth());
elem.setAttribute("height", "" + p.getHeight());
element.addContent(elem);
element.setAttribute("class", "jmri.jmrit.display.controlPanelEditor.shape.configurexml.PositionableEllipseXml");
return element;
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class SwitchboardEditorXml method load.
/**
* Create a SwitchboardEditor object, then register and fill it, then pop it in a
* JFrame
*
* @param shared Top level Element to unpack.
* @return true if successful
*/
@Override
public boolean load(Element shared, Element perNode) {
boolean result = true;
// find coordinates
int x = 0;
int y = 0;
int height = 400;
int width = 300;
int rangemin = 1;
int rangemax = 32;
int columns = 4;
String type = "T";
String connection = "I";
String shape = "key";
String name;
try {
x = shared.getAttribute("x").getIntValue();
y = shared.getAttribute("y").getIntValue();
height = shared.getAttribute("height").getIntValue();
width = shared.getAttribute("width").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert Switchboard's attribute");
result = false;
}
// find the name
// this will be replaced by the name as stored NOI18N
name = "Switchboard";
if (shared.getAttribute("name") != null) {
name = shared.getAttribute("name").getValue();
}
// confirm that panel hasn't already been loaded
if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(name)) {
log.warn("File contains a panel with the same name (" + name + ") as an existing panel");
result = false;
}
SwitchboardEditor panel = new SwitchboardEditor(name);
//panel.makeFrame(name);
jmri.jmrit.display.PanelMenu.instance().addEditorPanel(panel);
panel.getTargetFrame().setLocation(x, y);
panel.getTargetFrame().setSize(width, height);
panel.setTitle();
// Load editor option flags. This has to be done before the content
// items are loaded, to preserve the individual item settings.
Attribute a;
boolean value = true;
if ((a = shared.getAttribute("editable")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllEditable(value);
value = true;
if ((a = shared.getAttribute("showtooltips")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllShowTooltip(value);
value = true;
if ((a = shared.getAttribute("controlling")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllControlling(value);
value = false;
if ((a = shared.getAttribute("hide")) != null && a.getValue().equals("yes")) {
value = true;
}
panel.setShowHidden(value);
value = true;
if ((a = shared.getAttribute("panelmenu")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setPanelMenuVisible(value);
String state = "both";
if ((a = shared.getAttribute("scrollable")) != null) {
state = a.getValue();
}
panel.setScroll(state);
value = false;
if ((a = shared.getAttribute("hideunconnected")) != null && a.getValue().equals("yes")) {
value = true;
}
panel.setHideUnconnected(value);
try {
rangemin = shared.getAttribute("rangemin").getIntValue();
rangemax = shared.getAttribute("rangemax").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert Switchboard's range");
result = false;
}
panel.setPanelMenuRangeMin(rangemin);
panel.setPanelMenuRangeMax(rangemax);
type = shared.getAttribute("type").getValue();
panel.setSwitchType(type);
connection = shared.getAttribute("connection").getValue();
panel.setSwitchManu(connection);
shape = shared.getAttribute("shape").getValue();
panel.setSwitchShape(shape);
try {
columns = shared.getAttribute("columns").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert Switchboard's column count");
result = false;
}
panel.setColumns(columns);
String defaultTextColor = "black";
if (shared.getAttribute("defaulttextcolor") != null) {
defaultTextColor = shared.getAttribute("defaulttextcolor").getValue();
}
panel.setDefaultTextColor(defaultTextColor);
// set color if needed
try {
int red = shared.getAttribute("redBackground").getIntValue();
int blue = shared.getAttribute("blueBackground").getIntValue();
int green = shared.getAttribute("greenBackground").getIntValue();
//panel.setBackground(new Color(red, green, blue));
panel.setDefaultBackgroundColor(new Color(red, green, blue));
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse color attributes!");
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
//set the (global) editor display widgets to their flag settings
panel.initView();
// load the contents with their individual option settings
List<Element> items = shared.getChildren();
for (int i = 0; i < items.size(); i++) {
// get the class, hence the adapter object to do loading
Element item = items.get(i);
String adapterName = item.getAttribute("class").getValue();
log.debug("load via " + adapterName);
try {
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
adapter.load(item, panel);
if (!panel.loadOK()) {
result = false;
}
} catch (Exception e) {
log.error("Exception while loading " + item.getName() + ":" + e);
result = false;
e.printStackTrace();
}
}
// dispose of url correction data
panel.disposeLoadData();
// display the results, with the editor in back
panel.pack();
panel.setAllEditable(panel.isEditable());
// we don't pack the target frame here, because size was specified
// TODO: Work out why, when calling this method, panel size is increased
// vertically (at least on MS Windows)
// always show the panel
panel.getTargetFrame().setVisible(true);
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(panel);
}
// reset the size and position, in case the display caused it to change
panel.getTargetFrame().setLocation(x, y);
panel.getTargetFrame().setSize(width, height);
panel.updatePressed();
return result;
}
Aggregations