Search in sources :

Example 1 with RotatableIcon

use of com.github.weisj.darklaf.properties.icons.RotatableIcon in project darklaf by weisJ.

the class DarkSliderUI method getBaseline.

@Override
public int getBaseline(JComponent c, int width, int height) {
    if (isHorizontal() && PropertyUtil.getBooleanProperty(c, KEY_USE_TRACK_AS_BASELINE)) {
        int thumbY = focusInsets.top + trackBuffer;
        if (isPlainThumb()) {
            Dimension thumbSize = getThumbSize();
            return thumbY + thumbSize.height - focusBorderSize;
        } else {
            Icon icon = getThumbIcon();
            int baseline = thumbY + icon.getIconHeight();
            if (icon instanceof RotatableIcon) {
                icon = ((RotatableIcon) icon).getIcon();
            }
            if (icon instanceof VisualPaddingProvider) {
                baseline -= ((VisualPaddingProvider) icon).getVisualPaddings(slider).bottom;
            }
            return baseline;
        }
    } else {
        return super.getBaseline(c, width, height);
    }
}
Also used : VisualPaddingProvider(com.github.weisj.swingdsl.visualpadding.VisualPaddingProvider) RotatableIcon(com.github.weisj.darklaf.properties.icons.RotatableIcon) RotatableIcon(com.github.weisj.darklaf.properties.icons.RotatableIcon)

Example 2 with RotatableIcon

use of com.github.weisj.darklaf.properties.icons.RotatableIcon in project darklaf by weisJ.

the class DarkSliderUI method getThumbIcon.

protected Icon getThumbIcon() {
    boolean enabled = slider.isEnabled();
    boolean focused = slider.hasFocus();
    boolean volume = isVolumeSlider(slider);
    Icon icon;
    if (volume) {
        icon = enabled ? focused ? volumeThumbFocused : volumeThumb : volumeThumbDisabled;
    } else {
        icon = enabled ? focused ? thumbFocused : thumb : thumbDisabled;
    }
    rotatableIcon.setIcon(icon);
    if (isHorizontal()) {
        rotatableIcon.setOrientation(Alignment.NORTH);
    } else {
        if (slider.getComponentOrientation().isLeftToRight()) {
            rotatableIcon.setOrientation(Alignment.WEST);
        } else {
            rotatableIcon.setOrientation(Alignment.EAST);
        }
    }
    return rotatableIcon;
}
Also used : RotatableIcon(com.github.weisj.darklaf.properties.icons.RotatableIcon)

Example 3 with RotatableIcon

use of com.github.weisj.darklaf.properties.icons.RotatableIcon in project darklaf by weisJ.

the class DarkTabFrameTabLabelUI method getIcon.

@Override
protected Icon getIcon(final JLabel label) {
    Icon icon = tabComponent.isEnabled() ? tabComponent.getIcon() : tabComponent.getDisabledIcon();
    if (icon == null)
        return null;
    rotatableIcon.setIcon(icon);
    if (rotatableIcon.getOrientation() == null) {
        rotatableIcon.setOrientation(mapOrientation(tabComponent.getOrientation()));
    }
    return rotatableIcon;
}
Also used : RotatableIcon(com.github.weisj.darklaf.properties.icons.RotatableIcon)

Example 4 with RotatableIcon

use of com.github.weisj.darklaf.properties.icons.RotatableIcon 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)

Example 5 with RotatableIcon

use of com.github.weisj.darklaf.properties.icons.RotatableIcon in project darklaf by weisJ.

the class DarkSliderUI method installDefaults.

@Override
protected void installDefaults(final JSlider slider) {
    super.installDefaults(slider);
    LookAndFeel.installProperty(slider, PropertyKey.OPAQUE, false);
    arcSize = UIManager.getInt("Slider.arc");
    trackSize = UIManager.getInt("Slider.trackThickness");
    plainThumbRadius = UIManager.getInt("Slider.plainThumbRadius");
    thumbSize = UIManager.getDimension("Slider.thumbSize");
    iconPad = UIManager.getInt("Slider.iconPad");
    inactiveTickForeground = UIManager.getColor("Slider.disabledTickColor");
    trackBackground = UIManager.getColor("Slider.trackBackground");
    selectedTrackBackground = UIManager.getColor("Slider.selectedTrackColor");
    selectedTrackInactiveBackground = UIManager.getColor("Slider.disabledTrackColor");
    selectedVolumeTrackBackground = UIManager.getColor("Slider.volume.selectedTrackColor");
    selectedVolumeTrackInactiveBackground = UIManager.getColor("Slider.volume.disabledTrackColor");
    thumbBackground = UIManager.getColor("Slider.activeThumbFill");
    thumbInactiveBackground = UIManager.getColor("Slider.inactiveThumbFill");
    volumeThumbBackground = UIManager.getColor("Slider.volume.activeThumbFill");
    volumeThumbInactiveBackground = UIManager.getColor("Slider.volume.inactiveThumbFill");
    thumbBorderColor = UIManager.getColor("Slider.thumbBorderColor");
    thumbFocusBorderColor = UIManager.getColor("Slider.thumbFocusBorderColor");
    thumbInactiveBorderColor = UIManager.getColor("Slider.thumbBorderColorDisabled");
    focusBorderSize = UIManager.getInt("Slider.focusBorderSize");
    paintFocus = UIManager.getBoolean("Slider.paintFocusGlow");
    thumb = UIManager.getIcon("Slider.enabledThumb.icon");
    thumbDisabled = UIManager.getIcon("Slider.disabledThumb.icon");
    thumbFocused = UIManager.getIcon("Slider.focusedThumb.icon");
    volumeThumb = UIManager.getIcon("Slider.volume.enabledThumb.icon");
    volumeThumbDisabled = UIManager.getIcon("Slider.volume.disabledThumb.icon");
    volumeThumbFocused = UIManager.getIcon("Slider.volume.focusedThumb.icon");
    volume0 = UIManager.getIcon("Slider.volume.enabled_level_0.icon");
    volume1 = UIManager.getIcon("Slider.volume.enabled_level_1.icon");
    volume2 = UIManager.getIcon("Slider.volume.enabled_level_2.icon");
    volume3 = UIManager.getIcon("Slider.volume.enabled_level_3.icon");
    volume4 = UIManager.getIcon("Slider.volume.enabled_level_4.icon");
    volume0Inactive = UIManager.getIcon("Slider.volume.disabled_level_0.icon");
    volume1Inactive = UIManager.getIcon("Slider.volume.disabled_level_1.icon");
    volume2Inactive = UIManager.getIcon("Slider.volume.disabled_level_2.icon");
    volume3Inactive = UIManager.getIcon("Slider.volume.disabled_level_3.icon");
    volume4Inactive = UIManager.getIcon("Slider.volume.disabled_level_4.icon");
    rotatableIcon = new RotatableIcon();
}
Also used : RotatableIcon(com.github.weisj.darklaf.properties.icons.RotatableIcon)

Aggregations

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