Search in sources :

Example 21 with TableRowSorter

use of javax.swing.table.TableRowSorter in project processdash by dtuma.

the class UserEditor method makeTable.

private Component makeTable() {
    table = new JTable(model);
    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    rowSorter = new TableRowSorter(model);
    rowSorter.setSortable(UserTableModel.ROLES_COL, false);
    table.setRowSorter(rowSorter);
    table.getColumnModel().getColumn(UserTableModel.USERNAME_COL).setCellEditor(new UsernameCellEditor());
    table.getColumnModel().getColumn(UserTableModel.ROLES_COL).setCellEditor(new RolesCellEditor());
    table.getColumnModel().getColumn(UserTableModel.ROLES_COL).setHeaderRenderer(new RolesHeaderRenderer());
    table.getTableHeader().addMouseListener(new RolesColumnClickHandler());
    int preferredWidth = TableUtils.configureTable(table, UserTableModel.COLUMN_WIDTHS, UserTableModel.COLUMN_TOOLTIPS);
    int preferredHeight = 15 * table.getRowHeight();
    table.setPreferredScrollableViewportSize(new Dimension(preferredWidth, preferredHeight));
    // active, not us; so don't display the "Active" column in the table.
    if (isLegacyPdesMode()) {
        table.getColumnModel().removeColumn(table.getColumnModel().getColumn(UserTableModel.ACTIVE_COL));
    }
    return new JScrollPane(table);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTable(javax.swing.JTable) Dimension(java.awt.Dimension) TableRowSorter(javax.swing.table.TableRowSorter)

Example 22 with TableRowSorter

use of javax.swing.table.TableRowSorter 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 23 with TableRowSorter

use of javax.swing.table.TableRowSorter 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 24 with TableRowSorter

use of javax.swing.table.TableRowSorter in project JMRI by JMRI.

the class WarrantTableFrame method initComponents.

/**
     * By default, Swing components should be created an installed in this
     * method, rather than in the ctor itself.
     */
@Override
public void initComponents() throws Exception {
    //Casts at getTableCellEditorComponent() now fails with 3.0 ??
    JTable table = new JTable(_model);
    ComboBoxCellEditor comboEd;
    TableRowSorter<WarrantTableModel> sorter = new TableRowSorter<>(_model);
    comboEd = new ComboBoxCellEditor(new JComboBox<>());
    table.setRowSorter(sorter);
    // Use XTableColumnModel so we can control which columns are visible
    XTableColumnModel tcm = new XTableColumnModel();
    table.setColumnModel(tcm);
    table.getTableHeader().setReorderingAllowed(true);
    table.createDefaultColumnsFromModel();
    _model.addHeaderListener(table);
    table.setDefaultRenderer(Boolean.class, new ButtonRenderer());
    table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
    table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());
    JComboBox<String> box = new JComboBox<>(controls);
    box.setFont(new Font(null, Font.PLAIN, 12));
    table.getColumnModel().getColumn(WarrantTableModel.CONTROL_COLUMN).setCellEditor(new DefaultCellEditor(box));
    table.getColumnModel().getColumn(WarrantTableModel.ROUTE_COLUMN).setCellEditor(comboEd);
    table.getColumnModel().getColumn(WarrantTableModel.ALLOCATE_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.ALLOCATE_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.DEALLOC_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.DEALLOC_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.SET_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.SET_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.AUTO_RUN_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.AUTO_RUN_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.MANUAL_RUN_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.MANUAL_RUN_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.EDIT_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.EDIT_COLUMN).setCellRenderer(new ButtonRenderer());
    table.getColumnModel().getColumn(WarrantTableModel.DELETE_COLUMN).setCellEditor(new ButtonEditor(new JButton()));
    table.getColumnModel().getColumn(WarrantTableModel.DELETE_COLUMN).setCellRenderer(new ButtonRenderer());
    //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (int i = 0; i < _model.getColumnCount(); i++) {
        int width = _model.getPreferredWidth(i);
        table.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    tcm.setColumnVisible(tcm.getColumnByModelIndex(WarrantTableModel.MANUAL_RUN_COLUMN), false);
    _rowHeight = box.getPreferredSize().height;
    table.setRowHeight(_rowHeight);
    table.setDragEnabled(true);
    table.setTransferHandler(new jmri.util.DnDTableExportHandler());
    _tablePane = new JScrollPane(table);
    JPanel tablePanel = new JPanel();
    tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.Y_AXIS));
    tablePanel.add(Box.createVerticalGlue());
    JLabel title = new JLabel(Bundle.getMessage("ShowWarrants"));
    tablePanel.add(title);
    tablePanel.add(_tablePane);
    JPanel bottom = new JPanel();
    JPanel panel = new JPanel();
    JButton nxButton = new JButton(Bundle.getMessage("CreateNXWarrant"));
    nxButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            nxAction();
        }
    });
    panel.add(nxButton);
    panel.add(Box.createGlue());
    panel.add(new JLabel("status"));
    _status.addMouseListener(this);
    _status.setBackground(Color.white);
    _status.setFont(_status.getFont().deriveFont(Font.BOLD));
    _status.setEditable(false);
    setStatusText(BLANK.substring(0, 90), null, false);
    panel.add(_status);
    JButton haltAllButton = new JButton(Bundle.getMessage("HaltAllTrains"));
    haltAllButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            haltAllAction();
        }
    });
    haltAllButton.setForeground(Color.RED);
    panel.add(Box.createGlue());
    panel.add(haltAllButton);
    ///
    bottom.add(panel);
    tablePanel.add(bottom);
    addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            dispose();
        }
    });
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    fileMenu.add(new jmri.configurexml.SaveMenu());
    menuBar.add(fileMenu);
    JMenu warrantMenu = new JMenu(Bundle.getMessage("MenuWarrant"));
    warrantMenu.add(new AbstractAction(Bundle.getMessage("ConcatWarrants")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            concatMenuAction();
        }
    });
    warrantMenu.add(new jmri.jmrit.logix.WarrantTableAction("CreateWarrant"));
    warrantMenu.add(WarrantTableAction._trackerTable);
    warrantMenu.add(new AbstractAction(Bundle.getMessage("CreateNXWarrant")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            nxAction();
        }
    });
    warrantMenu.add(WarrantTableAction.makeLogMenu());
    menuBar.add(warrantMenu);
    setJMenuBar(menuBar);
    addHelpMenu("package.jmri.jmrit.logix.WarrantTable", true);
    getContentPane().add(tablePanel);
    //        setLocation(50,0);
    pack();
}
Also used : JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) Font(java.awt.Font) AbstractAction(javax.swing.AbstractAction) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) XTableColumnModel(jmri.util.swing.XTableColumnModel) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) ButtonRenderer(jmri.util.table.ButtonRenderer) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 25 with TableRowSorter

use of javax.swing.table.TableRowSorter 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)

Aggregations

TableRowSorter (javax.swing.table.TableRowSorter)32 JTable (javax.swing.JTable)23 JScrollPane (javax.swing.JScrollPane)22 JPanel (javax.swing.JPanel)17 JLabel (javax.swing.JLabel)15 BoxLayout (javax.swing.BoxLayout)13 JButton (javax.swing.JButton)13 TableColumnModel (javax.swing.table.TableColumnModel)10 Dimension (java.awt.Dimension)9 ActionEvent (java.awt.event.ActionEvent)9 SystemNameComparator (jmri.util.SystemNameComparator)9 ActionListener (java.awt.event.ActionListener)8 TableColumn (javax.swing.table.TableColumn)8 TableModel (javax.swing.table.TableModel)7 ButtonEditor (jmri.util.table.ButtonEditor)6 ButtonRenderer (jmri.util.table.ButtonRenderer)6 BorderLayout (java.awt.BorderLayout)5 FlowLayout (java.awt.FlowLayout)5 Point (java.awt.Point)5 JComboBox (javax.swing.JComboBox)5