Search in sources :

Example 26 with Positionable

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

Example 27 with Positionable

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

Example 28 with Positionable

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

the class ControlPanelServlet method getXmlPanel.

@Override
protected String getXmlPanel(String name) {
    log.debug("Getting {} for {}", getPanelType(), name);
    try {
        ControlPanelEditor editor = (ControlPanelEditor) getEditor(name);
        Element panel = new Element("panel");
        JFrame frame = editor.getTargetFrame();
        panel.setAttribute("name", name);
        panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
        panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
        panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
        panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
        panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
        panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
        if (editor.getBackgroundColor() != null) {
            Element color = new Element("backgroundColor");
            color.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
            color.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
            color.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
            panel.addContent(color);
        }
        // include contents
        List<Positionable> contents = editor.getContents();
        log.debug("N elements: {}", contents.size());
        for (Positionable sub : contents) {
            if (sub != null) {
                try {
                    Element e = ConfigXmlManager.elementFromObject(sub);
                    if (e != null) {
                        if ("signalmasticon".equals(e.getName())) {
                            //insert icon details into signalmast
                            e.addContent(getSignalMastIconsElement(e.getAttributeValue("signalmast")));
                        }
                        try {
                            e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
                        } catch (NullPointerException ex) {
                            if (sub.getNamedBean() == null) {
                                log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
                            } else {
                                log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
                            }
                        }
                        parsePortableURIs(e);
                        panel.addContent(e);
                    }
                } catch (Exception ex) {
                    log.error("Error storing panel element: " + ex, ex);
                }
            }
        }
        Document doc = new Document(panel);
        XMLOutputter out = new XMLOutputter();
        out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
        return out.outputString(doc);
    } catch (NullPointerException ex) {
        log.warn("Requested ControlPanel [" + name + "] does not exist.");
        return "ERROR Requested panel [" + name + "] does not exist.";
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) JFrame(javax.swing.JFrame) Element(org.jdom2.Element) Positionable(jmri.jmrit.display.Positionable) Document(org.jdom2.Document)

Example 29 with Positionable

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

Example 30 with Positionable

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

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