use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class PositionableLabelXml method load.
/**
* Create a PositionableLabel, 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
PositionableLabel l = null;
// get object class and determine editor being used
Editor editor = (Editor) o;
if (element.getAttribute("icon") != null) {
NamedIcon icon;
String name = element.getAttribute("icon").getValue();
// if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
if (name.equals("yes")) {
icon = getNamedIcon("icon", element, "PositionableLabel ", editor);
} else {
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = editor.loadFailed("PositionableLabel", name);
if (icon == null) {
log.info("PositionableLabel icon removed for url= " + name);
return;
}
}
}
// abort if name != yes and have null icon
if (icon == null && !name.equals("yes")) {
log.info("PositionableLabel icon removed for url= " + name);
return;
}
l = new PositionableLabel(icon, editor);
try {
Attribute a = element.getAttribute("rotate");
if (a != null && icon != null) {
int rotation = element.getAttribute("rotate").getIntValue();
icon.setRotation(rotation, l);
}
} catch (org.jdom2.DataConversionException e) {
}
if (name.equals("yes")) {
NamedIcon nIcon = loadIcon(l, "icon", element, "PositionableLabel ", editor);
if (nIcon != null) {
l.updateIcon(nIcon);
} else {
log.info("PositionableLabel icon removed for url= " + name);
return;
}
} else {
l.updateIcon(icon);
}
}
if (element.getAttribute("text") != null) {
if (l == null) {
l = new PositionableLabel(element.getAttribute("text").getValue(), editor);
}
loadTextInfo(l, element);
} else if (l == null) {
log.error("PositionableLabel is null!");
if (log.isDebugEnabled()) {
java.util.List<Attribute> attrs = element.getAttributes();
log.debug("\tElement Has " + attrs.size() + " Attributes:");
for (int i = 0; i < attrs.size(); i++) {
Attribute a = attrs.get(i);
log.debug("\t\t" + a.getName() + " = " + a.getValue());
}
java.util.List<Element> kids = element.getChildren();
log.debug("\tElementHas " + kids.size() + " children:");
for (int i = 0; i < kids.size(); i++) {
Element e = kids.get(i);
log.debug("\t\t" + e.getName() + " = \"" + e.getValue() + "\"");
}
}
editor.loadFailed();
return;
}
editor.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.LABELS, element);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class DrawPolygon method makeFigure.
/* @Override
public void paint(Graphics g) {
super.paint(g);
if (_editing) {
int hitIndex = _pShape.getHitIndex();
if (hitIndex>=0) {
super.paint(g);
Graphics2D g2d = (Graphics2D)g;
_lineWidth = _lineSlider.getValue();
BasicStroke stroke = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f);
g2d.setColor(_lineColor);
g2d.setStroke(stroke);
GeneralPath path = new GeneralPath();
if (hitIndex==0) {
Point p0 = _vertices.get(1);
path.moveTo(p0.x, p0.y);
path.lineTo(_curX, _curY);
} else if (hitIndex==_vertices.size()-1) {
Point p0 = _vertices.get(hitIndex-1);
path.moveTo(p0.x, p0.y);
path.lineTo(_curX, _curY);
} else {
Point p0 = _vertices.get(hitIndex-1);
Point p1 = _vertices.get(hitIndex+1);
path.moveTo(p0.x, p0.y);
path.lineTo(_curX, _curY);
path.lineTo(p1.x, p1.y);
}
g2d.draw(path);
}
}
}
/**
* Create a new PositionableShape
*/
@Override
protected boolean makeFigure(MouseEvent event) {
if (_editing) {
int hitIndex = _pShape.getHitIndex();
if (hitIndex >= 0) {
Point pt;
try {
pt = _pShape.getInversePoint(event.getX(), event.getY());
} catch (java.awt.geom.NoninvertibleTransformException nte) {
log.error("Can't locate Hit Rectangles " + nte.getMessage());
return false;
}
_vertices.remove(hitIndex);
_vertices.add(hitIndex, pt);
_pShape.setShape(makePath(getStartPoint()));
}
return false;
} else {
Point p = new Point(event.getX(), event.getY());
if (hitPolygonVertex(p)) {
if (near(_vertices.get(0), p)) {
// close polygon
_vertices.add(p);
}
Editor ed = _parent.getEditor();
Point spt = getStartPoint();
PositionablePolygon ps = new PositionablePolygon(ed, makePath(spt));
ps.setLocation(spt);
ps.updateSize();
setDisplayParams(ps);
ps.setEditFrame(this);
ed.putItem(ps);
return true;
}
_vertices.add(p);
return false;
}
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class AnalogClock2DisplayXml method load.
/**
* Create an AnalogClock2Display, 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) {
// get object class and create the clock object
Editor ed = (Editor) o;
AnalogClock2Display l = new AnalogClock2Display(ed);
// find coordinates
int x = 0;
int y = 0;
double scale = 1.0;
Colors color = Colors.Black;
try {
x = element.getAttribute("x").getIntValue();
y = element.getAttribute("y").getIntValue();
if (element.getAttribute("scale") != null) {
scale = element.getAttribute("scale").getDoubleValue();
}
if (element.getAttribute("color") != null) {
color = Colors.valueOf(element.getAttribute("color").getValue());
}
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert positional attribute");
}
if (element.getAttribute("link") != null) {
l.setUrl(element.getAttribute("link").getValue());
}
l.setOpaque(false);
l.update();
l.setLocation(x, y);
if (scale != 1.0 && 10.0 > scale && scale > 0.1) {
l.setScale(scale);
}
l.setColor(color);
// add the clock to the panel
l.setDisplayLevel(Editor.CLOCK);
ed.putItem(l);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class IndicatorTurnoutIconXml method load.
/**
* Create a IndicatorTurnoutIcon, 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 p = (Editor) o;
IndicatorTurnoutIcon l = new IndicatorTurnoutIcon(p);
Element name = element.getChild("turnout");
if (name == null) {
log.error("incorrect information for turnout; must use turnout name");
} else {
l.setTurnout(name.getText());
}
Element elem = element.getChild("iconmaps");
if (elem != null) {
List<Element> maps = elem.getChildren();
if (maps.size() > 0) {
for (int i = 0; i < maps.size(); i++) {
String status = maps.get(i).getName();
List<Element> states = maps.get(i).getChildren();
for (int k = 0; k < states.size(); k++) {
String msg = "IndicatorTurnout \"" + l.getNameString() + "\" icon \"" + states.get(k).getName() + "\" ";
NamedIcon icon = loadIcon(l, states.get(k).getName(), maps.get(i), msg, p);
if (icon != null) {
l.setIcon(status, states.get(k).getName(), icon);
} else {
log.info(msg + " removed for url= " + name);
return;
}
}
}
}
Attribute attr = elem.getAttribute("family");
if (attr != null) {
l.setFamily(attr.getValue());
}
}
name = element.getChild("occupancyblock");
if (name != null) {
l.setOccBlock(name.getText());
} else {
// only write sensor if no OBlock, don't write double sensing
name = element.getChild("occupancysensor");
if (name != null) {
l.setOccSensor(name.getText());
}
}
l.setShowTrain(false);
name = element.getChild("showTrainName");
if (name != null) {
if ("yes".equals(name.getText())) {
l.setShowTrain(true);
}
}
elem = element.getChild("paths");
if (elem != null) {
ArrayList<String> paths = new ArrayList<String>();
List<Element> pth = elem.getChildren();
for (int i = 0; i < pth.size(); i++) {
paths.add(pth.get(i).getText());
}
l.setPaths(paths);
}
l.updateSize();
p.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.TURNOUTS, element);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class PositionableRoundRectXml 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;
PositionableRoundRect ps = new PositionableRoundRect(ed);
Element elem = element.getChild("size");
ps.setWidth(getInt(elem, "width"));
ps.setHeight(getInt(elem, "height"));
ps.setCornerRadius(getInt(elem, "cornerRadius"));
ed.putItem(ps);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(ps, Editor.MARKERS, element);
}
Aggregations