Search in sources :

Example 1 with DarkSVGIcon

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;
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) DemoPanel(com.github.weisj.darklaf.ui.DemoPanel) OverlayScrollPane(com.github.weisj.darklaf.components.OverlayScrollPane) Alignment(com.github.weisj.darklaf.util.Alignment) RotatableIcon(com.github.weisj.darklaf.properties.icons.RotatableIcon) RotatableIcon(com.github.weisj.darklaf.properties.icons.RotatableIcon) DarkSVGIcon(com.github.weisj.darklaf.properties.icons.DarkSVGIcon)

Aggregations

OverlayScrollPane (com.github.weisj.darklaf.components.OverlayScrollPane)1 DarkSVGIcon (com.github.weisj.darklaf.properties.icons.DarkSVGIcon)1 RotatableIcon (com.github.weisj.darklaf.properties.icons.RotatableIcon)1 DemoPanel (com.github.weisj.darklaf.ui.DemoPanel)1 Alignment (com.github.weisj.darklaf.util.Alignment)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1