01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Sergey Burlak
20: * @version $Revision$
21: */package javax.swing.plaf.basic;
22:
23: import java.awt.Color;
24: import java.awt.Dimension;
25: import java.awt.Graphics;
26:
27: import javax.swing.JButton;
28: import javax.swing.SwingConstants;
29: import javax.swing.UIManager;
30:
31: import org.apache.harmony.x.swing.Utilities;
32:
33: public class BasicArrowButton extends JButton implements SwingConstants {
34: protected int direction;
35:
36: private static Color shadow = UIManager
37: .getColor("ScrollBar.shadow");
38: private static Color darkShadow = UIManager
39: .getColor("ScrollBar.darkShadow");
40:
41: public BasicArrowButton(final int direction) {
42: this .direction = direction;
43: }
44:
45: public BasicArrowButton(final int direction,
46: final Color background, final Color shadow,
47: final Color darkShadow, final Color highlight) {
48: BasicArrowButton.shadow = shadow;
49: BasicArrowButton.darkShadow = darkShadow;
50: this .direction = direction;
51: setBackground(background);
52: }
53:
54: public int getDirection() {
55: return direction;
56: }
57:
58: public void setDirection(final int dir) {
59: direction = dir;
60: }
61:
62: public void paint(final Graphics g) {
63: super .paint(g);
64: int arrowSize = Math.min(getSize().width, getSize().height) / 2;
65: int x = (getSize().width - arrowSize) / 2 + 1;
66: int y = (getSize().height - arrowSize) / 2 + 1;
67: paintTriangle(g, x, y, arrowSize, getDirection(), isEnabled());
68: }
69:
70: public Dimension getPreferredSize() {
71: return new Dimension(16, 16);
72: }
73:
74: public Dimension getMinimumSize() {
75: return new Dimension(5, 5);
76: }
77:
78: public Dimension getMaximumSize() {
79: return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
80: }
81:
82: public boolean isFocusTraversable() {
83: return false;
84: }
85:
86: public void paintTriangle(final Graphics g, final int x,
87: final int y, final int size, final int direction,
88: final boolean isEnabled) {
89: Utilities.fillArrow(g, x, y, direction, size, false,
90: isEnabled ? darkShadow : shadow);
91: }
92: }
|