Search in sources :

Example 21 with Positionable

use of jmri.jmrit.display.Positionable in project JMRI by JMRI.

the class ControlPanelEditor method paintTargetPanel.

@Override
protected void paintTargetPanel(Graphics g) {
    // needed to create PositionablePolygon
    _shapeDrawer.paint(g);
    if (_secondSelectionGroup != null) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(new Color(150, 150, 255));
        g2d.setStroke(new java.awt.BasicStroke(2.0f));
        for (Positionable p : _secondSelectionGroup) {
            if (!(p instanceof jmri.jmrit.display.controlPanelEditor.shape.PositionableShape)) {
                g.drawRect(p.getX(), p.getY(), p.maxWidth(), p.maxHeight());
            }
        }
    }
}
Also used : Color(java.awt.Color) Positionable(jmri.jmrit.display.Positionable) Graphics2D(java.awt.Graphics2D)

Example 22 with Positionable

use of jmri.jmrit.display.Positionable in project JMRI by JMRI.

the class ControlPanelEditor method selectLevel.

private void selectLevel(int i) {
    _selectionGroup = new ArrayList<Positionable>();
    Iterator<Positionable> it = _contents.iterator();
    while (it.hasNext()) {
        Positionable pos = it.next();
        if (pos.getDisplayLevel() == i) {
            _selectionGroup.add(pos);
        }
    }
    _targetPanel.repaint();
}
Also used : Positionable(jmri.jmrit.display.Positionable)

Example 23 with Positionable

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();
}
Also used : Positionable(jmri.jmrit.display.Positionable) Point(java.awt.Point)

Example 24 with Positionable

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;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) JFrame(javax.swing.JFrame) Element(org.jdom2.Element) Dimension(java.awt.Dimension) Point(java.awt.Point) Positionable(jmri.jmrit.display.Positionable)

Example 25 with Positionable

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();
}
Also used : Element(org.jdom2.Element) JComponent(javax.swing.JComponent) ArrayList(java.util.ArrayList) Positionable(jmri.jmrit.display.Positionable) XmlAdapter(jmri.configurexml.XmlAdapter)

Aggregations

Positionable (jmri.jmrit.display.Positionable)60 ArrayList (java.util.ArrayList)18 Point (java.awt.Point)15 IndicatorTrack (jmri.jmrit.display.IndicatorTrack)12 Portal (jmri.jmrit.logix.Portal)7 Element (org.jdom2.Element)7 JFrame (javax.swing.JFrame)6 OBlock (jmri.jmrit.logix.OBlock)6 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 IOException (java.io.IOException)4 JMenuItem (javax.swing.JMenuItem)4 Color (java.awt.Color)3 Dimension (java.awt.Dimension)3 Rectangle (java.awt.Rectangle)3 PanelEditor (jmri.jmrit.display.panelEditor.PanelEditor)3 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 Graphics2D (java.awt.Graphics2D)2 Clipboard (java.awt.datatransfer.Clipboard)2