Search in sources :

Example 16 with TableRowSorter

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

the class ConfigBaseStationFrame method initGui.

private void initGui() {
    // NOTE: Look at jmri.jmrit.vsdecoder.swing.ManageLocationsFrame
    // for how to add a tab for turnouts and other things.
    this.setTitle(Bundle.getMessage("FieldManageBaseStationFrameTitle"));
    this.buildMenu();
    // Panel for managing sensors
    sensorPanel = new JPanel();
    sensorPanel.setLayout(new GridBagLayout());
    JButton addButton = new JButton(Bundle.getMessage("ButtonAddSensor"));
    addButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFAdd"));
    // NOI18N
    addButton.setMnemonic(Mnemonics.get("AddButton"));
    addButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addButtonPressed(e);
        }
    });
    JButton closeButton = new JButton(Bundle.getMessage("ButtonClose"));
    closeButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFClose"));
    // NOI18N
    closeButton.setMnemonic(Mnemonics.get("CloseButton"));
    closeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeButtonPressed(e);
        }
    });
    JButton saveButton = new JButton(Bundle.getMessage("ButtonSaveSensors"));
    saveButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFSave"));
    // NOI18N
    saveButton.setMnemonic(Mnemonics.get("SaveButton"));
    saveButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveButtonPressed(e);
        }
    });
    JScrollPane sensorScrollPanel = new JScrollPane();
    sensorModel = new SensorTableModel();
    sensorTable = new JTable(sensorModel);
    sensorTable.setFillsViewportHeight(true);
    sensorScrollPanel.getViewport().add(sensorTable);
    sensorTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
    sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
    sensorTable.removeColumn(sensorTable.getColumn("isNew"));
    sensorTable.removeColumn(sensorTable.getColumn("isDirty"));
    sensorTable.removeColumn(sensorTable.getColumn("isDelete"));
    sensorTable.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            handleTableMouseClick(sensorTable, evt);
        }
    });
    sensorTable.setAutoCreateRowSorter(true);
    sensorSorter = new TableRowSorter<>(sensorTable.getModel());
    sensorTable.setRowSorter(sensorSorter);
    List<RowSorter.SortKey> sensorSortKeys = new ArrayList<>();
    //int columnIndexToSort = 1;
    sensorSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
    sensorSorter.setSortKeys(sensorSortKeys);
    sensorSorter.sort();
    sensorSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
    JScrollPane turnoutScrollPanel = new JScrollPane();
    turnoutModel = new TurnoutTableModel();
    turnoutTable = new JTable(turnoutModel);
    turnoutTable.setFillsViewportHeight(true);
    turnoutScrollPanel.getViewport().add(turnoutTable);
    turnoutTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
    turnoutTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
    turnoutTable.removeColumn(turnoutTable.getColumn("isNew"));
    turnoutTable.removeColumn(turnoutTable.getColumn("isDirty"));
    turnoutTable.removeColumn(turnoutTable.getColumn("isDelete"));
    turnoutTable.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            handleTableMouseClick(turnoutTable, evt);
        }
    });
    turnoutTable.setAutoCreateRowSorter(true);
    turnoutSorter = new TableRowSorter<>(turnoutTable.getModel());
    turnoutTable.setRowSorter(turnoutSorter);
    List<RowSorter.SortKey> turnoutSortKeys = new ArrayList<>();
    //int columnIndexToSort = 1;
    turnoutSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
    turnoutSorter.setSortKeys(turnoutSortKeys);
    turnoutSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
    turnoutSorter.sort();
    JScrollPane outputScrollPanel = new JScrollPane();
    outputModel = new OutputTableModel();
    outputTable = new JTable(outputModel);
    outputTable.setFillsViewportHeight(true);
    outputScrollPanel.getViewport().add(outputTable);
    outputTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
    outputTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
    outputTable.removeColumn(outputTable.getColumn("isNew"));
    outputTable.removeColumn(outputTable.getColumn("isDirty"));
    outputTable.removeColumn(outputTable.getColumn("isDelete"));
    outputTable.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            handleTableMouseClick(outputTable, evt);
        }
    });
    outputTable.setAutoCreateRowSorter(true);
    outputSorter = new TableRowSorter<>(outputTable.getModel());
    outputTable.setRowSorter(outputSorter);
    List<RowSorter.SortKey> outputSortKeys = new ArrayList<>();
    //int columnIndexToSort = 1;
    outputSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
    outputSorter.setSortKeys(outputSortKeys);
    outputSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
    outputSorter.sort();
    tabbedPane = new JTabbedPane();
    tabbedPane.addTab(Bundle.getMessage("FieldSensorsTabTitle"), sensorScrollPanel);
    tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipSensorTab"));
    // NOI18N
    tabbedPane.setMnemonicAt(0, Mnemonics.get("SensorTab"));
    tabbedPane.addTab(Bundle.getMessage("FieldTurnoutsTabTitle"), turnoutScrollPanel);
    tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipTurnoutTab"));
    // NOI18N
    tabbedPane.setMnemonicAt(0, Mnemonics.get("TurnoutTab"));
    tabbedPane.addTab(Bundle.getMessage("FieldOutputsTabTitle"), outputScrollPanel);
    tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipOutputTab"));
    // NOI18N
    tabbedPane.setMnemonicAt(0, Mnemonics.get("OutputTab"));
    cTab = CurrentTab.SENSOR;
    tabbedPane.setSelectedIndex(0);
    tabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            switch(tabbedPane.getSelectedIndex()) {
                case 2:
                    // Set Add to "Add Output"
                    cTab = CurrentTab.OUTPUT;
                    addButton.setText(Bundle.getMessage("ButtonAddOutput"));
                    saveButton.setText(Bundle.getMessage("ButtonSaveOutputs"));
                    log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
                    break;
                case 1:
                    // Set Add to "Add Turnout"
                    cTab = CurrentTab.TURNOUT;
                    addButton.setText(Bundle.getMessage("ButtonAddTurnout"));
                    saveButton.setText(Bundle.getMessage("ButtonSaveTurnouts"));
                    log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
                    break;
                case 0:
                default:
                    // Set Add to "Add Sensor"
                    cTab = CurrentTab.SENSOR;
                    addButton.setText(Bundle.getMessage("ButtonAddSensor"));
                    saveButton.setText(Bundle.getMessage("ButtonSaveSensors"));
                    log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
            }
        }
    });
    JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JPanel buttonPane2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    buttonPane.add(addButton);
    buttonPane.add(saveButton);
    buttonPane2.add(closeButton);
    this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
    this.getContentPane().add(tabbedPane);
    this.getContentPane().add(buttonPane);
    this.getContentPane().add(buttonPane2);
    this.pack();
    this.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) ChangeListener(javax.swing.event.ChangeListener) JScrollPane(javax.swing.JScrollPane) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) JTable(javax.swing.JTable)

Example 17 with TableRowSorter

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

the class RouteTableAction method addPressed.

@Override
protected void addPressed(ActionEvent e) {
    pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
    if (editMode) {
        cancelEdit();
    }
    jmri.TurnoutManager tm = InstanceManager.turnoutManagerInstance();
    List<String> systemNameList = tm.getSystemNameList();
    _turnoutList = new ArrayList<>(systemNameList.size());
    Iterator<String> iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        String userName = tm.getBySystemName(systemName).getUserName();
        _turnoutList.add(new RouteTurnout(systemName, userName));
    }
    jmri.SensorManager sm = InstanceManager.sensorManagerInstance();
    systemNameList = sm.getSystemNameList();
    _sensorList = new ArrayList<>(systemNameList.size());
    iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        Sensor s = sm.getBySystemName(systemName);
        if (s != null) {
            String userName = s.getUserName();
            _sensorList.add(new RouteSensor(systemName, userName));
        } else {
            log.error("Failed to get sensor {}", systemName);
        }
    }
    initializeIncludedList();
    // Set up window
    if (addFrame == null) {
        turnoutsAlignedSensor = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
        sensor1 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
        sensor2 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
        sensor3 = new JmriBeanComboBox(InstanceManager.sensorManagerInstance());
        cTurnout = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance());
        cLockTurnout = new JmriBeanComboBox(InstanceManager.turnoutManagerInstance());
        addFrame = new JmriJFrame(Bundle.getMessage("TitleAddRoute"), false, true);
        addFrame.addHelpMenu("package.jmri.jmrit.beantable.RouteAddEdit", true);
        addFrame.setLocation(100, 30);
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
        // add system name
        JPanel ps = new JPanel();
        ps.setLayout(new FlowLayout());
        ps.add(nameLabel);
        ps.add(_systemName);
        ps.add(_autoSystemName);
        _autoSystemName.addActionListener((ActionEvent e1) -> {
            autoSystemName();
        });
        if (pref.getSimplePreferenceState(systemNameAuto)) {
            _autoSystemName.setSelected(true);
        }
        _systemName.setToolTipText(Bundle.getMessage("TooltipRouteSystemName"));
        ps.add(fixedSystemName);
        fixedSystemName.setVisible(false);
        contentPanel.add(ps);
        // add user name
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        p.add(userLabel);
        p.add(_userName);
        _userName.setToolTipText(Bundle.getMessage("TooltipRouteUserName"));
        contentPanel.add(p);
        // add Turnout 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((ActionEvent e1) -> {
            // Setup for display of all Turnouts, if needed
            if (!showAll) {
                showAll = true;
                _routeTurnoutModel.fireTableDataChanged();
                _routeSensorModel.fireTableDataChanged();
            }
        });
        includedButton = new JRadioButton(Bundle.getMessage("Included"), false);
        selGroup.add(includedButton);
        py.add(includedButton);
        includedButton.addActionListener((ActionEvent e1) -> {
            // Setup for display of included Turnouts only, if needed
            if (showAll) {
                showAll = false;
                initializeIncludedList();
                _routeTurnoutModel.fireTableDataChanged();
                _routeSensorModel.fireTableDataChanged();
            }
        });
        py.add(new JLabel(Bundle.getMessage("_and_", Bundle.getMessage("Turnouts"), Bundle.getMessage("Sensors"))));
        // keys are in jmri.jmrit.Bundle
        contentPanel.add(py);
        // add Turnout table
        p2xt = new JPanel();
        JPanel p2xtSpace = new JPanel();
        p2xtSpace.setLayout(new BoxLayout(p2xtSpace, BoxLayout.Y_AXIS));
        p2xtSpace.add(new JLabel("XXX"));
        p2xt.add(p2xtSpace);
        JPanel p21t = new JPanel();
        p21t.setLayout(new BoxLayout(p21t, BoxLayout.Y_AXIS));
        p21t.add(new JLabel(Bundle.getMessage("SelectInRoute", Bundle.getMessage("Turnouts"))));
        p2xt.add(p21t);
        _routeTurnoutModel = new RouteTurnoutModel();
        JTable routeTurnoutTable = new JTable(_routeTurnoutModel);
        TableRowSorter<RouteTurnoutModel> rtSorter = new TableRowSorter<>(_routeTurnoutModel);
        rtSorter.setComparator(RouteTurnoutModel.SNAME_COLUMN, new SystemNameComparator());
        RowSorterUtil.setSortOrder(rtSorter, RouteTurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
        routeTurnoutTable.setRowSorter(rtSorter);
        routeTurnoutTable.setRowSelectionAllowed(false);
        routeTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
        ROW_HEIGHT = routeTurnoutTable.getRowHeight();
        JComboBox<String> stateTCombo = new JComboBox<>();
        stateTCombo.addItem(SET_TO_CLOSED);
        stateTCombo.addItem(SET_TO_THROWN);
        stateTCombo.addItem(SET_TO_TOGGLE);
        TableColumnModel routeTurnoutColumnModel = routeTurnoutTable.getColumnModel();
        TableColumn includeColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.INCLUDE_COLUMN);
        includeColumnT.setResizable(false);
        includeColumnT.setMinWidth(50);
        includeColumnT.setMaxWidth(60);
        TableColumn sNameColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.SNAME_COLUMN);
        sNameColumnT.setResizable(true);
        sNameColumnT.setMinWidth(75);
        sNameColumnT.setMaxWidth(95);
        TableColumn uNameColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.UNAME_COLUMN);
        uNameColumnT.setResizable(true);
        uNameColumnT.setMinWidth(210);
        uNameColumnT.setMaxWidth(260);
        TableColumn stateColumnT = routeTurnoutColumnModel.getColumn(RouteTurnoutModel.STATE_COLUMN);
        stateColumnT.setCellEditor(new DefaultCellEditor(stateTCombo));
        stateColumnT.setResizable(false);
        stateColumnT.setMinWidth(90);
        stateColumnT.setMaxWidth(100);
        _routeTurnoutScrollPane = new JScrollPane(routeTurnoutTable);
        p2xt.add(_routeTurnoutScrollPane, BorderLayout.CENTER);
        contentPanel.add(p2xt);
        p2xt.setVisible(true);
        // add Sensor table
        p2xs = new JPanel();
        JPanel p2xsSpace = new JPanel();
        p2xsSpace.setLayout(new BoxLayout(p2xsSpace, BoxLayout.Y_AXIS));
        p2xsSpace.add(new JLabel("XXX"));
        p2xs.add(p2xsSpace);
        JPanel p21s = new JPanel();
        p21s.setLayout(new BoxLayout(p21s, BoxLayout.Y_AXIS));
        p21s.add(new JLabel(Bundle.getMessage("SelectInRoute", Bundle.getMessage("Sensors"))));
        p2xs.add(p21s);
        _routeSensorModel = new RouteSensorModel();
        JTable routeSensorTable = new JTable(_routeSensorModel);
        TableRowSorter<RouteSensorModel> rsSorter = new TableRowSorter<>(_routeSensorModel);
        rsSorter.setComparator(RouteSensorModel.SNAME_COLUMN, new SystemNameComparator());
        RowSorterUtil.setSortOrder(rsSorter, RouteSensorModel.SNAME_COLUMN, SortOrder.ASCENDING);
        routeSensorTable.setRowSorter(rsSorter);
        routeSensorTable.setRowSelectionAllowed(false);
        routeSensorTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
        JComboBox<String> stateSCombo = new JComboBox<>();
        stateSCombo.addItem(SET_TO_ACTIVE);
        stateSCombo.addItem(SET_TO_INACTIVE);
        stateSCombo.addItem(SET_TO_TOGGLE);
        TableColumnModel routeSensorColumnModel = routeSensorTable.getColumnModel();
        TableColumn includeColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.INCLUDE_COLUMN);
        includeColumnS.setResizable(false);
        includeColumnS.setMinWidth(50);
        includeColumnS.setMaxWidth(60);
        TableColumn sNameColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.SNAME_COLUMN);
        sNameColumnS.setResizable(true);
        sNameColumnS.setMinWidth(75);
        sNameColumnS.setMaxWidth(95);
        TableColumn uNameColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.UNAME_COLUMN);
        uNameColumnS.setResizable(true);
        uNameColumnS.setMinWidth(210);
        uNameColumnS.setMaxWidth(260);
        TableColumn stateColumnS = routeSensorColumnModel.getColumn(RouteSensorModel.STATE_COLUMN);
        stateColumnS.setCellEditor(new DefaultCellEditor(stateSCombo));
        stateColumnS.setResizable(false);
        stateColumnS.setMinWidth(90);
        stateColumnS.setMaxWidth(100);
        _routeSensorScrollPane = new JScrollPane(routeSensorTable);
        p2xs.add(_routeSensorScrollPane, BorderLayout.CENTER);
        contentPanel.add(p2xs);
        p2xs.setVisible(true);
        // Enter filenames for sound, script
        JPanel p25 = new JPanel();
        p25.setLayout(new FlowLayout());
        p25.add(new JLabel(Bundle.getMessage("LabelPlaySound")));
        p25.add(soundFile);
        //NO18N
        JButton ss = new JButton("...");
        ss.addActionListener((ActionEvent e1) -> {
            setSoundPressed();
        });
        ss.setToolTipText(Bundle.getMessage("TooltipOpenFile", Bundle.getMessage("BeanNameAudio")));
        p25.add(ss);
        p25.add(new JLabel(Bundle.getMessage("LabelRunScript")));
        p25.add(scriptFile);
        //NO18N
        ss = new JButton("...");
        ss.addActionListener((ActionEvent e1) -> {
            setScriptPressed();
        });
        ss.setToolTipText(Bundle.getMessage("TooltipOpenFile", Bundle.getMessage("Script")));
        p25.add(ss);
        contentPanel.add(p25);
        //add turnouts aligned Sensor
        JPanel p27 = new JPanel();
        p27.setLayout(new FlowLayout());
        p27.add(new JLabel(Bundle.getMessage("LabelEnterSensorAligned")));
        p27.add(turnoutsAlignedSensor);
        turnoutsAlignedSensor.setFirstItemBlank(true);
        turnoutsAlignedSensor.setSelectedBean(null);
        turnoutsAlignedSensor.setToolTipText(Bundle.getMessage("TooltipEnterSensor"));
        contentPanel.add(p27);
        // add Control Sensor table
        JPanel p3 = new JPanel();
        p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
        JPanel p31 = new JPanel();
        p31.add(new JLabel(Bundle.getMessage("LabelEnterSensors")));
        p3.add(p31);
        JPanel p32 = new JPanel();
        //Sensor 1
        JPanel pS = new JPanel();
        pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 1"));
        pS.add(sensor1);
        pS.add(sensor1mode);
        p32.add(pS);
        //Sensor 2
        pS = new JPanel();
        pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 2"));
        pS.add(sensor2);
        pS.add(sensor2mode);
        p32.add(pS);
        //Sensor 3
        pS = new JPanel();
        pS.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("BeanNameSensor") + " 3"));
        pS.add(sensor3);
        pS.add(sensor3mode);
        p32.add(pS);
        sensor1.setFirstItemBlank(true);
        sensor2.setFirstItemBlank(true);
        sensor3.setFirstItemBlank(true);
        sensor1.setSelectedBean(null);
        sensor2.setSelectedBean(null);
        sensor3.setSelectedBean(null);
        String sensorHint = Bundle.getMessage("TooltipEnterSensors");
        sensor1.setToolTipText(sensorHint);
        sensor2.setToolTipText(sensorHint);
        sensor3.setToolTipText(sensorHint);
        p3.add(p32);
        // add control turnout
        JPanel p33 = new JPanel();
        p33.add(new JLabel(Bundle.getMessage("LabelEnterTurnout")));
        p3.add(p33);
        JPanel p34 = new JPanel();
        p34.add(new JLabel(Bundle.getMessage("BeanNameTurnout") + ":"));
        p34.add(cTurnout);
        cTurnout.setFirstItemBlank(true);
        cTurnout.setSelectedBean(null);
        cTurnout.setToolTipText(Bundle.getMessage("TooltipEnterTurnout"));
        p34.add(new JLabel("   " + Bundle.getMessage("LabelCondition") + ":"));
        cTurnoutStateBox.setToolTipText(Bundle.getMessage("TooltipTurnoutCondition"));
        p34.add(cTurnoutStateBox);
        p3.add(p34);
        // add added delay
        JPanel p36 = new JPanel();
        p36.add(new JLabel(Bundle.getMessage("LabelTurnoutDelay") + ":"));
        p36.add(timeDelay);
        timeDelay.setText("0");
        timeDelay.setToolTipText(Bundle.getMessage("TooltipTurnoutDelay"));
        p36.add(new JLabel(" " + Bundle.getMessage("LabelMilliseconds")));
        p3.add(p36);
        // complete this panel
        Border p3Border = BorderFactory.createEtchedBorder();
        p3.setBorder(p3Border);
        contentPanel.add(p3);
        // add lock control table
        JPanel p4 = new JPanel();
        p4.setLayout(new BoxLayout(p4, BoxLayout.Y_AXIS));
        // add lock control turnout
        JPanel p43 = new JPanel();
        p43.add(new JLabel(Bundle.getMessage("LabelLockTurnout")));
        p4.add(p43);
        JPanel p44 = new JPanel();
        p44.add(new JLabel(Bundle.getMessage("BeanNameTurnout") + ":"));
        p44.add(cLockTurnout);
        cLockTurnout.setFirstItemBlank(true);
        cLockTurnout.setSelectedBean(null);
        cLockTurnout.setToolTipText(Bundle.getMessage("TooltipEnterTurnout"));
        p44.add(new JLabel("   " + Bundle.getMessage("LabelCondition") + ":"));
        cLockTurnoutStateBox.setToolTipText(Bundle.getMessage("TooltipLockTurnout"));
        p44.add(cLockTurnoutStateBox);
        p4.add(p44);
        // complete this panel
        Border p4Border = BorderFactory.createEtchedBorder();
        p4.setBorder(p4Border);
        contentPanel.add(p4);
        // add notes panel
        JPanel pa = new JPanel();
        pa.setLayout(new BoxLayout(pa, BoxLayout.Y_AXIS));
        JPanel p1 = new JPanel();
        p1.setLayout(new FlowLayout());
        p1.add(status1);
        JPanel p2 = new JPanel();
        p2.setLayout(new FlowLayout());
        p2.add(status2);
        pa.add(p1);
        pa.add(p2);
        Border pBorder = BorderFactory.createEtchedBorder();
        pa.setBorder(pBorder);
        contentPanel.add(pa);
        // add Buttons panel
        JPanel pb = new JPanel();
        pb.setLayout(new FlowLayout(FlowLayout.TRAILING));
        // Cancel (Add) button
        pb.add(cancelButton);
        cancelButton.addActionListener(this::cancelAddPressed);
        // CancelEdit button
        pb.add(cancelEditButton);
        cancelEditButton.addActionListener(this::cancelPressed);
        cancelEditButton.setToolTipText(Bundle.getMessage("TooltipCancelRoute"));
        // Add Create Route button
        pb.add(createButton);
        createButton.addActionListener(this::createPressed);
        createButton.setToolTipText(Bundle.getMessage("TooltipCreateRoute"));
        // Edit Route button 
        pb.add(editButton);
        editButton.addActionListener(this::editPressed);
        editButton.setToolTipText(Bundle.getMessage("TooltipEditRoute"));
        // Delete Route button
        pb.add(deleteButton);
        deleteButton.addActionListener(this::deletePressed);
        deleteButton.setToolTipText(Bundle.getMessage("TooltipDeleteRoute"));
        // Update Route button
        pb.add(updateButton);
        updateButton.addActionListener((ActionEvent e1) -> {
            updatePressed(e1, false);
        });
        updateButton.setToolTipText(Bundle.getMessage("TooltipUpdateRoute"));
        // Export button
        pb.add(exportButton);
        exportButton.addActionListener(this::exportPressed);
        exportButton.setToolTipText(Bundle.getMessage("TooltipExportRoute"));
        // Show the initial buttons, and hide the others
        exportButton.setVisible(false);
        // show CancelAdd button
        cancelButton.setVisible(true);
        cancelEditButton.setVisible(false);
        updateButton.setVisible(true);
        editButton.setVisible(true);
        createButton.setVisible(true);
        deleteButton.setVisible(false);
        contentPanel.add(pb);
        addFrame.getContentPane().add(new JScrollPane(contentPanel), BorderLayout.CENTER);
        // pack and release space
        addFrame.pack();
        p2xsSpace.setVisible(false);
        p2xtSpace.setVisible(false);
    }
    // set listener for window closing
    addFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            // remind to save, if Route was created or edited
            if (routeDirty) {
                InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ReminderTitle"), Bundle.getMessage("ReminderSaveString", Bundle.getMessage("MenuItemRouteTable")), getClassName(), //NOI18N
                "remindSaveRoute");
                routeDirty = false;
            }
            // hide addFrame
            if (addFrame != null) {
                addFrame.setVisible(false);
            // addFrame.dispose(); // causes multiple empty Routes next time
            }
            // if in Edit, cancel edit mode
            if (editMode) {
                cancelEdit();
            }
            _routeSensorModel.dispose();
            _routeTurnoutModel.dispose();
        }
    });
    // display the window
    addFrame.setVisible(true);
    autoSystemName();
}
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) TableColumnModel(javax.swing.table.TableColumnModel) JmriBeanComboBox(jmri.util.swing.JmriBeanComboBox) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) JmriJFrame(jmri.util.JmriJFrame) ButtonGroup(javax.swing.ButtonGroup) JTable(javax.swing.JTable) SystemNameComparator(jmri.util.SystemNameComparator) Border(javax.swing.border.Border) Sensor(jmri.Sensor)

Example 18 with TableRowSorter

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

the class SignallingPanel method buildBlocksPanel.

/**
     * Compose GUI for setting up Blocks tab for an SML.
     *
     * @return a JPanel containing the SML control blocks configuration interface
     */
JPanel buildBlocksPanel() {
    JPanel blockPanel = new JPanel();
    blockPanel.setLayout(new BoxLayout(blockPanel, BoxLayout.Y_AXIS));
    jmri.BlockManager bm = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
    List<String> systemNameList = bm.getSystemNameList();
    _manualBlockList = new ArrayList<ManualBlockList>(systemNameList.size());
    Iterator<String> iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        _manualBlockList.add(new ManualBlockList(bm.getBySystemName(systemName)));
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Block> blkList = sml.getAutoBlocks(destMast);
        _automaticBlockList = new ArrayList<AutoBlockList>(blkList.size());
        Iterator<Block> iterBlk = blkList.iterator();
        while (iterBlk.hasNext()) {
            Block blk = iterBlk.next();
            AutoBlockList blockitem = new AutoBlockList(blk);
            blockitem.setState(sml.getAutoBlockState(blk, destMast));
            _automaticBlockList.add(blockitem);
        }
    }
    // this hides a field
    JPanel p2xc = new JPanel();
    JPanel p2xcSpace = new JPanel();
    p2xcSpace.setLayout(new BoxLayout(p2xcSpace, BoxLayout.Y_AXIS));
    p2xcSpace.add(new JLabel("XXX"));
    p2xc.add(p2xcSpace);
    JPanel p21c = new JPanel();
    p21c.setLayout(new BoxLayout(p21c, BoxLayout.Y_AXIS));
    p21c.add(new JLabel(Bundle.getMessage("LabelSelectChecked", Bundle.getMessage("Blocks"))));
    p2xc.add(p21c);
    _blockModel = new BlockModel();
    JTable manualBlockTable = new JTable(_blockModel);
    TableRowSorter<BlockModel> manualBlockSorter = new TableRowSorter<>(_blockModel);
    // configure row height for comboBox
    // row height has to be greater than for plain tables
    manualBlockTable.setRowHeight(Sizer.getPreferredSize().height - 2);
    manualBlockSorter.setComparator(BlockModel.SNAME_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(manualBlockSorter, BlockModel.SNAME_COLUMN, SortOrder.ASCENDING);
    // create static comboBox in State column
    _blockModel.configStateColumn(manualBlockTable);
    manualBlockTable.setRowSorter(manualBlockSorter);
    manualBlockTable.setRowSelectionAllowed(false);
    manualBlockTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    // JComboBox<String> stateCCombo = new JComboBox<>(); // moved to ManualBlockTable class
    TableColumnModel _manualBlockColumnModel = manualBlockTable.getColumnModel();
    TableColumn includeColumnC = _manualBlockColumnModel.getColumn(BlockModel.INCLUDE_COLUMN);
    includeColumnC.setResizable(false);
    // was fixed 60
    includeColumnC.setMinWidth(9 * Bundle.getMessage("Include").length());
    includeColumnC.setMaxWidth(includeColumnC.getMinWidth() + 5);
    TableColumn sNameColumnC = _manualBlockColumnModel.getColumn(BlockModel.SNAME_COLUMN);
    sNameColumnC.setResizable(true);
    sNameColumnC.setMinWidth(75);
    sNameColumnC.setMaxWidth(95);
    TableColumn stateColumnC = _manualBlockColumnModel.getColumn(BlockModel.STATE_COLUMN);
    //stateColumnC.setCellEditor(new DefaultCellEditor(stateCCombo)); // moved to ManualBlockTable class
    stateColumnC.setResizable(false);
    stateColumnC.setMinWidth(9 * Math.max(SET_TO_UNOCCUPIED.length(), SET_TO_OCCUPIED.length()) + 40);
    // was fixed 100
    stateColumnC.setMaxWidth(stateColumnC.getMinWidth() + 10);
    // remaining space is filled by UserName
    _manualBlockScrollPane = new JScrollPane(manualBlockTable);
    p2xc.add(_manualBlockScrollPane, BorderLayout.CENTER);
    blockPanel.add(p2xc);
    p2xc.setVisible(true);
    ROW_HEIGHT = manualBlockTable.getRowHeight();
    p2xcSpace.setVisible(false);
    JPanel p2xaSpace = new JPanel();
    p2xaSpace.setLayout(new BoxLayout(p2xaSpace, BoxLayout.Y_AXIS));
    p2xaSpace.add(new JLabel("XXX"));
    p2xb.add(p2xaSpace);
    JPanel p21a = new JPanel();
    p21a.setLayout(new BoxLayout(p21a, BoxLayout.Y_AXIS));
    p21a.add(new JLabel(Bundle.getMessage("LabelAutogenerated", Bundle.getMessage("Blocks"))));
    p2xb.add(p21a);
    _autoBlockModel = new AutoBlockModel();
    JTable autoBlockTable = new JTable(_autoBlockModel);
    TableRowSorter<AutoBlockModel> autoBlockSorter = new TableRowSorter<>(_autoBlockModel);
    autoBlockSorter.setComparator(AutoBlockModel.SNAME_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(autoBlockSorter, AutoBlockModel.SNAME_COLUMN, SortOrder.ASCENDING);
    autoBlockTable.setRowSorter(autoBlockSorter);
    autoBlockTable.setRowSelectionAllowed(false);
    autoBlockTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    TableColumnModel _autoBlockColumnModel = autoBlockTable.getColumnModel();
    TableColumn sNameColumnA = _autoBlockColumnModel.getColumn(AutoBlockModel.SNAME_COLUMN);
    sNameColumnA.setResizable(true);
    sNameColumnA.setMinWidth(75);
    sNameColumnA.setMaxWidth(95);
    TableColumn stateColumnA = _autoBlockColumnModel.getColumn(AutoBlockModel.STATE_COLUMN);
    stateColumnA.setResizable(false);
    stateColumnA.setMinWidth(90);
    stateColumnA.setMaxWidth(100);
    _autoBlockScrollPane = new JScrollPane(autoBlockTable);
    p2xb.add(_autoBlockScrollPane, BorderLayout.CENTER);
    blockPanel.add(p2xb);
    p2xb.setVisible(true);
    ROW_HEIGHT = autoBlockTable.getRowHeight();
    p2xaSpace.setVisible(false);
    return blockPanel;
}
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) Block(jmri.Block) SystemNameComparator(jmri.util.SystemNameComparator)

Example 19 with TableRowSorter

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

the class BoardListPanel method initComponents.

@Override
public void initComponents(Dcc4PcSystemConnectionMemo memo) {
    super.initComponents(memo);
    senMan = jmri.InstanceManager.getDefault(jmri.jmrix.dcc4pc.Dcc4PcSensorManager.class);
    _boardListCount = senMan.getBoards();
    setLayout(new BorderLayout());
    JPanel header = new JPanel();
    header.setLayout(new BoxLayout(header, BoxLayout.Y_AXIS));
    JPanel sourcePanel = new JPanel();
    header.add(sourcePanel);
    add(header, BorderLayout.NORTH);
    _BoardModel = new ReaderBoardModel();
    JTable boardTable = new JTable(_BoardModel);
    TableRowSorter<ReaderBoardModel> sorter = new TableRowSorter<>();
    sorter.setComparator(ReaderBoardModel.ADDRESS_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(sorter, ReaderBoardModel.ADDRESS_COLUMN, SortOrder.ASCENDING);
    boardTable.setRowSelectionAllowed(false);
    boardTable.setPreferredScrollableViewportSize(new java.awt.Dimension(600, 120));
    _BoardModel.configureTable(boardTable);
    _BoardScrollPane = new JScrollPane(boardTable);
    _BoardModel.fireTableDataChanged();
    add(_BoardScrollPane, BorderLayout.CENTER);
    JPanel footer = new JPanel();
    add(footer, BorderLayout.SOUTH);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) SystemNameComparator(jmri.util.SystemNameComparator) TableRowSorter(javax.swing.table.TableRowSorter)

Example 20 with TableRowSorter

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

the class EcosLocoTableAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // create the JTable model, with changes for specific NamedBean
    createModel();
    TableRowSorter<BeanTableDataModel> sorter = new TableRowSorter<>(m);
    JTable dataTable = m.makeJTable(getClassName(), m, sorter);
    // create the frame
    f = new jmri.jmrit.beantable.BeanTableFrame(m, helpTarget(), dataTable) {
    };
    setMenuBar(f);
    setTitle();
    addToFrame(f);
    f.pack();
    f.setVisible(true);
}
Also used : JTable(javax.swing.JTable) BeanTableDataModel(jmri.jmrit.beantable.BeanTableDataModel) 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