KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > SynthArrowButton


1 /*
2  * @(#)SynthArrowButton.java 1.15 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.plaf.synth;
8
9 import java.awt.*;
10 import javax.swing.*;
11 import javax.swing.plaf.UIResource JavaDoc;
12
13 /**
14  * JButton object that draws a scaled Arrow in one of the cardinal directions.
15  *
16  * @version 1.15, 12/19/03
17  * @author Scott Violet
18  */

19 class SynthArrowButton extends JButton implements SwingConstants, UIResource JavaDoc {
20     private int direction;
21
22     public SynthArrowButton(int direction) {
23         super();
24         setFocusable(false);
25         setDirection(direction);
26         setDefaultCapable(false);
27     }
28
29     public String JavaDoc getUIClassID() {
30         return "ArrowButtonUI";
31     }
32
33     public void updateUI() {
34         setUI(new SynthArrowButtonUI());
35     }
36
37     public void setDirection(int dir) {
38         direction = dir;
39         putClientProperty("__arrow_direction__", new Integer JavaDoc(dir));
40         repaint();
41     }
42
43     public int getDirection() {
44         return direction;
45     }
46
47
48     private static class SynthArrowButtonUI extends SynthButtonUI JavaDoc {
49         protected void installDefaults(AbstractButton b) {
50             super.installDefaults(b);
51             updateStyle(b);
52         }
53
54         protected void paint(SynthContext JavaDoc context, Graphics g) {
55             SynthArrowButton JavaDoc button = (SynthArrowButton JavaDoc)context.
56                                       getComponent();
57             context.getPainter().paintArrowButtonForeground(
58                 context, g, 0, 0, button.getWidth(), button.getHeight(),
59                 button.getDirection());
60         }
61
62         void paintBackground(SynthContext JavaDoc context, Graphics g, JComponent c) {
63             context.getPainter().paintArrowButtonBackground(context, g, 0, 0,
64                                                 c.getWidth(), c.getHeight());
65         }
66
67         public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
68                                 int y, int w, int h) {
69             context.getPainter().paintArrowButtonBorder(context, g, x, y, w,h);
70         }
71
72         public Dimension getMinimumSize() {
73             return new Dimension(5, 5);
74         }
75
76         public Dimension getMaximumSize() {
77             return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
78         }
79
80         public Dimension getPreferredSize(JComponent c) {
81             SynthContext JavaDoc context = getContext(c);
82             int size = context.getStyle().getInt(context, "ArrowButton.size",
83                                                  16);
84
85             context.dispose();
86             return new Dimension(size, size);
87         }
88     }
89 }
90
Popular Tags