1 package com.bric.multislider;
2
3 import java.awt.BasicStroke;
4 import java.awt.Color;
5 import java.awt.Dimension;
6 import java.awt.Graphics2D;
7 import java.awt.LinearGradientPaint;
8 import java.awt.Paint;
9 import java.awt.RenderingHints;
10 import java.awt.Shape;
11 import java.awt.geom.Point2D;
12 import java.awt.geom.Rectangle2D;
13
14 public class VistaMultiThumbSliderUI<T> extends DefaultMultiThumbSliderUi<T>
15 {
16
17
18
19
20 public VistaMultiThumbSliderUI(MultiThumbSlider<T> slider)
21 {
22 super(slider);
23 this.DEPTH = 8;
24 this.FOCUS_PADDING = 2;
25 this.trackHighlightColor = new Color(0x3a99fc);
26 }
27
28 @Override
29 protected int getPreferredComponentDepth()
30 {
31 return 22;
32 }
33
34 @Override
35 protected void paintFocus(Graphics2D g)
36 {
37
38 }
39
40 @Override
41 protected Dimension getThumbSize(int thumbIndex)
42 {
43 Thumb thumb = getThumb(thumbIndex);
44 if (Thumb.Hourglass.equals(thumb))
45 {
46 return new Dimension(8, 16);
47 }
48 else if (Thumb.Triangle.equals(thumb))
49 {
50 return new Dimension(10, 18);
51 }
52 else if (Thumb.Rectangle.equals(thumb))
53 {
54 return new Dimension(10, 20);
55 }
56 else
57 {
58 return new Dimension(16, 16);
59 }
60 }
61
62 @Override
63 protected void paintTrack(Graphics2D g)
64 {
65 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
66 Shape trackShape = getTrackOutline();
67
68 Paint fill = new Color(0xc0c0c0);
69 g.setPaint(fill);
70 g.fill(trackShape);
71 g.setPaint(new Color(0, 0, 0, 96));
72 g.drawLine(this.trackRect.x, this.trackRect.y, this.trackRect.x + this.trackRect.width, this.trackRect.y);
73 g.drawLine(this.trackRect.x, this.trackRect.y, this.trackRect.x, this.trackRect.y + this.trackRect.height);
74 g.drawLine(this.trackRect.x + this.trackRect.width, this.trackRect.y, this.trackRect.x + this.trackRect.width,
75 this.trackRect.y + this.trackRect.height);
76 g.setPaint(new Color(255, 255, 255, 16));
77 g.drawLine(this.trackRect.x, this.trackRect.y + this.trackRect.height, this.trackRect.x + this.trackRect.width,
78 this.trackRect.y + this.trackRect.height);
79
80 paintTrackHighlight(g);
81
82 if (this.slider.isPaintTicks())
83 {
84 g.setColor(new Color(0, 0, 0, 40));
85 g.setStroke(new BasicStroke(1));
86 paintTick(g, .25f, 4, 8, false);
87 paintTick(g, .5f, 4, 8, false);
88 paintTick(g, .75f, 4, 8, false);
89 paintTick(g, 0f, 4, 8, false);
90 paintTick(g, 1f, 4, 8, false);
91 }
92 }
93
94 @Override
95 protected Shape getTrackOutline()
96 {
97 this.trackRect = calculateTrackRect();
98 return this.trackRect;
99 }
100
101 @Override
102 protected void paintThumb(Graphics2D g, int thumbIndex, float selected)
103 {
104 Shape outline = getThumbShape(thumbIndex);
105
106 Rectangle2D thumbBounds = ShapeBounds.getBounds(outline);
107
108 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
109 g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
110 Paint fill;
111 Paint strokePaint;
112 if (this.mouseIsDown && thumbIndex == this.slider.getSelectedThumb())
113 {
114 fill = new LinearGradientPaint(new Point2D.Double(0, thumbBounds.getMinY()),
115 new Point2D.Double(0, thumbBounds.getMaxY()), new float[] {0, .55f, .5501f, 1},
116 new Color[] {new Color(0xe5f4fc), new Color(0x9dd5f3), new Color(0x6cbbe5), new Color(0x50a1cc)});
117 strokePaint = new Color(0x2c628b);
118 }
119 else
120 {
121 fill = new LinearGradientPaint(new Point2D.Double(0, thumbBounds.getMinY()),
122 new Point2D.Double(0, thumbBounds.getMaxY()), new float[] {0, .55f, .5501f, 1},
123 new Color[] {tween(new Color(0xf2f2f2), new Color(0xe9f6fd), selected),
124 tween(new Color(0xebebeb), new Color(0xd8effc), selected),
125 tween(new Color(0xdbdbdb), new Color(0xbde6fd), selected),
126 tween(new Color(0xd7d7d7), new Color(0xaedef8), selected)});
127 strokePaint = tween(new Color(0x707070), new Color(0x3c7fb1), selected);
128 }
129 g.setPaint(fill);
130 g.fill(outline);
131
132 Graphics2D g2 = (Graphics2D) g.create();
133 g2.clip(outline);
134 g2.setColor(new Color(255, 255, 255, 200));
135 g2.setStroke(new BasicStroke(4));
136 g2.draw(outline);
137 g2.dispose();
138
139 g.setStroke(new BasicStroke(1f));
140 g.setPaint(strokePaint);
141 g.draw(outline);
142 }
143
144 private static final Color tween(Color c1, Color c2, float f)
145 {
146 if (f < 0)
147 f = 0;
148 if (f > 1)
149 f = 1;
150 int r = (int) (c1.getRed() * (1 - f) + f * c2.getRed());
151 int g = (int) (c1.getGreen() * (1 - f) + f * c2.getGreen());
152 int b = (int) (c1.getBlue() * (1 - f) + f * c2.getBlue());
153 int a = (int) (c1.getAlpha() * (1 - f) + f * c2.getAlpha());
154 return new Color(r, g, b, a);
155 }
156 }