Java Code Examples for javax.swing.JSpinner#setToolTipText()

The following examples show how to use javax.swing.JSpinner#setToolTipText() . 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: GUIFrame.java    From jaamsim with Apache License 2.0 6 votes vote down vote up
private void addLineWidthSpinner(JToolBar buttonBar, Insets margin) {
	SpinnerNumberModel numberModel = new SpinnerNumberModel(1, 1, 10, 1);
	lineWidth = new JSpinner(numberModel);
	lineWidth.addChangeListener(new ChangeListener() {

		@Override
		public void stateChanged( ChangeEvent e ) {
			if (!(selectedEntity instanceof LineEntity))
				return;
			LineEntity lineEnt = (LineEntity) selectedEntity;
			int val = (int) lineWidth.getValue();
			if (val == lineEnt.getLineWidth())
				return;
			KeywordIndex kw = InputAgent.formatIntegers("LineWidth", val);
			InputAgent.storeAndExecute(new KeywordCommand((Entity)lineEnt, kw));
		}
	});

	lineWidth.setToolTipText(formatToolTip("Line Width",
			"Sets the width of the line in pixels."));

	buttonBar.add( lineWidth );
}
 
Example 2
Source File: RowEntryDialog.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Sets up time chooser with default values for the spinners. Bad defaults get
 * set to 0.
 *
 * @param hr   hour
 * @param min  minute
 * @param sec  second
 * @param msec msec
 */
private TimeChooser(final int hr, final int min, final int sec, final int msec) {
	final int hour = ((hr > 23) || (hr < 0)) ? 0 : hr;
	final int minute = ((min > 59) || (min < 0)) ? 0 : min;
	final int second = ((sec > 59) || (sec < 0)) ? 0 : sec;
	final int msecond = ((msec > 999) || (msec < 0)) ? 0 : msec;

	setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));

	h = new JSpinner(new SpinnerNumberModel(hour, 0, 23, 1));

	this.add(h);
	this.add(new JLabel(":"));

	m = new JSpinner(new SpinnerNumberModel(minute, 0, 59, 1));

	this.add(m);
	this.add(new JLabel(":"));

	s = new JSpinner(new SpinnerNumberModel(second, 0, 59, 1));

	this.add(s);
	this.add(new JLabel("."));

	ms = new JSpinner(new SpinnerNumberModel(msecond, 0, 999, 1));

	this.add(ms);
	h.setToolTipText("h");
	m.setToolTipText("m");
	s.setToolTipText("s");
	ms.setToolTipText("ms");
}
 
Example 3
Source File: LSpinner.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create an editable labeled spinner with provided
 * characteristics.
 *
 * @param label the string to be used as label text
 * @param tip   the related tool tip text
 */
public LSpinner (String label,
                 String tip)
{
    this.label = new JLabel(label, SwingConstants.RIGHT);
    spinner = new JSpinner();

    if (tip != null) {
        this.label.setToolTipText(tip);
        spinner.setToolTipText(tip);
    }
}
 
Example 4
Source File: TemplateBoard.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new {@code TemplateBoard} object.
 *
 * @param sheet           related sheet
 * @param table           the table of distances
 * @param templateService template bus
 */
public TemplateBoard (Sheet sheet,
                      DistanceTable table,
                      SelectionService templateService)
{
    super(Board.TEMPLATE, sheet.getLocationService(), eventsRead, true, false, false, false);
    this.sheet = sheet;
    this.table = table;
    this.templateService = templateService;

    // Shape spinner
    shapeSpinner = new JSpinner(
            new SpinnerListModel(new ArrayList<>(ShapeSet.getTemplateNotes(sheet))));
    shapeSpinner.addChangeListener(this);
    shapeSpinner.setName("shapeSpinner");
    shapeSpinner.setToolTipText("Selection of template shape");

    // Anchor spinner (with only relevant anchor values for templates)
    anchorSpinner = new JSpinner(
            new SpinnerListModel(
                    Arrays.asList(Anchor.LEFT_STEM, Anchor.RIGHT_STEM, Anchor.MIDDLE_LEFT)));
    anchorSpinner.addChangeListener(this);
    anchorSpinner.setName("anchorSpinner");
    anchorSpinner.setToolTipText("Selection of template anchor");

    // Eval field
    evalField.setEditable(false);
    evalField.setHorizontalAlignment(JTextField.CENTER);
    evalField.setToolTipText("Matching grade");

    defineLayout();
}
 
Example 5
Source File: ScoreParameters.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
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 6
Source File: GuiUtils.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a spinner whose value is bound to the specified settingKey.<br>
 * The spinner will be created with a {@link SpinnerNumberModel}.
 * The initial value of the spinner will be taken from the {@link Settings},
 * and a change listener will be added to the spinner to register changes at the {@link Settings}.<br>
 * Also sets a tool tip displaying the valid range.
 * 
 * @param settingKey key of the setting its value is bound to
 * @param minimum    the minimum allowed number
 * @param maximum    the maximum allowed number
 * @param stepSize   step size of the spinner
 * @return the created spinner
 */
public static JSpinner createSpinner( final String settingKey, final int minimum, final int maximum, final int stepSize ) {
	final JSpinner spinner = new JSpinner( new SpinnerNumberModel( Settings.getInt( settingKey ), minimum, maximum, stepSize ) );
	
	spinner.setToolTipText( Language.getText( "miscSettings.validRangeAndDefaultToolTip", minimum, maximum, Settings.getDefaultInt( settingKey ) ) );
	
	spinner.addChangeListener( new ChangeListener() {
		@Override
		public void stateChanged( final ChangeEvent event ) {
			Settings.set( settingKey, spinner.getValue() );
		}
	} );
	
	return spinner;
}
 
Example 7
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addSpeedMultiplier(JToolBar mainToolBar, Insets margin) {
	SpinnerNumberModel numberModel =
			new SpinnerModel(Simulation.DEFAULT_REAL_TIME_FACTOR,
			   Simulation.MIN_REAL_TIME_FACTOR, Simulation.MAX_REAL_TIME_FACTOR, 1);
	spinner = new JSpinner(numberModel);

	// show up to 6 decimal places
	JSpinner.NumberEditor numberEditor = new JSpinner.NumberEditor(spinner,"0.######");
	spinner.setEditor(numberEditor);

	// make sure spinner TextField is no wider than 9 digits
	int diff =
		((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().getPreferredSize().width -
		getPixelWidthOfString_ForFont("9", spinner.getFont()) * 9;
	Dimension dim = spinner.getPreferredSize();
	dim.width -= diff;
	spinner.setPreferredSize(dim);
	spinner.addChangeListener(new ChangeListener() {

		@Override
		public void stateChanged( ChangeEvent e ) {
			Double val = (Double)((JSpinner)e.getSource()).getValue();
			if (MathUtils.near(val, sim.getSimulation().getRealTimeFactor()))
				return;
			NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
			DecimalFormat df = (DecimalFormat)nf;
			df.applyPattern("0.######");
			KeywordIndex kw = InputAgent.formatArgs("RealTimeFactor", df.format(val));
			InputAgent.storeAndExecute(new KeywordCommand(sim.getSimulation(), kw));
			controlStartResume.requestFocusInWindow();
		}
	});

	spinner.setToolTipText(formatToolTip("Speed Multiplier (&lt and &gt keys)",
			"Target ratio of simulation time to wall clock time when Real Time mode is selected."));
	spinner.setEnabled(false);
	mainToolBar.add( spinner );
}
 
Example 8
Source File: LSpinner.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create an editable labelled spinner with provided
 * characteristics.
 *
 * @param label the string to be used as label text
 * @param tip   the related tool tip text
 */
public LSpinner (String label,
                 String tip)
{
    this.label = new JLabel(label, SwingConstants.RIGHT);
    spinner = new JSpinner();

    if (tip != null) {
        this.label.setToolTipText(tip);
        spinner.setToolTipText(tip);
    }
}
 
Example 9
Source File: ScoreParameters.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
public 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 10
Source File: AutoSavePanel.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() {

    chkUseFeature = new JCheckBox();
    chkSaveOnFocusLost = new JCheckBox();
    spnMinutes = new JSpinner();
    jLabel2 = new JLabel();

    Mnemonics.setLocalizedText(chkUseFeature, NbBundle.getMessage(AutoSavePanel.class, "AutoSavePanel.jLabel1.text")); // NOI18N
    chkUseFeature.setActionCommand(NbBundle.getMessage(AutoSavePanel.class, "AutoSavePanel.chkUseFeature.actionCommand")); // NOI18N
    chkUseFeature.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent evt) {
            chkUseFeatureItemStateChanged(evt);
        }
    });

    Mnemonics.setLocalizedText(chkSaveOnFocusLost, NbBundle.getMessage(AutoSavePanel.class,"AutoSavePanel.chkSaveOnFocusLost.text")); // NOI18N

    spnMinutes.setModel(this.spnModel);
    spnMinutes.setToolTipText(NbBundle.getMessage(AutoSavePanel.class, "AutoSavePanel.spnMinutes.toolTipText")); // NOI18N

    Mnemonics.setLocalizedText(jLabel2, NbBundle.getMessage(AutoSavePanel.class, "AutoSavePanel.jLabel2.text")); // NOI18N

    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(Alignment.LEADING)
                .addComponent(chkSaveOnFocusLost)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(chkUseFeature)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(spnMinutes, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(jLabel2)))
            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                .addComponent(chkUseFeature)
                .addComponent(spnMinutes, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addComponent(chkSaveOnFocusLost)
            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
}
 
Example 11
Source File: BayMunitionsChoicePanel.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
AmmoRowPanel(Mounted bay, int at, int rackSize, List<Mounted> ammoMounts) {
    this.bay = bay;
    this.at = at;
    this.rackSize = rackSize;
    this.ammoMounts = new ArrayList<>(ammoMounts);
    this.spinners = new ArrayList<>();
    Dimension spinnerSize =new Dimension(55, 25);
    
    final Optional<WeaponType> wtype = bay.getBayWeapons().stream()
            .map(wNum -> entity.getEquipment(wNum))
            .map(m -> (WeaponType) m.getType()).findAny();
    
    // set the bay's tech base to that of any weapon in the bay
    // an assumption is made here that bays don't mix clan-only and IS-only tech base
    this.techBase = wtype.isPresent() ? wtype.get().getTechBase() : WeaponType.TECH_BASE_ALL;
    
    munitions = AmmoType.getMunitionsFor(at).stream()
            .filter(this::includeMunition).collect(Collectors.toList());
    tonnage = ammoMounts.stream().mapToDouble(m -> m.getAmmoCapacity()).sum();
    Map<String,Integer> starting = new HashMap<>();
    ammoMounts.forEach(m -> starting.merge(m.getType().getInternalName(), m.getBaseShotsLeft(), Integer::sum));
    for (AmmoType atype : munitions) {
        JSpinner spn = new JSpinner(new SpinnerNumberModel(starting.getOrDefault(atype.getInternalName(), 0),
                0, null, 1));
        spn.setPreferredSize(spinnerSize);
        spn.setName(atype.getInternalName());
        spn.addChangeListener(this);
        if (atype.getTonnage(entity) > 1) {
            spn.setToolTipText(String.format(Messages.getString("CustomMechDialog.formatMissileTonnage"),
                    atype.getName(), atype.getTonnage(entity)));
        } else {
            spn.setToolTipText(String.format(Messages.getString("CustomMechDialog.formatShotsPerTon"),
                    atype.getName(), atype.getShots()));
        }
        spinners.add(spn);
    }
    
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(0, 5, 0, 5);
    gbc.gridwidth = 5;
    add(new JLabel("(" + entity.getLocationAbbr(bay.getLocation()) + ") "
            + (wtype.isPresent()? wtype.get().getName() : "?")), gbc);
    gbc.gridx = 5;
    gbc.gridwidth = 1;
    gbc.weightx = 1.0;
    add(lblTonnage, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth = 1;
    gbc.weightx = 0.0;
    for (int i = 0; i < munitions.size(); i++) {
        add(new JLabel(createMunitionLabel(munitions.get(i))), gbc);
        gbc.gridx++;
        add(spinners.get(i), gbc);
        gbc.gridx++;
        if (gbc.gridx > 5) {
            gbc.gridx = 0;
            gbc.gridy++;
        }
    }
    recalcMaxValues();
}
 
Example 12
Source File: EditTeamService.java    From Shuffle-Move with GNU General Public License v3.0 4 votes vote down vote up
private Component makeUpperPanel() {
   JPanel ret = new JPanel(new GridBagLayout());
   GridBagConstraints c = new GridBagConstraints();
   c.fill = GridBagConstraints.HORIZONTAL;
   c.weightx = 1.0;
   c.weighty = 0.0;
   c.gridx = 1;
   c.gridy = 1;
   c.gridwidth = 1;
   c.gridheight = 1;
   
   c.gridx += 1;
   c.weightx = 0.0;
   JPanel typePanel = new JPanel();
   typePanel.add(new JLabel(getString(KEY_TYPE)));
   typeChooser = new TypeChooser(true);
   typePanel.add(typeChooser);
   typePanel.setToolTipText(getString(KEY_TYPE_TOOLTIP));
   typeChooser.setToolTipText(getString(KEY_TYPE_TOOLTIP));
   ret.add(typePanel, c);
   
   c.gridx += 1;
   c.weightx = 0.0;
   JPanel levelPanel = new JPanel();
   levelPanel.add(new JLabel(getString(KEY_LEVEL)));
   SpinnerNumberModel snm = new SpinnerNumberModel(0, 0, Species.MAX_LEVEL, 1);
   levelSpinner = new JSpinner(snm);
   levelPanel.add(levelSpinner);
   levelPanel.setToolTipText(getString(KEY_LEVEL_TOOLTIP));
   levelSpinner.setToolTipText(getString(KEY_LEVEL_TOOLTIP));
   ret.add(levelPanel, c);
   
   c.gridx += 1;
   c.weightx = 1.0;
   JPanel stringPanel = new JPanel(new GridBagLayout());
   GridBagConstraints sc = new GridBagConstraints();
   sc.fill = GridBagConstraints.HORIZONTAL;
   sc.gridx = 1;
   stringPanel.add(new JLabel(getString(KEY_NAME)), sc);
   textField = new JTextField();
   sc.gridx += 1;
   sc.weightx = 1.0;
   sc.insets = new Insets(0, 5, 0, 5);
   stringPanel.add(textField, sc);
   stringPanel.setToolTipText(getString(KEY_NAME_TOOLTIP));
   textField.setToolTipText(getString(KEY_NAME_TOOLTIP));
   ret.add(stringPanel, c);
   
   c.gridx += 1;
   c.weightx = 0.0;
   megaFilter = new JCheckBox(getString(KEY_MEGA_FILTER));
   megaFilter.setToolTipText(getString(KEY_MEGA_FILTER_TOOLTIP));;
   ret.add(megaFilter, c);
   
   c.gridx += 1;
   c.weightx = 0.0;
   effectFilter = new EffectChooser(false, EffectChooser.DefaultEntry.NO_FILTER);
   effectFilter.setToolTipText(getString(KEY_EFFECT_FILTER_TOOLTIP));
   ret.add(effectFilter, c);
   
   c.gridx += 1;
   c.weightx = 0.0;
   @SuppressWarnings("serial")
   JButton copyToLauncher = new JButton(new AbstractAction(getString(KEY_MAKE_DEFAULT)) {
      @Override
      public void actionPerformed(ActionEvent e) {
         makeTeamDefault();
      }
   });
   copyToLauncher.setToolTipText(getString(KEY_MAKE_DEFAULT_TOOLTIP));
   ret.add(copyToLauncher, c);
   
   getMinUpperPanel = new Supplier<Dimension>() {
      
      @Override
      public Dimension get() {
         Dimension ret = new Dimension(10 + 50, 0);
         for (Component c : new Component[] { typePanel, levelPanel, stringPanel, megaFilter, effectFilter,
               copyToLauncher }) {
            Dimension temp = c.getPreferredSize();
            int width = temp.width + ret.width;
            int height = Math.max(temp.height, ret.height);
            ret.setSize(width, height);
         }
         return ret;
      }
   };
   
   return ret;
}
 
Example 13
Source File: EditRosterService.java    From Shuffle-Move with GNU General Public License v3.0 4 votes vote down vote up
private Component makeUpperPanel() {
   JPanel ret = new JPanel(new GridBagLayout());
   GridBagConstraints c = new GridBagConstraints();
   c.fill = GridBagConstraints.HORIZONTAL;
   c.weightx = 1.0;
   c.weighty = 0.0;
   c.gridx = 1;
   c.gridy = 1;
   c.gridwidth = 1;
   c.gridheight = 1;
   
   c.gridx += 1;
   c.weightx = 0.0;
   JPanel typePanel = new JPanel();
   typePanel.add(new JLabel(getString(KEY_TYPE)));
   typeChooser = new TypeChooser(true);
   typePanel.add(typeChooser);
   typePanel.setToolTipText(getString(KEY_TYPE_TOOLTIP));
   typeChooser.setToolTipText(getString(KEY_TYPE_TOOLTIP));
   ret.add(typePanel, c);
   
   c.gridx += 1;
   c.weightx = 0.0;
   JPanel levelPanel = new JPanel();
   levelPanel.add(new JLabel(getString(KEY_LEVEL)));
   SpinnerNumberModel snm = new SpinnerNumberModel(0, 0, Species.MAX_LEVEL, 1);
   levelSpinner = new JSpinner(snm);
   levelPanel.add(levelSpinner);
   levelPanel.setToolTipText(getString(KEY_LEVEL_TOOLTIP));
   levelSpinner.setToolTipText(getString(KEY_LEVEL_TOOLTIP));
   JButton applyAllButton = new JButton(getString(KEY_SET_FOR_ALL));
   applyAllButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
         applyLevelToAll();
      }
   });
   applyAllButton.setToolTipText(getString(KEY_SET_FOR_ALL_TOOLTIP));
   levelPanel.add(applyAllButton);
   ret.add(levelPanel, c);
   
   c.gridx += 1;
   c.weightx = 1.0;
   JPanel stringPanel = new JPanel(new GridBagLayout());
   GridBagConstraints sc = new GridBagConstraints();
   sc.fill = GridBagConstraints.HORIZONTAL;
   sc.gridx = 1;
   stringPanel.add(new JLabel(getString(KEY_NAME)), sc);
   textField = new JTextField();
   sc.gridx += 1;
   sc.weightx = 1.0;
   sc.insets = new Insets(0, 5, 0, 5);
   stringPanel.add(textField, sc);
   stringPanel.setToolTipText(getString(KEY_NAME_TOOLTIP));
   textField.setToolTipText(getString(KEY_NAME_TOOLTIP));
   ret.add(stringPanel, c);
   
   c.gridx += 1;
   c.weightx = 0.0;
   megaFilter = new JCheckBox(getString(KEY_MEGA_FILTER));
   megaFilter.setToolTipText(getString(KEY_MEGA_FILTER_TOOLTIP));
   ret.add(megaFilter, c);
   
   c.gridx += 1;
   c.weightx = 0.0;
   effectFilter = new EffectChooser(false, EffectChooser.DefaultEntry.NO_FILTER);
   effectFilter.setToolTipText(getString(KEY_EFFECT_FILTER_TOOLTIP));
   ret.add(effectFilter, c);
   
   getMinUpperPanel = new Supplier<Dimension>() {
      
      @Override
      public Dimension get() {
         Dimension ret = new Dimension(10 + 50, 0);
         for (Component c : new Component[] { typePanel, levelPanel, stringPanel, megaFilter, effectFilter }) {
            Dimension temp = c.getPreferredSize();
            int width = temp.width + ret.width;
            int height = Math.max(temp.height, ret.height);
            ret.setSize(width, height);
         }
         return ret;
      }
   };
   
   return ret;
}
 
Example 14
Source File: StatisticsPanel.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
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
        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;
}
 
Example 15
Source File: PreferencesDialog.java    From gpx-animator with Apache License 2.0 4 votes vote down vote up
public PreferencesDialog(final JFrame owner) {
    super(owner, true);

    final ResourceBundle resourceBundle = Preferences.getResourceBundle();

    setTitle(resourceBundle.getString("ui.dialog.preferences.title"));
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    final FileSelector tileCachePathSelector = new FileSelector(DIRECTORIES_ONLY) {
        private static final long serialVersionUID = 7372002778979993241L;
        @Override
        protected Type configure(final JFileChooser outputFileChooser) {
            return Type.OPEN;
        }
    };
    tileCachePathSelector.setToolTipText(resourceBundle.getString("ui.dialog.preferences.cachepath.tooltip"));

    final JSpinner tileCacheTimeLimitSpinner = new JSpinner();
    tileCacheTimeLimitSpinner.setToolTipText(resourceBundle.getString("ui.dialog.preferences.cachetimelimit.tooltip"));
    tileCacheTimeLimitSpinner.setModel(new DurationSpinnerModel());
    tileCacheTimeLimitSpinner.setEditor(new DurationEditor(tileCacheTimeLimitSpinner));

    final JPanel trackColorPanel = new JPanel(new BorderLayout());
    final JCheckBox trackColorRandom = new JCheckBox(resourceBundle.getString("ui.dialog.preferences.track.color.random"));
    final ColorSelector trackColorSelector = new ColorSelector();
    trackColorRandom.setSelected(Preferences.getTrackColorRandom());
    trackColorSelector.setColor(Preferences.getTrackColorDefault());
    trackColorSelector.setEnabled(!Preferences.getTrackColorRandom());
    trackColorRandom.addActionListener((event) -> trackColorSelector.setEnabled(!trackColorRandom.isSelected()));
    trackColorPanel.add(trackColorRandom, BorderLayout.LINE_START);
    trackColorPanel.add(trackColorSelector, BorderLayout.CENTER);


    final JButton cancelButton = new JButton(resourceBundle.getString("ui.dialog.preferences.button.cancel"));
    cancelButton.addActionListener(e -> SwingUtilities.invokeLater(() -> {
        setVisible(false);
        dispose();
    }));

    final JButton saveButton = new JButton(resourceBundle.getString("ui.dialog.preferences.button.save"));
    saveButton.addActionListener(e -> SwingUtilities.invokeLater(() -> {
        Preferences.setTileCacheDir(tileCachePathSelector.getFilename());
        Preferences.setTileCacheTimeLimit((Long) tileCacheTimeLimitSpinner.getValue());
        Preferences.setTrackColorRandom(trackColorRandom.isSelected());
        Preferences.setTrackColorDefault(trackColorSelector.getColor());
        setVisible(false);
        dispose();
    }));

    setContentPane(FormBuilder.create()
            .padding(new EmptyBorder(20, 20, 20, 20))
            .columns("right:p, 5dlu, fill:[200dlu, pref]") //NON-NLS
            .rows("p, 5dlu, p, 5dlu, p, 5dlu, p, 5dlu, p, 5dlu, p, 10dlu, p") //NON-NLS

            .addSeparator(resourceBundle.getString("ui.dialog.preferences.cache.separator")).xyw(1, 1, 3)
            .add(resourceBundle.getString("ui.dialog.preferences.cachepath.label")).xy(1, 3)
            .add(tileCachePathSelector).xy(3, 3)
            .add(resourceBundle.getString("ui.dialog.preferences.cachetimelimit.label")).xy(1, 5)
            .add(tileCacheTimeLimitSpinner).xy(3, 5)

            .addSeparator(resourceBundle.getString("ui.dialog.preferences.track")).xyw(1, 7, 3)
            .add(resourceBundle.getString("ui.dialog.preferences.track.color")).xy(1, 9)
            .add(trackColorPanel).xy(3, 9)

            .addSeparator("").xyw(1, 11, 3)
            .addBar(cancelButton, saveButton).xyw(1, 13, 3, CellConstraints.RIGHT, CellConstraints.FILL)
            .build());

    tileCachePathSelector.setFilename(Preferences.getTileCacheDir());
    tileCacheTimeLimitSpinner.setValue(Preferences.getTileCacheTimeLimit());

    pack();
    setLocationRelativeTo(owner);
}