001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Sergey Burlak
020: * @version $Revision$
021: */package javax.swing.plaf.metal;
022:
023: import java.awt.Color;
024: import java.awt.Dimension;
025: import java.awt.Graphics;
026: import java.awt.Rectangle;
027: import java.beans.PropertyChangeEvent;
028: import java.beans.PropertyChangeListener;
029:
030: import javax.swing.JButton;
031: import javax.swing.JComponent;
032: import javax.swing.LookAndFeel;
033: import javax.swing.UIManager;
034: import javax.swing.plaf.ComponentUI;
035: import javax.swing.plaf.UIResource;
036: import javax.swing.plaf.basic.BasicScrollBarUI;
037:
038: import org.apache.harmony.x.swing.Utilities;
039:
040: public class MetalScrollBarUI extends BasicScrollBarUI {
041:
042: public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding";
043:
044: protected MetalBumps bumps;
045: protected MetalScrollButton increaseButton;
046: protected MetalScrollButton decreaseButton;
047: protected int scrollBarWidth;
048: protected boolean isFreeStanding;
049:
050: // We need to hide these fields
051: private Color thumbColor;
052: private Color thumbHighlightColor;
053:
054: protected void paintTrack(final Graphics g, final JComponent c,
055: final Rectangle r) {
056: Color old = g.getColor();
057: Utilities.draw3DRect(g, r.x, r.y, r.width, r.height - 1,
058: Color.DARK_GRAY, Color.WHITE, false);
059: g.setColor(old);
060: }
061:
062: protected void paintThumb(final Graphics g, final JComponent c,
063: final Rectangle r) {
064: Color old = g.getColor();
065: Utilities.draw3DRect(g, r.x + 1, r.y + 1, r.width - 2,
066: r.height - 2, Color.DARK_GRAY, Color.WHITE, true);
067: g.setColor(thumbColor);
068: g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);
069:
070: MetalBumps.paintBumps(g, r.x + 4, r.y + 4, r.width - 8,
071: r.height - 8, thumbColor.darker(), thumbColor
072: .brighter());
073:
074: g.setColor(old);
075: }
076:
077: protected JButton createIncreaseButton(final int orient) {
078: increaseButton = new MetalScrollButton(orient, scrollBarWidth,
079: isFreeStanding);
080: return increaseButton;
081: }
082:
083: protected JButton createDecreaseButton(final int orient) {
084: decreaseButton = new MetalScrollButton(orient, scrollBarWidth,
085: isFreeStanding);
086: return decreaseButton;
087: }
088:
089: protected PropertyChangeListener createPropertyChangeListener() {
090: return new PropertyChangeHandler() {
091: public void propertyChange(final PropertyChangeEvent e) {
092: if (e.getPropertyName().equals(FREE_STANDING_PROP)) {
093: if (e.getNewValue() != null) {
094: isFreeStanding = ((Boolean) e.getNewValue())
095: .booleanValue();
096: } else {
097: isFreeStanding = false;
098: }
099: }
100: }
101: };
102: }
103:
104: protected Dimension getMinimumThumbSize() {
105: return super .getMinimumThumbSize();
106: }
107:
108: protected void setThumbBounds(final int x, final int y,
109: final int w, final int h) {
110: super .setThumbBounds(x, y, w, h);
111: }
112:
113: protected void installListeners() {
114: super .installListeners();
115: }
116:
117: protected void installDefaults() {
118: scrollBarWidth = UIManager.getInt("ScrollBar.width");
119:
120: configureScrollBarColors();
121:
122: if ((maximumThumbSize == null)
123: || (maximumThumbSize instanceof UIResource)) {
124: maximumThumbSize = UIManager
125: .getDimension("ScrollBar.maximumThumbSize");
126: }
127: if ((minimumThumbSize == null)
128: || (minimumThumbSize instanceof UIResource)) {
129: minimumThumbSize = UIManager
130: .getDimension("ScrollBar.minimumThumbSize");
131: }
132:
133: scrollbar.setLayout(this );
134:
135: LookAndFeel.installBorder(scrollbar, "ScrollBar.border");
136: super .installDefaults();
137: }
138:
139: protected void configureScrollBarColors() {
140: LookAndFeel.installColors(scrollbar, "ScrollBar.background",
141: "ScrollBar.foreground");
142:
143: if ((thumbColor == null) || (thumbColor instanceof UIResource)) {
144: thumbColor = UIManager.getColor("ScrollBar.thumb");
145: }
146: if ((thumbDarkShadowColor == null)
147: || (thumbDarkShadowColor instanceof UIResource)) {
148: thumbDarkShadowColor = UIManager
149: .getColor("ScrollBar.thumbDarkShadow");
150: }
151: if ((thumbHighlightColor == null)
152: || (thumbHighlightColor instanceof UIResource)) {
153: thumbHighlightColor = UIManager
154: .getColor("ScrollBar.thumbHighlight");
155: }
156: if ((thumbLightShadowColor == null)
157: || (thumbLightShadowColor instanceof UIResource)) {
158: thumbLightShadowColor = UIManager
159: .getColor("ScrollBar.thumbShadow");
160: }
161: if ((trackColor == null) || (trackColor instanceof UIResource)) {
162: trackColor = UIManager.getColor("ScrollBar.track");
163: }
164: if ((trackHighlightColor == null)
165: || (trackHighlightColor instanceof UIResource)) {
166: trackHighlightColor = UIManager
167: .getColor("ScrollBar.trackHighlight");
168: }
169: }
170:
171: public static ComponentUI createUI(final JComponent c) {
172: return new MetalScrollBarUI();
173: }
174: }
|