⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syntharrowbutton.java

📁 java1.6众多例子参考
💻 JAVA
字号:
/* * @(#)SynthArrowButton.java	1.20 08/05/22 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.synth;import java.awt.*;import javax.swing.*;import javax.swing.plaf.UIResource;/** * JButton object that draws a scaled Arrow in one of the cardinal directions. * * @version 1.20, 05/22/08 * @author Scott Violet */class SynthArrowButton extends JButton implements SwingConstants, UIResource {    private int direction;    public SynthArrowButton(int direction) {        super();        super.setFocusable(false);        setDirection(direction);        setDefaultCapable(false);    }    public String getUIClassID() {        return "ArrowButtonUI";    }    public void updateUI() {        setUI(new SynthArrowButtonUI());    }    public void setDirection(int dir) {        direction = dir;        putClientProperty("__arrow_direction__", new Integer(dir));        repaint();    }    public int getDirection() {        return direction;    }    public void setFocusable(boolean focusable) {}         private static class SynthArrowButtonUI extends SynthButtonUI {        protected void installDefaults(AbstractButton b) {            super.installDefaults(b);            updateStyle(b);        }        protected void paint(SynthContext context, Graphics g) {            SynthArrowButton button = (SynthArrowButton)context.                                      getComponent();            context.getPainter().paintArrowButtonForeground(                context, g, 0, 0, button.getWidth(), button.getHeight(),                button.getDirection());        }        void paintBackground(SynthContext context, Graphics g, JComponent c) {            context.getPainter().paintArrowButtonBackground(context, g, 0, 0,                                                c.getWidth(), c.getHeight());        }        public void paintBorder(SynthContext context, Graphics g, int x,                                int y, int w, int h) {            context.getPainter().paintArrowButtonBorder(context, g, x, y, w,h);        }        public Dimension getMinimumSize() {            return new Dimension(5, 5);        }        public Dimension getMaximumSize() {            return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);        }        public Dimension getPreferredSize(JComponent c) {            SynthContext context = getContext(c);            Dimension dim = null;            if (context.getComponent().getName() == "ScrollBar.button") {                // ScrollBar arrow buttons can be non-square when                // the ScrollBar.squareButtons property is set to FALSE                // and the ScrollBar.buttonSize property is non-null                dim = (Dimension)                    context.getStyle().get(context, "ScrollBar.buttonSize");            }            if (dim == null) {                // For all other cases (including Spinner, ComboBox), we will                // fall back on the single ArrowButton.size value to create                // a square return value                int size =                    context.getStyle().getInt(context, "ArrowButton.size", 16);                dim = new Dimension(size, size);            }            // handle scaling for sizeVarients for special case components. The            // key "JComponent.sizeVariant" scales for large/small/mini            // components are based on Apples LAF            JComponent parent = (JComponent)context.getComponent().getParent();            if (parent != null && !(parent instanceof JComboBox)){                String scaleKey = (String)parent.getClientProperty("JComponent.sizeVariant");                if (scaleKey != null){                    if ("large".equals(scaleKey)){                        dim = new Dimension(                                (int)(dim.width * 1.15),                                (int)(dim.height * 1.15));                    } else if ("small".equals(scaleKey)){                        dim = new Dimension(                                (int)(dim.width * 0.857),                                (int)(dim.height * 0.857));                    } else if ("mini".equals(scaleKey)){                        dim = new Dimension(                                (int)(dim.width * 0.714),                                (int)(dim.height * 0.714));                    }                }            }            context.dispose();            return dim;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -