001: /*
002: * Copyright 2005 Patrick Gotthardt
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package com.pagosoft.plaf;
017:
018: import com.pagosoft.swing.ColorUtils;
019:
020: import javax.swing.*;
021: import javax.swing.plaf.*;
022: import javax.swing.plaf.metal.*;
023: import java.awt.*;
024:
025: public class PgsScrollBarUI extends MetalScrollBarUI {
026: private static Color shadowColor;
027: private static Color highlightColor;
028: private static Color darkShadowColor;
029: private static Color thumbColor;
030: private static Color thumbShadow;
031: private static Color thumbHighlightColor;
032:
033: public static ComponentUI createUI(JComponent c) {
034: return new PgsScrollBarUI();
035: }
036:
037: protected void configureScrollBarColors() {
038: super .configureScrollBarColors();
039: shadowColor = UIManager.getColor("ScrollBar.shadow");
040: highlightColor = UIManager.getColor("ScrollBar.highlight");
041: darkShadowColor = UIManager.getColor("ScrollBar.darkShadow");
042: thumbColor = UIManager.getColor("ScrollBar.thumb");
043: thumbShadow = UIManager.getColor("ScrollBar.thumbShadow");
044: thumbHighlightColor = UIManager
045: .getColor("ScrollBar.thumbHighlight");
046: trackColor = UIManager.getColor("ScrollBar.track");
047: trackHighlightColor = UIManager
048: .getColor("ScrollBar.trackHighlight");
049: }
050:
051: protected void paintTrack(Graphics g, JComponent c, Rectangle r) {
052: super .paintTrack(g, c, r);
053: g.translate(r.x, r.y);
054: if (((JScrollBar) c).getOrientation() == SwingConstants.VERTICAL) {
055: Graphics2D gfx = (Graphics2D) g;
056: gfx.setPaint(new GradientPaint(0, 0, trackColor, r.width,
057: 0, trackHighlightColor, true));
058: gfx.fillRect(0, 0, r.width, r.height);
059: } else {
060: Graphics2D gfx = (Graphics2D) g;
061: gfx.setPaint(new GradientPaint(0, 0, trackColor, 0,
062: r.height, trackHighlightColor, true));
063: gfx.fillRect(0, 0, r.width, r.height);
064: }
065: g.translate(-r.x, -r.y);
066: }
067:
068: protected void paintThumb(Graphics g, JComponent c, Rectangle r) {
069: super .paintThumb(g, c, r);
070: if (!c.isEnabled()) {
071: return;
072: }
073: g.translate(r.x, r.y);
074:
075: if (((JScrollBar) c).getOrientation() == SwingConstants.VERTICAL) {
076: // Paints the thumbbackground
077: Graphics2D gfx = (Graphics2D) g;
078: if (PlafOptions.isOfficeScrollBarEnabled()) {
079: gfx.setPaint(new GradientPaint(0, 0,
080: thumbHighlightColor, 0, (r.height / 2) + 1,
081: thumbColor, true));
082: gfx.fillRect(0, 0, r.width - 1, r.height - 1);
083: } else {
084: gfx.setPaint(new GradientPaint(0, 0,
085: thumbHighlightColor, (r.width / 2) + 1, 0,
086: thumbColor, true));
087: gfx.fillRect(0, 0, r.width - 1, r.height - 1);
088: }
089:
090: g.setColor(thumbShadow);
091: g.drawRect(0, 0, r.width - 1, r.height - 1);
092:
093: g.setColor(thumbHighlightColor);
094: g.drawLine(1, 1, r.width - 3, 1);
095: g.drawLine(1, 1, 1, r.height - 2);
096:
097: int x = (int) r.getWidth() / 2;
098: int y = (int) r.getHeight() / 2;
099:
100: // one line = 4px; five lines = 20px
101: boolean isSmallThumb = r.getHeight() <= 20;
102:
103: g
104: .setColor(ColorUtils.getTranslucentColor(
105: thumbShadow, 150));
106: if (!isSmallThumb) {
107: g.drawLine(x - 3, y - 8, x + 3, y - 8);
108: }
109: g.drawLine(x - 3, y - 4, x + 3, y - 4);
110: g.drawLine(x - 3, y, x + 3, y);
111: g.drawLine(x - 3, y + 4, x + 3, y + 4);
112: if (!isSmallThumb) {
113: g.drawLine(x - 3, y + 8, x + 3, y + 8);
114: }
115:
116: g.setColor(ColorUtils.getTranslucentColor(
117: thumbHighlightColor, 150));
118: if (!isSmallThumb) {
119: g.drawLine(x - 2, y - 7, x + 4, y - 7);
120: }
121: g.drawLine(x - 2, y - 3, x + 4, y - 3);
122: g.drawLine(x - 2, y + 1, x + 4, y + 1);
123: g.drawLine(x - 2, y + 5, x + 4, y + 5);
124: if (!isSmallThumb) {
125: g.drawLine(x - 2, y + 9, x + 4, y + 9);
126: }
127: } else {
128: // Paints the thumbbackground
129: Graphics2D gfx = (Graphics2D) g;
130: if (PlafOptions.isOfficeScrollBarEnabled()) {
131: gfx.setPaint(new GradientPaint(0, 0,
132: thumbHighlightColor, (r.width / 2) + 1, 0,
133: thumbColor, true));
134: gfx.fillRect(0, 0, r.width - 1, r.height - 2);
135: } else {
136: gfx.setPaint(new GradientPaint(0, 0,
137: thumbHighlightColor, 0, (r.height / 2) + 1,
138: thumbColor, true));
139: gfx.fillRect(0, 0, r.width - 1, r.height - 2);
140: }
141:
142: g.setColor(thumbShadow);
143: g.drawRect(0, 0, r.width - 1, r.height - 1);
144:
145: g.setColor(thumbHighlightColor);
146: g.drawLine(1, 1, r.width - 3, 1);
147: g.drawLine(1, 1, 1, r.height - 3);
148:
149: int x = (int) r.getWidth() / 2;
150: int y = (int) r.getHeight() / 2;
151:
152: // one line = 4px; five lines = 20px
153: boolean isSmallThumb = r.getWidth() <= 20;
154:
155: g
156: .setColor(ColorUtils.getTranslucentColor(
157: thumbShadow, 200));
158: if (!isSmallThumb) {
159: g.drawLine(x - 8, y - 3, x - 8, y + 3);
160: }
161: g.drawLine(x - 4, y - 3, x - 4, y + 3);
162: g.drawLine(x, y - 3, x, y + 3);
163: g.drawLine(x + 4, y - 3, x + 4, y + 3);
164: if (!isSmallThumb) {
165: g.drawLine(x + 8, y - 3, x + 8, y + 3);
166: }
167:
168: g.setColor(ColorUtils.getTranslucentColor(
169: thumbHighlightColor, 200));
170: if (!isSmallThumb) {
171: g.drawLine(x - 7, y - 2, x - 7, y + 4);
172: }
173: g.drawLine(x - 3, y - 2, x - 3, y + 4);
174: g.drawLine(x + 1, y - 2, x + 1, y + 4);
175: g.drawLine(x + 5, y - 2, x + 5, y + 4);
176: if (!isSmallThumb) {
177: g.drawLine(x + 9, y - 2, x + 9, y + 4);
178: }
179: }
180: }
181:
182: protected JButton createDecreaseButton(int orientation) {
183: decreaseButton = new PgsScrollBarButton(orientation,
184: scrollBarWidth, isFreeStanding);
185: return decreaseButton;
186: }
187:
188: protected JButton createIncreaseButton(int orientation) {
189: increaseButton = new PgsScrollBarButton(orientation,
190: scrollBarWidth, isFreeStanding);
191: return increaseButton;
192: }
193: }
|