Search in sources :

Example 41 with ButtonGroup

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

the class LogixTableAction method setMenuBar.

/**
     * Insert 2 table specific menus.
     * <p>
     * Accounts for the Window and Help menus, which are already added to the menu bar
     * as part of the creation of the JFrame, by adding the new menus 2 places earlier
     * unless the table is part of the ListedTableFrame, which adds the Help menu later on.
     * @param f the JFrame of this table
     */
@Override
public void setMenuBar(BeanTableFrame f) {
    loadSelectionMode();
    JMenu menu = new JMenu(Bundle.getMessage("MenuOptions"));
    menu.setMnemonic(KeyEvent.VK_O);
    javax.swing.JMenuBar menuBar = f.getJMenuBar();
    // count the number of menus to insert the TableMenus before 'Window' and 'Help'
    int pos = menuBar.getMenuCount() - 1;
    int offset = 1;
    log.debug("setMenuBar number of menu items = " + pos);
    for (int i = 0; i <= pos; i++) {
        if (menuBar.getComponent(i) instanceof JMenu) {
            if (((JMenu) menuBar.getComponent(i)).getText().equals(Bundle.getMessage("MenuHelp"))) {
                // correct for use as part of ListedTableAction where the Help Menu is not yet present
                offset = -1;
            }
        }
    }
    ButtonGroup enableButtonGroup = new ButtonGroup();
    JRadioButtonMenuItem r = new JRadioButtonMenuItem(rbx.getString("EnableAll"));
    r.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            enableAll(true);
        }
    });
    enableButtonGroup.add(r);
    r.setSelected(true);
    menu.add(r);
    r = new JRadioButtonMenuItem(rbx.getString("DisableAll"));
    r.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            enableAll(false);
        }
    });
    enableButtonGroup.add(r);
    menu.add(r);
    menu.addSeparator();
    ButtonGroup modeButtonGroup = new ButtonGroup();
    r = new JRadioButtonMenuItem(rbx.getString("UseMultiPick"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USEMULTI);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USEMULTI);
    r = new JRadioButtonMenuItem(rbx.getString("UseSinglePick"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USESINGLE);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USESINGLE);
    r = new JRadioButtonMenuItem(rbx.getString("UseComboNameBoxes"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USECOMBO);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USECOMBO);
    menuBar.add(menu, pos + offset);
    menu = new JMenu(Bundle.getMessage("MenuTools"));
    menu.setMnemonic(KeyEvent.VK_T);
    JMenuItem item = new JMenuItem(rbx.getString("OpenPickListTables"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            OpenPickListTable();
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("FindOrphans"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            findOrphansPressed(e);
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("EmptyConditionals"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            findEmptyPressed(e);
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("CrossReference"));
    item.addActionListener(new ActionListener() {

        BeanTableFrame parent;

        @Override
        public void actionPerformed(ActionEvent e) {
            new RefDialog(parent);
        }

        ActionListener init(BeanTableFrame f) {
            parent = f;
            return this;
        }
    }.init(f));
    menu.add(item);
    item = new JMenuItem(rbx.getString("DisplayWhereUsed"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            makeWhereUsedWindow();
        }
    });
    menu.add(item);
    // add this menu to the right of the previous
    menuBar.add(menu, pos + offset + 1);
}
Also used : ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ItemListener(java.awt.event.ItemListener) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 42 with ButtonGroup

use of javax.swing.ButtonGroup 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 43 with ButtonGroup

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

the class PanelEditor method makeColorMenu.

protected void makeColorMenu(JMenu colorMenu) {
    ButtonGroup buttonGrp = new ButtonGroup();
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("Black"), Color.black);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("DarkGray"), Color.darkGray);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("Gray"), Color.gray);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("LightGray"), Color.lightGray);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("White"), Color.white);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("Red"), Color.red);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("Orange"), Color.orange);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("Yellow"), Color.yellow);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("Green"), Color.green);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("Blue"), Color.blue);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("Magenta"), Color.magenta);
    addColorMenuEntry(colorMenu, buttonGrp, Bundle.getMessage("ColorClear"), null);
}
Also used : ButtonGroup(javax.swing.ButtonGroup)

Example 44 with ButtonGroup

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

the class NXFrame method makeAutoRunPanel.

@SuppressFBWarnings(value = "DB_DUPLICATE_SWITCH_CLAUSES", justification = "Same code for both cases")
private JPanel makeAutoRunPanel(int interpretation) {
    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.PAGE_AXIS));
    float maxSpeed;
    float throttleIncr;
    String maxSpeedLabel;
    String throttleIncrLabel;
    switch(interpretation) {
        case SignalSpeedMap.PERCENT_NORMAL:
        case SignalSpeedMap.PERCENT_THROTTLE:
            maxSpeed = _maxThrottle;
            maxSpeedLabel = "MaxSpeed";
            throttleIncr = _minSpeed;
            throttleIncrLabel = "RampIncrement";
            break;
        case SignalSpeedMap.SPEED_MPH:
            // 2.2369363 is 3.6 converted by mile/km
            maxSpeed = _maxThrottle * _throttleFactor * 223.69363f;
            maxSpeedLabel = "MaxMph";
            throttleIncr = _minSpeed * _throttleFactor * 223.69363f;
            throttleIncrLabel = "MinMph";
            break;
        case SignalSpeedMap.SPEED_KMPH:
            maxSpeed = _maxThrottle * _throttleFactor * 360f;
            maxSpeedLabel = "MaxKMph";
            throttleIncr = _minSpeed * _throttleFactor * 360f;
            throttleIncrLabel = "MinKMph";
            break;
        default:
            maxSpeed = _maxThrottle;
            maxSpeedLabel = "MaxSpeed";
            throttleIncr = _minSpeed;
            throttleIncrLabel = "RampIncrement";
    }
    p1.add(makeTextBoxPanel(false, _maxSpeedBox, maxSpeedLabel, null));
    p1.add(makeTextBoxPanel(false, _rampInterval, "rampInterval", null));
    p1.add(makeTextBoxPanel(false, _rampIncre, throttleIncrLabel, "ToolTipRampIncrement"));
    p1.add(makeTextBoxPanel(false, _throttleFactorBox, "ThrottleScale", "ToolTipThrottleScale"));
    p1.add(makeTextBoxPanel(false, _shareRouteBox, "ShareRoute", "ToolTipShareRoute"));
    _maxSpeedBox.setText(Float.toString(maxSpeed));
    _rampInterval.setText(Float.toString(_intervalTime / 1000));
    _rampIncre.setText(Float.toString(throttleIncr));
    _throttleFactorBox.setText(Float.toString(_throttleFactor));
    JPanel p2 = new JPanel();
    p2.setLayout(new BoxLayout(p2, BoxLayout.PAGE_AXIS));
    //        JPanel trainPanel = makeTrainIdPanel(makeTextBoxPanel(
    //                false, _shareRouteBox, "ShareRoute", "ToolTipShareRoute"));
    JPanel trainPanel = makeTrainIdPanel(null);
    p2.add(trainPanel);
    JPanel autoRunPanel = new JPanel();
    autoRunPanel.setLayout(new BoxLayout(autoRunPanel, BoxLayout.PAGE_AXIS));
    JPanel pp = new JPanel();
    pp.setLayout(new BoxLayout(pp, BoxLayout.LINE_AXIS));
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(p1);
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(p2);
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    autoRunPanel.add(pp);
    ButtonGroup bg = new ButtonGroup();
    bg.add(_forward);
    bg.add(_reverse);
    p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.LINE_AXIS));
    p1.add(Box.createHorizontalGlue());
    p1.add(makeTextBoxPanel(false, _forward, "forward", null));
    p1.add(makeTextBoxPanel(false, _reverse, "reverse", null));
    p1.add(Box.createHorizontalGlue());
    pp = new JPanel();
    pp.setLayout(new BoxLayout(pp, BoxLayout.LINE_AXIS));
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(p1);
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(Box.createHorizontalStrut(2 * STRUT_SIZE));
    autoRunPanel.add(pp);
    JPanel ppp = new JPanel();
    ppp.setLayout(new BoxLayout(ppp, BoxLayout.LINE_AXIS));
    ppp.add(Box.createHorizontalStrut(STRUT_SIZE));
    ppp.add(makeTextBoxPanel(false, _stageEStop, "StageEStop", null));
    ppp.add(Box.createHorizontalStrut(STRUT_SIZE));
    ppp.add(makeTextBoxPanel(false, _haltStartBox, "HaltAtStart", null));
    ppp.add(Box.createHorizontalStrut(STRUT_SIZE));
    ppp.add(makeTextBoxPanel(false, _calibrateBox, "Calibrate", "calibBlockMessage"));
    ppp.add(Box.createHorizontalStrut(STRUT_SIZE));
    autoRunPanel.add(ppp);
    return autoRunPanel;
}
Also used : JPanel(javax.swing.JPanel) ButtonGroup(javax.swing.ButtonGroup) BoxLayout(javax.swing.BoxLayout) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 45 with ButtonGroup

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

the class NXFrame method makeSwitchPanel.

private JPanel makeSwitchPanel() {
    ButtonGroup bg = new ButtonGroup();
    bg.add(_runAuto);
    bg.add(_runManual);
    _runAuto.addActionListener((ActionEvent event) -> {
        enableAuto(true);
    });
    _runManual.addActionListener((ActionEvent event) -> {
        enableAuto(false);
    });
    _runAuto.setSelected(true);
    JPanel pp = new JPanel();
    pp.setLayout(new BoxLayout(pp, BoxLayout.LINE_AXIS));
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(_runAuto);
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    pp.add(_runManual);
    pp.add(Box.createHorizontalStrut(STRUT_SIZE));
    return pp;
}
Also used : JPanel(javax.swing.JPanel) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout)

Aggregations

ButtonGroup (javax.swing.ButtonGroup)339 JPanel (javax.swing.JPanel)202 JRadioButton (javax.swing.JRadioButton)186 JLabel (javax.swing.JLabel)148 ActionEvent (java.awt.event.ActionEvent)134 ActionListener (java.awt.event.ActionListener)118 BoxLayout (javax.swing.BoxLayout)83 GridBagLayout (java.awt.GridBagLayout)81 JButton (javax.swing.JButton)75 JTextField (javax.swing.JTextField)70 JMenu (javax.swing.JMenu)69 GridBagConstraints (java.awt.GridBagConstraints)67 BorderLayout (java.awt.BorderLayout)64 Insets (java.awt.Insets)64 Dimension (java.awt.Dimension)58 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)57 FlowLayout (java.awt.FlowLayout)53 JMenuItem (javax.swing.JMenuItem)50 JCheckBox (javax.swing.JCheckBox)47 JScrollPane (javax.swing.JScrollPane)47