Search in sources :

Example 1 with PositionableIcon

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

the class ControlPanelEditor method pasteFromClipboard.

private void pasteFromClipboard() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor[] flavors = clipboard.getAvailableDataFlavors();
    for (DataFlavor flavor : flavors) {
        if (_positionableListDataFlavor.equals(flavor)) {
            try {
                @SuppressWarnings("unchecked") List<Positionable> clipGroup = (List<Positionable>) clipboard.getData(_positionableListDataFlavor);
                if (clipGroup != null && clipGroup.size() > 0) {
                    Positionable pos = clipGroup.get(0);
                    int minX = pos.getLocation().x;
                    int minY = pos.getLocation().y;
                    // locate group at mouse point
                    for (int i = 1; i < clipGroup.size(); i++) {
                        pos = clipGroup.get(i);
                        minX = Math.min(minX, pos.getLocation().x);
                        minY = Math.min(minY, pos.getLocation().y);
                    }
                    if (_pastePending) {
                        abortPasteItems();
                    }
                    _selectionGroup = new ArrayList<Positionable>();
                    for (int i = 0; i < clipGroup.size(); i++) {
                        pos = clipGroup.get(i);
                        // make positionable belong to this editor
                        pos.setEditor(this);
                        pos.setLocation(pos.getLocation().x + _anchorX - minX, pos.getLocation().y + _anchorY - minY);
                        // now set display level in the pane.
                        pos.setDisplayLevel(pos.getDisplayLevel());
                        putItem(pos);
                        pos.updateSize();
                        pos.setVisible(true);
                        _selectionGroup.add(pos);
                        if (pos instanceof PositionableIcon) {
                            jmri.NamedBean bean = pos.getNamedBean();
                            if (bean != null) {
                                ((PositionableIcon) pos).displayState(bean.getState());
                            }
                        } else if (pos instanceof MemoryIcon) {
                            ((MemoryIcon) pos).displayState();
                        } else if (pos instanceof PositionableJComponent) {
                            ((PositionableJComponent) pos).displayState();
                        }
                        log.debug("Paste Added at ({}, {})", pos.getLocation().x, pos.getLocation().y);
                    }
                }
                return;
            } catch (IOException ioe) {
                log.warn("Editor Paste caught IOException", ioe);
            } catch (UnsupportedFlavorException ufe) {
                log.warn("Editor Paste caught UnsupportedFlavorException", ufe);
            }
        }
    }
}
Also used : MemoryIcon(jmri.jmrit.display.MemoryIcon) PositionableIcon(jmri.jmrit.display.PositionableIcon) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) DataFlavor(java.awt.datatransfer.DataFlavor) PositionableJComponent(jmri.jmrit.display.PositionableJComponent) List(java.util.List) ArrayList(java.util.ArrayList) Clipboard(java.awt.datatransfer.Clipboard) Positionable(jmri.jmrit.display.Positionable)

Example 2 with PositionableIcon

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

the class ControlPanelEditor method pasteItems.

void pasteItems() {
    if (_selectionGroup != null) {
        for (Positionable pos : _selectionGroup) {
            if (pos instanceof PositionableIcon) {
                jmri.NamedBean bean = pos.getNamedBean();
                if (bean != null) {
                    ((PositionableIcon) pos).displayState(bean.getState());
                }
            }
            putItem(pos);
            log.debug("Add {}", pos.getNameString());
        }
        if (_selectionGroup.get(0) instanceof LocoIcon) {
            LocoIcon p = (LocoIcon) _selectionGroup.get(0);
            CoordinateEdit f = new CoordinateEdit();
            f.init("Train Name", p, false);
            f.initText();
            f.setVisible(true);
            f.setLocationRelativeTo(p);
        }
    }
    _pastePending = false;
}
Also used : LocoIcon(jmri.jmrit.display.LocoIcon) PositionableIcon(jmri.jmrit.display.PositionableIcon) CoordinateEdit(jmri.jmrit.display.CoordinateEdit) Positionable(jmri.jmrit.display.Positionable)

Aggregations

Positionable (jmri.jmrit.display.Positionable)2 PositionableIcon (jmri.jmrit.display.PositionableIcon)2 Point (java.awt.Point)1 Clipboard (java.awt.datatransfer.Clipboard)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoordinateEdit (jmri.jmrit.display.CoordinateEdit)1 LocoIcon (jmri.jmrit.display.LocoIcon)1 MemoryIcon (jmri.jmrit.display.MemoryIcon)1 PositionableJComponent (jmri.jmrit.display.PositionableJComponent)1