List of usage examples for javax.swing JSpinner setEnabled
@BeanProperty(expert = true, preferred = true, visualUpdate = true, description = "The enabled state of the component.") public void setEnabled(boolean enabled)
From source file:net.sf.jhylafax.AbstractFaxDialog.java
protected void addDateControls() { dateNowRadionButton = new JRadioButton(); dateNowRadionButton.setSelected(true); dateLabel = builder.append("", dateNowRadionButton); builder.nextLine();//from w ww . ja v a 2 s. c o m dateLaterRadionButton = new JRadioButton(); dateModel = new SpinnerDateModel(); final JSpinner dateSpinner = new JSpinner(dateModel); dateSpinner.setEnabled(false); dateLaterRadionButton.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { dateSpinner.setEnabled(dateLaterRadionButton.isSelected()); } }); builder.append("", dateLaterRadionButton, dateSpinner); builder.nextLine(); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(dateNowRadionButton); buttonGroup.add(dateLaterRadionButton); }
From source file:Forms.FrmPrincipal.java
private void genCapasOcultas() { pnlCapas.removeAll();// www . ja va 2 s.co m int n = Integer.parseInt(spIntermedias.getValue().toString()) + 2; for (int i = 0; i < n; i++) { JSpinner spinner = new JSpinner(); spinner.setName("capa" + String.valueOf(i)); spinner.setValue(100); spinner.setSize(70, 20); spinner.setVisible(false); spinner.setVisible(true); pnlCapas.add(spinner); if (i == 0) { spinner.setValue(matrizPatrones[0].length - 1); spinner.setEnabled(false); } else if (i == n - 1) { spinner.setValue(String.valueOf(matrizPatrones[0][matrizPatrones[0].length - 1]).length()); spinner.setEnabled(false); } } pnlCapas.setVisible(false); pnlCapas.setVisible(true); }
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
/** * Update a linked checkbox and spinner. The spinner will be enabled * if the checkbox is selected/*from ww w. j av a2s . c om*/ * * @param component1 The checkbox that controls the spinner * @param component2 The spinner * @param state The new state to set the checkbox to * @param value The value to store in the spinner */ protected void updateSpinner(JCheckBox component1, JSpinner component2, boolean state, int value) { component1.setSelected(state); component2.setEnabled(state); component2.setValue(value); }
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
/** * Update a linked checkbox and spinner. The spinner will be enabled * if the checkbox is selected/*from www . j a v a 2 s .com*/ * * @param component1 The checkbox that controls the spinner * @param component2 The spinner * @param state The new state to set the checkbox to * @param value The value to store in the spinner */ protected void updateSpinner(JCheckBox component1, JSpinner component2, boolean state, double value) { component1.setSelected(state); component2.setEnabled(state); component2.setValue(value); }
From source file:configuration.Util.java
public static void buttonEventSpinner(workflow_properties properties, javax.swing.JRadioButton b, javax.swing.JSpinner s) { if (b == null) { properties.put(s.getName(), s.getValue()); } else {//from ww w . j a va 2 s . co m 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()); } } } }
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 {//from ww w . ja 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:dk.dma.epd.common.prototype.gui.route.RoutePropertiesDialogCommon.java
/** * Configures the given date picker and associated time spinner * @param picker the date picker//from w ww . j a v a2 s. c om * @param spinner the time spinner */ private void initDatePicker(JXDatePicker picker, JSpinner spinner) { picker.setFormats(new SimpleDateFormat("E dd/MM/yyyy")); picker.addPropertyChangeListener("date", this); DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm"); DateFormatter formatter = (DateFormatter) editor.getTextField().getFormatter(); formatter.setAllowsInvalid(false); formatter.setOverwriteMode(true); formatter.setCommitsOnValidEdit(true); spinner.setEditor(editor); spinner.addChangeListener(new SpinnerChangeListener()); // Set the enabled state picker.setEnabled(!readOnlyRoute); spinner.setEnabled(!readOnlyRoute); }
From source file:org.esa.snap.rcp.statistics.StatisticsPanel.java
private JPanel createAccuracyPanel() { final JPanel accuracyPanel = new JPanel(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); final JLabel label = new JLabel("Histogram accuracy:"); accuracyModel = new AccuracyModel(); final BindingContext bindingContext = new BindingContext( PropertyContainer.createObjectBacked(accuracyModel)); final SpinnerNumberModel accuracyNumberModel = new SpinnerNumberModel(accuracyModel.accuracy, 0, Util.MAX_ACCURACY, 1); final JSpinner accuracySpinner = new JSpinner(accuracyNumberModel); ((JSpinner.DefaultEditor) accuracySpinner.getEditor()).getTextField().setEditable(false); bindingContext.bind("accuracy", accuracySpinner); final JCheckBox checkBox = new JCheckBox("Auto accuracy"); bindingContext.bind("useAutoAccuracy", checkBox); final IntervalValidator rangeValidator = new IntervalValidator(new ValueRange(0, Util.MAX_ACCURACY)); final PropertyDescriptor accuracyDescriptor = bindingContext.getPropertySet().getDescriptor("accuracy"); accuracyDescriptor.setValidator(rangeValidator); checkBox.setSelected(accuracyModel.useAutoAccuracy); bindingContext.getPropertySet().getProperty("useAutoAccuracy") .addPropertyChangeListener(new PropertyChangeListener() { @Override//w ww . ja va 2s .c o m public void propertyChange(PropertyChangeEvent evt) { label.setEnabled(!checkBox.isSelected()); accuracySpinner.setEnabled(!checkBox.isSelected()); if (checkBox.isSelected()) { bindingContext.getBinding("accuracy").setPropertyValue(3); } computePanel.updateEnablement(); } }); label.setEnabled(false); accuracySpinner.setEnabled(false); accuracySpinner.setToolTipText("Specify the number of histogram bins (#bins: 10^accuracy)."); accuracySpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { computePanel.updateEnablement(); } }); GridBagUtils.addToPanel(accuracyPanel, new TitledSeparator("Histogram accuracy"), gbc, "fill=HORIZONTAL, weightx=1.0,anchor=NORTH,gridwidth=2"); GridBagUtils.addToPanel(accuracyPanel, checkBox, gbc, "gridy=1,insets.left=5,insets.top=2"); GridBagUtils.addToPanel(accuracyPanel, label, gbc, "gridy=2, insets.left=26,weightx=0.0,fill=NONE,anchor=WEST,gridwidth=1"); GridBagUtils.addToPanel(accuracyPanel, accuracySpinner, gbc, "gridx=1,weightx=1.0,fill=HORIZONTAL,insets.right=5,insets.left=5"); return accuracyPanel; }
From source file:userinterface.graph.Histogram.java
/** * Generates the property dialog for a Histogram. Allows the user to select either a new or an exisitng Histogram * to plot data on/* w w w . j a v a 2 s. co m*/ * * @param defaultSeriesName * @param handler instance of {@link GUIGraphHandler} * @param minVal the min value in data cache * @param maxVal the max value in data cache * @return Either a new instance of a Histogram or an old one depending on what the user selects */ public static Pair<Histogram, SeriesKey> showPropertiesDialog(String defaultSeriesName, GUIGraphHandler handler, double minVal, double maxVal) { // make sure that the probabilities are valid if (maxVal > 1.0) maxVal = 1.0; if (minVal < 0.0) minVal = 0.0; // set properties for the dialog JDialog dialog = new JDialog(GUIPrism.getGUI(), "Histogram properties", true); dialog.setLayout(new BorderLayout()); JPanel p1 = new JPanel(new FlowLayout()); p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Number of buckets")); JPanel p2 = new JPanel(new FlowLayout()); p2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name")); JSpinner buckets = new JSpinner(new SpinnerNumberModel(10, 5, Integer.MAX_VALUE, 1)); buckets.setToolTipText("Select the number of buckets for this Histogram"); // provides the ability to select a new or an old histogram to plot the series on JTextField seriesName = new JTextField(defaultSeriesName); JRadioButton newSeries = new JRadioButton("New Histogram"); JRadioButton existing = new JRadioButton("Existing Histogram"); newSeries.setSelected(true); JPanel seriesSelectPanel = new JPanel(); seriesSelectPanel.setLayout(new BoxLayout(seriesSelectPanel, BoxLayout.Y_AXIS)); JPanel seriesTypeSelect = new JPanel(new FlowLayout()); JPanel seriesOptionsPanel = new JPanel(new FlowLayout()); seriesTypeSelect.add(newSeries); seriesTypeSelect.add(existing); JComboBox<String> seriesOptions = new JComboBox<>(); seriesOptionsPanel.add(seriesOptions); seriesSelectPanel.add(seriesTypeSelect); seriesSelectPanel.add(seriesOptionsPanel); seriesSelectPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Add series to")); // provides ability to select the min/max range of the plot JLabel minValsLabel = new JLabel("Min range:"); JSpinner minVals = new JSpinner(new SpinnerNumberModel(0.0, 0.0, minVal, 0.01)); minVals.setToolTipText("Does not allow value more than the min value in the probabilities"); JLabel maxValsLabel = new JLabel("Max range:"); JSpinner maxVals = new JSpinner(new SpinnerNumberModel(1.0, maxVal, 1.0, 0.01)); maxVals.setToolTipText("Does not allow value less than the max value in the probabilities"); JPanel minMaxPanel = new JPanel(); minMaxPanel.setLayout(new BoxLayout(minMaxPanel, BoxLayout.X_AXIS)); JPanel leftValsPanel = new JPanel(new BorderLayout()); JPanel rightValsPanel = new JPanel(new BorderLayout()); minMaxPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Range")); leftValsPanel.add(minValsLabel, BorderLayout.WEST); leftValsPanel.add(minVals, BorderLayout.CENTER); rightValsPanel.add(maxValsLabel, BorderLayout.WEST); rightValsPanel.add(maxVals, BorderLayout.CENTER); minMaxPanel.add(leftValsPanel); minMaxPanel.add(rightValsPanel); // fill the old histograms in the property dialog boolean found = false; for (int i = 0; i < handler.getNumModels(); i++) { if (handler.getModel(i) instanceof Histogram) { seriesOptions.addItem(handler.getGraphName(i)); found = true; } } existing.setEnabled(found); seriesOptions.setEnabled(false); // the bottom panel JPanel options = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton ok = new JButton("Plot"); JButton cancel = new JButton("Cancel"); // bind keyboard keys to plot and cancel buttons to improve usability ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { private static final long serialVersionUID = -7324877661936685228L; @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ok"); cancel.getActionMap().put("ok", new AbstractAction() { private static final long serialVersionUID = 2642213543774356676L; @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); //Action listener for the new series radio button newSeries.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (newSeries.isSelected()) { existing.setSelected(false); seriesOptions.setEnabled(false); buckets.setEnabled(true); buckets.setToolTipText("Select the number of buckets for this Histogram"); minVals.setEnabled(true); maxVals.setEnabled(true); } } }); //Action listener for the existing series radio button existing.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (existing.isSelected()) { newSeries.setSelected(false); seriesOptions.setEnabled(true); buckets.setEnabled(false); minVals.setEnabled(false); maxVals.setEnabled(false); buckets.setToolTipText("Number of buckets can't be changed on an existing Histogram"); } } }); //Action listener for the plot button ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); if (newSeries.isSelected()) { hist = new Histogram(); hist.setNumOfBuckets((int) buckets.getValue()); hist.setIsNew(true); } else if (existing.isSelected()) { String HistName = (String) seriesOptions.getSelectedItem(); hist = (Histogram) handler.getModel(HistName); hist.setIsNew(false); } key = hist.addSeries(seriesName.getText()); if (minVals.isEnabled() && maxVals.isEnabled()) { hist.setMinProb((double) minVals.getValue()); hist.setMaxProb((double) maxVals.getValue()); } } }); //Action listener for the cancel button cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); hist = null; } }); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { hist = null; } }); p1.add(buckets, BorderLayout.CENTER); p2.add(seriesName, BorderLayout.CENTER); options.add(ok); options.add(cancel); // add everything to the main panel of the dialog JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(seriesSelectPanel); mainPanel.add(p1); mainPanel.add(p2); mainPanel.add(minMaxPanel); // add main panel to the dialog dialog.add(mainPanel, BorderLayout.CENTER); dialog.add(options, BorderLayout.SOUTH); // set dialog properties dialog.setSize(320, 290); dialog.setLocationRelativeTo(GUIPrism.getGUI()); dialog.setVisible(true); // return the user selected Histogram with the properties set return new Pair<Histogram, SeriesKey>(hist, key); }