Search in sources :

Example 11 with JSpinner

use of javax.swing.JSpinner in project jgnash by ccavanaugh.

the class NetworkOptions method initComponents.

private void initComponents() {
    proxyCheckBox = new JCheckBox(rb.getString("Button.UseProxy"));
    hostField = new JTextFieldEx();
    portField = new JIntegerField();
    authCheckBox = new JCheckBox(rb.getString("Button.HTTPAuth"));
    nameField = new JTextFieldEx();
    passwordField = new JPasswordField();
    SpinnerNumberModel model = new SpinnerNumberModel(ConnectionFactory.getConnectionTimeout(), ConnectionFactory.MIN_TIMEOUT, ConnectionFactory.MAX_TIMEOUT, 1);
    connectionTimeout = new JSpinner(model);
}
Also used : JCheckBox(javax.swing.JCheckBox) JIntegerField(jgnash.ui.components.JIntegerField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JPasswordField(javax.swing.JPasswordField) JSpinner(javax.swing.JSpinner) JTextFieldEx(jgnash.ui.components.JTextFieldEx)

Example 12 with JSpinner

use of javax.swing.JSpinner in project jgnash by ccavanaugh.

the class YearTab method layoutMainPanel.

private void layoutMainPanel() {
    FormLayout layout = new FormLayout("right:p, $lcgap, f:p, 2dlu, max(48dlu;min), 2dlu, f:p", "f:p, $lgap, f:p, $lgap, f:p");
    layout.setRowGroups(new int[][] { { 1, 3, 5 } });
    setLayout(layout);
    setBorder(Borders.DIALOG);
    CellConstraints cc = new CellConstraints();
    noEndButton = new JRadioButton(rb.getString("Button.NoEndDate"));
    endButton = new JRadioButton();
    endDateField = new DatePanel();
    group.add(noEndButton);
    group.add(endButton);
    numberSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 100, 1));
    add(new JLabel(rb.getString("Label.Every")), cc.xy(1, 1));
    add(numberSpinner, cc.xywh(3, 1, 3, 1));
    add(new JLabel(rb.getString("Tab.Year")), cc.xy(7, 1));
    add(new JLabel(rb.getString("Label.EndOn")), cc.xy(1, 3));
    add(noEndButton, cc.xywh(3, 3, 5, 1));
    add(endButton, cc.xy(3, 5));
    add(endDateField, cc.xy(5, 5));
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JRadioButton(javax.swing.JRadioButton) DatePanel(jgnash.ui.components.DatePanel) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Example 13 with JSpinner

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

the class MemoryItemPanel method makeDndIconPanel.

@Override
protected void makeDndIconPanel(java.util.HashMap<String, NamedIcon> iconMap, String displayKey) {
    if (_update) {
        return;
    }
    JPanel panel = new JPanel();
    panel.setLayout(new java.awt.GridBagLayout());
    java.awt.GridBagConstraints c = new java.awt.GridBagConstraints();
    c.gridwidth = 1;
    c.gridheight = 1;
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = java.awt.GridBagConstraints.CENTER;
    c.weightx = 1.0;
    panel.add(new JLabel(Bundle.getMessage("ReadWriteMemory")), c);
    c.gridy = 1;
    _writeMem = new MemoryInputIcon(5, _editor);
    //        JPanel p0 = makeDragIcon(_writeMem, Type.READWRITE);
    panel.add(makeDragIcon(_writeMem, Type.READWRITE), c);
    _spinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
    JTextField field = ((JSpinner.DefaultEditor) _spinner.getEditor()).getTextField();
    field.setColumns(2);
    field.setText("5");
    _spinner.setMaximumSize(_spinner.getPreferredSize());
    _spinner.addChangeListener(this);
    c.gridy = 2;
    panel.add(_spinner, c);
    c.gridy = 3;
    c.anchor = java.awt.GridBagConstraints.NORTH;
    panel.add(new JLabel(Bundle.getMessage("NumColsLabel")), c);
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = java.awt.GridBagConstraints.CENTER;
    panel.add(new JLabel(Bundle.getMessage("ReadMemory")), c);
    c.gridy = 1;
    _readMem = new MemoryIcon(NamedIcon.getIconByName("resources/icons/misc/X-red.gif"), _editor);
    panel.add(makeDragIcon(_readMem, Type.READONLY), c);
    c.gridx = 2;
    c.gridy = 0;
    panel.add(new JLabel(Bundle.getMessage("SpinnerMemory")), c);
    c.gridy = 1;
    _spinMem = new MemorySpinnerIcon(_editor);
    panel.add(makeDragIcon(_spinMem, Type.SPINNER), c);
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 4;
    panel.add(new JLabel(Bundle.getMessage("ComboMemory")), c);
    c.gridy = 3;
    _comboMem = new MemoryComboIcon(_editor, null);
    panel.add(makeDragIcon(_comboMem, Type.COMBO), c);
    _dragIconPanel = panel;
    _dragIconPanel.invalidate();
}
Also used : JPanel(javax.swing.JPanel) MemoryIcon(jmri.jmrit.display.MemoryIcon) MemorySpinnerIcon(jmri.jmrit.display.MemorySpinnerIcon) JLabel(javax.swing.JLabel) MemoryInputIcon(jmri.jmrit.display.MemoryInputIcon) JTextField(javax.swing.JTextField) MemoryComboIcon(jmri.jmrit.display.MemoryComboIcon) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JSpinner(javax.swing.JSpinner)

Example 14 with JSpinner

use of javax.swing.JSpinner 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 15 with JSpinner

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

the class LnTcpPreferencesPanel method initComponents.

private void initComponents() {
    bindingGroup = new BindingGroup();
    port = new JSpinner();
    portLabel = new JLabel();
    startup = new JCheckBox();
    port.setModel(new SpinnerNumberModel(1234, 1, 65535, 1));
    port.setEditor(new JSpinner.NumberEditor(port, "#"));
    // NOI18N
    port.setToolTipText(Bundle.getMessage("ToolTipPort"));
    Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${port}"), port, BeanProperty.create("value"));
    bindingGroup.addBinding(binding);
    // NOI18N
    portLabel.setText(Bundle.getMessage("LabelPort"));
    // NOI18N
    portLabel.setToolTipText(Bundle.getMessage("ToolTipPort"));
    startup.setSelected(this.isStartupAction());
    // NOI18N
    startup.setText(Bundle.getMessage("LabelStartup"));
    this.startupItemListener = (ItemEvent e) -> {
        this.startup.removeItemListener(this.startupItemListener);
        StartupActionsManager manager = InstanceManager.getDefault(StartupActionsManager.class);
        if (this.startup.isSelected()) {
            PerformActionModel model = new PerformActionModel();
            model.setClassName(LnTcpServerAction.class.getName());
            if (this.startupActionPosition == -1 || this.startupActionPosition >= manager.getActions().length) {
                manager.addAction(model);
            } else {
                manager.setActions(this.startupActionPosition, model);
            }
        } else {
            manager.getActions(PerformActionModel.class).stream().filter((model) -> (LnTcpServerAction.class.getName().equals(model.getClassName()))).forEach((model) -> {
                this.startupActionPosition = Arrays.asList(manager.getActions()).indexOf(model);
                manager.removeAction(model);
            });
        }
        this.startup.addItemListener(this.startupItemListener);
    };
    this.startup.addItemListener(this.startupItemListener);
    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(port, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(portLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addComponent(startup, GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)).addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(port, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(portLabel)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(startup).addContainerGap(198, Short.MAX_VALUE)));
    bindingGroup.bind();
}
Also used : AutoBinding(org.jdesktop.beansbinding.AutoBinding) Binding(org.jdesktop.beansbinding.Binding) PerformActionModel(apps.PerformActionModel) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) InstanceManager(jmri.InstanceManager) BeanProperty(org.jdesktop.beansbinding.BeanProperty) Arrays(java.util.Arrays) JSpinner(javax.swing.JSpinner) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Bindings(org.jdesktop.beansbinding.Bindings) ItemListener(java.awt.event.ItemListener) StartupActionsManager(apps.StartupActionsManager) AutoBinding(org.jdesktop.beansbinding.AutoBinding) LayoutStyle(javax.swing.LayoutStyle) PerformActionModel(apps.PerformActionModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) JCheckBox(javax.swing.JCheckBox) ELProperty(org.jdesktop.beansbinding.ELProperty) Binding(org.jdesktop.beansbinding.Binding) JPanel(javax.swing.JPanel) PreferencesPanel(jmri.swing.PreferencesPanel) ItemEvent(java.awt.event.ItemEvent) JLabel(javax.swing.JLabel) StartupActionsManager(apps.StartupActionsManager) JCheckBox(javax.swing.JCheckBox) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) GroupLayout(javax.swing.GroupLayout) JSpinner(javax.swing.JSpinner)

Aggregations

JSpinner (javax.swing.JSpinner)76 SpinnerNumberModel (javax.swing.SpinnerNumberModel)61 JLabel (javax.swing.JLabel)47 JPanel (javax.swing.JPanel)41 ActionEvent (java.awt.event.ActionEvent)28 ActionListener (java.awt.event.ActionListener)27 JCheckBox (javax.swing.JCheckBox)22 JRadioButton (javax.swing.JRadioButton)21 GridBagConstraints (java.awt.GridBagConstraints)18 Insets (java.awt.Insets)18 ChangeEvent (javax.swing.event.ChangeEvent)18 GridBagLayout (java.awt.GridBagLayout)17 JButton (javax.swing.JButton)15 Dimension (java.awt.Dimension)13 ChangeListener (javax.swing.event.ChangeListener)13 ButtonGroup (javax.swing.ButtonGroup)12 BorderLayout (java.awt.BorderLayout)11 JTextField (javax.swing.JTextField)11 JScrollPane (javax.swing.JScrollPane)10 JMenuItem (javax.swing.JMenuItem)8