use of jmri.jmrit.display.PositionableLabel in project JMRI by JMRI.
the class ControlPanelEditor method showPopUp.
/**
* Create popup for a Positionable object Popup items common to all
* positionable objects are done before and after the items that pertain
* only to specific Positionable types.
*/
@Override
protected void showPopUp(Positionable p, MouseEvent event) {
if (!((JComponent) p).isVisible()) {
// component must be showing on the screen to determine its location
return;
}
JPopupMenu popup = new JPopupMenu();
PositionablePopupUtil util = p.getPopupUtility();
if (p.isEditable()) {
// items common to all
if (p.doViemMenu()) {
popup.add(p.getNameString());
setPositionableMenu(p, popup);
if (p.isPositionable()) {
setShowCoordinatesMenu(p, popup);
setShowAlignmentMenu(p, popup);
}
setDisplayLevelMenu(p, popup);
setHiddenMenu(p, popup);
popup.addSeparator();
setCopyMenu(p, popup);
}
// items with defaults or using overrides
boolean popupSet = false;
// popupSet |= p.setRotateOrthogonalMenu(popup);
popupSet |= p.setRotateMenu(popup);
popupSet |= p.setScaleMenu(popup);
if (popupSet) {
popup.addSeparator();
popupSet = false;
}
popupSet = p.setEditItemMenu(popup);
if (popupSet) {
popup.addSeparator();
popupSet = false;
}
if (p instanceof PositionableLabel) {
PositionableLabel pl = (PositionableLabel) p;
/* if (pl.isIcon() && "javax.swing.JLabel".equals(pl.getClass().getSuperclass().getName()) ) {
popupSet |= setTextAttributes(pl, popup); // only for plain icons
} Add backgrounds & text over icons later */
if (!pl.isIcon()) {
popupSet |= setTextAttributes(pl, popup);
if (p instanceof MemoryIcon) {
popupSet |= p.setTextEditMenu(popup);
}
} else if (p instanceof SensorIcon) {
popup.add(CoordinateEdit.getTextEditAction(p, "OverlayText"));
if (pl.isText()) {
popupSet |= setTextAttributes(p, popup);
}
} else {
popupSet = p.setTextEditMenu(popup);
}
} else if (p instanceof PositionableJPanel) {
popupSet |= setTextAttributes(p, popup);
}
if (p instanceof LinkingObject) {
((LinkingObject) p).setLinkMenu(popup);
}
if (popupSet) {
popup.addSeparator();
popupSet = false;
}
p.setDisableControlMenu(popup);
if (util != null) {
util.setAdditionalEditPopUpMenu(popup);
}
// for Positionables with unique settings
p.showPopUp(popup);
if (p.doViemMenu()) {
setShowTooltipMenu(p, popup);
setRemoveMenu(p, popup);
}
} else {
if (p instanceof LocoIcon) {
setCopyMenu(p, popup);
}
p.showPopUp(popup);
if (util != null) {
util.setAdditionalViewPopUpMenu(popup);
}
}
popup.show((Component) p, p.getWidth() / 2 + (int) ((getPaintScale() - 1.0) * p.getX()), p.getHeight() / 2 + (int) ((getPaintScale() - 1.0) * p.getY()));
_currentSelection = null;
}
use of jmri.jmrit.display.PositionableLabel in project JMRI by JMRI.
the class PositionableLabelXml method store.
/**
* Default implementation for storing the contents of a PositionableLabel
*
* @param o Object to store, of type PositionableLabel
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
PositionableLabel p = (PositionableLabel) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("positionablelabel");
storeCommonAttributes(p, element);
if (p.isText()) {
if (p.getUnRotatedText() != null) {
element.setAttribute("text", p.getUnRotatedText());
}
storeTextInfo(p, element);
}
if (p.isIcon() && p.getIcon() != null) {
element.setAttribute("icon", "yes");
element.addContent(storeIcon("icon", (NamedIcon) p.getIcon()));
}
element.setAttribute("class", "jmri.jmrit.display.configurexml.PositionableLabelXml");
return element;
}
use of jmri.jmrit.display.PositionableLabel 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.PositionableLabel in project JMRI by JMRI.
the class DecoratorPanel method initDecoratorPanel.
/* Called by Editor's TextAttrDialog - i.e. update a panel item from menu */
public void initDecoratorPanel(Positionable pos) {
// copy of PositionableLabel being edited
Positionable item = pos.deepClone();
_util = item.getPopupUtility();
if (pos instanceof SensorIcon && !((SensorIcon) pos).isIcon()) {
SensorIcon si = (SensorIcon) pos;
if (!si.isIcon() && si.isText()) {
PositionableLabel sample = new PositionableLabel(si.getActiveText(), _editor);
sample.setForeground(si.getTextActive());
Color color = si.getBackgroundActive();
if (color != null) {
sample.setBackground(color);
sample.setOpaque(true);
}
// NOI18N
doPopupUtility("Active", ACTIVE_FONT, sample, _util, true);
sample = new PositionableLabel(si.getInactiveText(), _editor);
sample.setForeground(si.getTextInActive());
color = si.getBackgroundInActive();
if (color != null) {
sample.setBackground(color);
sample.setOpaque(true);
}
// NOI18N
doPopupUtility("InActive", INACTIVE_FONT, sample, _util, true);
sample = new PositionableLabel(si.getUnknownText(), _editor);
sample.setForeground(si.getTextUnknown());
color = si.getBackgroundUnknown();
if (color != null) {
sample.setBackground(color);
sample.setOpaque(true);
}
// NOI18N
doPopupUtility("Unknown", UNKOWN_FONT, sample, _util, true);
sample = new PositionableLabel(si.getInconsistentText(), _editor);
sample.setForeground(si.getTextInconsistent());
color = si.getBackgroundInconsistent();
if (color != null) {
sample.setBackground(color);
sample.setOpaque(true);
}
// NOI18N
doPopupUtility("Inconsistent", INCONSISTENT_FONT, sample, _util, true);
}
} else {
// not a SensorIcon
PositionableLabel sample = new PositionableLabel("", _editor);
sample.setForeground(pos.getForeground());
sample.setBackground(pos.getBackground());
sample.setOpaque(_util.hasBackground());
boolean addtextField;
if (pos instanceof PositionableLabel) {
sample.setText(((PositionableLabel) pos).getUnRotatedText());
if (pos instanceof jmri.jmrit.display.MemoryIcon) {
addtextField = false;
} else {
addtextField = true;
}
} else if (pos instanceof jmri.jmrit.display.MemoryInputIcon) {
JTextField field = (JTextField) ((jmri.jmrit.display.MemoryInputIcon) pos).getTextComponent();
sample.setText(field.getText());
addtextField = false;
} else if (pos instanceof jmri.jmrit.display.MemoryComboIcon) {
JComboBox<String> box = ((jmri.jmrit.display.MemoryComboIcon) pos).getTextComponent();
sample.setText(box.getSelectedItem().toString());
addtextField = false;
} else if (pos instanceof jmri.jmrit.display.MemorySpinnerIcon) {
JTextField field = (JTextField) ((jmri.jmrit.display.MemorySpinnerIcon) pos).getTextComponent();
sample.setText(field.getText());
addtextField = false;
} else {
addtextField = true;
}
doPopupUtility("Text", TEXT_FONT, sample, _util, addtextField);
}
makeFontPanels();
// item.setVisible(false); // otherwise leaves traces for PositionableJPanels
_chooser.getSelectionModel().addChangeListener(this);
_chooser.setPreviewPanel(new JPanel());
this.add(_chooser);
_previewPanel.add(_samplePanel, java.awt.BorderLayout.CENTER);
this.add(_previewPanel);
updateSamples();
}
Aggregations