Search in sources :

Example 46 with TableColumnModel

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

the class SignalGroupSubTableAction method editHead.

/**
     * Open an editor to set the details of a Signal Head as part of a Signal Group.
     * Called when user clicks the Edit button for a Head in the Add/Edit Signal Group pane.
     * @see SignalGroupTableAction#signalHeadEditPressed(int) SignalGroupTableAction.signalHeadEditPressed
     * @param g Parent Signal Head
     * @param headName System or User Name of this Signal Head
     */
void editHead(SignalGroup g, String headName) {
    curSignalGroup = g;
    curHeadName = headName;
    curSignalHead = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(curHeadName);
    // shows i18n strings from signal head definition
    _OnAppearance = new JComboBox<String>(curSignalHead.getValidStateNames());
    _OffAppearance = new JComboBox<String>(curSignalHead.getValidStateNames());
    _systemName = new JLabel(headName);
    _systemName.setVisible(true);
    jmri.TurnoutManager tm = InstanceManager.turnoutManagerInstance();
    List<String> systemNameList = tm.getSystemNameList();
    _turnoutList = new ArrayList<SignalGroupTurnout>(systemNameList.size());
    Iterator<String> iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        String userName = tm.getBySystemName(systemName).getUserName();
        _turnoutList.add(new SignalGroupTurnout(systemName, userName));
    }
    jmri.SensorManager sm = InstanceManager.sensorManagerInstance();
    systemNameList = sm.getSystemNameList();
    _sensorList = new ArrayList<SignalGroupSensor>(systemNameList.size());
    iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        Sensor sen = sm.getBySystemName(systemName);
        if (sen != null) {
            String userName = sen.getUserName();
            _sensorList.add(new SignalGroupSensor(systemName, userName));
        }
    }
    initializeIncludedList();
    // Set up sub panel for editing of a Signal Group Signal Head item
    if (addSubFrame == null) {
        // create one if not yet available
        addSubFrame = new JmriJFrame((Bundle.getMessage("EditSignalGroup") + " - " + Bundle.getMessage("BeanNameSignalHead")), false, true);
        addSubFrame.addHelpMenu("package.jmri.jmrit.beantable.SignalGroupAddEdit", true);
        addSubFrame.setLocation(100, 30);
        addSubFrame.getContentPane().setLayout(new BoxLayout(addSubFrame.getContentPane(), BoxLayout.Y_AXIS));
        Container contentPane = addSubFrame.getContentPane();
        // add system name label
        JPanel ps = new JPanel();
        ps.setLayout(new FlowLayout());
        ps.add(nameLabel);
        ps.add(_systemName);
        contentPane.add(ps);
        // add user name label
        JPanel pc = new JPanel();
        pc.setLayout(new FlowLayout());
        pc.add(signalOnStateLabel);
        // comboBox to set On Appearance
        pc.add(_OnAppearance);
        _OnAppearance.setToolTipText(Bundle.getMessage("StateWhenMetTooltip"));
        pc.add(spacer);
        pc.add(signalOffStateLabel);
        // comboBox to set On Appearance
        pc.add(_OffAppearance);
        _OffAppearance.setToolTipText(Bundle.getMessage("StateWhenNotMetTooltip"));
        contentPane.add(pc);
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        p.add(userLabel);
        contentPane.add(p);
        // fill in info for the Signal Head being configured
        if (curSignalHead.getClass().getName().contains("SingleTurnoutSignalHead")) {
            jmri.implementation.SingleTurnoutSignalHead stsh = (jmri.implementation.SingleTurnoutSignalHead) InstanceManager.getDefault(jmri.SignalHeadManager.class).getByUserName(curHeadName);
            // we may use a user name in the editing pane, so look for that first
            if (stsh == null) {
                stsh = (jmri.implementation.SingleTurnoutSignalHead) InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(curHeadName);
            // when user name is empty, get by user name
            }
            if (stsh != null) {
                log.debug("SGsubTA #279 editHead: setting props for signal head {}", curHeadName);
                if ((g.getHeadOnState(curSignalHead) == 0x00) && (g.getHeadOffState(curSignalHead) == 0x00)) {
                    g.setHeadOnState(curSignalHead, stsh.getOnAppearance());
                    g.setHeadOffState(curSignalHead, stsh.getOffAppearance());
                }
            } else {
                // nothing found
                log.error("Failed to get signal head object named {}", curHeadName);
            }
        }
        setSignalHeadStateBox(g.getHeadOnState(curSignalHead), _OnAppearance);
        setSignalHeadStateBox(g.getHeadOffState(curSignalHead), _OffAppearance);
        // 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(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // Setup for display of all Turnouts, if needed
                if (!showAll) {
                    showAll = true;
                    _SignalGroupTurnoutModel.fireTableDataChanged();
                    _SignalGroupSensorModel.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();
                    _SignalGroupTurnoutModel.fireTableDataChanged();
                    _SignalGroupSensorModel.fireTableDataChanged();
                }
            }
        });
        py.add(new JLabel("  " + Bundle.getMessage("_and_", Bundle.getMessage("Turnouts"), Bundle.getMessage("Sensors"))));
        contentPane.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("SelectInGroup", Bundle.getMessage("Turnouts"))));
        p2xt.add(p21t);
        _SignalGroupTurnoutModel = new SignalGroupTurnoutModel();
        JTable SignalGroupTurnoutTable = new JTable(_SignalGroupTurnoutModel);
        TableRowSorter<SignalGroupTurnoutModel> sgtSorter = new TableRowSorter<>(_SignalGroupTurnoutModel);
        sgtSorter.setComparator(SignalGroupTurnoutModel.SNAME_COLUMN, new SystemNameComparator());
        RowSorterUtil.setSortOrder(sgtSorter, SignalGroupTurnoutModel.SNAME_COLUMN, SortOrder.ASCENDING);
        SignalGroupTurnoutTable.setRowSorter(sgtSorter);
        SignalGroupTurnoutTable.setRowSelectionAllowed(false);
        SignalGroupTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
        ROW_HEIGHT = SignalGroupTurnoutTable.getRowHeight();
        JComboBox<String> stateTCombo = new JComboBox<String>();
        stateTCombo.addItem(SET_TO_CLOSED);
        stateTCombo.addItem(SET_TO_THROWN);
        TableColumnModel SignalGroupTurnoutColumnModel = SignalGroupTurnoutTable.getColumnModel();
        TableColumn includeColumnT = SignalGroupTurnoutColumnModel.getColumn(SignalGroupTurnoutModel.INCLUDE_COLUMN);
        includeColumnT.setResizable(false);
        includeColumnT.setMinWidth(50);
        includeColumnT.setMaxWidth(60);
        TableColumn sNameColumnT = SignalGroupTurnoutColumnModel.getColumn(SignalGroupTurnoutModel.SNAME_COLUMN);
        sNameColumnT.setResizable(true);
        sNameColumnT.setMinWidth(75);
        sNameColumnT.setMaxWidth(95);
        TableColumn uNameColumnT = SignalGroupTurnoutColumnModel.getColumn(SignalGroupTurnoutModel.UNAME_COLUMN);
        uNameColumnT.setResizable(true);
        uNameColumnT.setMinWidth(210);
        uNameColumnT.setMaxWidth(260);
        TableColumn stateColumnT = SignalGroupTurnoutColumnModel.getColumn(SignalGroupTurnoutModel.STATE_COLUMN);
        stateColumnT.setCellEditor(new DefaultCellEditor(stateTCombo));
        stateColumnT.setResizable(false);
        stateColumnT.setMinWidth(90);
        stateColumnT.setMaxWidth(100);
        _SignalGroupTurnoutScrollPane = new JScrollPane(SignalGroupTurnoutTable);
        p2xt.add(_SignalGroupTurnoutScrollPane, BorderLayout.CENTER);
        contentPane.add(p2xt);
        p2xt.setVisible(true);
        JPanel po = new JPanel();
        po.setLayout(new FlowLayout());
        JLabel operLabel = new JLabel(Bundle.getMessage("ChooseOrAnd"));
        po.add(operLabel);
        po.add(_SensorTurnoutOper);
        contentPane.add(po);
        // 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("SelectInGroup", Bundle.getMessage("Sensors"))));
        p2xs.add(p21s);
        _SignalGroupSensorModel = new SignalGroupSensorModel();
        JTable SignalGroupSensorTable = new JTable(_SignalGroupSensorModel);
        TableRowSorter<SignalGroupSensorModel> sgsSorter = new TableRowSorter<>(_SignalGroupSensorModel);
        sgsSorter.setComparator(SignalGroupSensorModel.SNAME_COLUMN, new SystemNameComparator());
        RowSorterUtil.setSortOrder(sgsSorter, SignalGroupSensorModel.SNAME_COLUMN, SortOrder.ASCENDING);
        SignalGroupSensorTable.setRowSorter(sgsSorter);
        SignalGroupSensorTable.setRowSelectionAllowed(false);
        SignalGroupSensorTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 80));
        JComboBox<String> stateSCombo = new JComboBox<String>();
        stateSCombo.addItem(SET_TO_ACTIVE);
        stateSCombo.addItem(SET_TO_INACTIVE);
        TableColumnModel SignalGroupSensorColumnModel = SignalGroupSensorTable.getColumnModel();
        TableColumn includeColumnS = SignalGroupSensorColumnModel.getColumn(SignalGroupSensorModel.INCLUDE_COLUMN);
        includeColumnS.setResizable(false);
        includeColumnS.setMinWidth(50);
        includeColumnS.setMaxWidth(60);
        TableColumn sNameColumnS = SignalGroupSensorColumnModel.getColumn(SignalGroupSensorModel.SNAME_COLUMN);
        sNameColumnS.setResizable(true);
        sNameColumnS.setMinWidth(75);
        sNameColumnS.setMaxWidth(95);
        TableColumn uNameColumnS = SignalGroupSensorColumnModel.getColumn(SignalGroupSensorModel.UNAME_COLUMN);
        uNameColumnS.setResizable(true);
        uNameColumnS.setMinWidth(210);
        uNameColumnS.setMaxWidth(260);
        TableColumn stateColumnS = SignalGroupSensorColumnModel.getColumn(SignalGroupSensorModel.STATE_COLUMN);
        stateColumnS.setCellEditor(new DefaultCellEditor(stateSCombo));
        stateColumnS.setResizable(false);
        stateColumnS.setMinWidth(90);
        stateColumnS.setMaxWidth(100);
        _SignalGroupSensorScrollPane = new JScrollPane(SignalGroupSensorTable);
        p2xs.add(_SignalGroupSensorScrollPane, BorderLayout.CENTER);
        contentPane.add(p2xs);
        p2xs.setVisible(true);
        // 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);
        pa.add(p1);
        Border pBorder = BorderFactory.createEtchedBorder();
        pa.setBorder(pBorder);
        contentPane.add(pa);
        // add buttons - Add SignalGroup button
        JPanel pb = new JPanel();
        pb.setLayout(new FlowLayout(FlowLayout.TRAILING));
        // add Cancel button
        pb.add(cancelButton);
        cancelButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancelSubPressed(e);
            }
        });
        // add Update SignalGroup button
        pb.add(updateSubButton);
        updateSubButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                updateSubPressed(e, false);
            }
        });
        updateSubButton.setToolTipText(Bundle.getMessage("TooltipUpdate"));
        p2xtSpace.setVisible(false);
        p2xsSpace.setVisible(false);
        updateSubButton.setVisible(true);
        contentPane.add(pb);
        addSubFrame.pack();
    }
    // set listener for window closing
    addSubFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            addSubFrame.setVisible(false);
            cancelSubEdit();
            _SignalGroupSensorModel.dispose();
            _SignalGroupTurnoutModel.dispose();
        }
    });
    addSubFrame.setVisible(true);
    // add AND/OR choice box
    setoperBox(curSignalGroup.getSensorTurnoutOper(curSignalHead), _SensorTurnoutOper);
    setSignalHeadStateBox(curSignalGroup.getHeadOnState(curSignalHead), _OnAppearance);
    setSignalHeadStateBox(curSignalGroup.getHeadOffState(curSignalHead), _OffAppearance);
    int setRow = 0;
    for (int i = _turnoutList.size() - 1; i >= 0; i--) {
        SignalGroupTurnout turnout = _turnoutList.get(i);
        Turnout tTurnout = turnout.getTurnout();
        if (curSignalGroup.isTurnoutIncluded(curSignalHead, tTurnout)) {
            turnout.setIncluded(true);
            turnout.setState(curSignalGroup.getTurnoutState(curSignalHead, tTurnout));
            setRow = i;
        } else {
            turnout.setIncluded(false);
            turnout.setState(Turnout.CLOSED);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _SignalGroupTurnoutScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _SignalGroupTurnoutModel.fireTableDataChanged();
    for (int i = _sensorList.size() - 1; i >= 0; i--) {
        SignalGroupSensor sensor = _sensorList.get(i);
        Sensor tSensor = sensor.getSensor();
        if (curSignalGroup.isSensorIncluded(curSignalHead, tSensor)) {
            sensor.setIncluded(true);
            sensor.setState(curSignalGroup.getSensorState(curSignalHead, tSensor));
            setRow = i;
        } else {
            sensor.setIncluded(false);
            sensor.setState(Sensor.INACTIVE);
        }
    }
    status1.setText(updateInst);
    updateSubButton.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) TableColumnModel(javax.swing.table.TableColumnModel) Container(java.awt.Container) 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) 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) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 47 with TableColumnModel

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

the class SectionTableAction method addEditPressed.

void addEditPressed() {
    pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
    if (addFrame == null) {
        addFrame = new JmriJFrame(Bundle.getMessage("TitleAddSection"));
        addFrame.addHelpMenu("package.jmri.jmrit.beantable.SectionAddEdit", true);
        addFrame.getContentPane().setLayout(new BoxLayout(addFrame.getContentPane(), BoxLayout.Y_AXIS));
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        p.add(sysNameLabel);
        p.add(sysNameFixed);
        p.add(sysName);
        p.add(_autoSystemName);
        _autoSystemName.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                autoSystemName();
            }
        });
        if (pref.getSimplePreferenceState(systemNameAuto)) {
            _autoSystemName.setSelected(true);
        }
        sysName.setToolTipText(rbx.getString("SectionSystemNameHint"));
        p.add(new JLabel("     "));
        p.add(userNameLabel);
        p.add(userName);
        userName.setToolTipText(rbx.getString("SectionUserNameHint"));
        addFrame.getContentPane().add(p);
        JPanel pa = new JPanel();
        pa.setLayout(new FlowLayout());
        pa.add(generationStateLabel);
        addFrame.getContentPane().add(pa);
        addFrame.getContentPane().add(new JSeparator());
        JPanel p1 = new JPanel();
        p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
        JPanel p11 = new JPanel();
        p11.setLayout(new FlowLayout());
        p11.add(new JLabel(rbx.getString("BlockTableMessage")));
        p1.add(p11);
        JPanel p12 = new JPanel();
        // initialize table of blocks
        blockTableModel = new BlockTableModel();
        JTable blockTable = new JTable(blockTableModel);
        blockTable.setRowSelectionAllowed(false);
        blockTable.setPreferredScrollableViewportSize(new java.awt.Dimension(350, 100));
        TableColumnModel blockColumnModel = blockTable.getColumnModel();
        TableColumn sNameColumn = blockColumnModel.getColumn(BlockTableModel.SNAME_COLUMN);
        sNameColumn.setResizable(true);
        sNameColumn.setMinWidth(90);
        sNameColumn.setMaxWidth(130);
        TableColumn uNameColumn = blockColumnModel.getColumn(BlockTableModel.UNAME_COLUMN);
        uNameColumn.setResizable(true);
        uNameColumn.setMinWidth(210);
        uNameColumn.setMaxWidth(260);
        JScrollPane blockTableScrollPane = new JScrollPane(blockTable);
        p12.add(blockTableScrollPane, BorderLayout.CENTER);
        p1.add(p12);
        JPanel p13 = new JPanel();
        p13.setLayout(new FlowLayout());
        p13.add(deleteBlocks = new JButton(rbx.getString("DeleteAllBlocksButton")));
        deleteBlocks.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                deleteBlocksPressed(e);
            }
        });
        deleteBlocks.setToolTipText(rbx.getString("DeleteAllBlocksButtonHint"));
        p13.add(new JLabel("     "));
        p13.add(blockBox);
        blockBox.setToolTipText(rbx.getString("BlockBoxHint"));
        p13.add(addBlock = new JButton(rbx.getString("AddBlockButton")));
        addBlock.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                addBlockPressed(e);
            }
        });
        addBlock.setToolTipText(rbx.getString("AddBlockButtonHint"));
        p1.add(p13);
        addFrame.getContentPane().add(p1);
        addFrame.getContentPane().add(new JSeparator());
        JPanel p31 = new JPanel();
        p31.setLayout(new FlowLayout());
        p31.add(new JLabel(rbx.getString("EntryPointTable")));
        addFrame.getContentPane().add(p31);
        JPanel p32 = new JPanel();
        p32.setLayout(new FlowLayout());
        entryPointOptions = new ButtonGroup();
        p32.add(manually);
        entryPointOptions.add(manually);
        manually.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                manualEntryPoints = true;
            }
        });
        manually.setToolTipText(rbx.getString("SetManuallyHint"));
        p32.add(new JLabel("   "));
        p32.add(automatic);
        entryPointOptions.add(automatic);
        automatic.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                manualEntryPoints = false;
            }
        });
        automatic.setToolTipText(rbx.getString("SetAutomaticHint"));
        p32.add(layoutEditorBox);
        layoutEditorBox.setToolTipText(rbx.getString("LayoutEditorBoxHint"));
        layoutEditorBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                layoutEditorSelectionChanged();
            }
        });
        // djd debugging - temporarily hide these items until the automatic setting of entry point direction is ready
        //   addFrame.getContentPane().add(p32);
        // end djd debugging
        JPanel p33 = new JPanel();
        // initialize table of entry points
        entryPointTableModel = new EntryPointTableModel();
        JTable entryPointTable = new JTable(entryPointTableModel);
        entryPointTable.setRowSelectionAllowed(false);
        // GT - 12-Oct-2009
        entryPointTable.setPreferredScrollableViewportSize(new java.awt.Dimension(550, 100));
        TableColumnModel entryPointColumnModel = entryPointTable.getColumnModel();
        TableColumn fromBlockColumn = entryPointColumnModel.getColumn(EntryPointTableModel.BLOCK_COLUMN);
        fromBlockColumn.setResizable(true);
        fromBlockColumn.setMinWidth(250);
        fromBlockColumn.setMaxWidth(310);
        // GT - 12-Oct-2009 - start   
        TableColumn toBlockColumn = entryPointColumnModel.getColumn(EntryPointTableModel.TO_BLOCK_COLUMN);
        toBlockColumn.setResizable(true);
        toBlockColumn.setMinWidth(150);
        toBlockColumn.setMaxWidth(210);
        // GT - 12-Oct-2009 - end   
        JComboBox<String> directionCombo = new JComboBox<String>();
        directionCombo.addItem(rbx.getString("SectionForward"));
        directionCombo.addItem(rbx.getString("SectionReverse"));
        directionCombo.addItem(Bundle.getMessage("BeanStateUnknown"));
        TableColumn directionColumn = entryPointColumnModel.getColumn(EntryPointTableModel.DIRECTION_COLUMN);
        directionColumn.setCellEditor(new DefaultCellEditor(directionCombo));
        entryPointTable.setRowHeight(directionCombo.getPreferredSize().height);
        directionColumn.setPreferredWidth(directionCombo.getPreferredSize().width);
        directionColumn.setResizable(false);
        JScrollPane entryPointTableScrollPane = new JScrollPane(entryPointTable);
        p33.add(entryPointTableScrollPane, BorderLayout.CENTER);
        addFrame.getContentPane().add(p33);
        p33.setVisible(true);
        JPanel p34 = new JPanel();
        p34.setLayout(new FlowLayout());
        p34.add(new JLabel(rbx.getString("DirectionNote")));
        addFrame.getContentPane().add(p34);
        addFrame.getContentPane().add(new JSeparator());
        // set up for direction sensors
        JPanel p20 = new JPanel();
        p20.setLayout(new FlowLayout());
        p20.add(new JLabel(rbx.getString("DirectionSensorLabel")));
        addFrame.getContentPane().add(p20);
        JPanel p21 = new JPanel();
        p21.setLayout(new FlowLayout());
        p21.add(new JLabel(rbx.getString("ForwardSensor")));
        p21.add(forwardSensorField);
        forwardSensorField.setToolTipText(rbx.getString("ForwardSensorHint"));
        p21.add(new JLabel("     "));
        p21.add(new JLabel(rbx.getString("ReverseSensor")));
        p21.add(reverseSensorField);
        reverseSensorField.setToolTipText(rbx.getString("ReverseSensorHint"));
        addFrame.getContentPane().add(p21);
        addFrame.getContentPane().add(new JSeparator());
        // set up for stopping sensors
        JPanel p40 = new JPanel();
        p40.setLayout(new FlowLayout());
        p40.add(new JLabel(rbx.getString("StoppingSensorLabel")));
        addFrame.getContentPane().add(p40);
        JPanel p41 = new JPanel();
        p41.setLayout(new FlowLayout());
        p41.add(new JLabel(rbx.getString("ForwardStopSensor")));
        p41.add(forwardStopSensorField);
        forwardStopSensorField.setToolTipText(rbx.getString("ForwardStopSensorHint"));
        p41.add(new JLabel("     "));
        p41.add(new JLabel(rbx.getString("ReverseStopSensor")));
        p41.add(reverseStopSensorField);
        reverseStopSensorField.setToolTipText(rbx.getString("ReverseStopSensorHint"));
        addFrame.getContentPane().add(p41);
        addFrame.getContentPane().add(new JSeparator());
        // set up bottom buttons
        JButton cancel = null;
        JPanel pb = new JPanel();
        pb.setLayout(new FlowLayout());
        pb.add(cancel = new JButton(Bundle.getMessage("ButtonCancel")));
        cancel.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancelPressed(e);
            }
        });
        cancel.setToolTipText(rbx.getString("CancelButtonHint"));
        pb.add(create = new JButton(Bundle.getMessage("ButtonCreate")));
        create.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                createPressed(e);
            }
        });
        create.setToolTipText(rbx.getString("SectionCreateButtonHint"));
        pb.add(update = new JButton(Bundle.getMessage("ButtonUpdate")));
        update.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                updatePressed(e);
            }
        });
        update.setToolTipText(rbx.getString("SectionUpdateButtonHint"));
        addFrame.getContentPane().add(pb);
    }
    if (editMode) {
        // setup for edit window
        _autoSystemName.setVisible(false);
        sysNameLabel.setEnabled(true);
        create.setVisible(false);
        update.setVisible(true);
        sysName.setVisible(false);
        sysNameFixed.setVisible(true);
        initializeEditInformation();
    } else {
        // setup for create window
        _autoSystemName.setVisible(true);
        create.setVisible(true);
        update.setVisible(false);
        sysName.setVisible(true);
        sysNameFixed.setVisible(false);
        autoSystemName();
        clearForCreate();
    }
    // initialize layout editor panels
    if (initializeLayoutEditorCombo(layoutEditorBox)) {
        manually.setVisible(true);
        automatic.setVisible(true);
        layoutEditorBox.setVisible(true);
    } else {
        manually.setVisible(false);
        automatic.setVisible(false);
        layoutEditorBox.setVisible(false);
    }
    // initialize block combo - first time
    initializeBlockCombo();
    addFrame.pack();
    addFrame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) JSeparator(javax.swing.JSeparator) DefaultCellEditor(javax.swing.DefaultCellEditor) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) ButtonGroup(javax.swing.ButtonGroup) JTable(javax.swing.JTable)

Example 48 with TableColumnModel

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

the class ListFrame method initComponents.

@Override
public void initComponents() throws Exception {
    // set the frame's initial state
    setTitle(rb.getString("WindowTitle"));
    setSize(500, 400);
    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // Set up the node selection panel
    initializeNodes();
    nodeSelBox.setEditable(false);
    if (numConfigNodes > 0) {
        nodeSelBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                displayNodeInfo((String) nodeSelBox.getSelectedItem());
            }
        });
        inputBits.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                if (inputSelected == false) {
                    inputSelected = true;
                    displayNodeInfo(selNodeID);
                }
            }
        });
        outputBits.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                if (inputSelected == true) {
                    inputSelected = false;
                    displayNodeInfo(selNodeID);
                }
            }
        });
    } else {
        nodeInfoText.setText(rb.getString("NoNodesError"));
    }
    nodeSelBox.setToolTipText(rb.getString("NodeBoxTip"));
    inputBits.setToolTipText(rb.getString("ShowInputTip"));
    outputBits.setToolTipText(rb.getString("ShowOutputTip"));
    JPanel panel1 = new JPanel();
    panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
    JPanel panel11 = new JPanel();
    panel11.add(nodeLabel);
    panel11.add(nodeSelBox);
    bitTypeGroup.add(outputBits);
    bitTypeGroup.add(inputBits);
    panel11.add(inputBits);
    panel11.add(outputBits);
    JPanel panel12 = new JPanel();
    panel12.add(nodeInfoText);
    panel1.add(panel11);
    panel1.add(panel12);
    Border panel1Border = BorderFactory.createEtchedBorder();
    Border panel1Titled = BorderFactory.createTitledBorder(panel1Border, rb.getString("NodePanelName"));
    panel1.setBorder(panel1Titled);
    contentPane.add(panel1);
    if (numConfigNodes > 0) {
        // Set up the assignment panel
        assignmentPanel = new JPanel();
        assignmentPanel.setLayout(new BoxLayout(assignmentPanel, BoxLayout.Y_AXIS));
        assignmentListModel = new AssignmentTableModel();
        assignmentTable = new JTable(assignmentListModel);
        assignmentTable.setRowSelectionAllowed(false);
        assignmentTable.setPreferredScrollableViewportSize(new java.awt.Dimension(300, 350));
        TableColumnModel assignmentColumnModel = assignmentTable.getColumnModel();
        TableColumn bitColumn = assignmentColumnModel.getColumn(AssignmentTableModel.BIT_COLUMN);
        bitColumn.setMinWidth(20);
        bitColumn.setMaxWidth(40);
        bitColumn.setResizable(true);
        TableColumn addressColumn = assignmentColumnModel.getColumn(AssignmentTableModel.ADDRESS_COLUMN);
        addressColumn.setMinWidth(40);
        addressColumn.setMaxWidth(85);
        addressColumn.setResizable(true);
        TableColumn sysColumn = assignmentColumnModel.getColumn(AssignmentTableModel.SYSNAME_COLUMN);
        sysColumn.setMinWidth(75);
        sysColumn.setMaxWidth(100);
        sysColumn.setResizable(true);
        TableColumn userColumn = assignmentColumnModel.getColumn(AssignmentTableModel.USERNAME_COLUMN);
        userColumn.setMinWidth(90);
        userColumn.setMaxWidth(450);
        userColumn.setResizable(true);
        JScrollPane assignmentScrollPane = new JScrollPane(assignmentTable);
        assignmentPanel.add(assignmentScrollPane, BorderLayout.CENTER);
        if (inputSelected) {
            assignmentPanel.setBorder(inputBorderTitled);
        } else {
            assignmentPanel.setBorder(outputBorderTitled);
        }
        contentPane.add(assignmentPanel);
    }
    // Set up Print button
    JPanel panel3 = new JPanel();
    panel3.setLayout(new FlowLayout());
    printButton.setVisible(true);
    printButton.setToolTipText(rb.getString("PrintButtonTip"));
    if (numConfigNodes > 0) {
        printButton.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                printButtonActionPerformed(e);
            }
        });
    }
    panel3.add(printButton);
    contentPane.add(panel3);
    if (numConfigNodes > 0) {
        // initialize for the first time
        displayNodeInfo((String) nodeSelBox.getSelectedItem());
    }
    addHelpMenu("package.jmri.jmrix.maple.assignment.ListFrame", true);
    // pack for display
    pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) ActionEvent(java.awt.event.ActionEvent) Container(java.awt.Container) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) Border(javax.swing.border.Border)

Example 49 with TableColumnModel

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

the class LogixTableAction method makeEditLogixWindow.

/**
     * Create and/or initialize the Edit Logix pane.
     */
void makeEditLogixWindow() {
    // Setup the name box components.
    setNameBoxListeners();
    //if (log.isDebugEnabled()) log.debug("makeEditLogixWindow ");
    editUserName.setText(_curLogix.getUserName());
    // clear conditional table if needed
    if (conditionalTableModel != null) {
        conditionalTableModel.fireTableStructureChanged();
    }
    inEditMode = true;
    if (editLogixFrame == null) {
        editLogixFrame = new JmriJFrame(rbx.getString("TitleEditLogix"), false, false);
        editLogixFrame.addHelpMenu("package.jmri.jmrit.beantable.LogixAddEdit", true);
        editLogixFrame.setLocation(100, 30);
        Container contentPane = editLogixFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        JPanel panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        JLabel systemNameLabel = new JLabel(Bundle.getMessage("ColumnSystemName") + ":");
        panel1.add(systemNameLabel);
        JLabel fixedSystemName = new JLabel(_curLogix.getSystemName());
        panel1.add(fixedSystemName);
        contentPane.add(panel1);
        JPanel panel2 = new JPanel();
        panel2.setLayout(new FlowLayout());
        JLabel userNameLabel = new JLabel(Bundle.getMessage("ColumnUserName") + ":");
        panel2.add(userNameLabel);
        panel2.add(editUserName);
        editUserName.setToolTipText(rbx.getString("LogixUserNameHint2"));
        contentPane.add(panel2);
        // add table of Conditionals
        JPanel pctSpace = new JPanel();
        pctSpace.setLayout(new FlowLayout());
        pctSpace.add(new JLabel("   "));
        contentPane.add(pctSpace);
        JPanel pTitle = new JPanel();
        pTitle.setLayout(new FlowLayout());
        pTitle.add(new JLabel(rbx.getString("ConditionalTableTitle")));
        contentPane.add(pTitle);
        // initialize table of conditionals
        conditionalTableModel = new ConditionalTableModel();
        JTable conditionalTable = new JTable(conditionalTableModel);
        conditionalTable.setRowSelectionAllowed(false);
        TableColumnModel conditionalColumnModel = conditionalTable.getColumnModel();
        TableColumn sNameColumn = conditionalColumnModel.getColumn(ConditionalTableModel.SNAME_COLUMN);
        sNameColumn.setResizable(true);
        sNameColumn.setMinWidth(100);
        sNameColumn.setPreferredWidth(130);
        TableColumn uNameColumn = conditionalColumnModel.getColumn(ConditionalTableModel.UNAME_COLUMN);
        uNameColumn.setResizable(true);
        uNameColumn.setMinWidth(210);
        uNameColumn.setPreferredWidth(260);
        TableColumn stateColumn = conditionalColumnModel.getColumn(ConditionalTableModel.STATE_COLUMN);
        stateColumn.setResizable(true);
        stateColumn.setMinWidth(50);
        stateColumn.setMaxWidth(100);
        TableColumn buttonColumn = conditionalColumnModel.getColumn(ConditionalTableModel.BUTTON_COLUMN);
        // install button renderer and editor
        ButtonRenderer buttonRenderer = new ButtonRenderer();
        conditionalTable.setDefaultRenderer(JButton.class, buttonRenderer);
        TableCellEditor buttonEditor = new ButtonEditor(new JButton());
        conditionalTable.setDefaultEditor(JButton.class, buttonEditor);
        JButton testButton = new JButton("XXXXXX");
        conditionalTable.setRowHeight(testButton.getPreferredSize().height);
        buttonColumn.setMinWidth(testButton.getPreferredSize().width);
        buttonColumn.setMaxWidth(testButton.getPreferredSize().width);
        buttonColumn.setResizable(false);
        JScrollPane conditionalTableScrollPane = new JScrollPane(conditionalTable);
        Dimension dim = conditionalTable.getPreferredSize();
        dim.height = 450;
        conditionalTableScrollPane.getViewport().setPreferredSize(dim);
        contentPane.add(conditionalTableScrollPane);
        // add message area between table and buttons
        JPanel panel4 = new JPanel();
        panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
        JPanel panel41 = new JPanel();
        panel41.setLayout(new FlowLayout());
        panel41.add(status);
        panel4.add(panel41);
        JPanel panel42 = new JPanel();
        panel42.setLayout(new FlowLayout());
        // Conditional panel buttons - New Conditional
        JButton newConditionalButton = new JButton(rbx.getString("NewConditionalButton"));
        panel42.add(newConditionalButton);
        newConditionalButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                newConditionalPressed(e);
            }
        });
        newConditionalButton.setToolTipText(rbx.getString("NewConditionalButtonHint"));
        // Conditional panel buttons - Reorder
        JButton reorderButton = new JButton(rbx.getString("ReorderButton"));
        panel42.add(reorderButton);
        reorderButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                reorderPressed(e);
            }
        });
        reorderButton.setToolTipText(rbx.getString("ReorderButtonHint"));
        // Conditional panel buttons - Calculate
        JButton calculateButton = new JButton(rbx.getString("CalculateButton"));
        panel42.add(calculateButton);
        calculateButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                calculatePressed(e);
            }
        });
        calculateButton.setToolTipText(rbx.getString("CalculateButtonHint"));
        panel4.add(panel42);
        Border panel4Border = BorderFactory.createEtchedBorder();
        panel4.setBorder(panel4Border);
        contentPane.add(panel4);
        // add buttons at bottom of window
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout());
        // Bottom Buttons - Done Logix
        JButton done = new JButton(Bundle.getMessage("ButtonDone"));
        panel5.add(done);
        done.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                donePressed(e);
            }
        });
        done.setToolTipText(rbx.getString("DoneButtonHint"));
        // Delete Logix
        JButton delete = new JButton(Bundle.getMessage("ButtonDelete"));
        panel5.add(delete);
        delete.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                deletePressed(e);
            }
        });
        delete.setToolTipText(rbx.getString("DeleteLogixButtonHint"));
        contentPane.add(panel5);
    }
    editLogixFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            if (inEditMode) {
                donePressed(null);
            } else {
                finishDone();
            }
        }
    });
    editLogixFrame.pack();
    editLogixFrame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ButtonEditor(jmri.util.table.ButtonEditor) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) Container(java.awt.Container) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) JTable(javax.swing.JTable) TableCellEditor(javax.swing.table.TableCellEditor) Border(javax.swing.border.Border) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 50 with TableColumnModel

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

the class DispatcherFrame method openDispatcherWindow.

void openDispatcherWindow() {
    if (dispatcherFrame == null) {
        dispatcherFrame = this;
        dispatcherFrame.setTitle(Bundle.getMessage("TitleDispatcher"));
        JMenuBar menuBar = new JMenuBar();
        optionsMenu = new OptionsMenu(this);
        menuBar.add(optionsMenu);
        setJMenuBar(menuBar);
        dispatcherFrame.addHelpMenu("package.jmri.jmrit.dispatcher.Dispatcher", true);
        contentPane = dispatcherFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        // set up active trains table
        JPanel p11 = new JPanel();
        p11.setLayout(new FlowLayout());
        p11.add(new JLabel(Bundle.getMessage("ActiveTrainTableTitle")));
        contentPane.add(p11);
        JPanel p12 = new JPanel();
        p12.setLayout(new FlowLayout());
        activeTrainsTableModel = new ActiveTrainsTableModel();
        JTable activeTrainsTable = new JTable(activeTrainsTableModel);
        activeTrainsTable.setRowSelectionAllowed(false);
        activeTrainsTable.setPreferredScrollableViewportSize(new java.awt.Dimension(950, 160));
        TableColumnModel activeTrainsColumnModel = activeTrainsTable.getColumnModel();
        TableColumn transitColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TRANSIT_COLUMN);
        transitColumn.setResizable(true);
        transitColumn.setMinWidth(140);
        transitColumn.setMaxWidth(220);
        TableColumn trainColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TRAIN_COLUMN);
        trainColumn.setResizable(true);
        trainColumn.setMinWidth(90);
        trainColumn.setMaxWidth(160);
        TableColumn typeColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.TYPE_COLUMN);
        typeColumn.setResizable(true);
        typeColumn.setMinWidth(130);
        typeColumn.setMaxWidth(190);
        TableColumn statusColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.STATUS_COLUMN);
        statusColumn.setResizable(true);
        statusColumn.setMinWidth(90);
        statusColumn.setMaxWidth(140);
        TableColumn modeColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.MODE_COLUMN);
        modeColumn.setResizable(true);
        modeColumn.setMinWidth(90);
        modeColumn.setMaxWidth(140);
        TableColumn allocatedColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.ALLOCATED_COLUMN);
        allocatedColumn.setResizable(true);
        allocatedColumn.setMinWidth(120);
        allocatedColumn.setMaxWidth(200);
        TableColumn nextSectionColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.NEXTSECTION_COLUMN);
        nextSectionColumn.setResizable(true);
        nextSectionColumn.setMinWidth(120);
        nextSectionColumn.setMaxWidth(200);
        TableColumn allocateButtonColumn = activeTrainsColumnModel.getColumn(ActiveTrainsTableModel.ALLOCATEBUTTON_COLUMN);
        allocateButtonColumn.setCellEditor(new ButtonEditor(new JButton()));
        allocateButtonColumn.setMinWidth(110);
        allocateButtonColumn.setMaxWidth(190);
        allocateButtonColumn.setResizable(false);
        ButtonRenderer buttonRenderer = new ButtonRenderer();
        activeTrainsTable.setDefaultRenderer(JButton.class, buttonRenderer);
        JButton sampleButton = new JButton(Bundle.getMessage("AllocateButtonName"));
        activeTrainsTable.setRowHeight(sampleButton.getPreferredSize().height);
        allocateButtonColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
        JScrollPane activeTrainsTableScrollPane = new JScrollPane(activeTrainsTable);
        p12.add(activeTrainsTableScrollPane, BorderLayout.CENTER);
        contentPane.add(p12);
        JPanel p13 = new JPanel();
        p13.setLayout(new FlowLayout());
        p13.add(addTrainButton = new JButton(Bundle.getMessage("InitiateTrain") + "..."));
        addTrainButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!newTrainActive) {
                    atFrame.initiateTrain(e);
                    newTrainActive = true;
                } else {
                    atFrame.showActivateFrame();
                }
            }
        });
        addTrainButton.setToolTipText(Bundle.getMessage("InitiateTrainButtonHint"));
        p13.add(new JLabel("   "));
        p13.add(new JLabel("   "));
        p13.add(allocateExtraButton = new JButton(Bundle.getMessage("AllocateExtra") + "..."));
        allocateExtraButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                allocateExtraSection(e);
            }
        });
        allocateExtraButton.setToolTipText(Bundle.getMessage("AllocateExtraButtonHint"));
        p13.add(new JLabel("   "));
        p13.add(cancelRestartButton = new JButton(Bundle.getMessage("CancelRestart") + "..."));
        cancelRestartButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!newTrainActive) {
                    cancelRestart(e);
                } else if (restartingTrainsList.size() > 0) {
                    atFrame.showActivateFrame();
                    JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Message2"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
                } else {
                    atFrame.showActivateFrame();
                }
            }
        });
        cancelRestartButton.setToolTipText(Bundle.getMessage("CancelRestartButtonHint"));
        p13.add(new JLabel("   "));
        p13.add(terminateTrainButton = new JButton(Bundle.getMessage("TerminateTrain") + "..."));
        terminateTrainButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!newTrainActive) {
                    terminateTrain(e);
                } else if (activeTrainsList.size() > 0) {
                    atFrame.showActivateFrame();
                    JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Message1"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE);
                } else {
                    atFrame.showActivateFrame();
                }
            }
        });
        terminateTrainButton.setToolTipText(Bundle.getMessage("TerminateTrainButtonHint"));
        contentPane.add(p13);
        // set up pending allocations table
        contentPane.add(new JSeparator());
        JPanel p21 = new JPanel();
        p21.setLayout(new FlowLayout());
        p21.add(new JLabel(Bundle.getMessage("RequestedAllocationsTableTitle")));
        contentPane.add(p21);
        JPanel p22 = new JPanel();
        p22.setLayout(new FlowLayout());
        allocationRequestTableModel = new AllocationRequestTableModel();
        JTable allocationRequestTable = new JTable(allocationRequestTableModel);
        allocationRequestTable.setRowSelectionAllowed(false);
        allocationRequestTable.setPreferredScrollableViewportSize(new java.awt.Dimension(950, 100));
        TableColumnModel allocationRequestColumnModel = allocationRequestTable.getColumnModel();
        TableColumn activeColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.ACTIVE_COLUMN);
        activeColumn.setResizable(true);
        activeColumn.setMinWidth(210);
        activeColumn.setMaxWidth(260);
        TableColumn priorityColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.PRIORITY_COLUMN);
        priorityColumn.setResizable(true);
        priorityColumn.setMinWidth(40);
        priorityColumn.setMaxWidth(60);
        TableColumn trainTypColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.TRAINTYPE_COLUMN);
        trainTypColumn.setResizable(true);
        trainTypColumn.setMinWidth(130);
        trainTypColumn.setMaxWidth(190);
        TableColumn sectionColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.SECTION_COLUMN);
        sectionColumn.setResizable(true);
        sectionColumn.setMinWidth(140);
        sectionColumn.setMaxWidth(210);
        TableColumn secStatusColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.STATUS_COLUMN);
        secStatusColumn.setResizable(true);
        secStatusColumn.setMinWidth(90);
        secStatusColumn.setMaxWidth(150);
        TableColumn occupancyColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.OCCUPANCY_COLUMN);
        occupancyColumn.setResizable(true);
        occupancyColumn.setMinWidth(80);
        occupancyColumn.setMaxWidth(130);
        TableColumn secLengthColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.SECTIONLENGTH_COLUMN);
        secLengthColumn.setResizable(true);
        secLengthColumn.setMinWidth(40);
        secLengthColumn.setMaxWidth(60);
        TableColumn allocateColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.ALLOCATEBUTTON_COLUMN);
        allocateColumn.setCellEditor(new ButtonEditor(new JButton()));
        allocateColumn.setMinWidth(90);
        allocateColumn.setMaxWidth(170);
        allocateColumn.setResizable(false);
        allocationRequestTable.setDefaultRenderer(JButton.class, buttonRenderer);
        sampleButton = new JButton(Bundle.getMessage("AllocateButton"));
        allocationRequestTable.setRowHeight(sampleButton.getPreferredSize().height);
        allocateColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
        TableColumn cancelButtonColumn = allocationRequestColumnModel.getColumn(AllocationRequestTableModel.CANCELBUTTON_COLUMN);
        cancelButtonColumn.setCellEditor(new ButtonEditor(new JButton()));
        cancelButtonColumn.setMinWidth(75);
        cancelButtonColumn.setMaxWidth(170);
        cancelButtonColumn.setResizable(false);
        cancelButtonColumn.setPreferredWidth((sampleButton.getPreferredSize().width) + 2);
        JScrollPane allocationRequestTableScrollPane = new JScrollPane(allocationRequestTable);
        p22.add(allocationRequestTableScrollPane, BorderLayout.CENTER);
        contentPane.add(p22);
        // set up allocated sections table
        contentPane.add(new JSeparator());
        JPanel p30 = new JPanel();
        p30.setLayout(new FlowLayout());
        p30.add(new JLabel(Bundle.getMessage("AllocatedSectionsTitle") + "    "));
        autoReleaseBox = new JCheckBox(Bundle.getMessage("AutoReleaseBoxLabel"));
        p30.add(autoReleaseBox);
        autoReleaseBox.setToolTipText(Bundle.getMessage("AutoReleaseBoxHint"));
        autoReleaseBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                handleAutoReleaseChanged(e);
            }
        });
        // initiallize autoRelease to match autoAllocate
        autoReleaseBox.setSelected(_AutoAllocate);
        autoAllocateBox = new JCheckBox(Bundle.getMessage("AutoDispatchItem"));
        p30.add(autoAllocateBox);
        autoAllocateBox.setToolTipText(Bundle.getMessage("AutoAllocateBoxHint"));
        autoAllocateBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                handleAutoAllocateChanged(e);
            }
        });
        contentPane.add(p30);
        autoAllocateBox.setSelected(_AutoAllocate);
        JPanel p31 = new JPanel();
        p31.setLayout(new FlowLayout());
        allocatedSectionTableModel = new AllocatedSectionTableModel();
        JTable allocatedSectionTable = new JTable(allocatedSectionTableModel);
        allocatedSectionTable.setRowSelectionAllowed(false);
        allocatedSectionTable.setPreferredScrollableViewportSize(new java.awt.Dimension(730, 200));
        TableColumnModel allocatedSectionColumnModel = allocatedSectionTable.getColumnModel();
        TableColumn activeAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.ACTIVE_COLUMN);
        activeAColumn.setResizable(true);
        activeAColumn.setMinWidth(250);
        activeAColumn.setMaxWidth(350);
        TableColumn sectionAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.SECTION_COLUMN);
        sectionAColumn.setResizable(true);
        sectionAColumn.setMinWidth(200);
        sectionAColumn.setMaxWidth(350);
        TableColumn occupancyAColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.OCCUPANCY_COLUMN);
        occupancyAColumn.setResizable(true);
        occupancyAColumn.setMinWidth(80);
        occupancyAColumn.setMaxWidth(140);
        TableColumn useStatusColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.USESTATUS_COLUMN);
        useStatusColumn.setResizable(true);
        useStatusColumn.setMinWidth(90);
        useStatusColumn.setMaxWidth(150);
        TableColumn releaseColumn = allocatedSectionColumnModel.getColumn(AllocatedSectionTableModel.RELEASEBUTTON_COLUMN);
        releaseColumn.setCellEditor(new ButtonEditor(new JButton()));
        releaseColumn.setMinWidth(90);
        releaseColumn.setMaxWidth(170);
        releaseColumn.setResizable(false);
        allocatedSectionTable.setDefaultRenderer(JButton.class, buttonRenderer);
        JButton sampleAButton = new JButton(Bundle.getMessage("ReleaseButton"));
        allocatedSectionTable.setRowHeight(sampleAButton.getPreferredSize().height);
        releaseColumn.setPreferredWidth((sampleAButton.getPreferredSize().width) + 2);
        JScrollPane allocatedSectionTableScrollPane = new JScrollPane(allocatedSectionTable);
        p31.add(allocatedSectionTableScrollPane, BorderLayout.CENTER);
        contentPane.add(p31);
    }
    dispatcherFrame.pack();
    dispatcherFrame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ButtonEditor(jmri.util.table.ButtonEditor) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) JSeparator(javax.swing.JSeparator) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) JMenuBar(javax.swing.JMenuBar) ButtonRenderer(jmri.util.table.ButtonRenderer)

Aggregations

TableColumnModel (javax.swing.table.TableColumnModel)168 TableColumn (javax.swing.table.TableColumn)66 JTable (javax.swing.JTable)34 JScrollPane (javax.swing.JScrollPane)31 JButton (javax.swing.JButton)30 BoxLayout (javax.swing.BoxLayout)24 TableCellEditor (javax.swing.table.TableCellEditor)23 ButtonEditor (jmri.util.table.ButtonEditor)23 ButtonRenderer (jmri.util.table.ButtonRenderer)23 JLabel (javax.swing.JLabel)22 JPanel (javax.swing.JPanel)22 ActionEvent (java.awt.event.ActionEvent)20 ActionListener (java.awt.event.ActionListener)16 FlowLayout (java.awt.FlowLayout)15 Border (javax.swing.border.Border)13 Iterator (java.util.Iterator)12 Set (java.util.Set)12 JTableHeader (javax.swing.table.JTableHeader)12 TableCellRenderer (javax.swing.table.TableCellRenderer)12 Container (java.awt.Container)10