Search in sources :

Example 96 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class LightTableAction method addEditControlWindow.

/**
     * Creates the Add/Edit control window
     */
private void addEditControlWindow() {
    if (addControlFrame == null) {
        addControlFrame = new JmriJFrame(Bundle.getMessage("TitleAddLightControl"), false, true);
        addControlFrame.addHelpMenu("package.jmri.jmrit.beantable.LightAddEdit", true);
        addControlFrame.setLocation(120, 40);
        Container contentPane = addControlFrame.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        JPanel panel3 = new JPanel();
        panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
        JPanel panel31 = new JPanel();
        panel31.setLayout(new FlowLayout());
        panel31.add(typeBoxLabel);
        panel31.add(typeBox = new JComboBox<>(new String[] { noControl, sensorControl, fastClockControl, turnoutStatusControl, timedOnControl, twoSensorControl }));
        noControlIndex = 0;
        sensorControlIndex = 1;
        fastClockControlIndex = 2;
        turnoutStatusControlIndex = 3;
        timedOnControlIndex = 4;
        twoSensorControlIndex = 5;
        typeBox.addActionListener((ActionEvent e) -> {
            controlTypeChanged();
        });
        typeBox.setToolTipText(Bundle.getMessage("LightControlTypeHint"));
        JPanel panel32 = new JPanel();
        panel32.setLayout(new FlowLayout());
        panel32.add(f1Label);
        panel32.add(field1a);
        panel32.add(field1a2);
        panel32.add(field1b);
        panel32.add(field1c);
        panel32.add(field1d);
        field1a.setText("");
        field1a2.setText("");
        field1b.setText("00:00");
        field1c.setText("");
        field1d.setText("");
        field1b.setVisible(false);
        field1c.setVisible(false);
        field1d.setVisible(false);
        field1a.setToolTipText(Bundle.getMessage("LightSensorHint"));
        field1a2.setToolTipText(Bundle.getMessage("LightTwoSensorHint"));
        JPanel panel33 = new JPanel();
        panel33.setLayout(new FlowLayout());
        panel33.add(f2Label);
        panel33.add(stateBox = new JComboBox<>(new String[] { Bundle.getMessage("SensorStateActive"), Bundle.getMessage("SensorStateInactive") }));
        stateBox.setToolTipText(Bundle.getMessage("LightSensorSenseHint"));
        panel33.add(field2a);
        panel33.add(field2b);
        field2a.setText("00:00");
        field2a.setVisible(false);
        field2b.setText("0");
        field2b.setVisible(false);
        panel3.add(panel31);
        panel3.add(panel32);
        panel3.add(panel33);
        Border panel3Border = BorderFactory.createEtchedBorder();
        panel3.setBorder(panel3Border);
        contentPane.add(panel3);
        JPanel panel5 = new JPanel();
        panel5.setLayout(new FlowLayout(FlowLayout.TRAILING));
        panel5.add(cancelControl = new JButton(Bundle.getMessage("ButtonCancel")));
        cancelControl.addActionListener(this::cancelControlPressed);
        cancelControl.setToolTipText(Bundle.getMessage("LightCancelButtonHint"));
        panel5.add(createControl = new JButton(Bundle.getMessage("ButtonCreate")));
        createControl.addActionListener(this::createControlPressed);
        createControl.setToolTipText(Bundle.getMessage("LightCreateControlButtonHint"));
        panel5.add(updateControl = new JButton(Bundle.getMessage("ButtonUpdate")));
        updateControl.addActionListener(this::updateControlPressed);
        updateControl.setToolTipText(Bundle.getMessage("LightUpdateControlButtonHint"));
        cancelControl.setVisible(true);
        updateControl.setVisible(false);
        createControl.setVisible(true);
        contentPane.add(panel5);
        addControlFrame.addWindowListener(new java.awt.event.WindowAdapter() {

            @Override
            public void windowClosing(java.awt.event.WindowEvent e) {
                cancelControlPressed(null);
            }
        });
    }
    // force GUI status consistent
    typeBox.setSelectedIndex(defaultControlIndex);
    addControlFrame.pack();
    addControlFrame.setVisible(true);
}
Also used : 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) Container(java.awt.Container) JmriJFrame(jmri.util.JmriJFrame) Border(javax.swing.border.Border)

Example 97 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class TurnoutTableAction method makeAutomationBox.

/**
     * Create a {@literal JComboBox<String>} containing all the options for
     * turnout automation parameters for this turnout
     *
     * @param t the turnout
     * @return the JComboBox
     */
protected JComboBox<String> makeAutomationBox(Turnout t) {
    String[] str = new String[] { "empty" };
    final JComboBox<String> cb = new JComboBox<String>(str);
    final Turnout myTurnout = t;
    updateAutomationBox(t, cb);
    cb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setTurnoutOperation(myTurnout, cb);
            // avoid recursion
            cb.removeActionListener(this);
            updateAutomationBox(myTurnout, cb);
            cb.addActionListener(this);
        }
    });
    return cb;
}
Also used : JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Turnout(jmri.Turnout)

Example 98 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class TableFrames method makePathTurnoutFrame.

/*
     * ********************* PathTurnoutFrame *****************************
     */
protected JInternalFrame makePathTurnoutFrame(OBlock block, String pathName) {
    String title = Bundle.getMessage("TitlePathTurnoutTable", block.getDisplayName(), pathName);
    JInternalFrame frame = new JInternalFrame(title, true, true, false, true);
    if (log.isDebugEnabled()) {
        log.debug("makePathTurnoutFrame for Block " + block.getDisplayName() + " and Path " + pathName);
    }
    frame.setName(makePathTurnoutName(block.getSystemName(), pathName));
    OPath path = block.getPathByName(pathName);
    if (path == null) {
        return null;
    }
    PathTurnoutTableModel PathTurnoutModel = new PathTurnoutTableModel(path);
    PathTurnoutModel.init();
    JTable PathTurnoutTable = new JTable(PathTurnoutModel);
    PathTurnoutTable.setTransferHandler(new jmri.util.DnDTableImportExportHandler(new int[] { PathTurnoutTableModel.SETTINGCOLUMN, PathTurnoutTableModel.DELETE_COL }));
    PathTurnoutTable.setDragEnabled(true);
    JComboBox<String> box = new JComboBox<String>(PathTurnoutTableModel.turnoutStates);
    PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.SETTINGCOLUMN).setCellEditor(new DefaultCellEditor(box));
    PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.DELETE_COL).setCellEditor(new ButtonEditor(new JButton()));
    PathTurnoutTable.getColumnModel().getColumn(PathTurnoutTableModel.DELETE_COL).setCellRenderer(new ButtonRenderer());
    //PathTurnoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (int i = 0; i < PathTurnoutModel.getColumnCount(); i++) {
        int width = PathTurnoutModel.getPreferredWidth(i);
        PathTurnoutTable.getColumnModel().getColumn(i).setPreferredWidth(width);
    }
    PathTurnoutTable.sizeColumnsToFit(-1);
    int tableWidth = PathTurnoutTable.getPreferredSize().width;
    PathTurnoutTable.setPreferredScrollableViewportSize(new java.awt.Dimension(tableWidth, ROW_HEIGHT * 5));
    JScrollPane tablePane = new JScrollPane(PathTurnoutTable);
    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout(5, 5));
    JLabel prompt = new JLabel(Bundle.getMessage("AddTurnoutPrompt"));
    contentPane.add(prompt, BorderLayout.NORTH);
    contentPane.add(tablePane, BorderLayout.CENTER);
    frame.addInternalFrameListener(this);
    frame.setContentPane(contentPane);
    frame.setLocation(10, 270);
    frame.pack();
    return frame;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ButtonEditor(jmri.util.table.ButtonEditor) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) OPath(jmri.jmrit.logix.OPath) Point(java.awt.Point) DefaultCellEditor(javax.swing.DefaultCellEditor) Dimension(java.awt.Dimension) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) JInternalFrame(javax.swing.JInternalFrame) ButtonRenderer(jmri.util.table.ButtonRenderer)

Example 99 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class AddSignalMastPanel method copyFromMastSelection.

JComboBox<String> copyFromMastSelection() {
    JComboBox<String> mastSelect = new JComboBox<String>();
    List<String> names = InstanceManager.getDefault(jmri.SignalMastManager.class).getSystemNameList();
    for (String name : names) {
        if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
            if ((InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name) instanceof DccSignalMast) && InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name).getSignalSystem().getSystemName().equals(sigsysname) && !InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName().equals(userName.getText())) {
                // don't copy yourself
                mastSelect.addItem(InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName());
            }
        } else if ((Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem()))) {
            if ((InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name) instanceof MatrixSignalMast) && InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name).getSignalSystem().getSystemName().equals(sigsysname) && !InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName().equals(userName.getText())) {
                // don't copy yourself
                mastSelect.addItem(InstanceManager.getDefault(jmri.SignalMastManager.class).getNamedBean(name).getDisplayName());
            }
        }
    }
    if (mastSelect.getItemCount() == 0) {
        mastSelect.setEnabled(false);
    } else {
        mastSelect.insertItemAt("", 0);
        mastSelect.setSelectedIndex(0);
        mastSelect.addActionListener(new ActionListener() {

            // e.getSource() cast from mastSelect source
            @SuppressWarnings("unchecked")
            @Override
            public void actionPerformed(ActionEvent e) {
                JComboBox<String> eb = (JComboBox<String>) e.getSource();
                String sourceMast = (String) eb.getSelectedItem();
                if (sourceMast != null && !sourceMast.equals("")) {
                    if ((Bundle.getMessage("DCCMast").equals(signalMastDriver.getSelectedItem())) || (Bundle.getMessage("LNCPMast").equals(signalMastDriver.getSelectedItem()))) {
                        copyFromAnotherDCCMastAspect(sourceMast);
                    } else if ((Bundle.getMessage("MatrixCtlMast").equals(signalMastDriver.getSelectedItem()))) {
                        copyFromAnotherMatrixMastAspect(sourceMast);
                    }
                }
            }
        });
    }
    return mastSelect;
}
Also used : JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DccSignalMast(jmri.implementation.DccSignalMast) MatrixSignalMast(jmri.implementation.MatrixSignalMast)

Example 100 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class SensorTableDataModel method setValueAt.

@Override
public void setValueAt(Object value, int row, int col) {
    if (row >= sysNameList.size()) {
        log.debug("row is greater than name list");
        return;
    }
    String name = sysNameList.get(row);
    Sensor s = senManager.getBySystemName(name);
    if (s == null) {
        log.debug("error null sensor!");
        return;
    }
    if (col == INVERTCOL) {
        boolean b = ((Boolean) value).booleanValue();
        s.setInverted(b);
    } else if (col == USEGLOBALDELAY) {
        boolean b = ((Boolean) value).booleanValue();
        s.useDefaultTimerSettings(b);
    } else if (col == ACTIVEDELAY) {
        String val = (String) value;
        long goingActive = Long.valueOf(val);
        s.setSensorDebounceGoingActiveTimer(goingActive);
    } else if (col == INACTIVEDELAY) {
        String val = (String) value;
        long goingInActive = Long.valueOf(val);
        s.setSensorDebounceGoingInActiveTimer(goingInActive);
    } else if (col == EDITCOL) {
        class WindowMaker implements Runnable {

            Sensor s;

            WindowMaker(Sensor s) {
                this.s = s;
            }

            @Override
            public void run() {
                editButton(s);
            }
        }
        WindowMaker w = new WindowMaker(s);
        javax.swing.SwingUtilities.invokeLater(w);
    } else if (col == PULLUPCOL) {
        JComboBox<Sensor.PullResistance> cb = (JComboBox<Sensor.PullResistance>) value;
        s.setPullResistance((Sensor.PullResistance) cb.getSelectedItem());
    } else if (col == VALUECOL && _graphicState) {
        // respond to clicking on ImageIconRenderer CellEditor
        clickOn(s);
        fireTableRowsUpdated(row, row);
    } else {
        super.setValueAt(value, row, col);
    }
}
Also used : JComboBox(javax.swing.JComboBox) Sensor(jmri.Sensor)

Aggregations

JComboBox (javax.swing.JComboBox)150 JLabel (javax.swing.JLabel)66 JPanel (javax.swing.JPanel)57 ActionEvent (java.awt.event.ActionEvent)51 ActionListener (java.awt.event.ActionListener)48 JButton (javax.swing.JButton)47 JScrollPane (javax.swing.JScrollPane)28 JTextField (javax.swing.JTextField)27 BoxLayout (javax.swing.BoxLayout)26 Dimension (java.awt.Dimension)25 JCheckBox (javax.swing.JCheckBox)23 JTable (javax.swing.JTable)22 BorderLayout (java.awt.BorderLayout)21 GridBagLayout (java.awt.GridBagLayout)20 Insets (java.awt.Insets)20 GridBagConstraints (java.awt.GridBagConstraints)19 FlowLayout (java.awt.FlowLayout)18 DefaultCellEditor (javax.swing.DefaultCellEditor)17 TableColumn (javax.swing.table.TableColumn)14 ItemEvent (java.awt.event.ItemEvent)11