javax.swing.JSpinner.NumberEditor Java Examples

The following examples show how to use javax.swing.JSpinner.NumberEditor. 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 File: DoubleRangeConstraintEditor.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private boolean hasValidValue(JSpinner spinner) {
	NumberEditor numEditor = (NumberEditor) spinner.getEditor();
	JFormattedTextField textField = numEditor.getTextField();
	AbstractFormatter formatter = textField.getFormatter();
	String text = textField.getText();
	try {
		String roundTrip = formatter.valueToString(formatter.stringToValue(text));

		Double textDouble = Double.valueOf(text);
		Double roundTripDouble = Double.valueOf(roundTrip);

		return Double.compare(textDouble, roundTripDouble) == 0;
	}
	catch (ParseException e) {
		return false;
	}
	catch (NumberFormatException nfe) {
		return false;
	}
}
 
Example #2
Source File: DoubleValueConstraintEditor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean checkEditorValue() {
	NumberEditor numEditor = (NumberEditor) spinner.getEditor();
	JFormattedTextField textField = numEditor.getTextField();
	AbstractFormatter formatter = textField.getFormatter();

	// to test if the textfield has a valid value, we try and parse it.  There are two ways
	// in which it is invalid - it can't be parsed or when parsed it doesn't match the spinner
	// value.
	String text = textField.getText();
	try {
		Double valueFromTextField = (Double) formatter.stringToValue(text);
		Double spinnerValue = (Double) spinner.getValue();

		// to compare the two values, convert them back to formatted strings to avoid rounding issues
		String valueFromField = formatter.valueToString(valueFromTextField);
		String valueFromSpinner = formatter.valueToString(spinnerValue);

		if (valueFromField.equals(valueFromSpinner)) {
			errorMessage = "";
			return true;
		}
	}
	catch (ParseException e) {
		// Do nothing
	}
	errorMessage = "Invalid Value!";
	return false;
}
 
Example #3
Source File: DoubleValueConstraintEditorTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	constraint = findFloatConstraint();
	editor = (DoubleValueConstraintEditor) constraint.getEditor(null);
	forceBuildOfGuiComponents();
	spinner = editor.getSpinner();
	NumberEditor numEditor = (NumberEditor) spinner.getEditor();
	textField = numEditor.getTextField();

	assertNotNull("Unable to locate JTextField component", textField);
}
 
Example #4
Source File: FloatRangeConstraintEditorTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private JTextField findEditorForSpinner(Container container, String spinnerName) {
	Component comp = findComponentByName(container, spinnerName);
	if (comp != null) {
		JSpinner lowerSpinner = (JSpinner) comp;
		NumberEditor numberEditor = (NumberEditor) lowerSpinner.getEditor();
		return numberEditor.getTextField();
	}
	return null;
}
 
Example #5
Source File: FloatValueConstraintEditorTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private JTextField findEditorForSpinner(Container container, String spinnerName) {
	Component comp = findComponentByName(container, spinnerName);
	if (comp != null) {
		JSpinner lowerSpinner = (JSpinner) comp;
		NumberEditor numberEditor = (NumberEditor) lowerSpinner.getEditor();
		return numberEditor.getTextField();
	}
	return null;
}
 
Example #6
Source File: CustomizerDeployment.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new form CustomizerDeployment */
public CustomizerDeployment(CustomizerDataSupport custData) {
    this.custData = custData;
    initComponents();
    ((NumberEditor) deploymentTimeoutSpinner.getEditor()).getTextField().setColumns(5);
    // working around the issue #111094
    Mnemonics.setLocalizedText(driverDeploymentjCheckBox, NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.driverDeploymentjCheckBox.text"));
}
 
Example #7
Source File: BrushOptions.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates new form BrushOptions
 */
public BrushOptions() {
    initComponents();
    
    // Eliminate thousands separators to make spinners smaller:
    spinnerAbove.setEditor(new NumberEditor(spinnerAbove, "0"));
    spinnerBelow.setEditor(new NumberEditor(spinnerBelow, "0"));
}
 
Example #8
Source File: AddLayerDialog.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates new form AddLayerDialog
 */
public AddLayerDialog(Window parent, List<Layer> allLayers) {
    super(parent);
    this.allLayers = allLayers;
    
    initComponents();
    
    spinnerFactor.setEditor(new NumberEditor(spinnerFactor, "0"));
    
    rootPane.setDefaultButton(buttonOK);
    scaleToUI();
    pack();
    setLocationRelativeTo(parent);
}
 
Example #9
Source File: DoubleRangeConstraintEditor.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private static void markSpinnerAsValid(JSpinner spinner, boolean valid) {
	NumberEditor numEditor = (NumberEditor) spinner.getEditor();
	JFormattedTextField textField = numEditor.getTextField();

	textField.setBackground(valid ? VALID_INPUT_COLOR : INVALID_INPUT_COLOR);
}
 
Example #10
Source File: CustomizerDeployment.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    driverDeploymentjCheckBox = new javax.swing.JCheckBox();
    deploymentTimeoutSpinner = new javax.swing.JSpinner();
    deplolymentTimeoutLabel = new javax.swing.JLabel();

    driverDeploymentjCheckBox.setModel(custData.getDriverDeploymentModel());
    org.openide.awt.Mnemonics.setLocalizedText(driverDeploymentjCheckBox, org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.driverDeploymentjCheckBox.text")); // NOI18N
    driverDeploymentjCheckBox.setToolTipText(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.driverDeploymentjCheckBox.toolTipText")); // NOI18N
    driverDeploymentjCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    driverDeploymentjCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));

    deploymentTimeoutSpinner.setModel(custData.getDeploymentTimeoutModel());
    deploymentTimeoutSpinner.setToolTipText(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.deplolymentTimeoutSpinner.tooltip")); // NOI18N
    deploymentTimeoutSpinner.setEditor(new NumberEditor(deploymentTimeoutSpinner, "#"));

    deplolymentTimeoutLabel.setLabelFor(deploymentTimeoutSpinner);
    org.openide.awt.Mnemonics.setLocalizedText(deplolymentTimeoutLabel, org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.deplolymentTimeoutLabel.text")); // NOI18N
    deplolymentTimeoutLabel.setToolTipText(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.deplolymentTimeoutLabel.tooltip")); // NOI18N

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(deplolymentTimeoutLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(deploymentTimeoutSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addComponent(driverDeploymentjCheckBox))
            .addContainerGap(176, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(deplolymentTimeoutLabel)
                .addComponent(deploymentTimeoutSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(driverDeploymentjCheckBox)
            .addContainerGap(241, Short.MAX_VALUE))
    );

    driverDeploymentjCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.driverDeploymentjCheckBox.accessible.name")); // NOI18N
    driverDeploymentjCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.driverDeploymentjCheckBox.accessible.description")); // NOI18N
    deploymentTimeoutSpinner.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.deplolymentTimeoutSpinner.accessible.name")); // NOI18N
    deploymentTimeoutSpinner.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.deplolymentTimeoutSpinner.accessible.description")); // NOI18N
    deplolymentTimeoutLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.deplolymentTimeoutLabel.accessible.name")); // NOI18N
    deplolymentTimeoutLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerDeployment.class, "CustomizerDeployment.deplolymentTimeoutLabel.accessible.description")); // NOI18N
}
 
Example #11
Source File: DimensionPropertiesEditor.java    From WorldPainter with GNU General Public License v3.0 4 votes vote down vote up
/** Creates new form DimensionPropertiesEditor */
public DimensionPropertiesEditor() {
    initComponents();

    if ((Configuration.getInstance() != null) && Configuration.getInstance().isEasyMode()) {
        jLabel4.setVisible(false);
        radioButtonNoBorder.setVisible(false);
        radioButtonVoidBorder.setVisible(false);
        radioButtonWaterBorder.setVisible(false);
        jLabel5.setVisible(false);
        spinnerBorderLevel.setVisible(false);
        jLabel44.setVisible(false);
        radioButtonLavaBorder.setVisible(false);
        jLabel8.setVisible(false);
        spinnerBorderSize.setVisible(false);
        jLabel9.setVisible(false);
        checkBoxBedrockWall.setVisible(false);
        jLabel7.setVisible(false);
        spinnerMinecraftSeed.setVisible(false);

        checkBoxPopulate.setVisible(false);
        jLabel47.setVisible(false);
    }

    spinnerQuartzChance.setEditor(new NumberEditor(spinnerQuartzChance, "0"));
    spinnerGoldChance.setEditor(new NumberEditor(spinnerGoldChance, "0"));
    spinnerGoldMaxLevel.setEditor(new NumberEditor(spinnerGoldMaxLevel, "0"));
    spinnerIronChance.setEditor(new NumberEditor(spinnerIronChance, "0"));
    spinnerIronMaxLevel.setEditor(new NumberEditor(spinnerIronMaxLevel, "0"));
    spinnerCoalChance.setEditor(new NumberEditor(spinnerCoalChance, "0"));
    spinnerCoalMaxLevel.setEditor(new NumberEditor(spinnerCoalMaxLevel, "0"));
    spinnerLapisChance.setEditor(new NumberEditor(spinnerLapisChance, "0"));
    spinnerLapisMaxLevel.setEditor(new NumberEditor(spinnerLapisMaxLevel, "0"));
    spinnerDiamondChance.setEditor(new NumberEditor(spinnerDiamondChance, "0"));
    spinnerDiamondMaxLevel.setEditor(new NumberEditor(spinnerDiamondMaxLevel, "0"));
    spinnerRedstoneChance.setEditor(new NumberEditor(spinnerRedstoneChance, "0"));
    spinnerRedstoneMaxLevel.setEditor(new NumberEditor(spinnerRedstoneMaxLevel, "0"));
    spinnerWaterChance.setEditor(new NumberEditor(spinnerWaterChance, "0"));
    spinnerWaterMaxLevel.setEditor(new NumberEditor(spinnerWaterMaxLevel, "0"));
    spinnerLavaChance.setEditor(new NumberEditor(spinnerLavaChance, "0"));
    spinnerDirtChance.setEditor(new NumberEditor(spinnerDirtChance, "0"));
    spinnerLavaMaxLevel.setEditor(new NumberEditor(spinnerLavaMaxLevel, "0"));
    spinnerDirtMaxLevel.setEditor(new NumberEditor(spinnerDirtMaxLevel, "0"));
    spinnerGravelChance.setEditor(new NumberEditor(spinnerGravelChance, "0"));
    spinnerGravelMaxLevel.setEditor(new NumberEditor(spinnerGravelMaxLevel, "0"));
    spinnerEmeraldChance.setEditor(new NumberEditor(spinnerEmeraldChance, "0"));
    spinnerEmeraldMaxLevel.setEditor(new NumberEditor(spinnerEmeraldMaxLevel, "0"));
    spinnerGoldMinLevel.setEditor(new NumberEditor(spinnerGoldMinLevel, "0"));
    spinnerIronMinLevel.setEditor(new NumberEditor(spinnerIronMinLevel, "0"));
    spinnerCoalMinLevel.setEditor(new NumberEditor(spinnerCoalMinLevel, "0"));
    spinnerLapisMinLevel.setEditor(new NumberEditor(spinnerLapisMinLevel, "0"));
    spinnerDiamondMinLevel.setEditor(new NumberEditor(spinnerDiamondMinLevel, "0"));
    spinnerEmeraldMinLevel.setEditor(new NumberEditor(spinnerEmeraldMinLevel, "0"));
    spinnerWaterMinLevel.setEditor(new NumberEditor(spinnerWaterMinLevel, "0"));
    spinnerLavaMinLevel.setEditor(new NumberEditor(spinnerLavaMinLevel, "0"));
    spinnerDirtMinLevel.setEditor(new NumberEditor(spinnerDirtMinLevel, "0"));
    spinnerGravelMinLevel.setEditor(new NumberEditor(spinnerGravelMinLevel, "0"));
    spinnerRedstoneMinLevel.setEditor(new NumberEditor(spinnerRedstoneMinLevel, "0"));
    spinnerQuartzMinLevel.setEditor(new NumberEditor(spinnerQuartzMinLevel, "0"));
    spinnerQuartzMaxLevel.setEditor(new NumberEditor(spinnerQuartzMaxLevel, "0"));
    spinnerCavernsMinLevel.setEditor(new NumberEditor(spinnerCavernsMinLevel, "0"));
    spinnerCavernsMaxLevel.setEditor(new NumberEditor(spinnerCavernsMaxLevel, "0"));
    spinnerChasmsMinLevel.setEditor(new NumberEditor(spinnerChasmsMinLevel, "0"));
    spinnerChasmsMaxLevel.setEditor(new NumberEditor(spinnerChasmsMaxLevel, "0"));
    
    addListeners(spinnerGoldMinLevel,  spinnerGoldMaxLevel);
    addListeners(spinnerIronMinLevel,  spinnerIronMaxLevel);
    addListeners(spinnerCoalMinLevel,  spinnerCoalMaxLevel);
    addListeners(spinnerLapisMinLevel,  spinnerLapisMaxLevel);
    addListeners(spinnerDiamondMinLevel, spinnerDiamondMaxLevel);
    addListeners(spinnerEmeraldMinLevel, spinnerEmeraldMaxLevel);
    addListeners(spinnerWaterMinLevel, spinnerWaterMaxLevel);
    addListeners(spinnerLavaMinLevel, spinnerLavaMaxLevel);
    addListeners(spinnerDirtMinLevel, spinnerDirtMaxLevel);
    addListeners(spinnerGravelMinLevel, spinnerGravelMaxLevel);
    addListeners(spinnerRedstoneMinLevel, spinnerRedstoneMaxLevel);
    addListeners(spinnerQuartzMinLevel, spinnerQuartzMaxLevel);
    addListeners(spinnerCavernsMinLevel, spinnerCavernsMaxLevel);
    addListeners(spinnerChasmsMinLevel, spinnerChasmsMaxLevel);

    tableCustomLayers.setDefaultRenderer(CustomLayer.class, new CustomLayersTableCellRenderer());
    tableCustomLayers.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> setControlStates());

    scaleToUI(this);
}
 
Example #12
Source File: ImportHeightMapDialog.java    From WorldPainter with GNU General Public License v3.0 4 votes vote down vote up
public ImportHeightMapDialog(Window parent, Dimension currentDimension, ColourScheme colourScheme, boolean contourLines, int contourSeparation, TileRenderer.LightOrigin lightOrigin) {
    super(parent);
    this.currentDimension = currentDimension;
    this.colourScheme = colourScheme;
    this.contourLines = contourLines;
    this.contourSeparation = contourSeparation;
    this.lightOrigin = lightOrigin;

    initComponents();
    tiledImageViewer2.setZoom(0);
    tiledImageViewerContainer1.setView(tiledImageViewer2);
    
    themeEditor.setColourScheme(colourScheme);
    spinnerOffsetX.setEditor(new NumberEditor(spinnerOffsetX, "0"));
    spinnerOffsetY.setEditor(new NumberEditor(spinnerOffsetY, "0"));
    checkBoxCreateTiles.setSelected(true);
    labelWarning.setVisible(false);
    comboBoxPlatform.setModel(new DefaultComboBoxModel<>(PlatformManager.getInstance().getAllPlatforms().toArray(new Platform[0])));

    fieldFilename.getDocument().addDocumentListener(this);
    
    rootPane.setDefaultButton(buttonOk);
    
    if (currentDimension != null) {
        jTabbedPane1.setEnabledAt(1, false);
        comboBoxPlatform.setSelectedItem(currentDimension.getWorld().getPlatform());
        comboBoxPlatform.setEnabled(false);
        comboBoxHeight.setSelectedItem(currentDimension.getMaxHeight());
        comboBoxHeight.setEnabled(false);
        buttonResetDefaults.setEnabled(false);
        spinnerWorldMiddle.setValue(((HeightMapTileFactory) currentDimension.getTileFactory()).getTheme().clone().getWaterHeight());
        buttonLoadDefaults.setEnabled(true);
        buttonSaveAsDefaults.setEnabled(true);
    } else {
        themeEditor.setTheme((SimpleTheme) TileFactoryFactory.createNoiseTileFactory(new Random().nextLong(), Terrain.GRASS, DEFAULT_MAX_HEIGHT_ANVIL, 58, 62, false, true, 20, 1.0).getTheme());
        themeEditor.setChangeListener(this);
        comboBoxPlatform.setSelectedItem(JAVA_ANVIL);
        labelNoUndo.setText(" ");
        checkBoxCreateTiles.setEnabled(false);
        checkBoxOnlyRaise.setEnabled(false);
        loadDefaults();
    }

    scaleToUI();
    pack();
    setDefaultSizeAndLocation(this, 60);

    setControlStates();
    initialising = false;
}