use of com.github.weisj.darklaf.properties.icons.DarkSVGIcon in project darklaf by weisJ.
the class RotatableIconDemo method createComponent.
@Override
public JComponent createComponent() {
final int size = 25;
RotatableIcon rotateIcon = new RotatableIcon(((DarkSVGIcon) DemoResources.FOLDER_ICON).derive(size, size));
rotateIcon.setOrientation(Alignment.EAST);
JLabel iconLabel = new JLabel(rotateIcon);
DemoPanel panel = new DemoPanel(iconLabel);
Alignment[] orientations = new Alignment[8];
orientations[0] = Alignment.NORTH;
for (int i = 1; i <= 7; i++) {
orientations[i] = orientations[i - 1].clockwise();
}
int spacing = 360 / orientations.length;
JSlider slider = new JSlider(0, (orientations.length - 1) * spacing);
slider.setMajorTickSpacing(spacing);
slider.setSnapToTicks(true);
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setValue(rotateIcon.getOrientation().getIndex() * spacing);
slider.addChangeListener(e -> {
if (!slider.isEnabled())
return;
rotateIcon.setOrientation(orientations[slider.getValue() / spacing]);
iconLabel.repaint();
});
Timer timer = new Timer(1000, e -> {
Alignment orientation = rotateIcon.getOrientation().clockwise();
rotateIcon.setOrientation(orientation);
slider.setValue(orientation.getDegreeAngle());
iconLabel.repaint();
});
timer.setRepeats(true);
JCheckBox checkBox = new JCheckBox("Auto rotate");
checkBox.setSelected(false);
checkBox.addActionListener(e -> {
slider.setEnabled(!checkBox.isSelected());
if (checkBox.isSelected()) {
rotateIcon.setOrientation(Alignment.NORTH);
timer.start();
} else {
timer.stop();
}
});
JComponent controls = panel.addControls(new GridBagLayout());
controls.add(slider);
controls = panel.addControls(Box.createHorizontalBox());
controls.add(checkBox);
controls.add(Box.createHorizontalGlue());
controls = panel.addControls(new BorderLayout());
AtomicReference<Icon> nextIcon = new AtomicReference<>(rotateIcon.getIcon());
JList<AllIconsDemo.NamedIcon<? extends Icon>> list = AllIconsDemo.createIconJList(size);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(e -> nextIcon.set(list.getSelectedValue().getSecond()));
controls.add(new OverlayScrollPane(list));
Box box = Box.createHorizontalBox();
box.add(Box.createHorizontalGlue());
JButton apply = new JButton("Change Icon");
apply.addActionListener(e -> {
rotateIcon.setIcon(nextIcon.get());
iconLabel.repaint();
});
box.add(apply);
box.add(Box.createHorizontalGlue());
controls = panel.addControls(new BorderLayout());
controls.add(box);
return panel;
}
Aggregations