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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations