use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class PanelServlet method getJsonPanel.
@Override
protected String getJsonPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
PanelEditor editor = (PanelEditor) getEditor(name);
ObjectNode root = this.mapper.createObjectNode();
ObjectNode panel = root.putObject("panel");
JFrame frame = editor.getTargetFrame();
panel.put("name", name);
panel.put("height", frame.getContentPane().getHeight());
panel.put("width", frame.getContentPane().getWidth());
panel.put("panelheight", frame.getContentPane().getHeight());
panel.put("panelwidth", frame.getContentPane().getWidth());
panel.put("showtooltips", editor.showTooltip());
panel.put("controlling", editor.allControlling());
if (editor.getBackgroundColor() != null) {
ObjectNode color = panel.putObject("backgroundColor");
color.put("red", editor.getBackgroundColor().getRed());
color.put("green", editor.getBackgroundColor().getGreen());
color.put("blue", editor.getBackgroundColor().getBlue());
}
// include contents
log.debug("N elements: {}", editor.getContents().size());
for (Positionable sub : editor.getContents()) {
try {
// TODO: get all panel contents as JSON
// I tried using JavaBean Introspection to simply build the contents using Jackson Databindings,
// but when a panel element has a reference to the panel or to itself as a property, this leads
// to infinite recursion
} catch (Exception ex) {
log.error("Error storing panel element: " + ex, ex);
}
}
return this.mapper.writeValueAsString(root);
} catch (NullPointerException ex) {
log.warn("Requested Panel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
} catch (JsonGenerationException e) {
log.error("Error generating JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (JsonMappingException e) {
log.error("Error mapping JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (IOException e) {
log.error("IOException", e);
return "ERROR " + e.getLocalizedMessage();
}
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class CircuitBuilder method makeSelectionGroup.
/**
* ************* end convert icons ******************
*/
/**
* ************** select - deselect track icons ***********************
*/
/**
* select block's track icons for editing -***could be
* _circuitMap.get(block) is sufficient
*/
private ArrayList<Positionable> makeSelectionGroup(OBlock block, boolean showPortal) {
ArrayList<Positionable> group = new ArrayList<Positionable>();
List<Positionable> circuitIcons = _circuitMap.get(block);
Iterator<Positionable> iter = circuitIcons.iterator();
while (iter.hasNext()) {
Positionable p = iter.next();
if (p instanceof PortalIcon) {
if (showPortal) {
((PortalIcon) p).setStatus(PortalIcon.VISIBLE);
group.add(p);
}
} else {
group.add(p);
}
}
return group;
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method copyItem.
/**
* Set up selections for a paste. Note a copy of _selectionGroup is made
* that is NOT in the _contents. This disconnected ArrayList is added to the
* _contents when (if) a paste is made. The disconnected _selectionGroup can
* be dragged to a new location.
*/
@Override
protected void copyItem(Positionable p) {
if (log.isDebugEnabled()) {
// avoid string concatination if not debug
log.debug("Enter copyItem: _selectionGroup {}", _selectionGroup != null ? "size=" + _selectionGroup.size() : "null");
}
// If popup menu hit again, Paste selections and make another copy
if (_pastePending) {
pasteItems();
}
if (_selectionGroup != null && !_selectionGroup.contains(p)) {
deselectSelectionGroup();
}
if (_selectionGroup == null) {
_selectionGroup = new ArrayList<Positionable>();
_selectionGroup.add(p);
}
ArrayList<Positionable> selectionGroup = new ArrayList<Positionable>();
for (Positionable comp : _selectionGroup) {
Positionable pos = comp.deepClone();
selectionGroup.add(pos);
}
// group is now disconnected
_selectionGroup = selectionGroup;
_pastePending = true;
// if (_debug) log.debug("Exit copyItem: _selectionGroup.size()= "+_selectionGroup.size());
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method setDefaultPortalIcons.
public void setDefaultPortalIcons(HashMap<String, NamedIcon> map) {
_portalIconMap = map;
Iterator<Positionable> it = _contents.iterator();
while (it.hasNext()) {
Positionable pos = it.next();
if (pos instanceof PortalIcon) {
((PortalIcon) pos).initMap();
}
}
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method getCurrentSelection.
protected Positionable getCurrentSelection(MouseEvent event) {
if (_pastePending && !event.isPopupTrigger() && !event.isMetaDown() && !event.isAltDown()) {
return getCopySelection(event);
}
List<Positionable> selections = getSelectedItems(event);
if (_disableShapeSelection || _disablePortalSelection) {
ArrayList<Positionable> list = new ArrayList<Positionable>();
Iterator<Positionable> it = selections.iterator();
while (it.hasNext()) {
Positionable pos = it.next();
if (_disableShapeSelection && pos instanceof jmri.jmrit.display.controlPanelEditor.shape.PositionableShape) {
continue;
}
if (_disablePortalSelection && pos instanceof PortalIcon) {
continue;
}
list.add(pos);
}
selections = list;
}
Positionable selection = null;
if (selections.size() > 0) {
if (event.isControlDown()) {
if (event.isShiftDown() && selections.size() > 3) {
if (_manualSelection) {
// selection made - don't change it
deselectSelectionGroup();
return _currentSelection;
}
// show list
String[] selects = new String[selections.size()];
Iterator<Positionable> iter = selections.iterator();
int i = 0;
while (iter.hasNext()) {
Positionable pos = iter.next();
if (pos instanceof jmri.NamedBean) {
selects[i++] = ((jmri.NamedBean) pos).getDisplayName();
} else {
selects[i++] = pos.getNameString();
}
}
Object select = JOptionPane.showInputDialog(this, Bundle.getMessage("multipleSelections"), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE, null, selects, null);
if (select != null) {
iter = selections.iterator();
while (iter.hasNext()) {
Positionable pos = iter.next();
String name = null;
if (pos instanceof jmri.NamedBean) {
name = ((jmri.NamedBean) pos).getDisplayName();
} else {
name = pos.getNameString();
}
if (((String) select).equals(name)) {
_manualSelection = true;
return pos;
}
}
} else {
selection = selections.get(selections.size() - 1);
}
} else {
// select bottom-most item over the background, otherwise take the background item
selection = selections.get(selections.size() - 1);
if (selection.getDisplayLevel() <= BKG && selections.size() > 1) {
selection = selections.get(selections.size() - 2);
}
// _manualSelection = false;
}
} else {
if (event.isShiftDown() && selections.size() > 1) {
selection = selections.get(1);
} else {
selection = selections.get(0);
}
if (selection.getDisplayLevel() <= BKG) {
selection = null;
}
_manualSelection = false;
}
}
if (!isEditable() && selection != null && selection.isHidden()) {
selection = null;
}
return selection;
}
Aggregations