Search in sources :

Example 6 with SystemNameComparator

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

the class AbstractProxyManager method getSystemNameArray.

@Override
public String[] getSystemNameArray() {
    TreeSet<String> ts = new TreeSet<>(new SystemNameComparator());
    this.mgrs.stream().forEach((mgr) -> {
        ts.addAll(mgr.getSystemNameList());
    });
    return ts.toArray(new String[ts.size()]);
}
Also used : TreeSet(java.util.TreeSet) SystemNameComparator(jmri.util.SystemNameComparator)

Example 7 with SystemNameComparator

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

the class SignalGroupTableAction method addPressed.

/**
     * Respond to click on Add... button below Signal Group Table.
     * <p>
     * Create JPanel with options for configuration.
     * @param e Event from origin; null when called from Edit button in Signal Group Table row
     */
@Override
protected void addPressed(ActionEvent e) {
    if (inEditMode) {
        log.debug("Can not open another editing session for Signal Groups.");
        // add user warning that a 2nd session not allowed (cf. Logix)
        // Already editing a Signal Group, ask for completion of that edit first
        String workingTitle = _systemName.getText();
        if (workingTitle.isEmpty() || workingTitle == null) {
            workingTitle = Bundle.getMessage("NONE");
            _systemName.setText(workingTitle);
        }
        javax.swing.JOptionPane.showMessageDialog(addFrame, Bundle.getMessage("SigGroupEditBusyWarning", workingTitle), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    inEditMode = true;
    _mastAspectsList = null;
    jmri.SignalHeadManager shm = InstanceManager.getDefault(jmri.SignalHeadManager.class);
    List<String> systemNameList = shm.getSystemNameList();
    _signalHeadsList = new ArrayList<SignalGroupSignalHead>(systemNameList.size());
    // create list of all available Single Output Signal Heads to choose from
    Iterator<String> iter = systemNameList.iterator();
    // int i = 1; // for debug of iter next
    while (iter.hasNext()) {
        String systemName = iter.next();
        SignalHead sh = shm.getBySystemName(systemName);
        // debug using i & sysnamelist.size
        if (sh != null) {
            if (sh.getClass().getName().contains("SingleTurnoutSignalHead")) {
                String userName = sh.getUserName();
                // add every single output signal head item to the list
                _signalHeadsList.add(new SignalGroupSignalHead(systemName, userName));
            } else {
                log.debug("Signal Head " + systemName + " is not a Single Output Controlled Signal Head");
            }
        } else {
            // this is not an error and the value of systemName mentioned is actually from the last head that was indeed loaded
            log.error("Failed to get signal head {} (SGTA)", systemName);
        }
    }
    // Set up Add/Edit Signal Group window
    if (addFrame == null) {
        // if it's not yet present, create addFrame
        mainSignalComboBox = new JmriBeanComboBox(jmri.InstanceManager.getDefault(jmri.SignalMastManager.class), null, JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
        // causes NPE when user selects that 1st line, so do not respond to result null
        mainSignalComboBox.setFirstItemBlank(true);
        addFrame = new JmriJFrame(Bundle.getMessage("AddSignalGroup"), false, true);
        addFrame.addHelpMenu("package.jmri.jmrit.beantable.SignalGroupAddEdit", true);
        addFrame.setLocation(100, 30);
        addFrame.getContentPane().setLayout(new BoxLayout(addFrame.getContentPane(), BoxLayout.Y_AXIS));
        Container contentPane = addFrame.getContentPane();
        // add system name
        JPanel ps = new JPanel();
        ps.setLayout(new FlowLayout());
        ps.add(nameLabel);
        ps.add(_systemName);
        _systemName.setToolTipText(Bundle.getMessage("SignalGroupSysNameTooltip"));
        ps.add(fixedSystemName);
        fixedSystemName.setVisible(false);
        contentPane.add(ps);
        // add user name
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        p.add(userLabel);
        p.add(_userName);
        _userName.setToolTipText(Bundle.getMessage("SignalGroupUserNameTooltip"));
        contentPane.add(p);
        // add Signal Masts/Heads Display Choice
        JPanel py = new JPanel();
        py.add(new JLabel(Bundle.getMessage("Show")));
        selGroup = new ButtonGroup();
        allButton = new JRadioButton(Bundle.getMessage("All"), true);
        selGroup.add(allButton);
        py.add(allButton);
        allButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // Setup for display of all Signal Masts & SingleTO Heads, if needed
                if (!showAll) {
                    showAll = true;
                    _SignalGroupHeadModel.fireTableDataChanged();
                    _AspectModel.fireTableDataChanged();
                }
            }
        });
        includedButton = new JRadioButton(Bundle.getMessage("Included"), false);
        selGroup.add(includedButton);
        py.add(includedButton);
        includedButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // Setup for display of included Turnouts only, if needed
                if (showAll) {
                    showAll = false;
                    initializeIncludedList();
                    _SignalGroupHeadModel.fireTableDataChanged();
                    _AspectModel.fireTableDataChanged();
                }
            }
        });
        py.add(new JLabel("  " + Bundle.getMessage("_and_", Bundle.getMessage("LabelAspects"), Bundle.getMessage("SignalHeads"))));
        contentPane.add(py);
        // add main signal mast table
        JPanel p3 = new JPanel();
        p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
        JPanel p31 = new JPanel();
        p31.add(new JLabel(Bundle.getMessage("EnterMastAttached", Bundle.getMessage("BeanNameSignalMast"))));
        p3.add(p31);
        JPanel p32 = new JPanel();
        p32.add(new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanNameSignalMast"))));
        // comboBox to pick a main Signal Mast
        p32.add(mainSignalComboBox);
        p3.add(p32);
        p3xsi = new JPanel();
        JPanel p3xsiSpace = new JPanel();
        p3xsiSpace.setLayout(new BoxLayout(p3xsiSpace, BoxLayout.Y_AXIS));
        p3xsiSpace.add(new JLabel(" "));
        p3xsi.add(p3xsiSpace);
        JPanel p31si = new JPanel();
        p31si.setLayout(new BoxLayout(p31si, BoxLayout.Y_AXIS));
        p31si.add(new JLabel(Bundle.getMessage("SelectAppearanceTrigger")));
        p3xsi.add(p31si);
        _AspectModel = new SignalMastAspectModel();
        JTable SignalMastAspectTable = new JTable(_AspectModel);
        TableRowSorter<SignalMastAspectModel> smaSorter = new TableRowSorter<>(_AspectModel);
        smaSorter.setComparator(SignalMastAspectModel.ASPECT_COLUMN, new SystemNameComparator());
        RowSorterUtil.setSortOrder(smaSorter, SignalMastAspectModel.ASPECT_COLUMN, SortOrder.ASCENDING);
        SignalMastAspectTable.setRowSorter(smaSorter);
        SignalMastAspectTable.setRowSelectionAllowed(false);
        SignalMastAspectTable.setPreferredScrollableViewportSize(new java.awt.Dimension(200, 80));
        TableColumnModel SignalMastAspectColumnModel = SignalMastAspectTable.getColumnModel();
        TableColumn includeColumnA = SignalMastAspectColumnModel.getColumn(SignalGroupTableAction.SignalMastAspectModel.INCLUDE_COLUMN);
        includeColumnA.setResizable(false);
        includeColumnA.setMinWidth(30);
        includeColumnA.setMaxWidth(60);
        @SuppressWarnings("static-access") TableColumn sNameColumnA = SignalMastAspectColumnModel.getColumn(_AspectModel.ASPECT_COLUMN);
        sNameColumnA.setResizable(true);
        sNameColumnA.setMinWidth(75);
        sNameColumnA.setMaxWidth(140);
        _SignalAppearanceScrollPane = new JScrollPane(SignalMastAspectTable);
        p3xsi.add(_SignalAppearanceScrollPane, BorderLayout.CENTER);
        p3.add(p3xsi);
        p3xsi.setVisible(true);
        // respond to comboBox selection
        mainSignalComboBox.addActionListener(new ActionListener() {

            //public void focusGained(FocusEvent e) {
            //}
            @Override
            public void actionPerformed(ActionEvent event) {
                if (mainSignalComboBox.getSelectedBean() == null) {
                    // ie. empty first row was selected or set
                    log.debug("Empty line in mainSignal comboBox");
                //setValidSignalMastAspects(); // clears the Aspect table
                } else {
                    if (curSignalGroup == null || mainSignalComboBox.getSelectedBean() != curSignalGroup.getSignalMast()) {
                        log.debug("comboBox closed, choice: {}", mainSignalComboBox.getSelectedItem());
                        // refresh table with signal mast aspects
                        setValidSignalMastAspects();
                    } else {
                        log.debug("Mast {} picked in mainSignal comboBox", mainSignalComboBox.getSelectedItem());
                    }
                }
            }
        });
        // complete this panel
        Border p3Border = BorderFactory.createEtchedBorder();
        p3.setBorder(p3Border);
        contentPane.add(p3);
        p2xsi = new JPanel();
        JPanel p2xsiSpace = new JPanel();
        p2xsiSpace.setLayout(new BoxLayout(p2xsiSpace, BoxLayout.Y_AXIS));
        p2xsiSpace.add(new JLabel("XXX"));
        p2xsi.add(p2xsiSpace);
        JPanel p21si = new JPanel();
        p21si.setLayout(new BoxLayout(p21si, BoxLayout.Y_AXIS));
        p21si.add(new JLabel(Bundle.getMessage("SelectInGroup", Bundle.getMessage("SignalHeads"))));
        p2xsi.add(p21si);
        _SignalGroupHeadModel = new SignalGroupSignalHeadModel();
        JTable SignalGroupHeadTable = new JTable(_SignalGroupHeadModel);
        TableRowSorter<SignalGroupSignalHeadModel> sgsSorter = new TableRowSorter<>(_SignalGroupHeadModel);
        sgsSorter.setComparator(SignalGroupSignalHeadModel.SNAME_COLUMN, new SystemNameComparator());
        RowSorterUtil.setSortOrder(sgsSorter, SignalGroupSignalHeadModel.SNAME_COLUMN, SortOrder.ASCENDING);
        SignalGroupHeadTable.setRowSorter(sgsSorter);
        SignalGroupHeadTable.setRowSelectionAllowed(false);
        SignalGroupHeadTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 160));
        TableColumnModel SignalGroupSignalColumnModel = SignalGroupHeadTable.getColumnModel();
        TableColumn includeColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.INCLUDE_COLUMN);
        includeColumnSi.setResizable(false);
        includeColumnSi.setMinWidth(30);
        includeColumnSi.setMaxWidth(60);
        TableColumn sNameColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.SNAME_COLUMN);
        sNameColumnSi.setResizable(true);
        sNameColumnSi.setMinWidth(75);
        sNameColumnSi.setMaxWidth(95);
        TableColumn uNameColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.UNAME_COLUMN);
        uNameColumnSi.setResizable(true);
        uNameColumnSi.setMinWidth(100);
        uNameColumnSi.setMaxWidth(260);
        TableColumn stateOnColumnSi = SignalGroupSignalColumnModel.getColumn(// a 6 column table
        SignalGroupSignalHeadModel.STATE_ON_COLUMN);
        stateOnColumnSi.setResizable(false);
        // was 50
        stateOnColumnSi.setMinWidth(Bundle.getMessage("SignalHeadStateFlashingYellow").length());
        stateOnColumnSi.setMaxWidth(100);
        TableColumn stateOffColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.STATE_OFF_COLUMN);
        stateOffColumnSi.setResizable(false);
        stateOffColumnSi.setMinWidth(50);
        stateOffColumnSi.setMaxWidth(100);
        TableColumn editColumnSi = SignalGroupSignalColumnModel.getColumn(SignalGroupSignalHeadModel.EDIT_COLUMN);
        editColumnSi.setResizable(false);
        // was 50
        editColumnSi.setMinWidth(Bundle.getMessage("ButtonEdit").length());
        editColumnSi.setMaxWidth(100);
        JButton editButton = new JButton(Bundle.getMessage("ButtonEdit"));
        setColumnToHoldButton(SignalGroupHeadTable, SignalGroupSignalHeadModel.EDIT_COLUMN, editButton);
        _SignalGroupHeadScrollPane = new JScrollPane(SignalGroupHeadTable);
        p2xsi.add(_SignalGroupHeadScrollPane, BorderLayout.CENTER);
        // add tooltip to explain which head types are shown
        p2xsi.setToolTipText(Bundle.getMessage("SignalGroupHeadTableTooltip"));
        contentPane.add(p2xsi);
        p2xsi.setVisible(true);
        // add notes panel, may be empty (a dot on the screen)
        JPanel pa = new JPanel();
        pa.setLayout(new BoxLayout(pa, BoxLayout.Y_AXIS));
        Border pBorder = BorderFactory.createEtchedBorder();
        pa.setBorder(pBorder);
        contentPane.add(pa);
        // buttons at bottom of panel
        JPanel pb = new JPanel();
        pb.setLayout(new FlowLayout(FlowLayout.TRAILING));
        pb.add(cancelButton);
        cancelButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancelPressed(e);
            }
        });
        cancelButton.setVisible(true);
        pb.add(deleteButton);
        deleteButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                deletePressed(e);
            }
        });
        deleteButton.setToolTipText(Bundle.getMessage("DeleteSignalGroupInSystem"));
        // [Update] Signal Group button in Add/Edit SignalGroup pane
        pb.add(updateButton);
        updateButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                updatePressed(e, false, true);
            }
        });
        updateButton.setToolTipText(Bundle.getMessage("TooltipUpdate"));
        updateButton.setVisible(true);
        contentPane.add(pb);
        // pack and release space
        addFrame.pack();
        p2xsiSpace.setVisible(false);
    } else // set listener for window closing
    {
        mainSignalComboBox.setSelectedBean(null);
        // reset title for new group
        addFrame.setTitle(Bundle.getMessage("AddSignalGroup"));
    }
    addFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            // remind to save, if Signal Group was created or edited
            if (SignalGroupDirty) {
                InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ReminderTitle"), Bundle.getMessage("ReminderSaveString", Bundle.getMessage("SignalGroup")), "beantable.SignalGroupTableAction", // NOI18N
                "remindSignalGroup");
                SignalGroupDirty = false;
            }
            // hide first, could be gone by the time of the close event,
            if (addFrame != null) {
                addFrame.setVisible(false);
            }
            // so prevent NPE
            // release editing soon, as long as NPEs occor in the following methods
            inEditMode = false;
            finishUpdate();
            _SignalGroupHeadModel.dispose();
            _AspectModel.dispose();
        }
    });
    // display the pane
    addFrame.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) SignalHead(jmri.SignalHead) TableColumnModel(javax.swing.table.TableColumnModel) JmriBeanComboBox(jmri.util.swing.JmriBeanComboBox) Container(java.awt.Container) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) ButtonGroup(javax.swing.ButtonGroup) JTable(javax.swing.JTable) SystemNameComparator(jmri.util.SystemNameComparator) Border(javax.swing.border.Border)

Example 8 with SystemNameComparator

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

the class BeanTablePane method init.

public void init(BeanTableDataModel model) {
    dataModel = model;
    TableRowSorter<BeanTableDataModel> sorter = new TableRowSorter<>(dataModel);
    dataTable = dataModel.makeJTable(dataModel.getMasterClassName(), dataModel, sorter);
    dataScroll = new JScrollPane(dataTable);
    // give system name column as smarter sorter and use it initially
    sorter.setComparator(BeanTableDataModel.SYSNAMECOL, new SystemNameComparator());
    RowSorterUtil.setSortOrder(sorter, BeanTableDataModel.SYSNAMECOL, SortOrder.ASCENDING);
    this.dataTable.setRowSorter(sorter);
    // configure items for GUI
    dataModel.configureTable(dataTable);
    // general GUI config
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    // install items in GUI
    add(dataScroll);
    bottomBox = Box.createHorizontalBox();
    // stays at end of box
    bottomBox.add(Box.createHorizontalGlue());
    bottomBoxIndex = 0;
    add(bottomBox);
    // add extras, if desired by subclass
    extras();
    // set Viewport preferred size from size of table
    java.awt.Dimension dataTableSize = dataTable.getPreferredSize();
    // width is right, but if table is empty, it's not high
    // enough to reserve much space.
    dataTableSize.height = Math.max(dataTableSize.height, 400);
    dataScroll.getViewport().setPreferredSize(dataTableSize);
    // set preferred scrolling options
    dataScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    dataScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
}
Also used : JScrollPane(javax.swing.JScrollPane) BoxLayout(javax.swing.BoxLayout) SystemNameComparator(jmri.util.SystemNameComparator) TableRowSorter(javax.swing.table.TableRowSorter)

Example 9 with SystemNameComparator

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

the class PickListModel method makeSorter.

public void makeSorter(JTable table) {
    _sorter = new TableRowSorter<>(this);
    _sorter.setComparator(SNAME_COLUMN, new SystemNameComparator());
    table.setRowSorter(_sorter);
}
Also used : SystemNameComparator(jmri.util.SystemNameComparator)

Example 10 with SystemNameComparator

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

the class PickListModel method makePickTable.

/**
     * Make pick table, DND enabled.
     * @return the table
     */
public JTable makePickTable() {
    _sorter = new TableRowSorter<>(this);
    _table = new JTable(this) {

        /**
             * Overridden to prevent empty cells from being selected
             */
        @Override
        public void changeSelection(int row, int col, boolean toggle, boolean extend) {
            if (this.getValueAt(row, col) != null) {
                super.changeSelection(row, col, toggle, extend);
            }
        }
    };
    _sorter.setComparator(SNAME_COLUMN, new SystemNameComparator());
    _table.setRowSorter(_sorter);
    _table.setRowSelectionAllowed(true);
    _table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _table.setPreferredScrollableViewportSize(new java.awt.Dimension(250, _table.getRowHeight() * 7));
    _table.setDragEnabled(true);
    _table.setTransferHandler(new jmri.util.DnDTableExportHandler());
    _table.getTableHeader().setReorderingAllowed(true);
    _table.setColumnModel(new XTableColumnModel());
    _table.createDefaultColumnsFromModel();
    TableColumnModel columnModel = _table.getColumnModel();
    TableColumn sNameColumnT = columnModel.getColumn(SNAME_COLUMN);
    sNameColumnT.setResizable(true);
    sNameColumnT.setMinWidth(50);
    //sNameColumnT.setMaxWidth(200);
    TableColumn uNameColumnT = columnModel.getColumn(UNAME_COLUMN);
    uNameColumnT.setResizable(true);
    uNameColumnT.setMinWidth(100);
    //uNameColumnT.setMaxWidth(300);
    addMouseListenerToHeader(_table);
    _table.setAutoCreateColumnsFromModel(false);
    return _table;
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) XTableColumnModel(jmri.util.swing.XTableColumnModel) XTableColumnModel(jmri.util.swing.XTableColumnModel) TableColumn(javax.swing.table.TableColumn) JTable(javax.swing.JTable) SystemNameComparator(jmri.util.SystemNameComparator)

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