Search in sources :

Example 71 with ChangeEvent

use of javax.swing.event.ChangeEvent in project JMRI by JMRI.

the class ControlPanel method initGUI.

/**
     * Create, initialize and place GUI components.
     */
private void initGUI() {
    mainPanel = new JPanel();
    this.setContentPane(mainPanel);
    mainPanel.setLayout(new BorderLayout());
    this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    speedControlPanel = new JPanel();
    speedControlPanel.setLayout(new BoxLayout(speedControlPanel, BoxLayout.X_AXIS));
    speedControlPanel.setOpaque(false);
    mainPanel.add(speedControlPanel, BorderLayout.CENTER);
    sliderPanel = new JPanel();
    sliderPanel.setLayout(new GridBagLayout());
    sliderPanel.setOpaque(false);
    speedSlider = new JSlider(0, intSpeedSteps);
    speedSlider.setOpaque(false);
    speedSlider.setValue(0);
    speedSlider.setFocusable(false);
    // add mouse-wheel support
    speedSlider.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    decelerate1();
                }
            } else {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    accelerate1();
                }
            }
        }
    });
    speedSliderContinuous = new JSlider(-intSpeedSteps, intSpeedSteps);
    speedSliderContinuous.setValue(0);
    speedSliderContinuous.setOpaque(false);
    speedSliderContinuous.setFocusable(false);
    // add mouse-wheel support
    speedSliderContinuous.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    decelerate1();
                }
            } else {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    accelerate1();
                }
            }
        }
    });
    speedSpinner = new JSpinner();
    speedSpinnerModel = new SpinnerNumberModel(0, 0, intSpeedSteps, 1);
    speedSpinner.setModel(speedSpinnerModel);
    speedSpinner.setFocusable(false);
    SpeedStep128Button = new JRadioButton(Bundle.getMessage("Button128SS"));
    SpeedStep28Button = new JRadioButton(Bundle.getMessage("Button28SS"));
    SpeedStep27Button = new JRadioButton(Bundle.getMessage("Button27SS"));
    SpeedStep14Button = new JRadioButton(Bundle.getMessage("Button14SS"));
    forwardButton = new JRadioButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        forwardButton.setBorderPainted(false);
        forwardButton.setContentAreaFilled(false);
        forwardButton.setText(null);
        forwardButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-red.png")));
        forwardButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-green.png")));
        forwardButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        forwardButton.setToolTipText(Bundle.getMessage("ButtonForward"));
    } else {
        forwardButton.setText(Bundle.getMessage("ButtonForward"));
    }
    reverseButton = new JRadioButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        reverseButton.setBorderPainted(false);
        reverseButton.setContentAreaFilled(false);
        reverseButton.setText(null);
        reverseButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-red.png")));
        reverseButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-green.png")));
        reverseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        reverseButton.setToolTipText(Bundle.getMessage("ButtonReverse"));
    } else {
        reverseButton.setText(Bundle.getMessage("ButtonReverse"));
    }
    propertiesPopup = new JPopupMenu();
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridheight = 1;
    constraints.gridwidth = 1;
    constraints.ipadx = 0;
    constraints.ipady = 0;
    Insets insets = new Insets(2, 2, 2, 2);
    constraints.insets = insets;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridx = 0;
    constraints.gridy = 0;
    sliderPanel.add(speedSlider, constraints);
    //this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
    speedControlPanel.add(sliderPanel);
    speedSlider.setOrientation(JSlider.VERTICAL);
    speedSlider.setMajorTickSpacing(maxSpeed / 2);
    java.util.Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<Integer, JLabel>();
    labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
    labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
    labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
    speedSlider.setLabelTable(labelTable);
    speedSlider.setPaintTicks(true);
    speedSlider.setPaintLabels(true);
    // remove old actions
    speedSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                boolean doIt = false;
                if (!speedSlider.getValueIsAdjusting()) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
                } else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis();
                }
                if (doIt) {
                    float newSpeed = (speedSlider.getValue() / (intSpeedSteps * 1.0f));
                    if (log.isDebugEnabled()) {
                        log.debug("stateChanged: slider pos: " + speedSlider.getValue() + " speed: " + newSpeed);
                    }
                    if (sliderPanel.isVisible() && throttle != null) {
                        throttle.setSpeedSetting(newSpeed);
                    }
                    if (speedSpinner != null) {
                        speedSpinnerModel.setValue(Integer.valueOf(speedSlider.getValue()));
                    }
                    if (speedSliderContinuous != null) {
                        if (forwardButton.isSelected()) {
                            speedSliderContinuous.setValue(((Integer) speedSlider.getValue()).intValue());
                        } else {
                            speedSliderContinuous.setValue(-((Integer) speedSlider.getValue()).intValue());
                        }
                    }
                }
            }
        }
    });
    speedSliderContinuousPanel = new JPanel();
    speedSliderContinuousPanel.setLayout(new GridBagLayout());
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridheight = 1;
    constraints.gridwidth = 1;
    constraints.ipadx = 0;
    constraints.ipady = 0;
    insets = new Insets(2, 2, 2, 2);
    constraints.insets = insets;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridx = 0;
    constraints.gridy = 0;
    speedSliderContinuousPanel.add(speedSliderContinuous, constraints);
    //this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
    speedControlPanel.add(speedSliderContinuousPanel);
    speedSliderContinuous.setOrientation(JSlider.VERTICAL);
    speedSliderContinuous.setMajorTickSpacing(maxSpeed / 2);
    labelTable = new java.util.Hashtable<Integer, JLabel>();
    labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
    labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
    labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
    labelTable.put(Integer.valueOf(-maxSpeed / 2), new JLabel("-50%"));
    labelTable.put(Integer.valueOf(-maxSpeed), new JLabel("-100%"));
    speedSliderContinuous.setLabelTable(labelTable);
    speedSliderContinuous.setPaintTicks(true);
    speedSliderContinuous.setPaintLabels(true);
    // remove old actions
    speedSliderContinuous.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                boolean doIt = false;
                if (!speedSliderContinuous.getValueIsAdjusting()) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
                } else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis();
                }
                if (doIt) {
                    float newSpeed = (java.lang.Math.abs(speedSliderContinuous.getValue()) / (intSpeedSteps * 1.0f));
                    boolean newDir = (speedSliderContinuous.getValue() >= 0);
                    if (log.isDebugEnabled()) {
                        log.debug("stateChanged: slider pos: " + speedSliderContinuous.getValue() + " speed: " + newSpeed + " dir: " + newDir);
                    }
                    if (speedSliderContinuousPanel.isVisible() && throttle != null) {
                        throttle.setSpeedSetting(newSpeed);
                        if ((newSpeed > 0) && (newDir != forwardButton.isSelected())) {
                            throttle.setIsForward(newDir);
                        }
                    }
                    if (speedSpinner != null) {
                        speedSpinnerModel.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
                    }
                    if (speedSlider != null) {
                        speedSlider.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
                    }
                }
            }
        }
    });
    spinnerPanel = new JPanel();
    spinnerPanel.setLayout(new GridBagLayout());
    spinnerPanel.add(speedSpinner, constraints);
    speedControlPanel.add(spinnerPanel);
    // remove old actions
    speedSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                //if (!speedSpinner.getValueIsAdjusting())
                //{
                float newSpeed = ((Integer) speedSpinner.getValue()).floatValue() / (intSpeedSteps * 1.0f);
                if (log.isDebugEnabled()) {
                    log.debug("stateChanged: spinner pos: " + speedSpinner.getValue() + " speed: " + newSpeed);
                }
                if (throttle != null) {
                    if (spinnerPanel.isVisible()) {
                        throttle.setSpeedSetting(newSpeed);
                    }
                    speedSlider.setValue(((Integer) speedSpinner.getValue()).intValue());
                    if (speedSliderContinuous != null) {
                        if (forwardButton.isSelected()) {
                            speedSliderContinuous.setValue(((Integer) speedSpinner.getValue()).intValue());
                        } else {
                            speedSliderContinuous.setValue(-((Integer) speedSpinner.getValue()).intValue());
                        }
                    }
                } else {
                    log.warn("no throttle object in stateChanged, ignoring change of speed to " + newSpeed);
                }
            //}
            }
        }
    });
    ButtonGroup speedStepButtons = new ButtonGroup();
    speedStepButtons.add(SpeedStep128Button);
    speedStepButtons.add(SpeedStep28Button);
    speedStepButtons.add(SpeedStep27Button);
    speedStepButtons.add(SpeedStep14Button);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridy = 1;
    spinnerPanel.add(SpeedStep128Button, constraints);
    constraints.gridy = 2;
    spinnerPanel.add(SpeedStep28Button, constraints);
    constraints.gridy = 3;
    spinnerPanel.add(SpeedStep27Button, constraints);
    constraints.gridy = 4;
    spinnerPanel.add(SpeedStep14Button, constraints);
    SpeedStep14Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode14);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode14);
        }
    });
    SpeedStep27Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode27);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode27);
        }
    });
    SpeedStep28Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode28);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode28);
        }
    });
    SpeedStep128Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode128);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode128);
        }
    });
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    ButtonGroup directionButtons = new ButtonGroup();
    directionButtons.add(forwardButton);
    directionButtons.add(reverseButton);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridy = 1;
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 3;
    }
    buttonPanel.add(forwardButton, constraints);
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 1;
    } else {
        constraints.gridy = 2;
    }
    buttonPanel.add(reverseButton, constraints);
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 2;
    }
    forwardButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            throttle.setIsForward(true);
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(java.lang.Math.abs(speedSliderContinuous.getValue()));
            }
        }
    });
    reverseButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            throttle.setIsForward(false);
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(-java.lang.Math.abs(speedSliderContinuous.getValue()));
            }
        }
    });
    stopButton = new JButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        stopButton.setBorderPainted(false);
        stopButton.setContentAreaFilled(false);
        stopButton.setText(null);
        stopButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop.png")));
        stopButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop24.png")));
        stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        stopButton.setToolTipText(Bundle.getMessage("ButtonEStop"));
    } else {
        stopButton.setText(Bundle.getMessage("ButtonEStop"));
    }
    constraints.gridy = 4;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    buttonPanel.add(stopButton, constraints);
    stopButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
        }
    });
    stopButton.addMouseListener(new MouseListener() {

        @Override
        public void mousePressed(MouseEvent e) {
            stop();
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }
    });
    idleButton = new JButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        idleButton.setBorderPainted(false);
        idleButton.setContentAreaFilled(false);
        idleButton.setText(null);
        idleButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop.png")));
        idleButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop24.png")));
        idleButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        idleButton.setToolTipText(Bundle.getMessage("ButtonIdle"));
    } else {
        idleButton.setText(Bundle.getMessage("ButtonIdle"));
    }
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridy = 1;
    } else {
        constraints.gridy = 3;
    }
    buttonPanel.add(idleButton, constraints);
    idleButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            speedSlider.setValue(0);
            if (speedSpinner != null) {
                speedSpinner.setValue(Integer.valueOf(0));
            }
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(Integer.valueOf(0));
            }
            throttle.setSpeedSetting(0);
        }
    });
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            changeOrientation();
        }
    });
    JMenuItem propertiesItem = new JMenuItem(Bundle.getMessage("ControlPanelProperties"));
    propertiesItem.addActionListener(this);
    propertiesPopup.add(propertiesItem);
    // Add a mouse listener all components to trigger the popup menu.
    MouseInputAdapter popupListener = new PopupListener(propertiesPopup, this);
    MouseInputAdapterInstaller.installMouseInputAdapterOnAllComponents(popupListener, this);
    // Install the Key bindings on all Components
    KeyListenerInstaller.installKeyListenerOnAllComponents(new ControlPadKeyListener(), this);
    // set by default which speed selection method is on top
    setSpeedController(_displaySlider);
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) JRadioButton(javax.swing.JRadioButton) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) MouseWheelListener(java.awt.event.MouseWheelListener) SpinnerNumberModel(javax.swing.SpinnerNumberModel) MouseListener(java.awt.event.MouseListener) BorderLayout(java.awt.BorderLayout) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) JMenuItem(javax.swing.JMenuItem) ComponentAdapter(java.awt.event.ComponentAdapter) MouseEvent(java.awt.event.MouseEvent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) MouseWheelEvent(java.awt.event.MouseWheelEvent) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) JSpinner(javax.swing.JSpinner) ComponentEvent(java.awt.event.ComponentEvent) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 72 with ChangeEvent

use of javax.swing.event.ChangeEvent in project JMRI by JMRI.

the class DieselPane method initComponents.

@Override
public void initComponents() {
    listenerList = new javax.swing.event.EventListenerList();
    this.setLayout(new GridLayout(2, 0));
    //Setup the throttle slider.
    throttle_slider = new JSlider(JSlider.HORIZONTAL, THROTTLE_MIN, THROTTLE_MAX, THROTTLE_INIT);
    throttle_slider.setMajorTickSpacing(1);
    throttle_slider.setPaintTicks(true);
    throttle_slider.setMinimumSize(new Dimension(400, 0));
    throttle_slider.setSnapToTicks(true);
    throttle_slider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            throttleChange(e);
        }
    });
    this.add(throttle_slider);
    // Setup the start button
    start_button = new JToggleButton();
    start_button.setText("Engine Start");
    start_button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            startButtonChange(e);
        }
    });
    this.add(start_button);
    throttle_slider.setVisible(true);
    start_button.setVisible(true);
    this.setVisible(true);
    this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}
Also used : GridLayout(java.awt.GridLayout) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) Dimension(java.awt.Dimension)

Example 73 with ChangeEvent

use of javax.swing.event.ChangeEvent in project JMRI by JMRI.

the class ConfigBaseStationFrame method initGui.

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

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

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

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

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

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

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

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

Example 74 with ChangeEvent

use of javax.swing.event.ChangeEvent in project JMRI by JMRI.

the class SimpleServerPreferencesPanel method portPanel.

private JPanel portPanel() {
    JPanel panel = new JPanel();
    port = new JSpinner(new SpinnerNumberModel(preferences.getPort(), 1, 65535, 1));
    ((JSpinner.DefaultEditor) port.getEditor()).getTextField().setEditable(true);
    port.setEditor(new JSpinner.NumberEditor(port, "#"));
    this.port.addChangeListener((ChangeEvent e) -> {
        this.setValues();
    });
    this.port.setToolTipText(Bundle.getMessage("PortToolTip"));
    panel.add(port);
    panel.add(new JLabel(Bundle.getMessage("LabelPort")));
    return panel;
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) JPanel(javax.swing.JPanel) ChangeEvent(javax.swing.event.ChangeEvent) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel)

Example 75 with ChangeEvent

use of javax.swing.event.ChangeEvent in project JMRI by JMRI.

the class AudioSourceFrame method layoutFrame.

@Override
@SuppressWarnings("UnnecessaryBoxing")
public void layoutFrame() {
    super.layoutFrame();
    JPanel p;
    p = new JPanel();
    p.setLayout(new FlowLayout());
    p.add(assignedBufferLabel);
    p.add(assignedBuffer);
    main.add(p);
    p = new JPanel();
    p.setLayout(new FlowLayout());
    p.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Bundle.getMessage("LabelLoop")), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    p.add(loopMinLabel);
    loopMin.setPreferredSize(new JTextField(8).getPreferredSize());
    loopMin.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
    loopMin.addChangeListener((ChangeEvent e) -> {
        loopMax.setValue(((Integer) loopMin.getValue() < (Integer) loopMax.getValue()) ? loopMax.getValue() : loopMin.getValue());
    });
    p.add(loopMin);
    p.add(loopMaxLabel);
    loopMax.setPreferredSize(new JTextField(8).getPreferredSize());
    loopMax.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
    loopMax.addChangeListener((ChangeEvent e) -> {
        loopMin.setValue(((Integer) loopMax.getValue() < (Integer) loopMin.getValue()) ? loopMax.getValue() : loopMin.getValue());
    });
    p.add(loopMax);
    loopInfinite.addChangeListener((ChangeEvent e) -> {
        loopMin.setEnabled(!loopInfinite.isSelected());
        loopMax.setEnabled(!loopInfinite.isSelected());
    });
    p.add(loopInfinite);
    main.add(p);
    //        p = new JPanel(); p.setLayout(new FlowLayout());
    //        p.setBorder(BorderFactory.createCompoundBorder(
    //                        BorderFactory.createTitledBorder(Bundle.getMessage("LabelLoopDelay")),
    //                        BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    //        p.add(loopMinDelayLabel);
    //        loopMinDelay.setPreferredSize(new JTextField(8).getPreferredSize());
    //        loopMinDelay.setModel(new SpinnerNumberModel(0,0,Integer.MAX_VALUE,1));
    //        loopMinDelay.addChangeListener(new ChangeListener() {
    //            public void stateChanged(ChangeEvent e) {
    //                loopMaxDelay.setValue(
    //                        ((Integer)loopMinDelay.getValue()
    //                        <(Integer)loopMaxDelay.getValue())
    //                        ?loopMaxDelay.getValue()
    //                        :loopMinDelay.getValue());
    //            }
    //        });
    //        p.add(loopMinDelay);
    //        p.add(loopMaxDelayLabel);
    //        loopMaxDelay.setPreferredSize(new JTextField(8).getPreferredSize());
    //        loopMaxDelay.setModel(new SpinnerNumberModel(0,0,Integer.MAX_VALUE,1));
    //        loopMaxDelay.addChangeListener(new ChangeListener() {
    //            public void stateChanged(ChangeEvent e) {
    //                loopMinDelay.setValue(
    //                        ((Integer)loopMaxDelay.getValue()
    //                        <(Integer)loopMinDelay.getValue())
    //                        ?loopMaxDelay.getValue()
    //                        :loopMinDelay.getValue());
    //            }
    //        });
    //        p.add(loopMaxDelay);
    //        p.add(loopDelayUnitsLabel);
    //        main.add(p);
    //
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Bundle.getMessage("LabelPosition")), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    p.add(position);
    p.add(positionRelative);
    main.add(p);
    main.add(velocity);
    main.add(gain);
    main.add(pitch);
    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Bundle.getMessage("LabelDistances")), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    JPanel p2;
    p2 = new JPanel();
    p2.setLayout(new FlowLayout());
    p2.add(refDistanceLabel);
    refDistance.setPreferredSize(new JTextField(8).getPreferredSize());
    refDistance.setModel(new SpinnerNumberModel(Float.valueOf(0f), Float.valueOf(0f), Float.valueOf(Audio.MAX_DISTANCE), Float.valueOf(FLT_PRECISION)));
    refDistance.setEditor(new JSpinner.NumberEditor(refDistance, "0.00"));
    refDistance.addChangeListener((ChangeEvent e) -> {
        maxDistance.setValue(((Float) refDistance.getValue() < (Float) maxDistance.getValue()) ? maxDistance.getValue() : refDistance.getValue());
    });
    p2.add(refDistance);
    p2.add(maxDistanceLabel);
    maxDistance.setPreferredSize(new JTextField(8).getPreferredSize());
    maxDistance.setModel(new SpinnerNumberModel(Float.valueOf(0f), Float.valueOf(0f), Float.valueOf(Audio.MAX_DISTANCE), Float.valueOf(FLT_PRECISION)));
    maxDistance.setEditor(new JSpinner.NumberEditor(maxDistance, "0.00"));
    maxDistance.addChangeListener((ChangeEvent e) -> {
        refDistance.setValue(((Float) maxDistance.getValue() < (Float) refDistance.getValue()) ? maxDistance.getValue() : refDistance.getValue());
    });
    p2.add(maxDistance);
    p2.add(distancesLabel);
    p.add(p2);
    p2 = new JPanel();
    p2.setLayout(new FlowLayout());
    p2.add(rollOffFactorLabel);
    rollOffFactor.setPreferredSize(new JTextField(8).getPreferredSize());
    rollOffFactor.setModel(new SpinnerNumberModel(Float.valueOf(0f), Float.valueOf(0f), Float.valueOf(Audio.MAX_DISTANCE), Float.valueOf(FLT_PRECISION)));
    rollOffFactor.setEditor(new JSpinner.NumberEditor(rollOffFactor, "0.00"));
    p2.add(rollOffFactor);
    p.add(p2);
    main.add(p);
    p = new JPanel();
    p.setLayout(new FlowLayout());
    p.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Bundle.getMessage("LabelFadeTimes")), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    p.add(fadeInTimeLabel);
    fadeInTime.setPreferredSize(new JTextField(8).getPreferredSize());
    fadeInTime.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
    p.add(fadeInTime);
    p.add(fadeOutTimeLabel);
    fadeOutTime.setPreferredSize(new JTextField(8).getPreferredSize());
    fadeOutTime.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
    p.add(fadeOutTime);
    p.add(fadeTimeUnitsLabel);
    main.add(p);
    p = new JPanel();
    JButton apply;
    p.add(apply = new JButton(Bundle.getMessage("ButtonApply")));
    apply.addActionListener((ActionEvent e) -> {
        applyPressed(e);
    });
    JButton ok;
    p.add(ok = new JButton(Bundle.getMessage("ButtonOK")));
    ok.addActionListener((ActionEvent e) -> {
        applyPressed(e);
        frame.dispose();
    });
    JButton cancel;
    p.add(cancel = new JButton(Bundle.getMessage("ButtonCancel")));
    cancel.addActionListener((ActionEvent e) -> {
        frame.dispose();
    });
    frame.getContentPane().add(p);
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ChangeEvent(javax.swing.event.ChangeEvent) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JSpinner(javax.swing.JSpinner) JTextField(javax.swing.JTextField)

Aggregations

ChangeEvent (javax.swing.event.ChangeEvent)245 ChangeListener (javax.swing.event.ChangeListener)206 JPanel (javax.swing.JPanel)60 ActionEvent (java.awt.event.ActionEvent)52 ActionListener (java.awt.event.ActionListener)47 JLabel (javax.swing.JLabel)40 Dimension (java.awt.Dimension)30 GridBagConstraints (java.awt.GridBagConstraints)27 GridBagLayout (java.awt.GridBagLayout)24 JCheckBox (javax.swing.JCheckBox)24 Insets (java.awt.Insets)22 JButton (javax.swing.JButton)21 JSlider (javax.swing.JSlider)21 PropertyChangeEvent (java.beans.PropertyChangeEvent)20 JSpinner (javax.swing.JSpinner)19 SpinnerNumberModel (javax.swing.SpinnerNumberModel)19 BorderLayout (java.awt.BorderLayout)18 PropertyChangeListener (java.beans.PropertyChangeListener)17 IOException (java.io.IOException)16 BoxLayout (javax.swing.BoxLayout)16