Search in sources :

Example 11 with SystemNameComparator

use of jmri.util.SystemNameComparator in project JMRI by JMRI.

the class SignallingPanel method buildSignalMastPanel.

/**
     * Compose GUI for setting up the Signal Masts tab for an SML.
     *
     * @return a JPanel containing the SML control signal masts configuration interface
     */
JPanel buildSignalMastPanel() {
    JPanel SignalMastPanel = new JPanel();
    SignalMastPanel.setLayout(new BoxLayout(SignalMastPanel, BoxLayout.Y_AXIS));
    jmri.SignalMastManager bm = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class);
    List<String> systemNameList = bm.getSystemNameList();
    _manualSignalMastList = new ArrayList<ManualSignalMastList>(systemNameList.size());
    Iterator<String> iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        _manualSignalMastList.add(new ManualSignalMastList(bm.getBySystemName(systemName)));
    }
    p2xm = new JPanel();
    JPanel p2xmSpace = new JPanel();
    p2xmSpace.setLayout(new BoxLayout(p2xmSpace, BoxLayout.Y_AXIS));
    p2xmSpace.add(new JLabel("XXX"));
    p2xm.add(p2xmSpace);
    JPanel p21c = new JPanel();
    p21c.setLayout(new BoxLayout(p21c, BoxLayout.Y_AXIS));
    p21c.add(new JLabel(Bundle.getMessage("LabelSelectChecked", Bundle.getMessage("SignalMasts"))));
    p2xm.add(p21c);
    _signalMastModel = new SignalMastModel();
    TableRowSorter<SignalMastModel> sorter = new TableRowSorter<>(_signalMastModel);
    // don't use makeTable() since 4.7.1
    JTable manualSignalMastTable = new JTable(_signalMastModel);
    // configure (extra) row height for comboBox
    manualSignalMastTable.setRowHeight(Sizer.getPreferredSize().height - 2);
    // row height has to be greater than plain tables to properly show comboBox shape, but tightened a bit over preferred
    // create mast (row) specific comboBox in Aspect column
    _signalMastModel.configStateColumn(manualSignalMastTable);
    manualSignalMastTable.setRowSorter(sorter);
    manualSignalMastTable.setRowSelectionAllowed(false);
    manualSignalMastTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    TableColumnModel _manualSignalMastColumnModel = manualSignalMastTable.getColumnModel();
    TableColumn includeColumnC = _manualSignalMastColumnModel.getColumn(SignalMastModel.INCLUDE_COLUMN);
    includeColumnC.setResizable(false);
    // was fixed 60
    includeColumnC.setMinWidth(9 * Bundle.getMessage("Include").length());
    includeColumnC.setMaxWidth(includeColumnC.getMinWidth() + 5);
    TableColumn sNameColumnC = _manualSignalMastColumnModel.getColumn(SignalMastModel.SNAME_COLUMN);
    sNameColumnC.setResizable(true);
    sNameColumnC.setMinWidth(75);
    sNameColumnC.setMaxWidth(95);
    TableColumn stateColumnC = _manualSignalMastColumnModel.getColumn(SensorModel.STATE_COLUMN);
    stateColumnC.setResizable(false);
    stateColumnC.setMinWidth(9 * ("Diverging Approach Medium").length() + 20);
    // was fixed 100
    stateColumnC.setMaxWidth(stateColumnC.getMinWidth() + 10);
    // remaining space is filled by UserName
    _manualSignalMastScrollPane = new JScrollPane(manualSignalMastTable);
    p2xm.add(_manualSignalMastScrollPane, BorderLayout.CENTER);
    SignalMastPanel.add(p2xm);
    p2xm.setVisible(true);
    ROW_HEIGHT = manualSignalMastTable.getRowHeight();
    p2xmSpace.setVisible(false);
    JPanel p2xaSpace = new JPanel();
    p2xaSpace.setLayout(new BoxLayout(p2xaSpace, BoxLayout.Y_AXIS));
    p2xaSpace.add(new JLabel("XXX"));
    p2xsm.add(p2xaSpace);
    JPanel p21a = new JPanel();
    p21a.setLayout(new BoxLayout(p21a, BoxLayout.Y_AXIS));
    p21a.add(new JLabel(Bundle.getMessage("LabelAutogenerated", Bundle.getMessage("SignalMasts"))));
    p2xsm.add(p21a);
    _autoSignalMastModel = new AutoMastModel();
    JTable autoMastTable = new JTable(_autoSignalMastModel);
    TableRowSorter<AutoMastModel> autoMastSorter = new TableRowSorter<>(_autoSignalMastModel);
    autoMastSorter.setComparator(AutoMastModel.SNAME_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(autoMastSorter, AutoMastModel.SNAME_COLUMN, SortOrder.ASCENDING);
    autoMastTable.setRowSorter(autoMastSorter);
    autoMastTable.setRowSelectionAllowed(false);
    autoMastTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    TableColumnModel _autoMastColumnModel = autoMastTable.getColumnModel();
    TableColumn sNameColumnA = _autoMastColumnModel.getColumn(AutoMastModel.SNAME_COLUMN);
    sNameColumnA.setResizable(true);
    sNameColumnA.setMinWidth(75);
    sNameColumnA.setMaxWidth(95);
    TableColumn stateColumnA = _autoMastColumnModel.getColumn(AutoMastModel.STATE_COLUMN);
    stateColumnA.setResizable(false);
    stateColumnA.setMinWidth(90);
    stateColumnA.setMaxWidth(100);
    _autoSignalMastScrollPane = new JScrollPane(autoMastTable);
    p2xsm.add(_autoSignalMastScrollPane, BorderLayout.CENTER);
    SignalMastPanel.add(p2xsm);
    p2xsm.setVisible(true);
    ROW_HEIGHT = autoMastTable.getRowHeight();
    p2xaSpace.setVisible(false);
    return SignalMastPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) SignalMastModel(jmri.jmrit.signalling.SignallingPanel.SignalMastModel) JTable(javax.swing.JTable) SystemNameComparator(jmri.util.SystemNameComparator) SignalMastManager(jmri.SignalMastManager) TableRowSorter(javax.swing.table.TableRowSorter)

Example 12 with SystemNameComparator

use of jmri.util.SystemNameComparator in project JMRI by JMRI.

the class SignallingPanel method buildTurnoutPanel.

/**
     * Compose GUI for setting up the Turnouts tab for an SML.
     *
     * @return a JPanel containing the SML control turnouts configuration interface
     */
JPanel buildTurnoutPanel() {
    JPanel turnoutPanel = new JPanel();
    turnoutPanel.setLayout(new BoxLayout(turnoutPanel, BoxLayout.Y_AXIS));
    jmri.TurnoutManager bm = jmri.InstanceManager.turnoutManagerInstance();
    List<String> systemNameList = bm.getSystemNameList();
    _manualTurnoutList = new ArrayList<ManualTurnoutList>(systemNameList.size());
    Iterator<String> iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        String userName = bm.getBySystemName(systemName).getUserName();
        _manualTurnoutList.add(new ManualTurnoutList(systemName, userName));
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Turnout> turnList = sml.getAutoTurnouts(destMast);
        _automaticTurnoutList = new ArrayList<AutoTurnoutList>(turnList.size());
        Iterator<Turnout> iterTurn = turnList.iterator();
        while (iterTurn.hasNext()) {
            Turnout turn = iterTurn.next();
            String systemName = turn.getSystemName();
            String userName = turn.getUserName();
            AutoTurnoutList turnitem = new AutoTurnoutList(systemName, userName);
            turnitem.setState(sml.getAutoTurnoutState(turn, destMast));
            _automaticTurnoutList.add(turnitem);
        }
    }
    p2xt = new JPanel();
    JPanel p2xcSpace = new JPanel();
    p2xcSpace.setLayout(new BoxLayout(p2xcSpace, BoxLayout.Y_AXIS));
    p2xcSpace.add(new JLabel("XXX"));
    p2xt.add(p2xcSpace);
    JPanel p21c = new JPanel();
    p21c.setLayout(new BoxLayout(p21c, BoxLayout.Y_AXIS));
    p21c.add(new JLabel(Bundle.getMessage("LabelSelectChecked", Bundle.getMessage("Turnouts"))));
    p2xt.add(p21c);
    _turnoutModel = new TurnoutModel();
    JTable manualTurnoutTable = new JTable(_turnoutModel);
    TableRowSorter<TurnoutModel> manualTurnoutSorter = new TableRowSorter<>(_turnoutModel);
    // configure row height for comboBox
    // row height has to be greater than for plain tables
    manualTurnoutTable.setRowHeight(Sizer.getPreferredSize().height - 2);
    manualTurnoutSorter.setComparator(TurnoutModel.SNAME_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(manualTurnoutSorter, TurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
    // create static comboBox in State column
    _turnoutModel.configStateColumn(manualTurnoutTable);
    manualTurnoutTable.setRowSorter(manualTurnoutSorter);
    manualTurnoutTable.setRowSelectionAllowed(false);
    manualTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    // JComboBox<String> stateCCombo = new JComboBox<>(); // moved to ManualTurnoutTable class
    TableColumnModel _manualTurnoutColumnModel = manualTurnoutTable.getColumnModel();
    TableColumn includeColumnC = _manualTurnoutColumnModel.getColumn(TurnoutModel.INCLUDE_COLUMN);
    includeColumnC.setResizable(false);
    // was fixed 60
    includeColumnC.setMinWidth(9 * Bundle.getMessage("Include").length());
    includeColumnC.setMaxWidth(includeColumnC.getMinWidth() + 5);
    TableColumn sNameColumnC = _manualTurnoutColumnModel.getColumn(TurnoutModel.SNAME_COLUMN);
    sNameColumnC.setResizable(true);
    sNameColumnC.setMinWidth(75);
    sNameColumnC.setMaxWidth(95);
    TableColumn stateColumnC = _manualTurnoutColumnModel.getColumn(TurnoutModel.STATE_COLUMN);
    // stateColumnC.setCellEditor(new DefaultCellEditor(stateCCombo)); // moved to ManualTurnoutTable class
    stateColumnC.setResizable(false);
    log.debug("L = " + SET_TO_ANY.length());
    stateColumnC.setMinWidth(9 * Math.max(SET_TO_ANY.length(), SET_TO_CLOSED.length()) + 30);
    // was fixed 100
    stateColumnC.setMaxWidth(stateColumnC.getMinWidth() + 10);
    // remaining space is filled by UserName
    _manualTurnoutScrollPane = new JScrollPane(manualTurnoutTable);
    p2xt.add(_manualTurnoutScrollPane, BorderLayout.CENTER);
    turnoutPanel.add(p2xt);
    p2xt.setVisible(true);
    ROW_HEIGHT = manualTurnoutTable.getRowHeight();
    p2xcSpace.setVisible(false);
    JPanel p2xaSpace = new JPanel();
    p2xaSpace.setLayout(new BoxLayout(p2xaSpace, BoxLayout.Y_AXIS));
    p2xaSpace.add(new JLabel("XXX"));
    p2xa.add(p2xaSpace);
    JPanel p21a = new JPanel();
    p21a.setLayout(new BoxLayout(p21a, BoxLayout.Y_AXIS));
    p21a.add(new JLabel(Bundle.getMessage("LabelAutogenerated", Bundle.getMessage("Turnouts"))));
    p2xa.add(p21a);
    _autoTurnoutModel = new AutoTurnoutModel();
    JTable autoTurnoutTable = new JTable(_autoTurnoutModel);
    TableRowSorter<AutoTurnoutModel> autoTurnoutSorter = new TableRowSorter<>(_autoTurnoutModel);
    autoTurnoutSorter.setComparator(AutoTurnoutModel.SNAME_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(autoTurnoutSorter, AutoTurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
    autoTurnoutTable.setRowSorter(autoTurnoutSorter);
    autoTurnoutTable.setRowSelectionAllowed(false);
    autoTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    TableColumnModel _autoTurnoutColumnModel = autoTurnoutTable.getColumnModel();
    TableColumn sNameColumnA = _autoTurnoutColumnModel.getColumn(AutoTurnoutModel.SNAME_COLUMN);
    sNameColumnA.setResizable(true);
    sNameColumnA.setMinWidth(75);
    sNameColumnA.setMaxWidth(95);
    TableColumn stateColumnA = _autoTurnoutColumnModel.getColumn(AutoTurnoutModel.STATE_COLUMN);
    stateColumnA.setResizable(false);
    stateColumnA.setMinWidth(90);
    stateColumnA.setMaxWidth(100);
    _autoTurnoutScrollPane = new JScrollPane(autoTurnoutTable);
    p2xa.add(_autoTurnoutScrollPane, BorderLayout.CENTER);
    turnoutPanel.add(p2xa);
    p2xa.setVisible(true);
    ROW_HEIGHT = autoTurnoutTable.getRowHeight();
    p2xaSpace.setVisible(false);
    return turnoutPanel;
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) TableColumnModel(javax.swing.table.TableColumnModel) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) JTable(javax.swing.JTable) SystemNameComparator(jmri.util.SystemNameComparator) Turnout(jmri.Turnout)

Example 13 with SystemNameComparator

use of jmri.util.SystemNameComparator in project JMRI by JMRI.

the class SignallingPanel method buildSensorPanel.

/**
     * Compose GUI for setting up the Sensors tab for an SML.
     *
     * @return a JPanel containing the SML control sensors configuration interface
     */
JPanel buildSensorPanel() {
    JPanel sensorPanel = new JPanel();
    sensorPanel.setLayout(new BoxLayout(sensorPanel, BoxLayout.Y_AXIS));
    jmri.SensorManager bm = jmri.InstanceManager.sensorManagerInstance();
    List<String> systemNameList = bm.getSystemNameList();
    _manualSensorList = new ArrayList<ManualSensorList>(systemNameList.size());
    Iterator<String> iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        Sensor ss = bm.getBySystemName(systemName);
        if (ss != null) {
            String userName = ss.getUserName();
            _manualSensorList.add(new ManualSensorList(systemName, userName));
        } else {
            log.error("Failed to get sensor {}", systemName);
        }
    }
    p2xs = new JPanel();
    JPanel p2xsSpace = new JPanel();
    p2xsSpace.setLayout(new BoxLayout(p2xsSpace, BoxLayout.Y_AXIS));
    p2xsSpace.add(new JLabel("XXX"));
    p2xs.add(p2xsSpace);
    JPanel p21c = new JPanel();
    p21c.setLayout(new BoxLayout(p21c, BoxLayout.Y_AXIS));
    p21c.add(new JLabel(Bundle.getMessage("LabelSelectChecked", Bundle.getMessage("Sensors"))));
    p2xs.add(p21c);
    _sensorModel = new SensorModel();
    JTable manualSensorTable = new JTable(_sensorModel);
    TableRowSorter<SensorModel> manualSensorSorter = new TableRowSorter<>(_sensorModel);
    // configure row height for comboBox
    // row height has to be greater than for plain tables
    manualSensorTable.setRowHeight(Sizer.getPreferredSize().height - 2);
    manualSensorSorter.setComparator(SensorModel.SNAME_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(manualSensorSorter, SensorModel.SNAME_COLUMN, SortOrder.ASCENDING);
    // create static comboBox in State column
    _sensorModel.configStateColumn(manualSensorTable);
    manualSensorTable.setRowSorter(manualSensorSorter);
    manualSensorTable.setRowSelectionAllowed(false);
    manualSensorTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    //stateCCombo = new JComboBox<>(); // moved to ManualSensorTable class
    TableColumnModel _manualSensorColumnModel = manualSensorTable.getColumnModel();
    TableColumn includeColumnC = _manualSensorColumnModel.getColumn(SensorModel.INCLUDE_COLUMN);
    includeColumnC.setResizable(false);
    // was fixed 60
    includeColumnC.setMinWidth(9 * Bundle.getMessage("Include").length());
    includeColumnC.setMaxWidth(includeColumnC.getMinWidth() + 5);
    TableColumn sNameColumnC = _manualSensorColumnModel.getColumn(SensorModel.SNAME_COLUMN);
    sNameColumnC.setResizable(true);
    sNameColumnC.setMinWidth(75);
    sNameColumnC.setMaxWidth(95);
    TableColumn stateColumnC = _manualSensorColumnModel.getColumn(SensorModel.STATE_COLUMN);
    stateColumnC.setResizable(false);
    stateColumnC.setMinWidth(9 * SET_TO_INACTIVE.length() + 30);
    // was fixed 100
    stateColumnC.setMaxWidth(stateColumnC.getMinWidth() + 10);
    // remaining space is filled by UserName
    _manualSensorScrollPane = new JScrollPane(manualSensorTable);
    p2xs.add(_manualSensorScrollPane, BorderLayout.CENTER);
    sensorPanel.add(p2xs);
    p2xs.setVisible(true);
    ROW_HEIGHT = manualSensorTable.getRowHeight();
    p2xsSpace.setVisible(false);
    return sensorPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) JTable(javax.swing.JTable) SystemNameComparator(jmri.util.SystemNameComparator) TableRowSorter(javax.swing.table.TableRowSorter) Sensor(jmri.Sensor)

Aggregations

SystemNameComparator (jmri.util.SystemNameComparator)13 BoxLayout (javax.swing.BoxLayout)9 JScrollPane (javax.swing.JScrollPane)9 JTable (javax.swing.JTable)9 TableRowSorter (javax.swing.table.TableRowSorter)9 JPanel (javax.swing.JPanel)8 TableColumn (javax.swing.table.TableColumn)8 TableColumnModel (javax.swing.table.TableColumnModel)8 JLabel (javax.swing.JLabel)7 FlowLayout (java.awt.FlowLayout)3 ActionEvent (java.awt.event.ActionEvent)3 ButtonGroup (javax.swing.ButtonGroup)3 JRadioButton (javax.swing.JRadioButton)3 Border (javax.swing.border.Border)3 Sensor (jmri.Sensor)3 JmriJFrame (jmri.util.JmriJFrame)3 Container (java.awt.Container)2 ActionListener (java.awt.event.ActionListener)2 TreeSet (java.util.TreeSet)2 DefaultCellEditor (javax.swing.DefaultCellEditor)2