Search in sources :

Example 51 with JSpinner

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

the class MemoryInputIcon method edit.

@Override
protected void edit() {
    _iconEditor = new IconAdder("Memory") {

        JSpinner spinner = new JSpinner(_spinModel);

        @Override
        protected void addAdditionalButtons(JPanel p) {
            ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setColumns(2);
            spinner.setMaximumSize(spinner.getPreferredSize());
            spinner.setValue(Integer.valueOf(_textBox.getColumns()));
            JPanel p2 = new JPanel();
            //p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
            //p2.setLayout(new FlowLayout(FlowLayout.TRAILING));
            p2.add(new JLabel(Bundle.getMessage("NumColsLabel")));
            p2.add(spinner);
            p.add(p2);
            p.setVisible(true);
        }
    };
    makeIconEditorFrame(this, "Memory", true, _iconEditor);
    _iconEditor.setPickList(jmri.jmrit.picker.PickListModel.memoryPickModelInstance());
    ActionListener addIconAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            editMemory();
        }
    };
    _iconEditor.makeIconPanel(false);
    _iconEditor.complete(addIconAction, false, true, true);
    _iconEditor.setSelection(getMemory());
}
Also used : JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel)

Example 52 with JSpinner

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

the class WebServerPreferencesPanel method initComponents.

private void initComponents() {
    bindingGroup = new BindingGroup();
    port = new JSpinner();
    portLabel = new JLabel();
    readonlyPower = new JCheckBox();
    startup = new JCheckBox();
    port.setModel(new SpinnerNumberModel(12080, 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"));
    // NOI18N
    readonlyPower.setText(Bundle.getMessage("LabelReadonlyPower"));
    readonlyPower.addActionListener((ActionEvent e) -> {
        readonlyPower.setToolTipText(Bundle.getMessage(readonlyPower.isSelected() ? "ToolTipReadonlyPowerTrue" : "ToolTipReadonlyPowerFalse"));
    });
    binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${readonlyPower}"), readonlyPower, BeanProperty.create("selected"));
    bindingGroup.addBinding(binding);
    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(WebServerAction.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) -> (WebServerAction.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).addComponent(readonlyPower, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, 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(readonlyPower).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) ActionEvent(java.awt.event.ActionEvent) 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) ActionEvent(java.awt.event.ActionEvent) 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)

Example 53 with JSpinner

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

the class WiThrottlePrefsPanel method eStopDelayPanel.

private JPanel eStopDelayPanel() {
    JPanel panel = new JPanel();
    eStopCB = new JCheckBox(Bundle.getMessage("LabelUseEStop"));
    eStopCB.setToolTipText(Bundle.getMessage("ToolTipUseEStop"));
    SpinnerNumberModel spinMod = new SpinnerNumberModel(10, 4, 60, 2);
    delaySpinner = new JSpinner(spinMod);
    ((JSpinner.DefaultEditor) delaySpinner.getEditor()).getTextField().setEditable(false);
    panel.add(eStopCB);
    panel.add(delaySpinner);
    panel.add(new JLabel(Bundle.getMessage("LabelEStopDelay")));
    return panel;
}
Also used : JCheckBox(javax.swing.JCheckBox) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JPanel(javax.swing.JPanel) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel)

Example 54 with JSpinner

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

the class WiThrottlePrefsPanel method socketPortPanel.

private JPanel socketPortPanel() {
    JPanel SPPanel = new JPanel();
    port = new JSpinner(new SpinnerNumberModel(localPrefs.getPort(), 1, 65535, 1));
    port.setToolTipText(Bundle.getMessage("PortToolTip"));
    port.setEditor(new JSpinner.NumberEditor(port, "#"));
    JLabel label = new JLabel(Bundle.getMessage("PortLabel"));
    label.setToolTipText(port.getToolTipText());
    SPPanel.add(port);
    SPPanel.add(label);
    startupCB = new JCheckBox(Bundle.getMessage("LabelStartup"), isStartUpAction());
    startupItemListener = (ItemEvent e) -> {
        this.startupCB.removeItemListener(this.startupItemListener);
        StartupActionsManager manager = InstanceManager.getDefault(StartupActionsManager.class);
        if (this.startupCB.isSelected()) {
            PerformActionModel model = new PerformActionModel();
            model.setClassName(WiThrottleCreationAction.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) -> (WiThrottleCreationAction.class.getName().equals(model.getClassName()))).forEach((model) -> {
                this.startupActionPosition = Arrays.asList(manager.getActions()).indexOf(model);
                manager.removeAction(model);
            });
        }
        this.startupCB.addItemListener(this.startupItemListener);
    };
    this.startupCB.addItemListener(this.startupItemListener);
    SPPanel.add(startupCB);
    return SPPanel;
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) JCheckBox(javax.swing.JCheckBox) PerformActionModel(apps.PerformActionModel) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) InstanceManager(jmri.InstanceManager) Arrays(java.util.Arrays) JSpinner(javax.swing.JSpinner) ButtonGroup(javax.swing.ButtonGroup) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JTitledSeparator(jmri.swing.JTitledSeparator) ItemListener(java.awt.event.ItemListener) JOptionPane(javax.swing.JOptionPane) StartupActionsManager(apps.StartupActionsManager) File(java.io.File) JRadioButton(javax.swing.JRadioButton) ResourceBundle(java.util.ResourceBundle) FileUtil(jmri.util.FileUtil) PerformActionModel(apps.PerformActionModel) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) JFrame(javax.swing.JFrame) PropertyChangeEvent(java.beans.PropertyChangeEvent) JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) PreferencesPanel(jmri.swing.PreferencesPanel) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel) StartupActionsManager(apps.StartupActionsManager)

Example 55 with JSpinner

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

the class Editor method addMemoryEditor.

protected void addMemoryEditor() {
    IconAdder editor = new IconAdder("Memory") {

        JButton bSpin = new JButton(Bundle.getMessage("AddSpinner"));

        JButton bBox = new JButton(Bundle.getMessage("AddInputBox"));

        JSpinner spinner = new JSpinner(_spinCols);

        @Override
        protected void addAdditionalButtons(JPanel p) {
            bSpin.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent a) {
                    addMemorySpinner();
                }
            });
            JPanel p1 = new JPanel();
            //p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
            bBox.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent a) {
                    addMemoryInputBox();
                }
            });
            ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setColumns(2);
            spinner.setMaximumSize(spinner.getPreferredSize());
            JPanel p2 = new JPanel();
            p2.add(new JLabel(Bundle.getMessage("NumColsLabel")));
            p2.add(spinner);
            p1.add(p2);
            p1.add(bBox);
            p.add(p1);
            p1 = new JPanel();
            p1.add(bSpin);
            p.add(p1);
        }

        @Override
        public void valueChanged(ListSelectionEvent e) {
            super.valueChanged(e);
            bSpin.setEnabled(addIconIsEnabled());
            bBox.setEnabled(addIconIsEnabled());
        }
    };
    ActionListener addIconAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            putMemory();
        }
    };
    JFrameItem frame = makeAddIconFrame("Memory", true, true, editor);
    _iconEditorFrame.put("Memory", frame);
    editor.setPickList(PickListModel.memoryPickModelInstance());
    editor.makeIconPanel(true);
    editor.complete(addIconAction, false, true, false);
    frame.addHelpMenu("package.jmri.jmrit.display.IconAdder", true);
}
Also used : JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel)

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