Search in sources :

Example 11 with Manager

use of jmri.Manager in project JMRI by JMRI.

the class SignalHeadTableAction method createModel.

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

        public static final int LITCOL = NUMCOLUMN;

        public static final int HELDCOL = LITCOL + 1;

        public static final int EDITCOL = HELDCOL + 1;

        @Override
        public int getColumnCount() {
            return NUMCOLUMN + 3;
        }

        @Override
        public String getColumnName(int col) {
            if (col == VALUECOL) {
                // override default title, correct name SignalHeadAppearance i.e. "Red"
                return Bundle.getMessage("SignalMastAppearance");
            } else if (col == LITCOL) {
                return Bundle.getMessage("ColumnHeadLit");
            } else if (col == HELDCOL) {
                return Bundle.getMessage("ColumnHeadHeld");
            } else if (col == EDITCOL) {
                // no heading on "Edit"
                return "";
            } else {
                return super.getColumnName(col);
            }
        }

        @Override
        public Class<?> getColumnClass(int col) {
            if (col == VALUECOL) {
                // Use a JPanel containing a custom Appearance ComboBox
                return RowComboBoxPanel.class;
            } else if (col == LITCOL) {
                return Boolean.class;
            } else if (col == HELDCOL) {
                return Boolean.class;
            } else if (col == EDITCOL) {
                return JButton.class;
            } else {
                return super.getColumnClass(col);
            }
        }

        @Override
        public int getPreferredWidth(int col) {
            if (col == LITCOL) {
                return new JTextField(4).getPreferredSize().width;
            } else if (col == HELDCOL) {
                return new JTextField(4).getPreferredSize().width;
            } else if (col == EDITCOL) {
                return new JTextField(7).getPreferredSize().width;
            } else {
                return super.getPreferredWidth(col);
            }
        }

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

        @Override
        public Object getValueAt(int row, int col) {
            // some error checking
            if (row >= sysNameList.size()) {
                log.debug("row is greater than name list");
                return "error";
            }
            String name = sysNameList.get(row);
            SignalHead s = InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(name);
            if (s == null) {
                // if due to race condition, the device is going away
                return Boolean.valueOf(false);
            }
            if (col == LITCOL) {
                boolean val = s.getLit();
                return Boolean.valueOf(val);
            } else if (col == HELDCOL) {
                boolean val = s.getHeld();
                return Boolean.valueOf(val);
            } else if (col == EDITCOL) {
                return Bundle.getMessage("ButtonEdit");
            } else if (col == VALUECOL) {
                try {
                    return s.getAppearanceName();
                } catch (java.lang.NullPointerException e) {
                    //Appearance (head) not set
                    log.debug("Appearance for head {} not set", row);
                    // use place holder string in table
                    return Bundle.getMessage("BeanStateUnknown");
                }
            } else {
                return super.getValueAt(row, col);
            }
        }

        @Override
        public void setValueAt(Object value, int row, int col) {
            String name = sysNameList.get(row);
            SignalHead s = InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(name);
            if (s == null) {
                // device is going away anyway
                return;
            }
            if (col == VALUECOL) {
                if ((String) value != null) {
                    //row = table.convertRowIndexToModel(row); // find the right row in model instead of table (not needed here)
                    log.debug("SignalHead setValueAt (rowConverted={}; value={})", row, value);
                    // convert from String (selected item) to int
                    int newState = 99;
                    // Array of valid appearance names
                    String[] stateNameList = s.getValidStateNames();
                    // Array of valid appearance numbers
                    int[] validStateList = s.getValidStates();
                    for (int i = 0; i < stateNameList.length; i++) {
                        if (value.equals(stateNameList[i])) {
                            newState = validStateList[i];
                            break;
                        }
                    }
                    if (newState == 99) {
                        if (stateNameList.length == 0) {
                            newState = SignalHead.DARK;
                            log.warn("New signal state not found so setting to Dark " + s.getDisplayName());
                        } else {
                            newState = validStateList[0];
                            log.warn("New signal state not found so setting to the first available " + s.getDisplayName());
                        }
                    }
                    if (log.isDebugEnabled()) {
                        String oldAppearanceName = s.getAppearanceName();
                        log.debug("Signal Head set from: {} to: {} [{}]", oldAppearanceName, value, newState);
                    }
                    s.setAppearance(newState);
                    fireTableRowsUpdated(row, row);
                }
            } else if (col == LITCOL) {
                boolean b = ((Boolean) value).booleanValue();
                s.setLit(b);
            } else if (col == HELDCOL) {
                boolean b = ((Boolean) value).booleanValue();
                s.setHeld(b);
            } else if (col == EDITCOL) {
                // button clicked - edit
                editSignal(row);
            } else {
                super.setValueAt(value, row, col);
            }
        }

        @Override
        public String getValue(String name) {
            SignalHead s = InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(name);
            if (s == null) {
                // if due to race condition, the device is going away
                return "<lost>";
            }
            String val = null;
            try {
                val = s.getAppearanceName();
            } catch (java.lang.ArrayIndexOutOfBoundsException e) {
                log.error(e.getLocalizedMessage(), e);
            }
            if (val != null) {
                return val;
            } else {
                return "Unexpected null value";
            }
        }

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

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

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

        /*public int getDisplayDeleteMsg() { return InstanceManager.getDefault(jmri.UserPreferencesManager.class).getMultipleChoiceOption(getClassName(),"delete"); }
             public void setDisplayDeleteMsg(int boo) { InstanceManager.getDefault(jmri.UserPreferencesManager.class).setMultipleChoiceOption(getClassName(), "delete", boo); }*/
        @Override
        protected String getMasterClassName() {
            return getClassName();
        }

        // no longer used since 4.7.1, but have to override
        @Deprecated
        @Override
        public void clickOn(NamedBean t) {
            int oldState = ((SignalHead) t).getAppearance();
            int newState = 99;
            // getValidAppearances((String)
            int[] stateList = ((SignalHead) t).getValidStates();
            for (int i = 0; i < stateList.length; i++) {
                if (oldState == stateList[i]) {
                    if (i < stateList.length - 1) {
                        newState = stateList[i + 1];
                        break;
                    } else {
                        newState = stateList[0];
                        break;
                    }
                }
            }
            if (newState == 99) {
                if (stateList.length == 0) {
                    newState = SignalHead.DARK;
                    log.warn("New signal state not found so setting to Dark " + t.getDisplayName());
                } else {
                    newState = stateList[0];
                    log.warn("New signal state not found so setting to the first available " + t.getDisplayName());
                }
            }
            log.debug("was " + oldState + " becomes " + newState);
            ((SignalHead) t).setAppearance(newState);
        }

        /**
             * Set column width.
             * @return a button to fit inside the VALUE column
             */
        @Override
        public JButton configureButton() {
            // pick a large size
            // about the longest Appearance string
            JButton b = new JButton(Bundle.getMessage("SignalHeadStateYellow"));
            b.putClientProperty("JComponent.sizeVariant", "small");
            b.putClientProperty("JButton.buttonType", "square");
            return b;
        }

        @Override
        public boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
            if (e.getPropertyName().indexOf("Lit") >= 0 || e.getPropertyName().indexOf("Held") >= 0 || e.getPropertyName().indexOf("ValidStatesChanged") >= 0) {
                return true;
            } else {
                return super.matchPropertyName(e);
            }
        }

        @Override
        protected String getBeanType() {
            return Bundle.getMessage("BeanNameSignalHead");
        }

        /**
             * Respond to change from bean. Prevent Appearance change when Signal Head is set to Hold or Unlit.
             * @param e A property change of any bean
             */
        @Override
        public // At present, does not work/change when head Lit/Held checkboxes are (de)activated
        void propertyChange(java.beans.PropertyChangeEvent e) {
            if (e.getPropertyName().indexOf("Lit") < 0 || e.getPropertyName().indexOf("Held") >= 0 || e.getPropertyName().indexOf("ValidStatesChanged") >= 0) {
                if (e.getSource() instanceof NamedBean) {
                    String name = ((NamedBean) e.getSource()).getSystemName();
                    if (log.isDebugEnabled()) {
                        log.debug("Update cell {}, {} for {}", sysNameList.indexOf(name), VALUECOL, name);
                    }
                    // since we can add columns, the entire row is marked as updated
                    int row = sysNameList.indexOf(name);
                    this.fireTableRowsUpdated(row, row);
                    // activate this method below
                    clearAppearanceVector(row);
                }
            }
            super.propertyChange(e);
        }

        /**
             * Customize the SignalHead Value (Appearance) column to show an appropriate ComboBox of available Appearances
             * when the TableDataModel is being called from ListedTableAction.
             * @param table a JTable of Signal Head
             */
        @Override
        protected void configValueColumn(JTable table) {
            // have the value column hold a JPanel with a JComboBox for Appearances
            setColumnToHoldButton(table, VALUECOL, configureButton());
            // add extras, override BeanTableDataModel
            log.debug("Head configValueColumn (I am {})", super.toString());
            table.setDefaultEditor(RowComboBoxPanel.class, new AppearanceComboBoxPanel());
            // use same class for the renderer
            table.setDefaultRenderer(RowComboBoxPanel.class, new AppearanceComboBoxPanel());
        // Set more things?
        }

        /**
             * A row specific Appearance combobox cell editor/renderer.
             */
        class AppearanceComboBoxPanel extends RowComboBoxPanel {

            @Override
            protected final void eventEditorMousePressed() {
                // add editorBox to JPanel
                this.editor.add(getEditorBox(table.convertRowIndexToModel(this.currentRow)));
                this.editor.revalidate();
                SwingUtilities.invokeLater(this.comboBoxFocusRequester);
                log.debug("eventEditorMousePressed in row: {})", this.currentRow);
            }

            /**
                 * Call the method in the surrounding method for the SignalHeadTable.
                 * @param row the user clicked on in the table
                 * @return an appropriate combobox for this signal head
                 */
            @Override
            protected JComboBox getEditorBox(int row) {
                return getAppearanceEditorBox(row);
            }
        }

        // Methods to display VALUECOL (appearance) ComboBox in the Signal Head Table
        // Derived from the SignalMastJTable class (deprecated since 4.5.5):
        // All row values are in terms of the Model, not the Table as displayed.
        /**
             * Clear the old appearance comboboxes and force them to be rebuilt.
             * Used with the Single Output Signal Head to capture reconguration.
             * @param row Index of the signal mast (in TableDataModel) to be rebuilt in the Hashtables
             */
        public void clearAppearanceVector(int row) {
            boxMap.remove(this.getValueAt(row, SYSNAMECOL));
            editorMap.remove(this.getValueAt(row, SYSNAMECOL));
        }

        // Hashtables for Editors; not used for Renderer)
        /**
             * Provide a JComboBox element to display inside the JPanel CellEditor.
             * When not yet present, create, store and return a new one.
             * @param row Index number (in TableDataModel)
             * @return A combobox containing the valid appearance names for this mast
             */
        public JComboBox getAppearanceEditorBox(int row) {
            JComboBox editCombo = editorMap.get(this.getValueAt(row, SYSNAMECOL));
            if (editCombo == null) {
                // create a new one with correct appearances
                editCombo = new JComboBox<String>(getRowVector(row));
                editorMap.put(this.getValueAt(row, SYSNAMECOL), editCombo);
            }
            return editCombo;
        }

        Hashtable<Object, JComboBox> editorMap = new Hashtable<Object, JComboBox>();

        /**
             * returns a list of all the valid appearances that have not been disabled
             * @param head the name of the signal head
             * @return List of valid signal head appearance names
             */
        public Vector<String> getValidAppearances(String head) {
            // convert String[] validStateNames to Vector
            String[] app = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(head).getValidStateNames();
            Vector<String> v = new Vector<String>();
            for (int i = 0; i < app.length; i++) {
                String appearance = app[i];
                v.add(appearance);
            }
            return v;
        }

        /**
             * Holds a Hashtable of valid appearances per signal head,
             * used by getEditorBox()
             * @param row Index number (in TableDataModel)
             * @return The Vector of valid appearance names for this mast to show in the JComboBox
             */
        Vector<String> getRowVector(int row) {
            Vector<String> comboappearances = boxMap.get(this.getValueAt(row, SYSNAMECOL));
            if (comboappearances == null) {
                // create a new one with right appearance
                Vector<String> v = getValidAppearances((String) this.getValueAt(row, SYSNAMECOL));
                comboappearances = v;
                boxMap.put(this.getValueAt(row, SYSNAMECOL), comboappearances);
            }
            return comboappearances;
        }

        Hashtable<Object, Vector<String>> boxMap = new Hashtable<Object, Vector<String>>();
    };
}
Also used : NamedBean(jmri.NamedBean) JButton(javax.swing.JButton) QuadOutputSignalHead(jmri.implementation.QuadOutputSignalHead) DccSignalHead(jmri.implementation.DccSignalHead) DoubleTurnoutSignalHead(jmri.implementation.DoubleTurnoutSignalHead) TripleTurnoutSignalHead(jmri.implementation.TripleTurnoutSignalHead) SignalHead(jmri.SignalHead) SingleTurnoutSignalHead(jmri.implementation.SingleTurnoutSignalHead) TripleOutputSignalHead(jmri.implementation.TripleOutputSignalHead) JTextField(javax.swing.JTextField) InstanceManager(jmri.InstanceManager) Manager(jmri.Manager) Vector(java.util.Vector) JComboBox(javax.swing.JComboBox) Hashtable(java.util.Hashtable) JTable(javax.swing.JTable)

Example 12 with Manager

use of jmri.Manager in project JMRI by JMRI.

the class SignalGroupTableAction method createModel.

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

        public static final int COMMENTCOL = 2;

        public static final int DELETECOL = 3;

        public static final int ENABLECOL = 4;

        // default name: SETCOL
        public static final int EDITCOL = 5;

        @Override
        public int getColumnCount() {
            return 6;
        }

        @Override
        public String getColumnName(int col) {
            if (col == EDITCOL) {
                // no heading on "Edit" column
                return "";
            }
            if (col == ENABLECOL) {
                return Bundle.getMessage("ColumnHeadEnabled");
            }
            if (col == COMMENTCOL) {
                return Bundle.getMessage("ColumnComment");
            }
            if (col == DELETECOL) {
                return "";
            } else {
                return super.getColumnName(col);
            }
        }

        @Override
        public Class<?> getColumnClass(int col) {
            if (col == EDITCOL) {
                return JButton.class;
            }
            if (col == ENABLECOL) {
                return Boolean.class;
            }
            if (col == DELETECOL) {
                return JButton.class;
            }
            if (col == COMMENTCOL) {
                return String.class;
            } else {
                return super.getColumnClass(col);
            }
        }

        @Override
        public int getPreferredWidth(int col) {
            if (col == EDITCOL) {
                return new JTextField(Bundle.getMessage("ButtonEdit")).getPreferredSize().width;
            }
            if (col == ENABLECOL) {
                return new JTextField(6).getPreferredSize().width;
            }
            if (col == COMMENTCOL) {
                return new JTextField(30).getPreferredSize().width;
            }
            if (col == DELETECOL) {
                return new JTextField(Bundle.getMessage("ButtonDelete")).getPreferredSize().width;
            } else {
                return super.getPreferredWidth(col);
            }
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            if (col == COMMENTCOL) {
                return true;
            }
            if (col == EDITCOL) {
                return true;
            }
            if (col == ENABLECOL) {
                return true;
            }
            if (col == DELETECOL) {
                return true;
            } else {
                return super.isCellEditable(row, col);
            }
        }

        @Override
        public Object getValueAt(int row, int col) {
            NamedBean b;
            if (col == EDITCOL) {
                return Bundle.getMessage("ButtonEdit");
            } else if (col == ENABLECOL) {
                return Boolean.valueOf(((SignalGroup) getBySystemName((String) getValueAt(row, SYSNAMECOL))).getEnabled());
            //return true;
            } else if (col == COMMENTCOL) {
                b = getBySystemName(sysNameList.get(row));
                return (b != null) ? b.getComment() : null;
            } else if (//
            col == DELETECOL) {
                return Bundle.getMessage("ButtonDelete");
            } else {
                return super.getValueAt(row, col);
            }
        }

        @Override
        public void setValueAt(Object value, int row, int col) {
            if (col == EDITCOL) {
                // set up to Edit. Use separate Runnable so window is created on top
                class WindowMaker implements Runnable {

                    int row;

                    WindowMaker(int r) {
                        row = r;
                    }

                    @Override
                    public void run() {
                        // set up add/edit panel addFrame (starts as Add pane)
                        addPressed(null);
                        _systemName.setText((String) getValueAt(row, SYSNAMECOL));
                        // adjust addFrame for Edit
                        editPressed(null);
                    }
                }
                WindowMaker t = new WindowMaker(row);
                javax.swing.SwingUtilities.invokeLater(t);
            } else if (col == ENABLECOL) {
                // alternate
                SignalGroup r = (SignalGroup) getBySystemName((String) getValueAt(row, SYSNAMECOL));
                boolean v = r.getEnabled();
                r.setEnabled(!v);
            } else if (col == COMMENTCOL) {
                getBySystemName(sysNameList.get(row)).setComment((String) value);
                fireTableRowsUpdated(row, row);
            } else if (col == DELETECOL) {
                // button fired, delete Bean
                deleteBean(row, col);
            } else {
                super.setValueAt(value, row, col);
            }
        }

        @Override
        public void configureTable(JTable table) {
            table.setDefaultRenderer(Boolean.class, new EnablingCheckboxRenderer());
            table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
            table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
            super.configureTable(table);
        }

        @Override
        protected void configDeleteColumn(JTable table) {
            // have the delete column hold a button
            SignalGroupTableAction.this.setColumnToHoldButton(table, DELETECOL, new JButton(Bundle.getMessage("ButtonDelete")));
        }

        /**
             * Delete the bean after all the checking has been done.
             * <P>
             * (Deactivate the Signal Group), then use the superclass to delete it.
             */
        @Override
        void doDelete(NamedBean bean) {
            //((SignalGroup)bean).deActivateSignalGroup();
            super.doDelete(bean);
        }

        // want to update when enabled parameter changes
        @Override
        protected boolean matchPropertyName(java.beans.PropertyChangeEvent e) {
            if (e.getPropertyName().equals("Enabled")) {
                return true;
            } else {
                return super.matchPropertyName(e);
            }
        }

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

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

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

        @Override
        public int getDisplayDeleteMsg() {
            return 0x00;
        /*return InstanceManager.getDefault(jmri.UserPreferencesManager.class).getWarnDeleteSignalGroup();*/
        }

        @Override
        public void setDisplayDeleteMsg(int boo) {
        /*InstanceManager.getDefault(jmri.UserPreferencesManager.class).setWarnDeleteSignalGroup(boo); */
        }

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

        @Override
        public void clickOn(NamedBean t) {
        // mute action
        //((SignalGroup)t).setSignalGroup();
        }

        @Override
        public String getValue(String s) {
            // not directly used but should be present to implement abstract class
            return "Set";
        }

        /*            public JButton configureButton() {
                return new JButton(" Set ");
            }*/
        @Override
        protected String getBeanType() {
            return "Signal Group";
        }
    };
}
Also used : SignalGroup(jmri.SignalGroup) NamedBean(jmri.NamedBean) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) InstanceManager(jmri.InstanceManager) Manager(jmri.Manager) JTable(javax.swing.JTable)

Example 13 with Manager

use of jmri.Manager in project JMRI by JMRI.

the class ReporterTableAction method canAddRange.

private void canAddRange(ActionEvent e) {
    range.setEnabled(false);
    range.setSelected(false);
    if (reportManager.getClass().getName().contains("ProxyReporterManager")) {
        jmri.managers.ProxyReporterManager proxy = (jmri.managers.ProxyReporterManager) reportManager;
        List<Manager> managerList = proxy.getManagerList();
        String systemPrefix = ConnectionNameFromSystemName.getPrefixFromName((String) prefixBox.getSelectedItem());
        for (int x = 0; x < managerList.size(); x++) {
            jmri.ReporterManager mgr = (jmri.ReporterManager) managerList.get(x);
            if (mgr.getSystemPrefix().equals(systemPrefix) && mgr.allowMultipleAdditions(systemPrefix)) {
                range.setEnabled(true);
                return;
            }
        }
    } else if (reportManager.allowMultipleAdditions(ConnectionNameFromSystemName.getPrefixFromName((String) prefixBox.getSelectedItem()))) {
        range.setEnabled(true);
    }
}
Also used : ReporterManager(jmri.ReporterManager) ReporterManager(jmri.ReporterManager) InstanceManager(jmri.InstanceManager) Manager(jmri.Manager) ReporterManager(jmri.ReporterManager)

Example 14 with Manager

use of jmri.Manager in project JMRI by JMRI.

the class ReporterTableAction method addPressed.

@Override
protected void addPressed(ActionEvent e) {
    pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
    if (addFrame == null) {
        addFrame = new JmriJFrame(Bundle.getMessage("TitleAddReporter"), false, true);
        addFrame.addHelpMenu("package.jmri.jmrit.beantable.ReporterAddEdit", true);
        ActionListener okListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                okPressed(e);
            }
        };
        ActionListener cancelListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancelPressed(e);
            }
        };
        ActionListener rangeListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                canAddRange(e);
            }
        };
        if (reportManager.getClass().getName().contains("ProxyReporterManager")) {
            jmri.managers.ProxyReporterManager proxy = (jmri.managers.ProxyReporterManager) reportManager;
            List<Manager> managerList = proxy.getManagerList();
            for (int x = 0; x < managerList.size(); x++) {
                String manuName = ConnectionNameFromSystemName.getConnectionName(managerList.get(x).getSystemPrefix());
                Boolean addToPrefix = true;
                //Simple test not to add a system with a duplicate System prefix
                for (int i = 0; i < prefixBox.getItemCount(); i++) {
                    if ((prefixBox.getItemAt(i)).equals(manuName)) {
                        addToPrefix = false;
                    }
                }
                if (addToPrefix) {
                    prefixBox.addItem(manuName);
                }
            }
            if (pref.getComboBoxLastSelection(systemSelectionCombo) != null) {
                prefixBox.setSelectedItem(pref.getComboBoxLastSelection(systemSelectionCombo));
            }
        } else {
            prefixBox.addItem(ConnectionNameFromSystemName.getConnectionName(reportManager.getSystemPrefix()));
        }
        sysName.setName("sysName");
        userName.setName("userName");
        prefixBox.setName("prefixBox");
        addFrame.add(new AddNewHardwareDevicePanel(sysName, userName, prefixBox, numberToAdd, range, "ButtonOK", okListener, cancelListener, rangeListener));
        canAddRange(null);
    }
    addFrame.pack();
    addFrame.setVisible(true);
}
Also used : ActionEvent(java.awt.event.ActionEvent) InstanceManager(jmri.InstanceManager) Manager(jmri.Manager) ReporterManager(jmri.ReporterManager) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame)

Example 15 with Manager

use of jmri.Manager 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

Manager (jmri.Manager)16 InstanceManager (jmri.InstanceManager)12 JTable (javax.swing.JTable)9 JTextField (javax.swing.JTextField)9 NamedBean (jmri.NamedBean)9 JButton (javax.swing.JButton)6 JComboBox (javax.swing.JComboBox)6 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)5 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 MouseEvent (java.awt.event.MouseEvent)4 SensorManager (jmri.SensorManager)4 TurnoutManager (jmri.TurnoutManager)4 Image (java.awt.Image)3 MouseAdapter (java.awt.event.MouseAdapter)3 BufferedImage (java.awt.image.BufferedImage)3 File (java.io.File)3 IOException (java.io.IOException)3 AbstractCellEditor (javax.swing.AbstractCellEditor)3 ImageIcon (javax.swing.ImageIcon)3