List of usage examples for javax.swing JSpinner setToolTipText
@BeanProperty(bound = false, preferred = true, description = "The text to display in a tool tip.") public void setToolTipText(String text)
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 ww . 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); }
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/*from w ww . jav a 2 s .com*/ 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:org.n52.ifgicopter.spf.input.FakeInputPlugin.java
/** * /* w ww .j av a 2 s . c om*/ * @return */ private JPanel makeControlPanel() { if (this.controlPanel == null) { this.controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); JButton startButton = new JButton("Start"); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { start(); } }); } }); this.controlPanel.add(startButton); JButton stopButton = new JButton("Stop"); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { stop(); } }); } }); this.controlPanel.add(stopButton); JLabel sleepTimeLabel = new JLabel("Time between points in seconds:"); this.controlPanel.add(sleepTimeLabel); double spinnerMin = 0.1d; double spinnerMax = 10000.0d; SpinnerModel model = new SpinnerNumberModel(DEFAULT_INTERVAL_MILLIS / SECONDS_TO_MILLISECONDS, spinnerMin, spinnerMax, 0.1d); JSpinner sleepTimeSpinner = new JSpinner(model); sleepTimeSpinner.setToolTipText("Select time using controls or manual input within the range of " + spinnerMin + " to " + spinnerMax + "."); sleepTimeSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Object source = e.getSource(); if (source instanceof JSpinner) { final JSpinner spinner = (JSpinner) source; EventQueue.invokeLater(new Runnable() { @Override public void run() { Double value = (Double) spinner.getValue(); value = Double.valueOf(value.doubleValue() * SECONDS_TO_MILLISECONDS); FakeInputPlugin.this.sleepTimeMillis = value.longValue(); } }); } else log.warn("Unsupported ChangeEvent, need JSpinner as source: " + e); } }); // catch text change events without loosing the focus // JSpinner.DefaultEditor editor = (DefaultEditor) sleepTimeSpinner.getEditor(); // not implemented, can be done using KeyEvent, but then it hast to be checked where in the text // field the keystroke was etc. --> too complicated. this.controlPanel.add(sleepTimeSpinner); } return this.controlPanel; }
From source file:org.n52.ifgicopter.spf.input.GpxInputPlugin.java
/** * @return// w ww . jav a 2 s . c om * */ private JPanel makeControlPanel() { if (this.controlPanel == null) { this.controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); JButton startButton = new JButton("Start"); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { start(); } }); } }); this.controlPanel.add(startButton); JButton stopButton = new JButton("Stop"); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { stop(); } }); } }); this.controlPanel.add(stopButton); JButton selectFileButton = new JButton("Select GPX File"); selectFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectGpxFileAction(); } }); this.controlPanel.add(selectFileButton); JLabel sleepTimeLabel = new JLabel("Time between points in seconds:"); this.controlPanel.add(sleepTimeLabel); double spinnerMin = 0.5d; double spinnerMax = 10000.0d; SpinnerModel model = new SpinnerNumberModel(2.0d, spinnerMin, spinnerMax, 0.1d); JSpinner sleepTimeSpinner = new JSpinner(model); sleepTimeSpinner.setToolTipText("Select time using controls or manual input within the range of " + spinnerMin + " to " + spinnerMax + "."); sleepTimeSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Object source = e.getSource(); if (source instanceof JSpinner) { final JSpinner spinner = (JSpinner) source; EventQueue.invokeLater(new Runnable() { @Override public void run() { Double value = (Double) spinner.getValue(); value = Double.valueOf(value.doubleValue() * SECONDS_TO_MILLISECONDS); setSleepTimeMillis(value.longValue()); } }); } else getLog().warn("Unsupported ChangeEvent, need JSpinner as source: " + e); } }); // catch text change events without loosing the focus // JSpinner.DefaultEditor editor = (DefaultEditor) sleepTimeSpinner.getEditor(); // not implemented, can be done using KeyEvent, but then it hast to be checked where in the text // field the keystroke was etc. --> too complicated. this.controlPanel.add(sleepTimeSpinner); } return this.controlPanel; }
From source file:org.n52.ifgicopter.spf.input.HistoryPostgisInputPlugin.java
/** * @return/*from w w w. j a v a2s. c o m*/ * */ @Override protected JPanel makeControlPanel() { if (this.controlPanel == null) { this.controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); JButton startButton = new JButton("Start"); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { start(); } }); } }); this.controlPanel.add(startButton); JButton stopButton = new JButton("Stop"); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { stop(); } }); } }); this.controlPanel.add(stopButton); JLabel sleepTimeLabel = new JLabel("Time between points in seconds:"); this.controlPanel.add(sleepTimeLabel); double spinnerMin = 0.1d; double spinnerMax = 10000.0d; SpinnerModel model = new SpinnerNumberModel(2.0d, spinnerMin, spinnerMax, 0.1d); JSpinner sleepTimeSpinner = new JSpinner(model); sleepTimeSpinner.setToolTipText("Select time using controls or manual input within the range of " + spinnerMin + " to " + spinnerMax + "."); sleepTimeSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Object source = e.getSource(); if (source instanceof JSpinner) { final JSpinner spinner = (JSpinner) source; EventQueue.invokeLater(new Runnable() { @Override public void run() { Double value = (Double) spinner.getValue(); value = Double.valueOf(value.doubleValue() * 1000d); setSleepTimeMillis(value.longValue()); } }); } else log.warn("Unsupported ChangeEvent, need JSpinner as source: " + e); } }); // catch text change events without loosing the focus // JSpinner.DefaultEditor editor = (DefaultEditor) sleepTimeSpinner.getEditor(); // not implemented, can be done using KeyEvent, but then it hast to be checked where in the text // field the keystroke was etc. --> too complicated. this.controlPanel.add(sleepTimeSpinner); JLabel whereLabel = new JLabel("Where clause: "); this.whereField = new JTextField(this.where); this.whereField.setPreferredSize(new Dimension(200, 20)); this.whereField.setToolTipText("Insert a valid SQL 'WHERE' clause here."); this.whereButton = new JButton("Load data"); this.whereButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { updateWhere(); loadAllData(); } }); } }); this.controlPanel.add(whereLabel); this.controlPanel.add(this.whereField); this.controlPanel.add(this.whereButton); } return this.controlPanel; }