use of javax.swing.JSlider in project jna by java-native-access.
the class AlphaMaskDemo2 method run.
public void run() {
// Must find a graphics configuration with a depth of 32 bits
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
frame = new JFrame("Alpha Mask Demo");
alphaWindow = new JWindow(frame, gconfig);
icon = new JLabel();
icon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
alphaWindow.getContentPane().add(icon);
JButton quit = new JButton("Quit");
JLabel label = new JLabel("Drag this window by its image");
label.setHorizontalAlignment(SwingConstants.CENTER);
alphaWindow.getContentPane().add(label, BorderLayout.NORTH);
alphaWindow.getContentPane().add(quit, BorderLayout.SOUTH);
quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
MouseInputAdapter handler = new MouseInputAdapter() {
private Point offset;
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e))
offset = e.getPoint();
}
public void mouseReleased(MouseEvent e) {
offset = null;
}
public void mouseDragged(MouseEvent e) {
if (offset != null) {
Window w = (Window) e.getSource();
Point where = e.getPoint();
where.translate(-offset.x, -offset.y);
Point loc = w.getLocationOnScreen();
loc.translate(where.x, where.y);
w.setLocation(loc.x, loc.y);
}
}
};
alphaWindow.addMouseListener(handler);
alphaWindow.addMouseMotionListener(handler);
JPanel p = new JPanel(new BorderLayout(8, 8));
p.setBorder(new EmptyBorder(8, 8, 8, 8));
p.setTransferHandler(new TransferHandler() {
private static final long serialVersionUID = 1L;
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
List<DataFlavor> list = Arrays.asList(transferFlavors);
if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR) || list.contains(DataFlavor.imageFlavor) || list.contains(DataFlavor.javaFileListFlavor)) {
return true;
}
if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
return true;
}
System.err.println("No acceptable flavor found in " + Arrays.asList(transferFlavors));
return false;
}
public boolean importData(JComponent comp, Transferable t) {
try {
if (t.isDataFlavorSupported(URL_FLAVOR)) {
URL url = (URL) t.getTransferData(URL_FLAVOR);
setImage(Toolkit.getDefaultToolkit().getImage(url));
return true;
}
if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
String s = (String) t.getTransferData(URI_LIST_FLAVOR);
String[] uris = s.split("[\r\n]");
if (uris.length > 0) {
URL url = new URL(uris[0]);
setImage(Toolkit.getDefaultToolkit().getImage(url));
return true;
}
return false;
}
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
setImage(image);
return true;
}
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
File f = files.get(0);
URL url = new URL("file://" + f.toURI().toURL().getPath());
Image image = Toolkit.getDefaultToolkit().getImage(url);
setImage(image);
return true;
}
DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
if (flavor != null) {
Reader reader = flavor.getReaderForText(t);
char[] buf = new char[512];
StringBuilder b = new StringBuilder();
int count;
// encoding wrong
while ((count = reader.read(buf)) > 0) {
for (int i = 0; i < count; i++) {
if (buf[i] != 0)
b.append(buf, i, 1);
}
}
String html = b.toString();
Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"", Pattern.CANON_EQ | Pattern.UNICODE_CASE);
Matcher m = p.matcher(html);
if (m.find()) {
URL url = new URL(m.group(1));
System.out.println("Load image from " + url);
Image image = Toolkit.getDefaultToolkit().getImage(url);
setImage(image);
return true;
}
System.err.println("Can't parse text: " + html);
return false;
}
System.err.println("No flavor available: " + Arrays.asList(t.getTransferDataFlavors()));
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}
});
p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>" + "You may also adjust the overall transparency with the slider</center></html>"), BorderLayout.NORTH);
p.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
final JSlider slider = new JSlider(0, 255, 255);
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int value = slider.getValue();
WindowUtils.setWindowAlpha(alphaWindow, value / 255f);
}
});
p.add(slider, BorderLayout.SOUTH);
frame.getContentPane().add(p);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
centerOnScreen(frame);
frame.setVisible(true);
WindowUtils.setWindowTransparent(alphaWindow, true);
alphaWindow.setLocation(frame.getX() + frame.getWidth() + 4, frame.getY());
try {
URL url = getClass().getResource("tardis.png");
if (url != null) {
setImage(Toolkit.getDefaultToolkit().getImage(url));
}
} catch (Exception e) {
}
}
use of javax.swing.JSlider in project zaproxy by zaproxy.
the class OptionsScannerPanel method getSliderHostPerScan.
/**
* This method initializes sliderHostPerScan
*
* @return javax.swing.JSlider
*/
private JSlider getSliderHostPerScan() {
if (sliderHostPerScan == null) {
sliderHostPerScan = new JSlider();
sliderHostPerScan.setMaximum(5);
sliderHostPerScan.setMinimum(1);
sliderHostPerScan.setMinorTickSpacing(1);
sliderHostPerScan.setPaintTicks(true);
sliderHostPerScan.setPaintLabels(true);
sliderHostPerScan.setName("");
sliderHostPerScan.setMajorTickSpacing(1);
sliderHostPerScan.setSnapToTicks(true);
sliderHostPerScan.setPaintTrack(true);
}
return sliderHostPerScan;
}
use of javax.swing.JSlider in project jdk8u_jdk by JetBrains.
the class DimensionEncapsulation method run.
@Override
public void run() {
runTest(new Panel());
runTest(new Button());
runTest(new Checkbox());
runTest(new Canvas());
runTest(new Choice());
runTest(new Label());
runTest(new Scrollbar());
runTest(new TextArea());
runTest(new TextField());
runTest(new Dialog(new JFrame()));
runTest(new Frame());
runTest(new Window(new JFrame()));
runTest(new FileDialog(new JFrame()));
runTest(new List());
runTest(new ScrollPane());
runTest(new JFrame());
runTest(new JDialog(new JFrame()));
runTest(new JWindow(new JFrame()));
runTest(new JLabel("hi"));
runTest(new JMenu());
runTest(new JTree());
runTest(new JTable());
runTest(new JMenuItem());
runTest(new JCheckBoxMenuItem());
runTest(new JToggleButton());
runTest(new JSpinner());
runTest(new JSlider());
runTest(Box.createVerticalBox());
runTest(Box.createHorizontalBox());
runTest(new JTextField());
runTest(new JTextArea());
runTest(new JTextPane());
runTest(new JPasswordField());
runTest(new JFormattedTextField());
runTest(new JEditorPane());
runTest(new JButton());
runTest(new JColorChooser());
runTest(new JFileChooser());
runTest(new JCheckBox());
runTest(new JInternalFrame());
runTest(new JDesktopPane());
runTest(new JTableHeader());
runTest(new JLayeredPane());
runTest(new JRootPane());
runTest(new JMenuBar());
runTest(new JOptionPane());
runTest(new JRadioButton());
runTest(new JRadioButtonMenuItem());
runTest(new JPopupMenu());
//runTest(new JScrollBar()); --> don't test defines max and min in
// terms of preferred
runTest(new JScrollPane());
runTest(new JViewport());
runTest(new JSplitPane());
runTest(new JTabbedPane());
runTest(new JToolBar());
runTest(new JSeparator());
runTest(new JProgressBar());
if (!failures.isEmpty()) {
System.out.println("These classes failed");
for (final Component failure : failures) {
System.out.println(failure.getClass());
}
throw new RuntimeException("Test failed");
}
}
use of javax.swing.JSlider in project zaproxy by zaproxy.
the class OptionsSpiderPanel method getSliderMaxDepth.
/**
* This method initializes the slider for MaxDepth.
*
* @return the slider for max depth
*/
private JSlider getSliderMaxDepth() {
if (sliderMaxDepth == null) {
sliderMaxDepth = new JSlider();
sliderMaxDepth.setMaximum(19);
sliderMaxDepth.setMinimum(1);
sliderMaxDepth.setMinorTickSpacing(1);
sliderMaxDepth.setPaintTicks(true);
sliderMaxDepth.setPaintLabels(true);
sliderMaxDepth.setName("");
sliderMaxDepth.setMajorTickSpacing(1);
sliderMaxDepth.setSnapToTicks(true);
sliderMaxDepth.setPaintTrack(true);
}
return sliderMaxDepth;
}
use of javax.swing.JSlider in project ChatGameFontificator by GlitchCog.
the class ControlPanelFont method build.
@Override
protected void build() {
sliderListener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (fontScaleSlider.getSlider().equals(source)) {
config.setFontScale(fontScaleSlider.getScaledValue());
fontScaleSlider.setValueTextColor(((int) config.getFontScale() == config.getFontScale()) ? SCALE_EVEN : SCALE_UNEVEN);
} else if (borderScaleSlider.getSlider().equals(source)) {
config.setBorderScale(borderScaleSlider.getScaledValue());
borderScaleSlider.setValueTextColor(((int) config.getBorderScale() == config.getBorderScale()) ? SCALE_EVEN : SCALE_UNEVEN);
} else if (borderInsetXSlider.getSlider().equals(source)) {
config.setBorderInsetX(borderInsetXSlider.getValue());
} else if (borderInsetYSlider.getSlider().equals(source)) {
config.setBorderInsetY(borderInsetYSlider.getValue());
} else if (spaceWidthSlider.getSlider().equals(source)) {
config.setSpaceWidth(spaceWidthSlider.getValue());
} else if (baselineOffsetSlider.getSlider().equals(source)) {
config.setBaselineOffset(baselineOffsetSlider.getValue());
} else if (lineSpacingSlider.getSlider().equals(source)) {
config.setLineSpacing(lineSpacingSlider.getValue());
} else if (charSpacingSlider.getSlider().equals(source)) {
config.setCharSpacing(charSpacingSlider.getValue());
}
chat.repaint();
}
};
ActionListener fontAl = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
DropdownLabel key = new DropdownLabel(source.getText());
if (CUSTOM_KEY.equals(key)) {
int selectionResult = fontPngPicker.showDialog(ControlWindow.me, "Select Font PNG");
if (selectionResult == JFileChooser.APPROVE_OPTION) {
fontFilenameInput.setText(fontPngPicker.getSelectedFile().getAbsolutePath());
fontPresetDropdown.setSelectedText(fontPngPicker.getSelectedFile().getName());
}
} else {
fontFilenameInput.setText(PRESET_FONT_FILE_MAP.get(key).getFontFilename());
fontTypeCheckbox.setSelected(FontType.VARIABLE_WIDTH.equals(PRESET_FONT_FILE_MAP.get(key).getDefaultType()));
spaceWidthSlider.setEnabled(fontTypeCheckbox.isSelected());
}
updateFontOrBorder(true);
}
};
ActionListener borderAl = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
DropdownLabel key = new DropdownLabel(source.getText());
if (CUSTOM_KEY.equals(key)) {
int selectionResult = borderPngPicker.showDialog(ControlWindow.me, "Select Border PNG");
if (selectionResult == JFileChooser.APPROVE_OPTION) {
borderFilenameInput.setText(borderPngPicker.getSelectedFile().getAbsolutePath());
borderPresetDropdown.setSelectedText(borderPngPicker.getSelectedFile().getName());
}
} else {
DropdownBorder border = PRESET_BORDER_FILE_MAP.get(key);
borderFilenameInput.setText(border.getBorderFilename());
colorPanel.setBorderColor(border.getDefaultTint());
}
updateFontOrBorder(false);
}
};
fontTypeListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
config.setFontType(fontTypeCheckbox.isSelected() ? FontType.VARIABLE_WIDTH : FontType.FIXED_WIDTH);
spaceWidthSlider.setEnabled(fontTypeCheckbox.isSelected());
updateFontOrBorder(true);
}
};
extendedCharBox = new JCheckBox("Display Extended Characters");
extendedCharBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final boolean ecbSelected = extendedCharBox.isSelected();
config.setExtendedCharEnabled(ecbSelected);
unknownCharPopupButton.setEnabled(!ecbSelected);
unknownCharLabel.setEnabled(!ecbSelected);
chat.repaint();
}
});
unknownCharLabel = new JLabel("");
charPicker = new CharacterPicker(ControlWindow.me, fProps.getFontConfig(), unknownCharLabel, chat);
Map<String, List<String>> fontMenuMap = getMenuMapFromPresets(PRESET_FONT_FILE_MAP.keySet());
fontMenuMap.put(CUSTOM_KEY.getLabel(), null);
Map<String, List<String>> borderMenuMap = getMenuMapFromPresets(PRESET_BORDER_FILE_MAP.keySet());
borderMenuMap.put(CUSTOM_KEY.getLabel(), null);
fontTypeCheckbox = new JCheckBox("Variable Width Characters");
fontFilenameInput = new LabeledInput("Font Filename", 32);
fontPresetDropdown = new ComboMenuBar(fontMenuMap, fontAl);
borderFilenameInput = new LabeledInput("Border Filename", 32);
borderPresetDropdown = new ComboMenuBar(borderMenuMap, borderAl);
gridWidthInput = new LabeledInput("Grid Width", 4);
gridHeightInput = new LabeledInput("Grid Height", 4);
fontScaleSlider = new LabeledSlider("Font Scale", "x", ConfigFont.MIN_FONT_SCALE, ConfigFont.MAX_FONT_SCALE, ConfigFont.FONT_BORDER_SCALE_GRANULARITY);
borderScaleSlider = new LabeledSlider("Border Scale", "x", ConfigFont.MIN_BORDER_SCALE, ConfigFont.MAX_BORDER_SCALE, ConfigFont.FONT_BORDER_SCALE_GRANULARITY);
borderInsetXSlider = new LabeledSlider("X", "pixels", ConfigFont.MIN_BORDER_INSET, ConfigFont.MAX_BORDER_INSET);
borderInsetYSlider = new LabeledSlider("Y", "pixels", ConfigFont.MIN_BORDER_INSET, ConfigFont.MAX_BORDER_INSET);
characterKeyInput = new LabeledInput("Character Key", 32);
spaceWidthSlider = new LabeledSlider("Space Width", "%", ConfigFont.MIN_SPACE_WIDTH, ConfigFont.MAX_SPACE_WIDTH);
baselineOffsetSlider = new LabeledSlider("Baseline Height Offset", "pixels", ConfigFont.MIN_BASELINE_OFFSET, ConfigFont.MAX_BASELINE_OFFSET);
lineSpacingSlider = new LabeledSlider("Line Spacing", "pixels", ConfigFont.MIN_LINE_SPACING, ConfigFont.MAX_LINE_SPACING);
charSpacingSlider = new LabeledSlider("Char Spacing", "pixels", ConfigFont.MIN_CHAR_SPACING, ConfigFont.MAX_LINE_SPACING);
unknownCharPopupButton = new JButton("Select Missing Character");
unknownCharPopupButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
charPicker.setVisible(true);
}
});
fontFilenameInput.setEnabled(false);
borderFilenameInput.setEnabled(false);
fontScaleSlider.addChangeListener(sliderListener);
borderScaleSlider.addChangeListener(sliderListener);
borderInsetXSlider.addChangeListener(sliderListener);
borderInsetYSlider.addChangeListener(sliderListener);
spaceWidthSlider.addChangeListener(sliderListener);
baselineOffsetSlider.addChangeListener(sliderListener);
lineSpacingSlider.addChangeListener(sliderListener);
charSpacingSlider.addChangeListener(sliderListener);
JPanel fontPanel = new JPanel(new GridBagLayout());
JPanel borderPanel = new JPanel(new GridBagLayout());
JPanel unknownPanel = new JPanel(new GridBagLayout());
fontPanel.setBorder(new TitledBorder(baseBorder, "Font"));
borderPanel.setBorder(new TitledBorder(baseBorder, "Border"));
unknownPanel.setBorder(new TitledBorder(baseBorder, "Extended and Unicode Characters"));
GridBagConstraints fontGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
GridBagConstraints borderGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
GridBagConstraints unknownGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
// Fields are still used and stored in properties files when saved, but the values are either fixed or meant to
// be filled by other components
// add(fontFilenameInput);
// add(borderFilenameInput);
// add(gridWidthInput);
// add(gridHeightInput);
// add(characterKeyInput);
fontPanel.add(fontPresetDropdown, fontGbc);
fontGbc.gridx++;
// This slider being on the same row as the preset dropdown keeps the combo menu bar from collapsing to no
// height in the layout
fontPanel.add(fontScaleSlider, fontGbc);
fontGbc.gridwidth = 2;
fontGbc.gridx = 0;
fontGbc.gridy++;
fontPanel.add(lineSpacingSlider, fontGbc);
fontGbc.gridy++;
fontPanel.add(charSpacingSlider, fontGbc);
fontGbc.gridy++;
JPanel variableWidthPanel = new JPanel(new GridBagLayout());
GridBagConstraints vwpGbc = getGbc();
vwpGbc.anchor = GridBagConstraints.EAST;
vwpGbc.weightx = 0.0;
vwpGbc.fill = GridBagConstraints.NONE;
variableWidthPanel.add(fontTypeCheckbox, vwpGbc);
vwpGbc.anchor = GridBagConstraints.WEST;
vwpGbc.weightx = 1.0;
vwpGbc.fill = GridBagConstraints.HORIZONTAL;
vwpGbc.gridx++;
variableWidthPanel.add(spaceWidthSlider, vwpGbc);
fontPanel.add(variableWidthPanel, fontGbc);
fontGbc.gridy++;
fontPanel.add(baselineOffsetSlider, fontGbc);
fontGbc.gridy++;
borderPanel.add(borderPresetDropdown, borderGbc);
borderGbc.gridx++;
// This slider being on the same row as the preset dropdown keeps the combo menu bar from collapsing to no
// height in the layout
borderPanel.add(borderScaleSlider, borderGbc);
borderGbc.gridwidth = 2;
borderGbc.gridx = 0;
borderGbc.gridy++;
borderGbc.anchor = GridBagConstraints.CENTER;
borderPanel.add(new JLabel("Font Insets Off Border"), borderGbc);
borderGbc.gridy++;
borderPanel.add(borderInsetXSlider, borderGbc);
borderGbc.gridy++;
borderPanel.add(borderInsetYSlider, borderGbc);
borderGbc.gridy++;
unknownPanel.add(extendedCharBox, unknownGbc);
unknownGbc.gridx++;
unknownPanel.add(unknownCharPopupButton, unknownGbc);
unknownGbc.gridx++;
unknownPanel.add(unknownCharLabel, unknownGbc);
unknownGbc.gridx++;
JPanel everything = new JPanel(new GridBagLayout());
GridBagConstraints eGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 10, 10);
everything.add(fontPanel, eGbc);
eGbc.gridy++;
everything.add(borderPanel, eGbc);
eGbc.gridy++;
everything.add(unknownPanel, eGbc);
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.CENTER;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
add(everything, gbc);
// Filler panel
gbc.gridy++;
gbc.weighty = 1.0;
gbc.anchor = GridBagConstraints.SOUTH;
add(new JPanel(), gbc);
}
Aggregations