Search in sources :

Example 21 with JSlider

use of javax.swing.JSlider in project zaproxy by zaproxy.

the class OptionsScannerPanel method getSliderDelayInMs.

private JSlider getSliderDelayInMs() {
    if (sliderDelayInMs == null) {
        sliderDelayInMs = new JSlider();
        sliderDelayInMs.setMaximum(1000);
        sliderDelayInMs.setMinimum(0);
        sliderDelayInMs.setValue(0);
        sliderDelayInMs.setPaintTicks(true);
        sliderDelayInMs.setPaintLabels(true);
        sliderDelayInMs.setMinorTickSpacing(25);
        sliderDelayInMs.setMajorTickSpacing(100);
        sliderDelayInMs.setSnapToTicks(true);
        sliderDelayInMs.setPaintTrack(true);
        sliderDelayInMs.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                setLabelDelayInMsValue(getSliderDelayInMs().getValue());
            }
        });
    }
    return sliderDelayInMs;
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener)

Example 22 with JSlider

use of javax.swing.JSlider in project EnrichmentMapApp by BaderLab.

the class SliderBarPanel method getSlider.

JSlider getSlider() {
    if (slider == null) {
        slider = new JSlider(S_MIN, S_MAX);
        final Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
        final double range = max - min;
        final int originalPrecision = PRECISION - 1;
        final int intRange = (int) (range * Math.pow(10, originalPrecision));
        Optional<Integer> result = Arrays.asList(new Integer[] { 5, 4, 3, 2 }).stream().filter(n -> intRange % n == 0).findFirst();
        int n = result.isPresent() ? result.get() : 10;
        slider.setMajorTickSpacing(S_RANGE / n);
        if (n <= 5) {
            if (S_RANGE / (n * n) > 0)
                slider.setMinorTickSpacing(S_RANGE / (n * n));
            else
                slider.setMinorTickSpacing(S_RANGE / (n * 2));
        }
        labelTable.put(S_MIN, new JLabel(format.format(min)));
        if ((S_MIN + S_RANGE / 2) % 2 == 0)
            labelTable.put(S_MIN + S_RANGE / 2, new JLabel(format.format(min + range / 2)));
        labelTable.put(S_MAX, new JLabel(format.format(max)));
        slider.setLabelTable(labelTable);
        slider.setPaintTicks(true);
        slider.setPaintLabels(true);
        setSliderValue();
        setFieldValue();
        slider.addChangeListener((ChangeEvent e) -> {
            if (ignore)
                return;
            ignore = true;
            // update the value
            double val = getSlider().getValue();
            val = Math.min(val, S_MAX);
            val = Math.max(val, S_MIN);
            val = min + (val - S_MIN) * (max - min) / (double) S_RANGE;
            // Due to small inaccuracies in the slider position, it's possible
            // to get values less than the min or greater than the max.  If so,
            // just adjust the value and don't issue a warning.
            value = clamp(val);
            // set text field value
            setFieldValue();
            // fire event
            fireChangeEvent();
            ignore = false;
        });
    }
    return slider;
}
Also used : LookAndFeelUtil.getErrorColor(org.cytoscape.util.swing.LookAndFeelUtil.getErrorColor) Color(java.awt.Color) IntStream(java.util.stream.IntStream) UIManager(javax.swing.UIManager) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) JTextField(javax.swing.JTextField) ParsePosition(java.text.ParsePosition) ArrayList(java.util.ArrayList) FocusAdapter(java.awt.event.FocusAdapter) ChangeListener(javax.swing.event.ChangeListener) SwingUtil.makeSmall(org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil.makeSmall) Hashtable(java.util.Hashtable) DEFAULT_SIZE(javax.swing.GroupLayout.DEFAULT_SIZE) ChangeEvent(javax.swing.event.ChangeEvent) JFormattedTextField(javax.swing.JFormattedTextField) Iterator(java.util.Iterator) LookAndFeelUtil.getSmallFontSize(org.cytoscape.util.swing.LookAndFeelUtil.getSmallFontSize) Font(java.awt.Font) DecimalFormat(java.text.DecimalFormat) JOptionPane(javax.swing.JOptionPane) PREFERRED_SIZE(javax.swing.GroupLayout.PREFERRED_SIZE) Dimension(java.awt.Dimension) List(java.util.List) Alignment(javax.swing.GroupLayout.Alignment) LookAndFeelUtil(org.cytoscape.util.swing.LookAndFeelUtil) FocusEvent(java.awt.event.FocusEvent) JLabel(javax.swing.JLabel) JSlider(javax.swing.JSlider) GroupLayout(javax.swing.GroupLayout) Optional(java.util.Optional) Dictionary(java.util.Dictionary) JPanel(javax.swing.JPanel) ChangeEvent(javax.swing.event.ChangeEvent) Hashtable(java.util.Hashtable) JSlider(javax.swing.JSlider) JLabel(javax.swing.JLabel)

Example 23 with JSlider

use of javax.swing.JSlider in project pcgen by PCGen.

the class Utils method buildIntegerFieldWithSlider.

/**
	 *
	 * <p>
	 * Builds a formatted text field with specified min and max, and attaches
	 * the slider to it via listeners. The text field gets it's min and max from
	 * the slider.
	 * </p>
	 *
	 * @param matchingSlider
	 * @return JFormattedTextField
	 */
public static JFormattedTextField buildIntegerFieldWithSlider(final JSlider matchingSlider) {
    final JFormattedTextField returnValue = buildIntegerField(matchingSlider.getMinimum(), matchingSlider.getMaximum());
    returnValue.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ("value".equals(evt.getPropertyName())) {
                Number value = (Number) evt.getNewValue();
                if (value != null) {
                    matchingSlider.setValue(value.intValue());
                }
            }
        }
    });
    matchingSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            int value = source.getValue();
            if (!source.getValueIsAdjusting()) {
                //done adjusting
                //update ftf value
                returnValue.setValue(value);
            } else {
                //value is adjusting; just set the text
                returnValue.setText(String.valueOf(value));
            }
        }
    });
    return returnValue;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) JFormattedTextField(javax.swing.JFormattedTextField) JSlider(javax.swing.JSlider) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Example 24 with JSlider

use of javax.swing.JSlider in project pcgen by PCGen.

the class Utils method buildSlider.

/**
	 *
	 * <p>Builds the specified slider.</p>
	 * @param min
	 * @param max
	 * @param minorTick
	 * @param majorTick
	 * @return JSlider
	 */
public static JSlider buildSlider(int min, int max, int minorTick, int majorTick) {
    JSlider slider = new JSlider();
    slider.setMinimum(min);
    slider.setMaximum(max);
    slider.setMajorTickSpacing(majorTick);
    slider.setMinorTickSpacing(minorTick);
    slider.setPaintTicks(true);
    return slider;
}
Also used : JSlider(javax.swing.JSlider)

Example 25 with JSlider

use of javax.swing.JSlider in project ChatGameFontificator by GlitchCog.

the class ControlPanelDebug method build.

@Override
protected void build() {
    postTestMessage = new JButton("Post Debug Message");
    postTestMessage.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ctrlWindow.addManualMessage("Test", SpriteFont.NORMAL_ASCII_KEY);
        }
    });
    postMessagesButton = new JToggleButton("Post Messages");
    postRateSlider = new LabeledSlider("Post Rate ", " / min", 1, 120, 15, 3);
    postClock = new Timer(60000 / postRateSlider.getValue(), new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            postRandomMessage();
        }
    });
    postRateSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!((JSlider) e.getSource()).getValueIsAdjusting()) {
                postClock.setDelay(60000 / postRateSlider.getValue());
                if (postClock.isRunning()) {
                    postRandomMessage();
                    postClock.restart();
                }
            }
        }
    });
    postMessagesButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            postRandomMessage();
            if (postMessagesButton.isSelected()) {
                postClock.start();
            } else {
                postClock.stop();
            }
        }
    });
    drawTextGridBox = new JCheckBox("Draw Text Grid");
    textGridColorButton = new ColorButton("Text Grid Color", new Color(0x99FF88), "Color of the border grid", this);
    drawBorderGridBox = new JCheckBox("Draw Border Grid");
    borderGridColorButton = new ColorButton("Border Grid Color", new Color(0x9988FF), "Color of the border grid", this);
    ActionListener refreshListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (chat != null) {
                chat.repaint();
            }
        }
    };
    drawTextGridBox.addActionListener(refreshListener);
    drawBorderGridBox.addActionListener(refreshListener);
    JPanel topPanel = new JPanel(new GridBagLayout());
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.fill = GridBagConstraints.NONE;
    topPanel.add(postTestMessage, gbc);
    gbc.gridx++;
    topPanel.add(postMessagesButton, gbc);
    gbc.gridx++;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    topPanel.add(postRateSlider, gbc);
    gbc.gridwidth = 4;
    gbc.gridx = 0;
    gbc.gridy = 0;
    add(topPanel, gbc);
    gbc.gridy++;
    gbc.gridwidth = 1;
    gbc.weightx = 0.5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    add(drawTextGridBox, gbc);
    gbc.gridx++;
    add(textGridColorButton, gbc);
    gbc.gridx++;
    add(drawBorderGridBox, gbc);
    gbc.gridx++;
    add(borderGridColorButton, gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 4;
    gbc.weighty = 0.1;
    CollagePanel collagePanel = new CollagePanel(chat);
    add(collagePanel, gbc);
    gbc.gridy++;
    gbc.weightx = 1.0;
    gbc.weighty = 0.9;
    gbc.anchor = GridBagConstraints.SOUTH;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = 4;
    add(logBox, gbc);
}
Also used : JPanel(javax.swing.JPanel) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JButton(javax.swing.JButton) JCheckBox(javax.swing.JCheckBox) LabeledSlider(com.glitchcog.fontificator.gui.component.LabeledSlider) ActionListener(java.awt.event.ActionListener) JToggleButton(javax.swing.JToggleButton) Timer(javax.swing.Timer) ChangeEvent(javax.swing.event.ChangeEvent) ColorButton(com.glitchcog.fontificator.gui.component.ColorButton) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener)

Aggregations

JSlider (javax.swing.JSlider)43 ChangeEvent (javax.swing.event.ChangeEvent)23 ChangeListener (javax.swing.event.ChangeListener)23 JLabel (javax.swing.JLabel)14 JPanel (javax.swing.JPanel)14 JButton (javax.swing.JButton)12 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)11 GridBagLayout (java.awt.GridBagLayout)8 Dimension (java.awt.Dimension)7 GridBagConstraints (java.awt.GridBagConstraints)7 BorderLayout (java.awt.BorderLayout)6 JCheckBox (javax.swing.JCheckBox)6 JComponent (javax.swing.JComponent)6 JToggleButton (javax.swing.JToggleButton)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 JRadioButton (javax.swing.JRadioButton)5 JTextField (javax.swing.JTextField)5 Color (java.awt.Color)4 Point (java.awt.Point)4