001: package org.zilonis.tool.ext.aerith.ui;
002:
003: import java.awt.AlphaComposite;
004: import java.awt.BasicStroke;
005: import java.awt.Color;
006: import java.awt.Composite;
007: import java.awt.GradientPaint;
008: import java.awt.Graphics;
009: import java.awt.Graphics2D;
010: import java.awt.Paint;
011: import java.awt.Rectangle;
012: import java.awt.RenderingHints;
013: import java.awt.Stroke;
014: import java.awt.geom.Area;
015: import java.awt.geom.Rectangle2D;
016: import java.awt.geom.RoundRectangle2D;
017: import javax.swing.JButton;
018: import javax.swing.JComponent;
019: import javax.swing.JScrollBar;
020: import javax.swing.plaf.metal.MetalScrollBarUI;
021:
022: public class AerithScrollbarUI extends MetalScrollBarUI {
023: @Override
024: public void installUI(JComponent c) {
025: super .installUI(c);
026: c.setOpaque(false);
027: }
028:
029: @Override
030: protected JButton createDecreaseButton(int orientation) {
031: decreaseButton = new AerithScrollButton(orientation,
032: scrollBarWidth, isFreeStanding);
033: return decreaseButton;
034: }
035:
036: @Override
037: protected JButton createIncreaseButton(int orientation) {
038: increaseButton = new AerithScrollButton(orientation,
039: scrollBarWidth, isFreeStanding);
040: return increaseButton;
041: }
042:
043: @Override
044: protected void paintTrack(Graphics g, JComponent c,
045: Rectangle trackBounds) {
046: Graphics2D g2 = (Graphics2D) g;
047: g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
048: RenderingHints.VALUE_ANTIALIAS_ON);
049:
050: if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
051: int width = trackBounds.width - 4;
052: int height = trackBounds.height;
053:
054: g2.translate(trackBounds.x + 2, trackBounds.y);
055:
056: Rectangle2D casing = new Rectangle2D.Double(0, 0, width,
057: height);
058: g2.setColor(Color.WHITE);
059:
060: float alpha = 0.5f;
061: Composite composite = g2.getComposite();
062: if (composite instanceof AlphaComposite) {
063: alpha *= ((AlphaComposite) composite).getAlpha();
064: }
065: g2.setComposite(AlphaComposite.getInstance(
066: AlphaComposite.SRC_OVER, alpha));
067: g2.fill(casing);
068: g2.setComposite(composite);
069:
070: g2.drawLine(-1, 0, -1, height);
071: g2.drawLine(-2, 0, -2, height);
072:
073: g2.drawLine(width, 0, width, height);
074: g2.drawLine(width + 1, 0, width + 1, height);
075:
076: RoundRectangle2D roundCasing = new RoundRectangle2D.Double(
077: 0, 2, width, height - 4, width, width);
078: Area area = new Area(casing);
079: area.subtract(new Area(roundCasing));
080: g2.fill(area);
081:
082: g2.translate(-trackBounds.x - 2, -trackBounds.y);
083: } else {
084: int width = trackBounds.width;
085: int height = trackBounds.height - 4;
086:
087: g2.translate(trackBounds.x, trackBounds.y + 2);
088:
089: Rectangle2D casing = new Rectangle2D.Double(0, 0, width,
090: height);
091: g2.setColor(Color.WHITE);
092:
093: float alpha = 0.5f;
094: Composite composite = g2.getComposite();
095: if (composite instanceof AlphaComposite) {
096: alpha *= ((AlphaComposite) composite).getAlpha();
097: }
098: g2.setComposite(AlphaComposite.getInstance(
099: AlphaComposite.SRC_OVER, alpha));
100: g2.fill(casing);
101: g2.setComposite(composite);
102:
103: g2.drawLine(0, -1, width, -1);
104: g2.drawLine(0, -2, width, -2);
105:
106: g2.drawLine(0, height, width, height);
107: g2.drawLine(0, height + 1, width, height + 1);
108:
109: RoundRectangle2D roundCasing = new RoundRectangle2D.Double(
110: 2, 0, width - 4, height, height, height);
111: Area area = new Area(casing);
112: area.subtract(new Area(roundCasing));
113: g2.fill(area);
114:
115: g2.translate(-trackBounds.x, -trackBounds.y - 2);
116: }
117:
118: }
119:
120: @Override
121: protected void paintThumb(Graphics g, JComponent c,
122: Rectangle thumbBounds) {
123: Graphics2D g2 = (Graphics2D) g;
124: g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
125: RenderingHints.VALUE_ANTIALIAS_ON);
126:
127: if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
128: g2.translate(thumbBounds.x + 1, thumbBounds.y + 2);
129:
130: int width = thumbBounds.width - 3;
131: int height = thumbBounds.height - 4;
132:
133: RoundRectangle2D casing = new RoundRectangle2D.Double(0, 0,
134: width, height, width, width);
135: g2.setColor(Color.WHITE);
136:
137: //float alpha = 0.7f;
138: //Composite composite = g2.getComposite();
139: //if (composite instanceof AlphaComposite) {
140: // alpha *= ((AlphaComposite) composite).getAlpha();
141: // }
142: //g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
143: Paint paint = g2.getPaint();
144: g2.setPaint(new GradientPaint(0, 0, new Color(0x818a9b), 0,
145: height, new Color(0x3a4252)));
146: g2.fill(casing);
147: //g2.setComposite(composite);
148: g2.setPaint(paint);
149: // g2.setComposite(composite);
150:
151: Stroke stroke = g2.getStroke();
152: g2.setStroke(new BasicStroke(2.0f));
153: g2.draw(casing);
154: g2.setStroke(stroke);
155:
156: g2.translate(-thumbBounds.x - 1, -thumbBounds.y - 2);
157: } else {
158: g2.translate(thumbBounds.x + 2, thumbBounds.y + 1);
159:
160: int width = thumbBounds.width - 4;
161: int height = thumbBounds.height - 3;
162:
163: RoundRectangle2D casing = new RoundRectangle2D.Double(0, 0,
164: width, height, height, height);
165: g2.setColor(Color.WHITE);
166:
167: // float alpha = 0.7f;
168: // Composite composite = g2.getComposite();
169: // if (composite instanceof AlphaComposite) {
170: // alpha *= ((AlphaComposite) composite).getAlpha();
171: // }
172: // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
173: Paint paint = g2.getPaint();
174: g2.setPaint(new GradientPaint(0, 0, new Color(0x818a9b), 0,
175: height, new Color(0x3a4252)));
176: g2.fill(casing);
177: g2.setPaint(paint);
178: // g2.setComposite(composite);
179:
180: Stroke stroke = g2.getStroke();
181: g2.setStroke(new BasicStroke(2.0f));
182: g2.draw(casing);
183: g2.setStroke(stroke);
184:
185: g2.translate(-thumbBounds.x - 2, -thumbBounds.y - 1);
186: }
187: }
188: }
|