Example usage for javax.swing JSpinner getValue

List of usage examples for javax.swing JSpinner getValue

Introduction

In this page you can find the example usage for javax.swing JSpinner getValue.

Prototype

public Object getValue() 

Source Link

Document

Returns the current value of the model, typically this value is displayed by the editor.

Usage

From source file:configuration.Util.java

public static void boxEventSpinner(workflow_properties properties, javax.swing.JCheckBox b,
        javax.swing.JSpinner s) {
    if (b == null) {
        properties.put(s.getName(), s.getValue());
    } else {/* w  w w .  j  a  v  a2  s. com*/
        if (b.isSelected() == true) {
            if (s == null) {
                properties.put(b.getName(), b.isSelected());
            } else {
                s.setEnabled(true);
                properties.put(s.getName(), s.getValue());
                properties.put(b.getName(), s.getValue());
            }
        } else {
            properties.remove(b.getName());
            if (s != null) {
                s.setEnabled(false);
            }
        }
    }
}

From source file:com.alvermont.terraj.planet.ui.MainFrame.java

private void lonSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_lonSpinnerStateChanged
{//GEN-HEADEREND:event_lonSpinnerStateChanged

    final JSpinner source = (JSpinner) evt.getSource();
    params.getProjectionParameters().setLat((Double) source.getValue());
}

From source file:com.alvermont.terraj.planet.ui.MainFrame.java

private void latSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_latSpinnerStateChanged
{//GEN-HEADEREND:event_latSpinnerStateChanged

    final JSpinner source = (JSpinner) evt.getSource();
    params.getProjectionParameters().setLat((Double) source.getValue());
}

From source file:com.alvermont.terraj.planet.ui.MainFrame.java

private void scaleSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_scaleSpinnerStateChanged
{//GEN-HEADEREND:event_scaleSpinnerStateChanged

    final JSpinner source = (JSpinner) evt.getSource();
    params.getProjectionParameters().setScale((Double) source.getValue());
}

From source file:com.alvermont.terraj.planet.ui.MainFrame.java

private void hgridSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_hgridSpinnerStateChanged
{//GEN-HEADEREND:event_hgridSpinnerStateChanged

    final JSpinner source = (JSpinner) evt.getSource();
    params.getProjectionParameters().setHgrid((Double) source.getValue());
}

From source file:com.alvermont.terraj.planet.ui.MainFrame.java

private void vgridSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_vgridSpinnerStateChanged
{//GEN-HEADEREND:event_vgridSpinnerStateChanged

    final JSpinner source = (JSpinner) evt.getSource();
    params.getProjectionParameters().setVgrid((Double) source.getValue());
}

From source file:io.github.jeremgamer.editor.panels.components.PanelsPanel.java

public PanelsPanel(JFrame frame, final PanelSave ps) {
    this.ps = ps;
    this.frame = frame;
    this.setSize(new Dimension(395, frame.getHeight() - 27 - 23));
    this.setLocation(300, 0);
    this.setBorder(BorderFactory.createTitledBorder("Edition du panneau"));

    JPanel content = new JPanel();
    JScrollPane scroll = new JScrollPane(content);
    scroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    scroll.setBorder(null);/*from   w  w w  .j a va 2 s.  c o m*/
    content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
    scroll.setPreferredSize(new Dimension(382, frame.getHeight() - 27 - 46 - 20));

    JPanel namePanel = new JPanel();
    name.setPreferredSize(new Dimension(this.getWidth() - 280, 30));
    name.setEditable(false);
    namePanel.add(new JLabel("Nom :"));
    namePanel.add(name);
    namePanel.add(Box.createRigidArea(new Dimension(10, 1)));
    layout.addItem("Basique");
    layout.addItem("Bordures");
    layout.addItem("Ligne");
    layout.addItem("Colonne");
    layout.addItem("Grille");
    layout.addItem("Empil");
    layout.setPreferredSize(new Dimension(110, 30));
    layout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            cl.show(advanced, listContent[combo.getSelectedIndex()]);
            ps.set("layout", combo.getSelectedIndex());
            ActionPanel.updateLists();
        }

    });
    namePanel.add(new JLabel("Disposition :"));
    namePanel.add(layout);
    namePanel.setPreferredSize(new Dimension(365, 50));
    namePanel.setMaximumSize(new Dimension(365, 50));
    content.add(namePanel);

    advanced.setPreferredSize(new Dimension(365, 300));
    advanced.setMaximumSize(new Dimension(365, 300));
    advanced.add(ble, listContent[0]);
    advanced.add(brdle, listContent[1]);
    advanced.add(lle, listContent[2]);
    advanced.add(rle, listContent[3]);
    advanced.add(gle, listContent[4]);
    advanced.add(cle, listContent[5]);

    content.add(advanced);

    topBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.top", combo.getSelectedItem());
        }

    });
    leftBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.left", combo.getSelectedItem());
        }

    });
    centerBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.center", combo.getSelectedItem());
        }

    });
    rightBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.right", combo.getSelectedItem());
        }

    });
    bottomBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.bottom", combo.getSelectedItem());
        }

    });

    JPanel prefSize = new JPanel();
    prefSize.setPreferredSize(new Dimension(365, 110));
    prefSize.setMaximumSize(new Dimension(365, 110));
    prefSize.setBorder(BorderFactory.createTitledBorder("Taille prfre"));
    JPanel prefSizePanel = new JPanel();
    prefSizePanel.setLayout(new GridLayout(2, 4));
    prefSizePanel.setPreferredSize(new Dimension(300, 55));
    prefSizePanel.setMaximumSize(new Dimension(300, 55));
    prefSizePanel.add(prefSizeEnabled);
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel("(en pixels)"));
    prefSizePanel.add(new JLabel("Largeur :"));
    prefSizePanel.add(prefWidth);
    prefSizePanel.add(new JLabel("Hauteur :"));
    prefSizePanel.add(prefHeight);
    prefWidth.setEnabled(false);
    prefHeight.setEnabled(false);
    prefSizeEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            ps.set("preferredSize", check.isSelected());
            prefWidth.setEnabled(check.isSelected());
            prefHeight.setEnabled(check.isSelected());
        }
    });
    prefWidth.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredWidth", spinner.getValue());
        }
    });
    prefHeight.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredHeight", spinner.getValue());
        }
    });
    prefSize.add(prefSizePanel);

    content.add(prefSize);

    JPanel insetsPanel = new JPanel();
    insetsPanel.setBorder(BorderFactory.createTitledBorder("carts"));
    insetsPanel.setPreferredSize(new Dimension(365, 100));
    insetsPanel.setMaximumSize(new Dimension(365, 100));

    JPanel insetsContent = new JPanel();
    insetsContent.setLayout(new BoxLayout(insetsContent, BoxLayout.PAGE_AXIS));

    JPanel insetInput = new JPanel();
    insetInput.setLayout(new GridLayout(2, 4));
    insetInput.add(insetsEnabled);
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel("(en pixels)"));
    insetInput.add(new JLabel("Horizontaux :"));
    insetInput.add(insetHz);
    insetInput.add(new JLabel("Verticaux :"));
    insetInput.add(insetVt);

    insetsEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            if (check.isSelected()) {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", true);
            } else {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", false);
            }
        }

    });

    insetHz.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.horizontal", spinner.getValue());
        }
    });
    insetVt.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.vertical", spinner.getValue());
        }
    });

    insetsContent.add(insetInput);
    insetsPanel.add(insetsContent);

    content.add(insetsPanel);

    JPanel web = new JPanel();
    web.setPreferredSize(new Dimension(365, 100));
    web.setMaximumSize(new Dimension(365, 100));
    web.setBorder(BorderFactory.createTitledBorder("Page Web"));

    JPanel webContent = new JPanel();
    webContent.setLayout(new BorderLayout());
    webContent.add(webEnabled, BorderLayout.NORTH);
    webEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("web", check.isSelected());
            if (check.isSelected() == true) {
                layout.setSelectedIndex(0);
                layout.setEnabled(false);
                ble.removeAllComponents();
                ble.disableComponents();
                adress.setEnabled(true);
            } else {
                ble.enableComponents();
                layout.setEnabled(true);
                adress.setEnabled(false);
            }
        }
    });
    JPanel webInput = new JPanel();
    webInput.add(new JLabel("Adresse :"));
    adress.setPreferredSize(new Dimension(250, 30));
    CaretListener caretUpdate = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            ps.set("web.adress", text.getText());
        }
    };
    adress.addCaretListener(caretUpdate);
    webInput.add(adress);
    webContent.add(webInput, BorderLayout.CENTER);

    web.add(webContent);

    JPanel background = new JPanel();
    BorderLayout bLayout = new BorderLayout();
    bLayout.setVgap(12);
    background.setLayout(bLayout);
    background.setBorder(BorderFactory.createTitledBorder("Couleur de fond"));
    background.setPreferredSize(new Dimension(365, 210));
    background.setMaximumSize(new Dimension(365, 210));
    cp.setPreferredSize(new Dimension(347, 145));
    cp.setMaximumSize(new Dimension(347, 145));
    opaque.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("background.opaque", check.isSelected());
            cp.enableComponents(check.isSelected());
        }
    });
    background.add(opaque, BorderLayout.NORTH);
    background.add(cp, BorderLayout.CENTER);

    JPanel image = new JPanel();
    image.setBorder(BorderFactory.createTitledBorder("Image de fond"));
    image.setPreferredSize(new Dimension(365, 125));
    image.setMaximumSize(new Dimension(365, 125));
    image.setLayout(new BorderLayout());
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.setEnabled(false);
    remove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            File img = new File(
                    "projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png");
            if (img.exists()) {
                img.delete();
            }
            browseImage.setEnabled(true);
        }

    });
    JPanel top = new JPanel();
    browseImage.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton) e.getSource();
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "background.png");
                nameBackground.setText(new File(path).getName());
                ps.set("background.image", new File(path).getName());
                button.setEnabled(false);
                size.setEnabled(true);
                size2.setEnabled(true);
                remove.setEnabled(true);
            }
        }

    });
    bg.add(size);
    bg.add(size2);
    JPanel sizePanel = new JPanel();
    sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.PAGE_AXIS));
    size.setEnabled(false);
    size2.setEnabled(false);
    sizePanel.add(size);
    sizePanel.add(size2);
    size.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 0);
        }

    });
    size2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 1);
        }

    });
    top.add(browseImage);
    top.add(sizePanel);

    remove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JButton button = (JButton) event.getSource();
            new File("projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png")
                    .delete();
            nameBackground.setText("");
            ps.set("background.image", "");
            button.setEnabled(false);
        }

    });
    nameBackground.setFont(new Font("Sans Serif", Font.PLAIN, 15));
    JPanel center = new JPanel(new BorderLayout());
    center.add(nameBackground, BorderLayout.CENTER);
    center.add(remove, BorderLayout.EAST);

    image.add(top, BorderLayout.NORTH);
    image.add(center, BorderLayout.CENTER);

    content.add(web);
    content.add(background);
    content.add(image);

    this.add(scroll);
}

From source file:org.adamkrajcik.gui.MainForm.java

private void createWineMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createWineMenuItemActionPerformed
    JTextField name = new JTextField();
    SpinnerNumberModel model = new SpinnerNumberModel((short) Calendar.getInstance().get(Calendar.YEAR),
            (short) 1700, (short) Calendar.getInstance().get(Calendar.YEAR), (short) 1);
    JSpinner vintage = new JSpinner(model);
    SpinnerNumberModel model2 = new SpinnerNumberModel(1, 1, Integer.MAX_VALUE, 1);
    JSpinner quantity = new JSpinner(model2);
    String[] wineTypes = { "RED", "WHITE", "ROSE" };
    JComboBox type = new JComboBox(wineTypes);

    List<String> myList = new ArrayList<String>();
    for (String countryCode : Locale.getISOCountries()) {

        Locale obj = new Locale("", countryCode);
        myList.add(obj.getDisplayCountry(Locale.ENGLISH));
    }/*w  ww . j  a v a  2 s.  com*/
    String[] x = new String[myList.size()];
    myList.toArray(x);
    JComboBox countryList = new JComboBox(x);

    Object[] message = { "Name:", name, "Country:", countryList, "Vintage:", vintage, "Quantity", quantity,
            "Type", type, };

    int option = JOptionPane.showConfirmDialog(null, message, "New Wine", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
    if (option == JOptionPane.OK_OPTION) {
        if (name.getText().length() == 0) {
            JOptionPane.showConfirmDialog(null, langResource.getString("errorName"),
                    langResource.getString("errorName"), JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);
            createWineMenuItemActionPerformed(null);
            return;
        }
        new CreateWineSwingWorker(newWine(name.getText(), (String) countryList.getSelectedItem(),
                (short) ((int) vintage.getValue()), (int) quantity.getValue(),
                WineType.valueOf((String) type.getSelectedItem()))).execute();
    }
}

From source file:com.alvermont.terraj.fracplanet.ui.ControlsDialog.java

private void cloudsHeightSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_cloudsHeightSpinnerStateChanged
{//GEN-HEADEREND:event_cloudsHeightSpinnerStateChanged

    final JSpinner source = (JSpinner) evt.getSource();
    final CloudParameters params = this.parent.getParameters().getCloudParameters();

    params.setHeight((Integer) source.getValue());
}

From source file:com.alvermont.terraj.fracplanet.ui.ControlsDialog.java

private void cloudsSeedSpinnerStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_cloudsSeedSpinnerStateChanged
{//GEN-HEADEREND:event_cloudsSeedSpinnerStateChanged

    final JSpinner source = (JSpinner) evt.getSource();
    final CloudParameters params = this.parent.getParameters().getCloudParameters();

    Integer intval = (Integer) source.getValue();

    params.setSeed(intval);/*from  w  w  w  .  j a  va2  s .c  om*/
}