use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class PositionableLabelXml method loadCommonAttributes.
public void loadCommonAttributes(Positionable l, int defaultLevel, Element element) {
Attribute a = element.getAttribute("forcecontroloff");
if ((a != null) && a.getValue().equals("true")) {
l.setControlling(false);
} else {
l.setControlling(true);
}
// find coordinates
int x = 0;
int y = 0;
try {
x = element.getAttribute("x").getIntValue();
y = element.getAttribute("y").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert positional attribute");
}
l.setLocation(x, y);
// find display level
int level = defaultLevel;
try {
level = element.getAttribute("level").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse level attribute!");
} catch (NullPointerException e) {
// considered normal if the attribute not present
}
l.setDisplayLevel(level);
a = element.getAttribute("hidden");
if ((a != null) && a.getValue().equals("yes")) {
l.setHidden(true);
l.setVisible(false);
}
a = element.getAttribute("positionable");
if ((a != null) && a.getValue().equals("true")) {
l.setPositionable(true);
} else {
l.setPositionable(false);
}
a = element.getAttribute("showtooltip");
if ((a != null) && a.getValue().equals("true")) {
l.setShowTooltip(true);
} else {
l.setShowTooltip(false);
}
a = element.getAttribute("editable");
if ((a != null) && a.getValue().equals("true")) {
l.setEditable(true);
} else {
l.setEditable(false);
}
a = element.getAttribute("degrees");
if (a != null && l instanceof PositionableLabel) {
try {
int deg = a.getIntValue();
((PositionableLabel) l).setDegrees(deg);
} catch (org.jdom2.DataConversionException dce) {
}
}
Element elem = element.getChild("tooltip");
if (elem == null) {
// pre JMRI 3.5.2
elem = element.getChild("toolTip");
}
if (elem != null) {
ToolTip tip = l.getTooltip();
if (tip != null) {
tip.setText(elem.getText());
}
}
}
use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class MultiSensorIconXml method load.
/**
* Create a PositionableLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o an Editor an Object
*/
@Override
public void load(Element element, Object o) {
Editor pe = (Editor) o;
MultiSensorIcon l = new MultiSensorIcon(pe);
// create the objects
int rotation = 0;
try {
rotation = element.getAttribute("rotate").getIntValue();
} catch (org.jdom2.DataConversionException e) {
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
NamedIcon icon = loadSensorIcon("inactive", rotation, l, element, pe);
if (icon != null) {
l.setInactiveIcon(icon);
} else {
return;
}
icon = loadSensorIcon("unknown", rotation, l, element, pe);
if (icon != null) {
l.setUnknownIcon(icon);
} else {
return;
}
icon = loadSensorIcon("inconsistent", rotation, l, element, pe);
if (icon != null) {
l.setInconsistentIcon(icon);
} else {
return;
}
Attribute a = element.getAttribute("updown");
if ((a != null) && a.getValue().equals("true")) {
l.setUpDown(true);
} else {
l.setUpDown(false);
}
// get the icon pairs & load
List<Element> items = element.getChildren();
for (int i = 0; i < items.size(); i++) {
// get the class, hence the adapter object to do loading
Element item = items.get(i);
if (item.getAttribute("sensor") != null) {
String sensor = item.getAttribute("sensor").getValue();
if (item.getAttribute("url") != null) {
String name = item.getAttribute("url").getValue();
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = pe.loadFailed("MultiSensor \"" + l.getNameString() + "\" ", name);
if (icon == null) {
log.error("MultiSensor \"" + l.getNameString() + "\" removed for url= " + name);
return;
}
}
try {
int deg = 0;
a = item.getAttribute("degrees");
if (a != null) {
deg = a.getIntValue();
double scale = 1.0;
a = item.getAttribute("scale");
if (a != null) {
scale = item.getAttribute("scale").getDoubleValue();
}
icon.setLoad(deg, scale, l);
}
if (deg == 0) {
a = item.getAttribute("rotate");
if (a != null) {
rotation = a.getIntValue();
icon.setRotation(rotation, l);
}
}
} catch (org.jdom2.DataConversionException dce) {
}
} else {
String name = item.getAttribute("icon").getValue();
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = pe.loadFailed("MultiSensor \"" + l.getNameString(), name);
if (icon == null) {
log.info("MultiSensor \"" + l.getNameString() + " removed for url= " + name);
return;
}
}
if (rotation != 0) {
icon.setRotation(rotation, l);
}
}
l.addEntry(sensor, icon);
}
}
pe.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.SENSORS, element);
}
use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class PositionableLabelXml method loadIcon.
public NamedIcon loadIcon(PositionableLabel l, String attrName, Element element, String name, Editor ed) {
NamedIcon icon = getNamedIcon(attrName, element, name, ed);
if (icon != null) {
try {
int deg = 0;
double scale = 1.0;
Element elem = element.getChild(attrName);
if (elem != null) {
Attribute a = elem.getAttribute("degrees");
if (a != null) {
deg = a.getIntValue();
}
a = elem.getAttribute("scale");
if (a != null) {
scale = elem.getAttribute("scale").getDoubleValue();
}
icon.setLoad(deg, scale, l);
if (deg == 0) {
// "rotate" attribute is JMRI 2.9.3 and before
a = elem.getAttribute("rotate");
if (a != null) {
int rotation = a.getIntValue();
// 2.9.3 and before, only unscaled icons rotate
if (scale == 1.0) {
icon.setRotation(rotation, l);
}
}
// "rotation" element is JMRI 2.9.4 and after
Element e = elem.getChild("rotation");
if (e != null) {
// ver 2.9.4 allows orthogonal rotations of scaled icons
int rotation = Integer.parseInt(e.getText());
icon.setRotation(rotation, l);
}
}
}
} catch (org.jdom2.DataConversionException dce) {
}
}
return icon;
}
use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class SensorIconXml method load.
/**
* Create a PositionableLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o an Editor as an Object
*/
@Override
public void load(Element element, Object o) {
Editor ed = (Editor) o;
SensorIcon l;
String name;
Attribute attr = element.getAttribute("sensor");
if (attr == null) {
log.error("incorrect information for sensor; must use sensor name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
}
_icon = true;
if (element.getAttribute("icon") != null) {
String yesno = element.getAttribute("icon").getValue();
if ((yesno != null) && (!yesno.equals(""))) {
if (yesno.equals("yes")) {
_icon = true;
} else if (yesno.equals("no")) {
_icon = false;
}
}
}
if (_icon) {
l = new SensorIcon(new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"), ed);
} else {
l = new SensorIcon(" ", ed);
}
int rotation = 0;
try {
rotation = element.getAttribute("rotate").getIntValue();
} catch (org.jdom2.DataConversionException e) {
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
if (loadSensorIcon("active", rotation, l, element, name, ed) == null) {
return;
}
if (loadSensorIcon("inactive", rotation, l, element, name, ed) == null) {
return;
}
if (loadSensorIcon("unknown", rotation, l, element, name, ed) == null) {
return;
}
if (loadSensorIcon("inconsistent", rotation, l, element, name, ed) == null) {
return;
}
Element elem = element.getChild("iconmaps");
if (elem != null) {
attr = elem.getAttribute("family");
if (attr != null) {
l.setFamily(attr.getValue());
}
}
Attribute a = element.getAttribute("momentary");
if ((a != null) && a.getValue().equals("true")) {
l.setMomentary(true);
} else {
l.setMomentary(false);
}
loadTextInfo(l, element);
l.setSensor(name);
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.SENSORS, element);
if (l.isIcon() && l.getText() != null) {
l.setOpaque(false);
}
}
use of org.bouncycastle.asn1.x509.Attribute 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