Java Code Examples for javax.swing.SpinnerModel

The following examples show how to use javax.swing.SpinnerModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   Source File: DocumentsPanelProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void openIndex(LukeState state) {
  documentsModel = documentsFactory.newInstance(state.getIndexReader());

  addDocBtn.setEnabled(!state.readOnly() && state.hasDirectoryReader());

  int maxDoc = documentsModel.getMaxDoc();
  maxDocsLbl.setText("in " + maxDoc + " docs");
  if (maxDoc > 0) {
    int max = Math.max(maxDoc - 1, 0);
    SpinnerModel spinnerModel = new SpinnerNumberModel(0, 0, max, 1);
    docNumSpnr.setModel(spinnerModel);
    docNumSpnr.setEnabled(true);
    displayDoc(0);
  } else {
    docNumSpnr.setEnabled(false);
  }

  documentsModel.getFieldNames().stream().sorted().forEach(fieldsCombo::addItem);
}
 
Example 2
Source Project: swingsane   Source File: KnownSaneOptions.java    License: Apache License 2.0 6 votes vote down vote up
public static SpinnerModel getBlackThresholdModel(Scanner scanner) {
  SpinnerNumberModel blackThresholdModel = new SpinnerNumberModel(0, MIN_BLACK_THRESHOLD,
      MAX_BLACK_THRESHOLD, 1);

  HashMap<String, FixedOption> fixedOptions = scanner.getFixedOptions();

  FixedOption fixedOption = fixedOptions.get(SANE_NAME_THRESHOLD);

  if (fixedOption == null) {
    return null;
  }

  Constraints constraints = fixedOption.getConstraints();
  Integer maxInt = constraints.getMaximumInteger();
  Integer minInt = constraints.getMinimumInteger();

  blackThresholdModel.setMaximum(maxInt);
  blackThresholdModel.setMinimum(minInt);
  blackThresholdModel.setStepSize(constraints.getQuantumInteger());

  blackThresholdModel.setValue(fixedOption.getValue());

  return blackThresholdModel;
}
 
Example 3
Source Project: wpcleaner   Source File: OptionsPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Restore all integer options to their default values.
 */
private void defaultValuesInteger() {
  for (Entry<ConfigurationValueInteger, Object> entry : integerValues.entrySet()) {
    if ((entry.getValue() != null) && (entry.getKey() != null)) {
      if (entry.getValue() instanceof JSpinner) {
        JSpinner spinner = (JSpinner) entry.getValue();
        SpinnerModel model = spinner.getModel();
        model.setValue(Integer.valueOf(entry.getKey().getDefaultValue()));
      }
      if (entry.getValue() instanceof ButtonGroup) {
        ButtonGroup group = (ButtonGroup) entry.getValue();
        setButtonGroupSelection(group, entry.getKey().getDefaultValue());
      }
    }
  }
}
 
Example 4
Source Project: chipster   Source File: IntegerInputComponent.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a new IntegerInputComponent.
 * 
 * @param param The IntegerParameter to be controlled.
 * @param parameterPanel The ParameterPanel to which this component is to
 * 				 be placed.
 */
public IntegerInputComponent(
		IntegerParameter param, ParameterPanel parameterPanel) {
	super(parameterPanel);
	this.param = param;
	this.state = ParameterInputComponent.INPUT_IS_INITIALIZED;
	SpinnerModel model = new NullableSpinnerModel();
	model.setValue(param.getValue());
	this.spinner = new JSpinner(model);
	spinner.addFocusListener(this);
	spinner.setPreferredSize(ParameterInputComponent.PREFERRED_SIZE);	
	
	// The second parameter of NumberEditor constructor is number format
	// The string "0" means that it is a digit without any thousand separators
	// or decimals
	spinner.setEditor(new NullableSpinnerEditor(spinner, "0"));
	
	spinner.addChangeListener(this);
	field = ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField();
	field.addCaretListener(this);
       field.setBackground(BG_VALID);
	this.add(spinner, BorderLayout.CENTER);		
}
 
Example 5
private JSpinner createSpinner(int value)
{
	SpinnerModel model = new SpinnerNumberModel(value, Integer.MIN_VALUE, Integer.MAX_VALUE, 1);
	JSpinner spinner = new JSpinner(model);
	Component editor = spinner.getEditor();
	JFormattedTextField spinnerTextField = ((JSpinner.DefaultEditor) editor).getTextField();
	spinnerTextField.setColumns(4);

	return spinner;
}
 
Example 6
Source Project: marathonv5   Source File: JSpinnerJavaElementTest.java    License: Apache License 2.0 5 votes vote down vote up
private JSpinner createNumberSpinner(Calendar calendar) {
    int currentYear = calendar.get(Calendar.YEAR);
    SpinnerModel yearModel = new SpinnerNumberModel(currentYear, currentYear - 100, currentYear + 100, 1);
    JSpinner numberSpinner = new JSpinner(yearModel);
    numberSpinner.setEditor(new JSpinner.NumberEditor(numberSpinner, "#"));
    numberSpinner.setName("number-spinner");
    return numberSpinner;
}
 
Example 7
Source Project: netbeans   Source File: JExtendedSpinner.java    License: Apache License 2.0 5 votes vote down vote up
public JExtendedSpinner(SpinnerModel model) {
    super(model);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().setFont(UIManager.getFont("Label.font")); // NOI18N
    ((JSpinner.DefaultEditor) getEditor()).getTextField().addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(final java.awt.event.KeyEvent e) {
                if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
                    processKeyEvent(e);
                }
            }
        });
    configureWheelListener();
}
 
Example 8
Source Project: netbeans   Source File: JExtendedSpinner.java    License: Apache License 2.0 5 votes vote down vote up
public void setModel(SpinnerModel model) {
    Font font = ((JSpinner.DefaultEditor) getEditor()).getTextField().getFont();
    String accessibleName = ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext().getAccessibleName();
    String accessibleDescription = ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext()
                                    .getAccessibleDescription();
    super.setModel(model);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().setFont(font);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext().setAccessibleName(accessibleName);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext()
     .setAccessibleDescription(accessibleDescription);
}
 
Example 9
Source Project: openjdk-jdk9   Source File: bug8008657.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void createDateSpinner() {
    Calendar calendar = Calendar.getInstance();
    Date initDate = calendar.getTime();
    calendar.add(Calendar.YEAR, -1);
    Date earliestDate = calendar.getTime();
    calendar.add(Calendar.YEAR, 1);
    Date latestDate = calendar.getTime();
    SpinnerModel dateModel = new SpinnerDateModel(initDate,
            earliestDate,
            latestDate,
            Calendar.YEAR);
    spinner = new JSpinner();
    spinner.setModel(dateModel);
}
 
Example 10
Source Project: openjdk-jdk9   Source File: bug8008657.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void createNumberSpinner() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.YEAR, -1);
    calendar.add(Calendar.YEAR, 1);
    int currentYear = calendar.get(Calendar.YEAR);
    SpinnerModel yearModel = new SpinnerNumberModel(currentYear, //initial value
            currentYear - 1, //min
            currentYear + 2, //max
            1);                //step
    spinner = new JSpinner();
    spinner.setModel(yearModel);
}
 
Example 11
/**
 * Returns a minimal value. Returns null if model is not one of the
 * following: {@code javax.swing.SpinnerDateModel},
 * {@code javax.swing.SpinnerListModel},
 * {@code javax.swing.SpinnerNumberModel}. Also, returns null if the
 * model does not have a minimal value.
 *
 * @return a minimal value.
 */
public Object getMinimum() {
    SpinnerModel model = getModel();
    if (model instanceof SpinnerNumberModel) {
        return ((SpinnerNumberModel) model).getMinimum();
    } else if (model instanceof SpinnerDateModel) {
        return ((SpinnerDateModel) model).getEnd();
    } else if (model instanceof SpinnerListModel) {
        List<?> list = ((SpinnerListModel) model).getList();
        return list.get(list.size() - 1);
    } else {
        return null;
    }
}
 
Example 12
/**
 * Returns a maximal value. Returns null if model is not one of the
 * following: {@code javax.swing.SpinnerDateModel},
 * {@code javax.swing.SpinnerListModel},
 * {@code javax.swing.SpinnerNumberModel}. Also, returns null if the
 * model does not have a maximal value.
 *
 * @return a maximal value.
 */
public Object getMaximum() {
    SpinnerModel model = getModel();
    if (model instanceof SpinnerNumberModel) {
        return ((SpinnerNumberModel) model).getMaximum();
    } else if (model instanceof SpinnerDateModel) {
        return ((SpinnerDateModel) model).getEnd();
    } else if (model instanceof SpinnerListModel) {
        List<?> list = ((SpinnerListModel) model).getList();
        return list.get(list.size() - 1);
    } else {
        return null;
    }
}
 
Example 13
/**
 * Maps {@code JSpinner.setModel(SpinnerModel)} through queue
 */
public void setModel(final SpinnerModel spinnerModel) {
    runMapping(new MapVoidAction("setModel") {
        @Override
        public void map() {
            ((JSpinner) getSource()).setModel(spinnerModel);
        }
    });
}
 
Example 14
/**
 * Maps {@code JSpinner.getModel()} through queue
 */
public SpinnerModel getModel() {
    return (runMapping(new MapAction<SpinnerModel>("getModel") {
        @Override
        public SpinnerModel map() {
            return ((JSpinner) getSource()).getModel();
        }
    }));
}
 
Example 15
Source Project: audiveris   Source File: SpinnerUtil.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Assign the List model (for a list-based spinner)
 *
 * @param spinner the spinner to update
 * @param values  the model list values
 */
public static void setList (JSpinner spinner,
                            List<?> values)
{
    SpinnerModel model = spinner.getModel();

    if (model instanceof SpinnerListModel) {
        ((SpinnerListModel) model).setList(values);
    } else {
        throw new IllegalArgumentException("Spinner model is not a SpinnerListModel");
    }
}
 
Example 16
SpinData (String label,
          String tip,
          SpinnerModel model)
{
    this.label = new JLabel(label, SwingConstants.RIGHT);

    spinner = new JSpinner(model);
    SpinnerUtil.setRightAlignment(spinner);
    SpinnerUtil.setEditable(spinner, true);
    spinner.setToolTipText(tip);
}
 
Example 17
Source Project: visualvm   Source File: JExtendedSpinner.java    License: GNU General Public License v2.0 5 votes vote down vote up
public JExtendedSpinner(SpinnerModel model) {
    super(model);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().setFont(UIManager.getFont("Label.font")); // NOI18N
    ((JSpinner.DefaultEditor) getEditor()).getTextField().addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(final java.awt.event.KeyEvent e) {
                if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
                    processKeyEvent(e);
                }
            }
        });
    configureWheelListener();
}
 
Example 18
Source Project: visualvm   Source File: JExtendedSpinner.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setModel(SpinnerModel model) {
    Font font = ((JSpinner.DefaultEditor) getEditor()).getTextField().getFont();
    String accessibleName = ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext().getAccessibleName();
    String accessibleDescription = ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext()
                                    .getAccessibleDescription();
    super.setModel(model);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().setFont(font);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext().setAccessibleName(accessibleName);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext()
     .setAccessibleDescription(accessibleDescription);
}
 
Example 19
Source Project: visualvm   Source File: JExtendedSpinner.java    License: GNU General Public License v2.0 5 votes vote down vote up
public JExtendedSpinner(SpinnerModel model) {
    super(model);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().setFont(UIManager.getFont("Label.font")); // NOI18N
    ((JSpinner.DefaultEditor) getEditor()).getTextField().addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(final java.awt.event.KeyEvent e) {
                if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) {
                    processKeyEvent(e);
                }
            }
        });
    configureWheelListener();
}
 
Example 20
Source Project: visualvm   Source File: JExtendedSpinner.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setModel(SpinnerModel model) {
    Font font = ((JSpinner.DefaultEditor) getEditor()).getTextField().getFont();
    String accessibleName = ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext().getAccessibleName();
    String accessibleDescription = ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext()
                                    .getAccessibleDescription();
    super.setModel(model);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().setFont(font);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext().setAccessibleName(accessibleName);
    ((JSpinner.DefaultEditor) getEditor()).getTextField().getAccessibleContext()
     .setAccessibleDescription(accessibleDescription);
}
 
Example 21
Source Project: pumpernickel   Source File: LengthSpinner.java    License: MIT License 5 votes vote down vote up
/**
 * Sets the spinner model. If the argument is not a
 * <code>LengthSpinnerModel</code> then an
 * <code>IllegalArgumentException</code> is thrown.
 */
@Override
public void setModel(SpinnerModel c) {
	if (getModel() instanceof LengthSpinnerModel
			&& (c instanceof LengthSpinnerModel) == false)
		throw new IllegalArgumentException(
				"LengthSpinner.setModel() can only be called for LengthSpinnerModels ("
						+ c.getClass().getName() + ")");
	super.setModel(c);
}
 
Example 22
Source Project: Ardulink-2   Source File: GenericPanelBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private static SpinnerModel createModel(ConfigAttribute attribute) {
	ValidationInfo info = attribute.getValidationInfo();
	if (info instanceof NumberValidationInfo) {
		NumberValidationInfo nInfo = (NumberValidationInfo) info;
		if (wrap(attribute.getType()).equals(Integer.class)) {
			return new SpinnerNumberModel((int) nInfo.min(),
					(int) nInfo.min(), (int) nInfo.max(), 1);
		}
		return new SpinnerNumberModel(nInfo.min(), nInfo.min(),
				nInfo.max(), 1);
	}
	return new SpinnerNumberModel();
}
 
Example 23
Source Project: swingsane   Source File: ComponentController.java    License: Apache License 2.0 5 votes vote down vote up
private void updateBlackThresholdModel(SpinnerModel blackThresholdSpinnerModel) {
  JSpinner blackThresholdSpinner = components.getBlackThresholdSpinner();
  blackThresholdSpinner.setModel(blackThresholdSpinnerModel != null ? blackThresholdSpinnerModel
      : new SpinnerNumberModel(1, 1, null, 1));
  blackThresholdSpinner.setEnabled(blackThresholdSpinnerModel != null ? !(components
      .getDefaultThresholdCheckBox().isSelected()) : false);
}
 
Example 24
Source Project: EchoSim   Source File: ManualScriptPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void doNewApplication()
{
    if (mRuntime.getApp().getUtterances().size() > 0)
    {
        int numIntents = mRuntime.getApp().getUtterances().size();
        SpinnerModel sm = new SpinnerNumberModel(numIntents/2, 1, numIntents, Math.max(numIntents/10, 1));
        mNumberOfTests.setModel(sm);
    }
}
 
Example 25
/**
 *
 */
public void initSampleAliquots() {

    aliquotName_text.setDocument(
            new UnDoAbleDocument(aliquotName_text, true));
    aliquotName_text.setText("Aliquot Name");

    aliquotList = new ArrayList<>();
    if (mySample.getFractions().size() > 0) {
        for (int i = 0; i < mySample.getAliquots().size(); i++) {
            // only show aliquots with fractions because removed aliquots still exist with zero fraction
            if (((UPbReduxAliquot) mySample.getAliquots().get(i)).getAliquotFractions().size() > 0) {
                aliquotList.add(mySample.getAliquots().get(i).getAliquotName());
            }
        }
    }

    String[] aliquotArray = new String[aliquotList.size()];
    aliquotArray = aliquotList.toArray(aliquotArray);
    aliquotsList_jList.setListData(aliquotArray);
    aliquotsList_jList.addListSelectionListener(new AliquotListSelectionListener());
    if (aliquotList.size() > 1) {
        aliquotsList_jList.setSelectedIndex(1);
    } else {
        aliquotsList_jList.setSelectedIndex(0);
    }

    SpinnerModel valueDigits_spinnerModel
            = new SpinnerNumberModel(1, 1, 20, 1);
    insertFractionCount_spinner.setModel(valueDigits_spinnerModel);

}
 
Example 26
/**
     *
     */
    public void initSampleAliquots() {

        aliquotName_text.setDocument(
                new UnDoAbleDocument(aliquotName_text, true));
        aliquotName_text.setText("Aliquot Name");

        aliquotList = new ArrayList<>();
        if (mySample.getFractions().size() > 0) {
            for (int i = 0; i < mySample.getAliquots().size(); i++) {
                // only show aliquots with fractions because removed aliquots still exist with zero fraction
                if (((UPbReduxAliquot) mySample.getAliquots().get(i)).getAliquotFractions().size() > 0) {
                    aliquotList.add(mySample.getAliquots().get(i).getAliquotName());
                }
            }
        }

        String[] aliquotArray = new String[aliquotList.size()];
        aliquotArray = aliquotList.toArray(aliquotArray);
        aliquotsList_jList.setListData(aliquotArray);
//        aliquotsList_jList.setListData((String[]) aliquotList.toArray());
        aliquotsList_jList.addListSelectionListener(new AliquotListSelectionListener());
        if (aliquotList.size() > 1) {
            aliquotsList_jList.setSelectedIndex(1);
        } else {
            aliquotsList_jList.setSelectedIndex(0);
        }

        SpinnerModel valueDigits_spinnerModel
                = new SpinnerNumberModel(1, 1, 20, 1);
        insertFractionCount_spinner.setModel(valueDigits_spinnerModel);

    }
 
Example 27
Source Project: opensim-gui   Source File: AnalyzeAndForwardToolPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void StepIntervalSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_StepIntervalSpinnerStateChanged
// TODO add your handling code here:
          SpinnerModel stepModel = StepIntervalSpinner.getModel();
          int newStepInterval = (Integer) stepModel.getValue();
          //System.out.println("New step = "+newStepInterval);
         ((AnalyzeToolModel)toolModel).setAnalysisStepInterval(newStepInterval);
    
}
 
Example 28
private JPanel tracingPanel() {

		final JPanel tracingOptionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		useSnapWindow = new JCheckBox("Enable cursor [s]napping within: XY", plugin.snapCursor);
		useSnapWindow.setBorder(new EmptyBorder(0, 0, 0, 0));
		useSnapWindow.addItemListener(this);
		tracingOptionsPanel.add(useSnapWindow);

		final SpinnerModel xy_model = new SpinnerNumberModel(plugin.cursorSnapWindowXY * 2,
				SimpleNeuriteTracer.MIN_SNAP_CURSOR_WINDOW_XY, SimpleNeuriteTracer.MAX_SNAP_CURSOR_WINDOW_XY * 2, 2);
		snapWindowXYsizeSpinner = new JSpinner(xy_model);
		((DefaultEditor) snapWindowXYsizeSpinner.getEditor()).getTextField().setEditable(false);
		snapWindowXYsizeSpinner.addChangeListener(this);
		tracingOptionsPanel.add(snapWindowXYsizeSpinner);

		final JLabel z_spinner_label = leftAlignedLabel("Z", isStackAvailable());
		z_spinner_label.setBorder(new EmptyBorder(0, 2, 0, 0));
		tracingOptionsPanel.add(z_spinner_label);
		final SpinnerModel z_model = new SpinnerNumberModel(plugin.cursorSnapWindowZ * 2,
				SimpleNeuriteTracer.MIN_SNAP_CURSOR_WINDOW_Z, SimpleNeuriteTracer.MAX_SNAP_CURSOR_WINDOW_Z * 2, 2);
		snapWindowZsizeSpinner = new JSpinner(z_model);
		((DefaultEditor) snapWindowZsizeSpinner.getEditor()).getTextField().setEditable(false);
		snapWindowZsizeSpinner.addChangeListener(this);
		snapWindowZsizeSpinner.setEnabled(isStackAvailable());
		tracingOptionsPanel.add(snapWindowZsizeSpinner);
		// tracingOptionsPanel.setBorder(new EmptyBorder(0, 0, 0, 0));
		return tracingOptionsPanel;
	}
 
Example 29
public NoGroupingNumberEditor(JSpinner spinner, SpinnerModel model) {
	super(spinner);
	JFormattedTextField ftf = (JFormattedTextField) this
			.getComponent(0);
	NumberFormat fmt = NumberFormat.getIntegerInstance();
	fmt.setGroupingUsed(false);
	ftf.setFormatterFactory(new DefaultFormatterFactory(
			new NumberFormatter(fmt)));
	revalidate();
}
 
Example 30
/**
 * Assign the List model (for a list-based spinner)
 *
 * @param spinner the spinner to update
 * @param values  the model list values
 */
public static void setList (JSpinner spinner,
                            List<?> values)
{
    SpinnerModel model = spinner.getModel();

    if (model instanceof SpinnerListModel) {
        ((SpinnerListModel) model).setList(values);
    } else {
        throw new IllegalArgumentException(
                "Spinner model is not a SpinnerListModel");
    }
}