Search in sources :

Example 51 with Positionable

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

the class PortalIcon method setPositionableMenu.

private void setPositionableMenu(JPopupMenu popup) {
    JCheckBoxMenuItem lockItem = new JCheckBoxMenuItem(Bundle.getMessage("LockPosition"));
    lockItem.setSelected(!isPositionable());
    lockItem.addActionListener(new ActionListener() {

        Positionable comp;

        JCheckBoxMenuItem checkBox;

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            comp.setPositionable(!checkBox.isSelected());
        }

        ActionListener init(Positionable pos, JCheckBoxMenuItem cb) {
            comp = pos;
            checkBox = cb;
            return this;
        }
    }.init(this, lockItem));
    JMenuItem jmi = popup.add(lockItem);
    jmi.setEnabled(false);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Positionable(jmri.jmrit.display.Positionable) JMenuItem(javax.swing.JMenuItem) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 52 with Positionable

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

the class EditPortalFrame method iconIntersectsBlock.

/**
     * Query whether icon intersects any track icons of block
     *
     * @return null if intersection, otherwise a messags
     */
private String iconIntersectsBlock(PortalIcon icon, OBlock block) {
    java.util.List<Positionable> list = _parent.getCircuitIcons(block);
    if (list == null || list.size() == 0) {
        return Bundle.getMessage("needIcons", block.getDisplayName(), Bundle.getMessage("editCircuitItem"));
    }
    Rectangle rect = new Rectangle();
    Rectangle iconRect = icon.getBounds(new Rectangle());
    for (int i = 0; i < list.size(); i++) {
        Positionable comp = list.get(i);
        if (CircuitBuilder.isTrack(comp)) {
            rect = list.get(i).getBounds(rect);
            if (iconRect.intersects(rect)) {
                return null;
            }
        }
    }
    return Bundle.getMessage("iconNotOnBlock", block.getDisplayName(), icon.getNameString());
}
Also used : Rectangle(java.awt.Rectangle) Positionable(jmri.jmrit.display.Positionable) Point(java.awt.Point)

Example 53 with Positionable

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

the class EditCircuitPaths method updatePath.

/**
     * Sets the path icons for display
     *
     */
protected void updatePath(boolean pathChanged) {
    // to avoid ConcurrentModificationException now set data
    Iterator<Positionable> iter = _pathGroup.iterator();
    while (iter.hasNext()) {
        Positionable pos = iter.next();
        if (pos instanceof IndicatorTrack) {
            ((IndicatorTrack) pos).addPath(TEST_PATH);
        } else {
            ((PortalIcon) pos).setStatus(PortalIcon.PATH);
        }
    }
    _pathChange = pathChanged;
    String name = _pathName.getText();
    if (name == null || name.length() == 0) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("needPathName"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
    } else {
    }
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Positionable(jmri.jmrit.display.Positionable)

Example 54 with Positionable

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

the class EditCircuitPaths method makeOPath.

/**
     * Make the OPath from the icons in the Iterator
     */
private OPath makeOPath(String name, ArrayList<Positionable> pathGp, boolean showMsg) {
    if (pathGp.size() == 0) {
        if (showMsg) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPathIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
        }
        return null;
    }
    Iterator<Positionable> it = pathGp.iterator();
    ArrayList<BeanSetting> settings = new ArrayList<BeanSetting>();
    Portal fromPortal = null;
    Portal toPortal = null;
    boolean hasTrack = false;
    int portalIconCount = 0;
    while (it.hasNext()) {
        Positionable pos = it.next();
        if (pos instanceof IndicatorTurnoutIcon) {
            jmri.Turnout t = ((IndicatorTurnoutIcon) pos).getTurnout();
            String turnoutName = ((IndicatorTurnoutIcon) pos).getNamedTurnout().getName();
            int state = t.getKnownState();
            if (state != Turnout.CLOSED && state != Turnout.THROWN) {
                if (showMsg) {
                    JOptionPane.showMessageDialog(this, Bundle.getMessage("turnoutNotSet", t.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
                }
                return null;
            }
            settings.add(new BeanSetting(t, turnoutName, state));
            hasTrack = true;
        } else if (pos instanceof PortalIcon) {
            if (toPortal == null) {
                toPortal = ((PortalIcon) pos).getPortal();
            } else if (fromPortal == null) {
                fromPortal = ((PortalIcon) pos).getPortal();
            }
            portalIconCount++;
        } else if (pos instanceof IndicatorTrack) {
            hasTrack = true;
        }
    }
    if (showMsg) {
        if (!hasTrack) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPathIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
        if (toPortal == null && fromPortal == null) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("tooFewPortals"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
        if (portalIconCount == 0) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPortalIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
        }
        if (portalIconCount > 2) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("tooManyPortals"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
    }
    if (hasTrack && portalIconCount > 0 && portalIconCount < 3) {
        return new OPath(name, _block, fromPortal, toPortal, settings);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Turnout(jmri.Turnout) OPath(jmri.jmrit.logix.OPath) Point(java.awt.Point) BeanSetting(jmri.BeanSetting) IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable)

Example 55 with Positionable

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

the class EditCircuitFrame method changeBlockName.

/**
     * *********************** end setup *************************
     */
private void changeBlockName() {
    String name = _blockName.getText();
    if (name == null || name.trim().length() == 0) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("changeBlockName"), Bundle.getMessage("editCiruit"), JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    _block.setUserName(name);
    // block user name change will change portal names.  Change PortalIcon names to match
    java.util.List<Positionable> list = _parent.getCircuitIcons(_block);
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) instanceof PortalIcon) {
                PortalIcon icon = (PortalIcon) list.get(i);
                Portal portal = icon.getPortal();
                icon.setName(portal.getName());
                icon.setTooltip(new ToolTip(portal.getDescription(), 0, 0));
            }
        }
    }
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable) Point(java.awt.Point)

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