Search in sources :

Example 91 with NamedBean

use of jmri.NamedBean 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 92 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class SwitchboardEditor method okAddPressed.

protected void okAddPressed(ActionEvent e) {
    NamedBean nb = null;
    String manuPrefix = getSwitchManu();
    String user = userName.getText().trim();
    if (user.equals("")) {
        user = null;
    }
    // can't be changed, but pick it up from panel
    String sName = sysName.getText();
    addFrame.setVisible(false);
    addFrame.dispose();
    addFrame = null;
    switch(sName.charAt(manuPrefix.length())) {
        case 'T':
            Turnout t;
            try {
                // add turnout to JMRI (w/appropriate manager)
                t = InstanceManager.turnoutManagerInstance().provideTurnout(sName);
                t.setUserName(user);
            } catch (IllegalArgumentException ex) {
                // user input no good
                handleCreateException(sName);
                // without creating
                return;
            }
            nb = jmri.InstanceManager.turnoutManagerInstance().getTurnout(sName);
            break;
        case 'S':
            Sensor s;
            try {
                // add Sensor to JMRI (w/appropriate manager)
                s = InstanceManager.sensorManagerInstance().provideSensor(sName);
                s.setUserName(user);
            } catch (IllegalArgumentException ex) {
                // user input no good
                handleCreateException(sName);
                // without creating
                return;
            }
            nb = jmri.InstanceManager.sensorManagerInstance().getSensor(sName);
            break;
        case 'L':
            Light l;
            try {
                // add Light to JMRI (w/appropriate manager)
                l = InstanceManager.lightManagerInstance().provideLight(sName);
                l.setUserName(user);
            } catch (IllegalArgumentException ex) {
                // user input no good
                handleCreateException(sName);
                // without creating
                return;
            }
            nb = jmri.InstanceManager.lightManagerInstance().getLight(sName);
            break;
        default:
            log.error("connectNew - OKpressed: cannot parse bean name. sName = {}", sName);
            return;
    }
    if (nb == null) {
        log.warn("failed to connect switch to item {}", sName);
    } else {
        // set switch on Switchboard to display current state of just connected bean
        log.debug("sName state: {}", nb.getState());
        try {
            if (getSwitch(sName) == null) {
                log.warn("failed to update switch to state of {}", sName);
            } else {
                updatePressed();
            //                    getSwitch(sName).setNamedBean(nb);
            //                    getSwitch(sName).displayState(nb.getState());
            //                    getSwitch(sName).setEnabled(true);
            }
        } catch (NullPointerException npe) {
            handleCreateException(sName);
            // without updating
            return;
        }
    }
}
Also used : NamedBean(jmri.NamedBean) Light(jmri.Light) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 93 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class DefaultSignalMastLogic method vetoableChange.

//@todo need to think how we deal with auto generated lists based upon the layout editor.
@Override
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException {
    NamedBean nb = (NamedBean) evt.getOldValue();
    if ("CanDelete".equals(evt.getPropertyName())) {
        //NOI18N
        boolean found = false;
        StringBuilder message = new StringBuilder();
        if (nb instanceof SignalMast) {
            if (nb.equals(source)) {
                message.append("Has SignalMast Logic attached which will be <b>Deleted</b> to <ul>");
                for (SignalMast sm : getDestinationList()) {
                    message.append("<li>");
                    message.append(sm.getDisplayName());
                    message.append("</li>");
                }
                message.append("</ul>");
                throw new java.beans.PropertyVetoException(message.toString(), evt);
            } else if (isDestinationValid((SignalMast) nb)) {
                throw new java.beans.PropertyVetoException("Is the end point mast for logic attached to signal mast " + source.getDisplayName() + " which will be <b>Deleted</b> ", evt);
            }
            for (SignalMast sm : getDestinationList()) {
                if (isSignalMastIncluded((SignalMast) nb, sm)) {
                    message.append("<li>");
                    message.append("Used in conflicting logic of " + source.getDisplayName() + " & " + sm.getDisplayName());
                    message.append("</li>");
                }
            }
        }
        if (nb instanceof Turnout) {
            for (SignalMast sm : getDestinationList()) {
                if (isTurnoutIncluded((Turnout) nb, sm)) {
                    message.append("<li>Is in logic between Signal Masts " + source.getDisplayName() + " " + sm.getDisplayName() + "</li>");
                    found = true;
                }
            }
        }
        if (nb instanceof Sensor) {
            for (SignalMast sm : getDestinationList()) {
                if (isSensorIncluded((Sensor) nb, sm)) {
                    message.append("<li>");
                    message.append("Is in logic between Signal Masts " + source.getDisplayName() + " " + sm.getDisplayName());
                    message.append("</li>");
                    found = true;
                }
            }
        }
        if (found) {
            throw new java.beans.PropertyVetoException(message.toString(), evt);
        }
    } else if ("DoDelete".equals(evt.getPropertyName())) {
        //IN18N
        if (nb instanceof SignalMast) {
            if (nb.equals(source)) {
                dispose();
            }
            if (isDestinationValid((SignalMast) nb)) {
                removeDestination((SignalMast) nb);
            }
            for (SignalMast sm : getDestinationList()) {
                if (isSignalMastIncluded((SignalMast) nb, sm)) {
                    log.warn("Unhandled condition: signal mast included during DoDelete");
                // @todo need to deal with this situation
                }
            }
        }
        if (nb instanceof Turnout) {
            Turnout t = (Turnout) nb;
            for (SignalMast sm : getDestinationList()) {
                if (isTurnoutIncluded(t, sm)) {
                    removeTurnout(t, sm);
                }
            }
        }
        if (nb instanceof Sensor) {
            Sensor s = (Sensor) nb;
            for (SignalMast sm : getDestinationList()) {
                if (isSensorIncluded(s, sm)) {
                    removeSensor(s, sm);
                }
            }
        }
    }
}
Also used : NamedBean(jmri.NamedBean) SignalMast(jmri.SignalMast) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 94 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class DefaultSignalMastLogic method replaceSourceMast.

@Override
public void replaceSourceMast(SignalMast oldMast, SignalMast newMast) {
    if (oldMast != source) {
        //Old mast does not match new mast so will exit
        return;
    }
    source.removePropertyChangeListener(propertySourceMastListener);
    source = newMast;
    stopAspect = source.getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.DANGER);
    source.addPropertyChangeListener(propertySourceMastListener);
    if (source.getAspect() == null) {
        source.setAspect(stopAspect);
    }
    for (SignalMast sm : getDestinationList()) {
        DestinationMast destMast = destList.get(sm);
        if (destMast.getAssociatedSection() != null) {
            String oldUserName = destMast.getAssociatedSection().getUserName();
            String newUserName = source.getDisplayName() + ":" + sm.getDisplayName();
            jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).renameBean(oldUserName, newUserName, ((NamedBean) destMast.getAssociatedSection()));
        }
    }
    firePropertyChange("updatedSource", oldMast, newMast);
}
Also used : NamedBean(jmri.NamedBean) SignalMast(jmri.SignalMast)

Example 95 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class TransitTableAction method createModel.

/**
     * Create the JTable DataModel, along with the changes for the specific case
     * of Transit objects
     */
@Override
protected void createModel() {
    m = new BeanTableDataModel() {

        public static final int EDITCOL = NUMCOLUMN;

        public static final int DUPLICATECOL = EDITCOL + 1;

        @Override
        public String getValue(String name) {
            if (name == null) {
                log.warn("requested getValue(null)");
                return "(no name)";
            }
            Transit z = InstanceManager.getDefault(jmri.TransitManager.class).getBySystemName(name);
            if (z == null) {
                log.debug("requested getValue(\"" + name + "\"), Transit doesn't exist");
                return "(no Transit)";
            }
            return "Transit";
        }

        @Override
        public Manager getManager() {
            return InstanceManager.getDefault(jmri.TransitManager.class);
        }

        @Override
        public NamedBean getBySystemName(String name) {
            return InstanceManager.getDefault(jmri.TransitManager.class).getBySystemName(name);
        }

        @Override
        public NamedBean getByUserName(String name) {
            return InstanceManager.getDefault(jmri.TransitManager.class).getByUserName(name);
        }

        @Override
        protected String getMasterClassName() {
            return getClassName();
        }

        @Override
        public void clickOn(NamedBean t) {
        }

        @Override
        public int getColumnCount() {
            return DUPLICATECOL + 1;
        }

        @Override
        public Object getValueAt(int row, int col) {
            if (col == VALUECOL) {
                // some error checking
                if (row >= sysNameList.size()) {
                    log.debug("row is greater than name list");
                    return "";
                }
                Transit z = (Transit) getBySystemName(sysNameList.get(row));
                if (z == null) {
                    return "";
                } else {
                    int state = z.getState();
                    if (state == Transit.IDLE) {
                        return (rbx.getString("TransitIdle"));
                    } else if (state == Transit.ASSIGNED) {
                        return (rbx.getString("TransitAssigned"));
                    }
                }
            } else if (col == EDITCOL) {
                return Bundle.getMessage("ButtonEdit");
            } else if (col == DUPLICATECOL) {
                return rbx.getString("ButtonDuplicate");
            } else {
                return super.getValueAt(row, col);
            }
            return null;
        }

        @Override
        public void setValueAt(Object value, int row, int col) {
            if (col == EDITCOL) {
                class WindowMaker implements Runnable {

                    int row;

                    WindowMaker(int r) {
                        row = r;
                    }

                    @Override
                    public void run() {
                        String sName = (String) getValueAt(row, SYSNAMECOL);
                        editPressed(sName);
                    }
                }
                WindowMaker t = new WindowMaker(row);
                javax.swing.SwingUtilities.invokeLater(t);
            } else if (col == DUPLICATECOL) {
                // set up to duplicate
                class WindowMaker implements Runnable {

                    int row;

                    WindowMaker(int r) {
                        row = r;
                    }

                    @Override
                    public void run() {
                        String sName = (String) getValueAt(row, SYSNAMECOL);
                        duplicatePressed(sName);
                    }
                }
                WindowMaker t = new WindowMaker(row);
                javax.swing.SwingUtilities.invokeLater(t);
            } else {
                super.setValueAt(value, row, col);
            }
        }

        @Override
        public String getColumnName(int col) {
            if (col == EDITCOL) {
                // no namne on Edit column
                return "";
            }
            if (col == DUPLICATECOL) {
                // no namne on Duplicate column
                return "";
            }
            return super.getColumnName(col);
        }

        @Override
        public Class<?> getColumnClass(int col) {
            if (col == VALUECOL) {
                // not a button
                return String.class;
            }
            if (col == EDITCOL) {
                return JButton.class;
            }
            if (col == DUPLICATECOL) {
                return JButton.class;
            } else {
                return super.getColumnClass(col);
            }
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            if (col == VALUECOL) {
                return false;
            }
            if (col == EDITCOL) {
                return true;
            }
            if (col == DUPLICATECOL) {
                return true;
            } else {
                return super.isCellEditable(row, col);
            }
        }

        @Override
        public int getPreferredWidth(int col) {
            // override default value for SystemName and UserName columns
            if (col == SYSNAMECOL) {
                return new JTextField(9).getPreferredSize().width;
            }
            if (col == USERNAMECOL) {
                return new JTextField(17).getPreferredSize().width;
            }
            if (col == VALUECOL) {
                return new JTextField(6).getPreferredSize().width;
            }
            // new columns
            if (col == EDITCOL) {
                return new JTextField(6).getPreferredSize().width;
            }
            if (col == DUPLICATECOL) {
                return new JTextField(10).getPreferredSize().width;
            } else {
                return super.getPreferredWidth(col);
            }
        }

        @Override
        public void configValueColumn(JTable table) {
        // value column isn't button, so config is null
        }

        @Override
        protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
            return true;
        // return (e.getPropertyName().indexOf("alue")=0);
        }

        @Override
        public JButton configureButton() {
            log.error("configureButton should not have been called");
            return null;
        }

        @Override
        protected String getBeanType() {
            return "Transit";
        }
    };
}
Also used : NamedBean(jmri.NamedBean) JButton(javax.swing.JButton) SectionManager(jmri.SectionManager) InstanceManager(jmri.InstanceManager) TransitManager(jmri.TransitManager) Manager(jmri.Manager) SignalHeadManager(jmri.SignalHeadManager) SignalMastManager(jmri.SignalMastManager) JTextField(javax.swing.JTextField) Transit(jmri.Transit) EntryPoint(jmri.EntryPoint) TransitManager(jmri.TransitManager) JTable(javax.swing.JTable)

Aggregations

NamedBean (jmri.NamedBean)104 ArrayList (java.util.ArrayList)18 JTextField (javax.swing.JTextField)12 JmriException (jmri.JmriException)12 SignalMast (jmri.SignalMast)12 JTable (javax.swing.JTable)11 Manager (jmri.Manager)9 Sensor (jmri.Sensor)9 JButton (javax.swing.JButton)8 InstanceManager (jmri.InstanceManager)8 JComboBox (javax.swing.JComboBox)7 MouseEvent (java.awt.event.MouseEvent)6 Hashtable (java.util.Hashtable)6 SignalHead (jmri.SignalHead)6 Turnout (jmri.Turnout)6 OBlock (jmri.jmrit.logix.OBlock)5 File (java.io.File)4 JLabel (javax.swing.JLabel)4 TableCellEditor (javax.swing.table.TableCellEditor)4 TableCellRenderer (javax.swing.table.TableCellRenderer)4