All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mdlaf.components.spinner.MaterialSpinnerUI Maven / Gradle / Ivy

There is a newer version: 1.1.4
Show newest version
package mdlaf.components.spinner;

import mdlaf.animation.MaterialUIMovement;
import mdlaf.components.button.MaterialButtonUI;
import mdlaf.utils.MaterialBorders;
import mdlaf.utils.MaterialDrawingUtils;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicSpinnerUI;
import java.awt.*;

/**
 * @author https://github.com/vincenzopalazzo
 * @author https://github.com/atarw
 */
public class MaterialSpinnerUI extends BasicSpinnerUI {


    public static ComponentUI createUI(JComponent c) {
        return new MaterialSpinnerUI();
    }

    @Override
    public void installUI(JComponent c) {
        super.installUI(c);

        JSpinner spinner = (JSpinner) c;
        spinner.setOpaque(false);
        spinner.setFont(UIManager.getFont("Spinner.font"));
        spinner.setBackground(UIManager.getColor("Spinner.background"));
        spinner.setForeground(UIManager.getColor("Spinner.foreground"));
        spinner.setBorder(UIManager.getBorder("Spinner.border"));
        //c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }

    @Override
    public void uninstallUI(JComponent c) {
        //c.setCursor(null);

        super.uninstallUI(c);
    }

    @Override
    public void paint(Graphics g, JComponent c) {
        super.paint(g, c);

    }

    @Override
    public void update(Graphics g, JComponent c) {
        super.update(MaterialDrawingUtils.getAliasedGraphics(g), c);
    }

    @Override
    protected Component createNextButton() {
        Icon icon = UIManager.getIcon("Spinner.nextButtonIcon");
        JButton button;
        if (icon != null) {
            button = new JButton(icon);
        } else {
            button = new BasicArrowButton(SwingConstants.NORTH);
        }
        button.setOpaque(true);
        button.setFocusable(true);
        button.setBackground(UIManager.getColor("Spinner.arrowButtonBackground"));
        button.setBorder(UIManager.getBorder("Spinner.arrowButtonBorder"));
        if(UIManager.getBoolean("Spinner.mouseHoverEnabled")){
            button.addMouseListener(MaterialUIMovement.getMovement(button, UIManager.getColor ("Spinner.mouseHoverColor")));
        }
        installNextButtonListeners(button);
        button.setBorder(BorderFactory.createLineBorder(button.getBackground()));
        return button;
    }

    @Override
    protected Component createPreviousButton() {
        Icon icon = UIManager.getIcon("Spinner.previousButtonIcon");
        JButton button;
        if (icon != null) {
            button = new JButton(icon);
        } else {
            button = new BasicArrowButton(SwingConstants.SOUTH);
        }
        button.setOpaque(true);
        button.setBackground(UIManager.getColor("Spinner.arrowButtonBackground"));
        if(UIManager.getBoolean("Spinner.mouseHoverEnabled")){
            button.addMouseListener(MaterialUIMovement.getMovement(button, UIManager.getColor ("Spinner.mouseHoverColor")));
        }
        installPreviousButtonListeners(button);
        button.setBorder (BorderFactory.createLineBorder(button.getBackground()));
        return button;
    }




}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy