Search in sources :

Example 11 with Positionable

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

the class CircuitBuilder method getSelection.

private Positionable getSelection(List<Positionable> tracks) {
    if (tracks.size() > 0) {
        if (tracks.size() == 1) {
            return tracks.get(0);
        }
        if (tracks.size() > 1) {
            String[] selects = new String[tracks.size()];
            Iterator<Positionable> iter = tracks.iterator();
            int i = 0;
            while (iter.hasNext()) {
                selects[i++] = iter.next().getNameString();
            }
            Object select = JOptionPane.showInputDialog(_editor, Bundle.getMessage("multipleSelections"), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE, null, selects, null);
            if (select != null) {
                iter = tracks.iterator();
                while (iter.hasNext()) {
                    Positionable pos = iter.next();
                    if (((String) select).equals(pos.getNameString())) {
                        return pos;
                    }
                }
            } else {
                return tracks.get(tracks.size() - 1);
            }
        }
    }
    return null;
}
Also used : Positionable(jmri.jmrit.display.Positionable)

Example 12 with Positionable

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

the class CircuitBuilder method doMouseClicked.

protected boolean doMouseClicked(List<Positionable> selections, MouseEvent event) {
    if (_editCircuitFrame != null || _editPathsFrame != null || _editPortalFrame != null || _editDirectionFrame != null) {
        if (selections != null && selections.size() > 0) {
            ArrayList<Positionable> tracks = new ArrayList<Positionable>();
            Iterator<Positionable> iter = selections.iterator();
            if (_editCircuitFrame != null) {
                while (iter.hasNext()) {
                    Positionable pos = iter.next();
                    if (isTrack(pos)) {
                        tracks.add(pos);
                    }
                }
            } else if (_editPathsFrame != null) {
                while (iter.hasNext()) {
                    Positionable pos = iter.next();
                    if (isTrack(pos) || pos instanceof PortalIcon) {
                        tracks.add(pos);
                    }
                }
            } else {
                while (iter.hasNext()) {
                    Positionable pos = iter.next();
                    if (pos instanceof PortalIcon) {
                        tracks.add(pos);
                    }
                }
            }
            if (tracks.size() > 0) {
                Positionable selection = null;
                if (tracks.size() == 1) {
                    selection = tracks.get(0);
                } else {
                    selection = getSelection(tracks);
                }
                if (_editPathsFrame != null && event.isShiftDown() && !event.isControlDown()) {
                    selection.doMouseClicked(event);
                }
                handleSelection(selection, event);
            }
        }
        return true;
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) Positionable(jmri.jmrit.display.Positionable)

Example 13 with Positionable

use of jmri.jmrit.display.Positionable 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 14 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 15 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)

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