Search in sources :

Example 1 with PortalManager

use of jmri.jmrit.logix.PortalManager in project JMRI by JMRI.

the class CircuitBuilder method portalCircuitError.

private void portalCircuitError(String portalName) {
    if (editingOK()) {
        PortalManager portalMgr = InstanceManager.getDefault(jmri.jmrit.logix.PortalManager.class);
        Portal portal = portalMgr.getByUserName(portalName);
        if (portal == null) {
            JOptionPane.showMessageDialog(_editor, Bundle.getMessage("noSuchPortal", portalName), Bundle.getMessage("ErrorPortal"), JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        _currentBlock = portal.getToBlock();
        OBlock adjacentBlock = null;
        if (_currentBlock == null) {
            _currentBlock = portal.getFromBlock();
        } else {
            adjacentBlock = portal.getFromBlock();
        }
        if (adjacentBlock == null) {
            JOptionPane.showMessageDialog(_editor, Bundle.getMessage("invalidPortal", portalName, _currentBlock), Bundle.getMessage("ErrorPortal"), JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        if (_currentBlock != null) {
            // check icons to be indicator type
            _circuitIcons = _circuitMap.get(_currentBlock);
            if (!iconsConverted(_currentBlock)) {
                queryConvertIcons(_currentBlock);
            }
            _editor.setSelectionGroup(makeSelectionGroup(_currentBlock, false));
            _editor.setSecondSelectionGroup(makeSelectionGroup(adjacentBlock, false));
            _editor.disableMenus();
            TargetPane targetPane = (TargetPane) _editor.getTargetPanel();
            targetPane.setSelectGroupColor(_editGroupColor);
            targetPane.setHighlightColor(_highlightColor);
            PortalIcon icon = _portalIconMap.get(portalName);
            if (icon != null) {
                icon.setStatus(PortalIcon.VISIBLE);
            }
            setPortalsPositionable(_currentBlock, true);
            _editPortalFrame = new EditPortalFrame(Bundle.getMessage("OpenPortalTitle"), this, _currentBlock, portal, adjacentBlock);
        }
    }
}
Also used : PortalManager(jmri.jmrit.logix.PortalManager) Portal(jmri.jmrit.logix.Portal) TargetPane(jmri.jmrit.display.Editor.TargetPane) OBlock(jmri.jmrit.logix.OBlock)

Example 2 with PortalManager

use of jmri.jmrit.logix.PortalManager in project JMRI by JMRI.

the class CircuitBuilder method checkCircuits.

/**
     * ************** end closing frames *******************
     */
/**
     * Find the blocks with no icons and the blocks with icons that need
     * conversion Setup for main Frame - used in both initialization and close
     * of an editing frame Build Lists that are used to create menu items
     */
private void checkCircuits() {
    _portalIconMap.clear();
    _darkTrack.clear();
    _unconvertedTrack.clear();
    PortalManager portalMgr = InstanceManager.getDefault(jmri.jmrit.logix.PortalManager.class);
    Iterator<Positionable> it = _editor.getContents().iterator();
    while (it.hasNext()) {
        Positionable pos = it.next();
        //            if (log.isDebugEnabled()) log.debug("class: "+pos.getClass().getName());
        if (pos instanceof IndicatorTrack) {
            OBlock block = ((IndicatorTrack) pos).getOccBlock();
            ((IndicatorTrack) pos).removePath(EditCircuitPaths.TEST_PATH);
            if (block != null) {
                addIcon(block, pos);
            } else {
                _darkTrack.add(pos);
            }
        } else if (pos instanceof PortalIcon) {
            PortalIcon pIcon = (PortalIcon) pos;
            String name = pIcon.getName();
            Portal portal = portalMgr.getByUserName(name);
            if (portal == null) {
                log.error("No Portal for PortalIcon called \"" + name + "\". Discarding icon.");
                pIcon.remove();
            } else {
                PortalIcon pi = _portalIconMap.get(name);
                if (pi != null) {
                    log.error("Removing duplicate PortalIcon for Portal \"" + name + "\".");
                    pi.remove();
                }
                _portalIconMap.put(name, pIcon);
            }
        }
    }
    Iterator<Entry<OBlock, ArrayList<Positionable>>> iters = _circuitMap.entrySet().iterator();
    while (iters.hasNext()) {
        Entry<OBlock, ArrayList<Positionable>> entry = iters.next();
        Iterator<Positionable> iter = entry.getValue().iterator();
        while (iter.hasNext()) {
            Positionable pos = iter.next();
            if (isUnconvertedTrack(pos)) {
                if (!_unconvertedTrack.contains(pos)) {
                    _unconvertedTrack.add(pos);
                }
            }
        }
    }
    _bareBlock.clear();
    _convertBlock.clear();
    _badPortalIcon.clear();
    OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    String[] sysNames = manager.getSystemNameArray();
    hasOBlocks = (sysNames.length > 0);
    for (int i = 0; i < sysNames.length; i++) {
        OBlock block = manager.getBySystemName(sysNames[i]);
        java.util.List<Portal> list = block.getPortals();
        if (list != null) {
            Iterator<Portal> iter = list.iterator();
            while (iter.hasNext()) {
                Portal portal = iter.next();
                // update circuitMap
                PortalIcon pi = _portalIconMap.get(portal.getName());
                if (pi != null) {
                    addIcon(block, pi);
                }
            }
        }
        java.util.List<Positionable> icons = _circuitMap.get(block);
        if (log.isDebugEnabled()) {
            log.debug("checkCircuits: block " + block.getDisplayName() + " has " + icons.size() + " icons.");
        }
        if (icons == null || icons.size() == 0) {
            _bareBlock.add(block);
        } else {
            _bareBlock.remove(block);
            for (int k = 0; k < icons.size(); k++) {
                Positionable pos = icons.get(k);
                if (!(pos instanceof IndicatorTrack) && !(pos instanceof PortalIcon)) {
                    if (!_convertBlock.contains(block)) {
                        _convertBlock.add(block);
                        break;
                    }
                }
            }
        }
    }
    List<NamedBean> list = portalMgr.getNamedBeanList();
    Iterator<NamedBean> iter = list.iterator();
    while (iter.hasNext()) {
        Portal portal = (Portal) iter.next();
        String name = portal.getName();
        PortalIcon pi = _portalIconMap.get(name);
        if (pi != null) {
            if (!checkPortalIcon(portal, pi)) {
                _badPortalIcon.put(name, portal);
            }
        } else {
            // no icon for this Portal
            _badPortalIcon.put(name, portal);
        }
    }
    makeToDoMenu();
}
Also used : NamedBean(jmri.NamedBean) PortalManager(jmri.jmrit.logix.PortalManager) ArrayList(java.util.ArrayList) OBlockManager(jmri.jmrit.logix.OBlockManager) Entry(java.util.Map.Entry) IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock)

Example 3 with PortalManager

use of jmri.jmrit.logix.PortalManager in project JMRI by JMRI.

the class EditPortalFrame method deletePortal.

private void deletePortal() {
    String name = _portalName.getText();
    Portal portal = _portalList.getSelectedValue();
    if (portal == null) {
        PortalManager portalMgr = InstanceManager.getDefault(jmri.jmrit.logix.PortalManager.class);
        portal = portalMgr.getByUserName(name);
    }
    if (portal != null) {
        int result = JOptionPane.showConfirmDialog(this, Bundle.getMessage("confirmPortalDelete", portal.getName()), Bundle.getMessage("makePortal"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            // removes portal and stubs all paths through it.
            portal.dispose();
            _portalList.dataChange();
        }
    }
    _portalName.setText(null);
    PortalIcon icon = _parent.getPortalIconMap().get(name);
    if (icon != null) {
        deletePortalIcon(icon);
    }
    _currentPortalName = null;
}
Also used : PortalManager(jmri.jmrit.logix.PortalManager) Portal(jmri.jmrit.logix.Portal) Point(java.awt.Point)

Example 4 with PortalManager

use of jmri.jmrit.logix.PortalManager in project JMRI by JMRI.

the class BlockPathTableModel method setValueAt.

@Override
public void setValueAt(Object value, int row, int col) {
    String msg = null;
    if (_block.getPaths().size() == row) {
        switch(col) {
            case NAME_COLUMN:
                String strValue = (String) value;
                if (_block.getPathByName(strValue) != null) {
                    msg = Bundle.getMessage("DuplPathName", strValue);
                    tempRow[col] = strValue;
                } else {
                    Portal fromPortal = _block.getPortalByName(tempRow[FROM_PORTAL_COLUMN]);
                    Portal toPortal = _block.getPortalByName(tempRow[TO_PORTAL_COLUMN]);
                    if (fromPortal != null || toPortal != null) {
                        OPath path = new OPath(strValue, _block, fromPortal, toPortal, null);
                        float len = 0.0f;
                        try {
                            len = IntlUtilities.floatValue(tempRow[LENGTHCOL]);
                        } catch (ParseException e) {
                            JOptionPane.showMessageDialog(null, Bundle.getMessage("BadNumber", tempRow[LENGTHCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                        }
                        if (tempRow[UNITSCOL].equals((Bundle.getMessage("cm")))) {
                            path.setLength(len * 10.0f);
                        } else {
                            path.setLength(len * 25.4f);
                        }
                        if (!_block.addPath(path)) {
                            msg = Bundle.getMessage("AddPathFailed", strValue);
                            tempRow[NAME_COLUMN] = strValue;
                        } else {
                            initTempRow();
                            _parent.updateOpenMenu();
                            fireTableDataChanged();
                        }
                    } else {
                        tempRow[NAME_COLUMN] = strValue;
                    }
                }
                break;
            case LENGTHCOL:
                try {
                    _tempLen = IntlUtilities.floatValue(value.toString());
                    if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) {
                        _tempLen *= 10f;
                    } else {
                        _tempLen *= 25.4f;
                    }
                } catch (ParseException e) {
                    JOptionPane.showMessageDialog(null, Bundle.getMessage("BadNumber", tempRow[LENGTHCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
                }
                return;
            case UNITSCOL:
                _units.set(row, (Boolean) value);
                fireTableRowsUpdated(row, row);
                return;
            case DELETE_COL:
                initTempRow();
                fireTableRowsUpdated(row, row);
                break;
            default:
                // fall through
                break;
        }
        tempRow[col] = (String) value;
        if (msg != null) {
            JOptionPane.showMessageDialog(null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
        }
        return;
    }
    OPath path = (OPath) _block.getPaths().get(row);
    switch(col) {
        case FROM_PORTAL_COLUMN:
            String strValue = (String) value;
            if (strValue != null) {
                Portal portal = _block.getPortalByName(strValue);
                PortalManager portalMgr = InstanceManager.getDefault(PortalManager.class);
                if (portal == null || portalMgr.getPortal(strValue) == null) {
                    int response = JOptionPane.showConfirmDialog(null, Bundle.getMessage("BlockPortalConflict", value, _block.getDisplayName()), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                    if (response == JOptionPane.NO_OPTION) {
                        break;
                    }
                    portal = portalMgr.providePortal(strValue);
                    if (portal == null) {
                        msg = Bundle.getMessage("NoSuchPortalName", strValue);
                        break;
                    } else {
                        if (!portal.setFromBlock(_block, false)) {
                            response = JOptionPane.showConfirmDialog(null, Bundle.getMessage("BlockPathsConflict", value, portal.getFromBlockName()), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                            if (response == JOptionPane.NO_OPTION) {
                                break;
                            }
                        }
                        portal.setFromBlock(_block, true);
                        _parent.getPortalModel().fireTableDataChanged();
                    }
                }
                path.setFromPortal(portal);
                if (!portal.addPath(path)) {
                    msg = Bundle.getMessage("AddPathFailed", strValue);
                }
            } else {
                path.setFromPortal(null);
            }
            fireTableRowsUpdated(row, row);
            break;
        case NAME_COLUMN:
            strValue = (String) value;
            if (strValue != null) {
                if (_block.getPathByName(strValue) != null) {
                    msg = Bundle.getMessage("DuplPathName", strValue);
                }
                path.setName(strValue);
                fireTableRowsUpdated(row, row);
            }
            break;
        case TO_PORTAL_COLUMN:
            strValue = (String) value;
            if (strValue != null) {
                PortalManager portalMgr = InstanceManager.getDefault(PortalManager.class);
                Portal portal = _block.getPortalByName(strValue);
                if (portal == null || portalMgr.getPortal(strValue) == null) {
                    int response = JOptionPane.showConfirmDialog(null, Bundle.getMessage("BlockPortalConflict", value, _block.getDisplayName()), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                    if (response == JOptionPane.NO_OPTION) {
                        break;
                    }
                    portal = portalMgr.providePortal(strValue);
                    if (portal == null) {
                        msg = Bundle.getMessage("NoSuchPortalName", strValue);
                        break;
                    } else {
                        if (!portal.setToBlock(_block, false)) {
                            response = JOptionPane.showConfirmDialog(null, Bundle.getMessage("BlockPathsConflict", value, portal.getToBlockName()), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                            if (response == JOptionPane.NO_OPTION) {
                                break;
                            }
                        }
                        portal.setToBlock(_block, true);
                        _parent.getPortalModel().fireTableDataChanged();
                    }
                }
                path.setToPortal(portal);
                if (!portal.addPath(path)) {
                    msg = Bundle.getMessage("AddPathFailed", strValue);
                }
            } else {
                path.setToPortal(null);
            }
            fireTableRowsUpdated(row, row);
            break;
        case LENGTHCOL:
            try {
                float len = IntlUtilities.floatValue(value.toString());
                if (_units.get(row)) {
                    path.setLength(len * 10.0f);
                } else {
                    path.setLength(len * 25.4f);
                }
                fireTableRowsUpdated(row, row);
            } catch (ParseException e) {
                JOptionPane.showMessageDialog(null, Bundle.getMessage("BadNumber", value), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
            }
            return;
        case UNITSCOL:
            _units.set(row, (Boolean) value);
            fireTableRowsUpdated(row, row);
            return;
        case EDIT_COL:
            _parent.openPathTurnoutFrame(_parent.makePathTurnoutName(_block.getSystemName(), path.getName()));
            break;
        case DELETE_COL:
            if (deletePath(path)) {
                _units.remove(row);
                fireTableDataChanged();
            }
            break;
        default:
            // fall through
            break;
    }
    if (msg != null) {
        JOptionPane.showMessageDialog(null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
    }
}
Also used : PortalManager(jmri.jmrit.logix.PortalManager) Portal(jmri.jmrit.logix.Portal) OPath(jmri.jmrit.logix.OPath) ParseException(java.text.ParseException)

Aggregations

Portal (jmri.jmrit.logix.Portal)4 PortalManager (jmri.jmrit.logix.PortalManager)4 OBlock (jmri.jmrit.logix.OBlock)2 Point (java.awt.Point)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 NamedBean (jmri.NamedBean)1 TargetPane (jmri.jmrit.display.Editor.TargetPane)1 IndicatorTrack (jmri.jmrit.display.IndicatorTrack)1 Positionable (jmri.jmrit.display.Positionable)1 OBlockManager (jmri.jmrit.logix.OBlockManager)1 OPath (jmri.jmrit.logix.OPath)1