Search in sources :

Example 1 with Positionable

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

the class CircuitBuilder method makeToDoMenu.

// display "todo" (Error correction) items
private void makeToDoMenu() {
    if (_todoMenu == null) {
        _circuitMenu.remove(_circuitMenu.getItem(_circuitMenu.getItemCount() - 1));
        _todoMenu = new JMenu(Bundle.getMessage("circuitErrorsItem"));
        _circuitMenu.add(_todoMenu);
    } else {
        _todoMenu.removeAll();
    }
    JMenu blockNeeds = new JMenu(Bundle.getMessage("blockNeedsIconsItem"));
    _todoMenu.add(blockNeeds);
    ActionListener editCircuitAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            String sysName = event.getActionCommand();
            editCircuitError(sysName);
        }
    };
    if (_bareBlock.size() > 0) {
        for (int i = 0; i < _bareBlock.size(); i++) {
            OBlock block = _bareBlock.get(i);
            JMenuItem mi = new JMenuItem(java.text.MessageFormat.format(Bundle.getMessage("OpenCircuitItem"), block.getDisplayName()));
            mi.setActionCommand(block.getSystemName());
            mi.addActionListener(editCircuitAction);
            blockNeeds.add(mi);
        }
    } else {
        if (hasOBlocks) {
            blockNeeds.add(new JMenuItem(Bundle.getMessage("circuitsHaveIcons")));
        } else {
            blockNeeds.add(new JMenuItem(Bundle.getMessage("noTrackCircuits")));
        }
    }
    blockNeeds = new JMenu(Bundle.getMessage("blocksNeedConversionItem"));
    _todoMenu.add(blockNeeds);
    if (_convertBlock.size() > 0) {
        for (int i = 0; i < _convertBlock.size(); i++) {
            OBlock block = _convertBlock.get(i);
            JMenuItem mi = new JMenuItem(java.text.MessageFormat.format(Bundle.getMessage("OpenCircuitItem"), block.getDisplayName()));
            mi.setActionCommand(block.getSystemName());
            mi.addActionListener(editCircuitAction);
            blockNeeds.add(mi);
        }
    } else {
        if (hasOBlocks) {
            blockNeeds.add(new JMenuItem(Bundle.getMessage("circuitIconsConverted")));
        } else {
            blockNeeds.add(new JMenuItem(Bundle.getMessage("noTrackCircuits")));
        }
    }
    JMenuItem iconNeeds;
    if (_unconvertedTrack.size() > 0) {
        iconNeeds = new JMenuItem(Bundle.getMessage("iconsNeedConversionItem"));
        iconNeeds.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                ArrayList<Positionable> group = new ArrayList<Positionable>();
                for (int i = 0; i < _unconvertedTrack.size(); i++) {
                    group.add(_unconvertedTrack.get(i));
                }
                _editor.setSelectionGroup(group);
            }
        });
    } else {
        iconNeeds = new JMenuItem(Bundle.getMessage("circuitIconsConverted"));
    }
    _todoMenu.add(iconNeeds);
    if (_darkTrack.size() > 0) {
        iconNeeds = new JMenuItem(Bundle.getMessage("iconsNeedsBlocksItem"));
        iconNeeds.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                ArrayList<Positionable> group = new ArrayList<Positionable>();
                for (int i = 0; i < _darkTrack.size(); i++) {
                    group.add(_darkTrack.get(i));
                }
                _editor.setSelectionGroup(group);
            }
        });
    } else {
        if (hasOBlocks) {
            iconNeeds = new JMenuItem(Bundle.getMessage("IconsHaveCircuits"));
        } else {
            iconNeeds = new JMenuItem(Bundle.getMessage("noTrackCircuits"));
        }
    }
    _todoMenu.add(iconNeeds);
    blockNeeds = new JMenu(Bundle.getMessage("portalsMisplaced"));
    _todoMenu.add(blockNeeds);
    ActionListener portalCircuitAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            String portalName = event.getActionCommand();
            portalCircuitError(portalName);
        }
    };
    if (_badPortalIcon.size() > 0) {
        Iterator<String> it = _badPortalIcon.keySet().iterator();
        while (it.hasNext()) {
            String portalName = it.next();
            JMenuItem mi = new JMenuItem(java.text.MessageFormat.format(Bundle.getMessage("OpenPortalTitle"), portalName));
            mi.setActionCommand(portalName);
            mi.addActionListener(portalCircuitAction);
            blockNeeds.add(mi);
        }
    } else {
        if (hasOBlocks) {
            blockNeeds.add(new JMenuItem(Bundle.getMessage("portalsInPlace")));
        } else {
            blockNeeds.add(new JMenuItem(Bundle.getMessage("noTrackCircuits")));
        }
    }
    JMenuItem pError = new JMenuItem(Bundle.getMessage("CheckPortalPaths"));
    _todoMenu.add(pError);
    pError.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            errorCheck();
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) Positionable(jmri.jmrit.display.Positionable) JMenuItem(javax.swing.JMenuItem) OBlock(jmri.jmrit.logix.OBlock) JMenu(javax.swing.JMenu)

Example 2 with Positionable

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

the class CircuitBuilder method okPath.

/**
     * Can a path in this circuit be drawn through this icon?
     */
private boolean okPath(Positionable pos, OBlock block) {
    java.util.List<Positionable> icons = _circuitMap.get(block);
    if (pos instanceof PortalIcon) {
        Portal portal = ((PortalIcon) pos).getPortal();
        if (portal != null) {
            if (block.equals(portal.getFromBlock()) || block.equals(portal.getToBlock())) {
                ((PortalIcon) pos).setStatus(PortalIcon.PATH);
                return true;
            }
        }
        JOptionPane.showMessageDialog(_editor, java.text.MessageFormat.format(Bundle.getMessage("portalNotInCircuit"), block.getDisplayName()), Bundle.getMessage("badPath"), JOptionPane.WARNING_MESSAGE);
        return false;
    }
    if (!icons.contains(pos)) {
        JOptionPane.showMessageDialog(_editor, java.text.MessageFormat.format(Bundle.getMessage("iconNotInCircuit"), block.getDisplayName()), Bundle.getMessage("badPath"), JOptionPane.WARNING_MESSAGE);
        return false;
    }
    return true;
}
Also used : Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable)

Example 3 with Positionable

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

the class CircuitBuilder method setIconGroup.

/**
     * Edit frame closing, set block's icons
     */
private void setIconGroup(OBlock block, java.util.List<Positionable> selections) {
    java.util.List<Positionable> oldIcons = _circuitMap.get(block);
    if (oldIcons != null) {
        for (int i = 0; i < oldIcons.size(); i++) {
            Positionable pos = oldIcons.get(i);
            if (pos instanceof IndicatorTrack) {
                ((IndicatorTrack) pos).setOccBlockHandle(null);
            }
            _iconMap.remove(pos);
        }
    }
    // the selectionGroup for all edit frames is full collection of icons
    // comprising the block.  Gather them and store in the block's hashMap
    ArrayList<Positionable> icons = new ArrayList<Positionable>();
    if (selections != null) {
        if (log.isDebugEnabled()) {
            log.debug("setIconGroup: selectionGroup has " + selections.size() + " icons.");
        }
        NamedBeanHandle<OBlock> handle = InstanceManager.getDefault(NamedBeanHandleManager.class).getNamedBeanHandle(block.getSystemName(), block);
        for (int i = 0; i < selections.size(); i++) {
            Positionable pos = selections.get(i);
            if (pos instanceof IndicatorTrack) {
                ((IndicatorTrack) pos).setOccBlockHandle(handle);
            }
            icons.add(pos);
            _iconMap.put(pos, block);
        }
        java.util.List<Portal> portals = block.getPortals();
        for (int i = 0; i < portals.size(); i++) {
            PortalIcon icon = _portalIconMap.get(portals.get(i).getName());
            if (icon != null) {
                _iconMap.put(icon, block);
            }
        }
    }
    _circuitMap.put(block, icons);
    if (log.isDebugEnabled()) {
        log.debug("setIconGroup: block " + block.getDisplayName() + " has " + icons.size() + " icons.");
    }
}
Also used : ArrayList(java.util.ArrayList) NamedBeanHandleManager(jmri.NamedBeanHandleManager) IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock)

Example 4 with Positionable

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

the class CircuitBuilder method removeBlock.

/**
     * Remove block, but keep the track icons. Set block reference in icon null
     */
protected void removeBlock(OBlock block) {
    java.util.List<Positionable> list = _circuitMap.get(block);
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            Positionable pos = list.get(i);
            if (pos instanceof IndicatorTrack) {
                ((IndicatorTrack) pos).setOccBlockHandle(null);
            } else if (pos instanceof PortalIcon) {
                pos.remove();
            }
            _darkTrack.add(pos);
        }
    }
    _circuitMap.remove(block);
    block.dispose();
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Positionable(jmri.jmrit.display.Positionable)

Example 5 with Positionable

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

the class EditCircuitPaths method findErrors.

private boolean findErrors() {
    boolean error = false;
    if (checkForSavePath()) {
        return true;
    }
    java.util.List<Path> list = _block.getPaths();
    if (list.size() == 0) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("noPaths", _block.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
    }
    for (int i = 0; i < list.size(); i++) {
        OPath path = (OPath) list.get(i);
        ArrayList<Positionable> pathGp = makePathGroup(path);
        if (pathGp.size() == 0) {
            error = true;
            break;
        }
        OPath p = makeOPath(path.getName(), pathGp, false);
        if (p == null) {
            error = true;
            break;
        }
    }
    if (error) {
        int result = JOptionPane.showConfirmDialog(this, Bundle.getMessage("hasPathErrors"), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            error = false;
        }
    }
    return error;
}
Also used : OPath(jmri.jmrit.logix.OPath) Path(jmri.Path) OPath(jmri.jmrit.logix.OPath) 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