0N/A/*
2362N/A * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing.plaf.synth;
0N/A
0N/Aimport java.awt.*;
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.plaf.UIResource;
0N/A
0N/A/**
0N/A * JButton object that draws a scaled Arrow in one of the cardinal directions.
0N/A *
0N/A * @author Scott Violet
0N/A */
0N/Aclass SynthArrowButton extends JButton implements SwingConstants, UIResource {
0N/A private int direction;
0N/A
0N/A public SynthArrowButton(int direction) {
0N/A super();
0N/A super.setFocusable(false);
0N/A setDirection(direction);
0N/A setDefaultCapable(false);
0N/A }
0N/A
0N/A public String getUIClassID() {
0N/A return "ArrowButtonUI";
0N/A }
0N/A
0N/A public void updateUI() {
0N/A setUI(new SynthArrowButtonUI());
0N/A }
0N/A
0N/A public void setDirection(int dir) {
0N/A direction = dir;
215N/A putClientProperty("__arrow_direction__", Integer.valueOf(dir));
0N/A repaint();
0N/A }
0N/A
0N/A public int getDirection() {
0N/A return direction;
0N/A }
0N/A
0N/A public void setFocusable(boolean focusable) {}
0N/A
0N/A private static class SynthArrowButtonUI extends SynthButtonUI {
0N/A protected void installDefaults(AbstractButton b) {
0N/A super.installDefaults(b);
0N/A updateStyle(b);
0N/A }
0N/A
0N/A protected void paint(SynthContext context, Graphics g) {
0N/A SynthArrowButton button = (SynthArrowButton)context.
0N/A getComponent();
0N/A context.getPainter().paintArrowButtonForeground(
0N/A context, g, 0, 0, button.getWidth(), button.getHeight(),
0N/A button.getDirection());
0N/A }
0N/A
0N/A void paintBackground(SynthContext context, Graphics g, JComponent c) {
0N/A context.getPainter().paintArrowButtonBackground(context, g, 0, 0,
0N/A c.getWidth(), c.getHeight());
0N/A }
0N/A
0N/A public void paintBorder(SynthContext context, Graphics g, int x,
0N/A int y, int w, int h) {
0N/A context.getPainter().paintArrowButtonBorder(context, g, x, y, w,h);
0N/A }
0N/A
0N/A public Dimension getMinimumSize() {
0N/A return new Dimension(5, 5);
0N/A }
0N/A
0N/A public Dimension getMaximumSize() {
0N/A return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
0N/A }
0N/A
0N/A public Dimension getPreferredSize(JComponent c) {
0N/A SynthContext context = getContext(c);
0N/A Dimension dim = null;
0N/A if (context.getComponent().getName() == "ScrollBar.button") {
0N/A // ScrollBar arrow buttons can be non-square when
0N/A // the ScrollBar.squareButtons property is set to FALSE
0N/A // and the ScrollBar.buttonSize property is non-null
0N/A dim = (Dimension)
0N/A context.getStyle().get(context, "ScrollBar.buttonSize");
0N/A }
0N/A if (dim == null) {
0N/A // For all other cases (including Spinner, ComboBox), we will
0N/A // fall back on the single ArrowButton.size value to create
0N/A // a square return value
0N/A int size =
0N/A context.getStyle().getInt(context, "ArrowButton.size", 16);
0N/A dim = new Dimension(size, size);
0N/A }
1173N/A
1173N/A // handle scaling for sizeVarients for special case components. The
1173N/A // key "JComponent.sizeVariant" scales for large/small/mini
1173N/A // components are based on Apples LAF
1173N/A Container parent = context.getComponent().getParent();
1173N/A if (parent instanceof JComponent && !(parent instanceof JComboBox)) {
1173N/A Object scaleKey = ((JComponent)parent).
1173N/A getClientProperty("JComponent.sizeVariant");
1173N/A if (scaleKey != null){
1173N/A if ("large".equals(scaleKey)){
1173N/A dim = new Dimension(
1173N/A (int)(dim.width * 1.15),
1173N/A (int)(dim.height * 1.15));
1173N/A } else if ("small".equals(scaleKey)){
1173N/A dim = new Dimension(
1173N/A (int)(dim.width * 0.857),
1173N/A (int)(dim.height * 0.857));
1173N/A } else if ("mini".equals(scaleKey)){
1173N/A dim = new Dimension(
1173N/A (int)(dim.width * 0.714),
1173N/A (int)(dim.height * 0.714));
1173N/A }
1173N/A }
1173N/A }
1173N/A
0N/A context.dispose();
0N/A return dim;
0N/A }
0N/A }
0N/A}