use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method keyPressed.
/**
* ********* KeyListener of Editor ********
*/
@Override
public void keyPressed(KeyEvent e) {
int x = 0;
int y = 0;
switch(e.getKeyCode()) {
case KeyEvent.VK_UP:
case KeyEvent.VK_KP_UP:
case KeyEvent.VK_NUMPAD8:
y = -1;
break;
case KeyEvent.VK_DOWN:
case KeyEvent.VK_KP_DOWN:
case KeyEvent.VK_NUMPAD2:
y = 1;
break;
case KeyEvent.VK_LEFT:
case KeyEvent.VK_KP_LEFT:
case KeyEvent.VK_NUMPAD4:
x = -1;
break;
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_KP_RIGHT:
case KeyEvent.VK_NUMPAD6:
x = 1;
break;
case KeyEvent.VK_D:
case KeyEvent.VK_DELETE:
case KeyEvent.VK_MINUS:
_shapeDrawer.delete();
break;
case KeyEvent.VK_A:
case KeyEvent.VK_INSERT:
case KeyEvent.VK_PLUS:
_shapeDrawer.add(e.isShiftDown());
break;
default:
return;
}
if (e.isShiftDown()) {
x *= 5;
y *= 5;
}
if (_selectionGroup != null) {
for (Positionable comp : _selectionGroup) {
moveItem(comp, x, y);
}
}
repaint();
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditorXml method store.
/**
* Default implementation for storing the contents of a ControlPanelEditor
*
* @param o Object to store, of type ControlPanelEditor
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
ControlPanelEditor p = (ControlPanelEditor) o;
Element panel = new Element("paneleditor");
JFrame frame = p.getTargetFrame();
Dimension size = frame.getSize();
Point posn = frame.getLocation();
panel.setAttribute("class", "jmri.jmrit.display.controlPanelEditor.configurexml.ControlPanelEditorXml");
panel.setAttribute("name", "" + frame.getName());
panel.setAttribute("x", "" + posn.x);
panel.setAttribute("y", "" + posn.y);
panel.setAttribute("height", "" + size.height);
panel.setAttribute("width", "" + size.width);
panel.setAttribute("editable", "" + (p.isEditable() ? "yes" : "no"));
panel.setAttribute("positionable", "" + (p.allPositionable() ? "yes" : "no"));
//panel.setAttribute("showcoordinates", ""+(p.showCoordinates()?"yes":"no"));
panel.setAttribute("showtooltips", "" + (p.showTooltip() ? "yes" : "no"));
panel.setAttribute("controlling", "" + (p.allControlling() ? "yes" : "no"));
panel.setAttribute("hide", p.isVisible() ? "no" : "yes");
panel.setAttribute("panelmenu", p.isPanelMenuVisible() ? "yes" : "no");
panel.setAttribute("scrollable", p.getScrollable());
if (p.getBackgroundColor() != null) {
panel.setAttribute("redBackground", "" + p.getBackgroundColor().getRed());
panel.setAttribute("greenBackground", "" + p.getBackgroundColor().getGreen());
panel.setAttribute("blueBackground", "" + p.getBackgroundColor().getBlue());
}
panel.setAttribute("state", "" + p.getExtendedState());
panel.setAttribute("shapeSelect", "" + (p.getShapeSelect() ? "yes" : "no"));
Element elem = new Element("icons");
HashMap<String, NamedIcon> map = p.getPortalIconMap();
elem.addContent(storeIcon("visible", map.get(PortalIcon.VISIBLE)));
elem.addContent(storeIcon("path_edit", map.get(PortalIcon.PATH)));
elem.addContent(storeIcon("hidden", map.get(PortalIcon.HIDDEN)));
elem.addContent(storeIcon("to_arrow", map.get(PortalIcon.TO_ARROW)));
elem.addContent(storeIcon("from_arrow", map.get(PortalIcon.FROM_ARROW)));
panel.addContent(elem);
// include contents
List<Positionable> contents = p.getContents();
log.debug("N elements: {}", contents.size());
for (Positionable sub : contents) {
if (sub != null && sub.storeItem()) {
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel element: {}", e.getMessage(), e);
}
}
}
return panel;
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class PanelEditor method pasteItem.
protected void pasteItem(MouseEvent e) {
pasteItemFlag = true;
XmlAdapter adapter;
String className;
int x;
int y;
int xOrig;
int yOrig;
if (_multiItemCopyGroup != null) {
JComponent copied;
int xoffset;
int yoffset;
x = _multiItemCopyGroup.get(0).getX();
y = _multiItemCopyGroup.get(0).getY();
xoffset = e.getX() - x;
yoffset = e.getY() - y;
/*We make a copy of the selected items and work off of that copy
as amendments are made to the multiItemCopyGroup during this process
which can result in a loop*/
ArrayList<Positionable> _copyOfMultiItemCopyGroup = new ArrayList<Positionable>(_multiItemCopyGroup);
Collections.copy(_copyOfMultiItemCopyGroup, _multiItemCopyGroup);
for (Positionable comp : _copyOfMultiItemCopyGroup) {
copied = (JComponent) comp;
xOrig = copied.getX();
yOrig = copied.getY();
x = xOrig + xoffset;
y = yOrig + yoffset;
if (x < 0) {
x = 1;
}
if (y < 0) {
y = 1;
}
className = ConfigXmlManager.adapterName(copied);
copied.setLocation(x, y);
try {
adapter = (XmlAdapter) Class.forName(className).newInstance();
Element el = adapter.store(copied);
adapter.load(el, this);
} catch (Exception ex) {
log.debug(ex.getLocalizedMessage(), ex);
}
/*We remove the original item from the list, so we end up with
just the new items selected and allow the items to be moved around */
amendSelectionGroup(comp);
copied.setLocation(xOrig, yOrig);
}
_selectionGroup = null;
}
pasteItemFlag = false;
_targetPanel.repaint();
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class PanelEditor method mouseMoved.
@Override
public void mouseMoved(MouseEvent event) {
//if (_debug) log.debug("mouseMoved at ("+event.getX()+","+event.getY()+")");
if (_dragging || event.isPopupTrigger()) {
return;
}
List<Positionable> selections = getSelectedItems(event);
Positionable selection = null;
if (selections.size() > 0) {
if (event.isShiftDown() && selections.size() > 1) {
selection = selections.get(1);
} else {
selection = selections.get(0);
}
}
if (isEditable() && selection != null && selection.getDisplayLevel() > BKG) {
_highlightcomponent = new Rectangle(selection.getX(), selection.getY(), selection.maxWidth(), selection.maxHeight());
_targetPanel.repaint();
} else {
_highlightcomponent = null;
_targetPanel.repaint();
}
if (selection != null && selection.getDisplayLevel() > BKG && selection.showTooltip()) {
showToolTip(selection, event);
//selection.highlightlabel(true);
_targetPanel.repaint();
} else {
setToolTip(null);
_highlightcomponent = null;
_targetPanel.repaint();
}
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class PanelEditor method removeMultiItems.
private void removeMultiItems() {
boolean itemsInCopy = false;
if (_selectionGroup == _multiItemCopyGroup) {
itemsInCopy = true;
}
for (Positionable comp : _selectionGroup) {
comp.remove();
}
//As we have removed all the items from the panel we can remove the group.
_selectionGroup = null;
//clear the copy group as the originals no longer exist.
if (itemsInCopy) {
_multiItemCopyGroup = null;
}
}
Aggregations