/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/basic/FantasiaFaderUI.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/basic/FantasiaFaderUI.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1785 - (show annotations) (download)
Tue Oct 7 00:07:14 2008 UTC (15 years, 6 months ago) by iliev
File size: 9388 byte(s)
* Fantasia: Implemented multiple channels panels
* Fantasia: Refactoring - all basic UI components moved to
  org.jsampler.view.fantasia.basic package

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view.fantasia.basic;
24
25 import java.awt.AlphaComposite;
26 import java.awt.Color;
27 import java.awt.Dimension;
28 import java.awt.GradientPaint;
29 import java.awt.Graphics;
30 import java.awt.Graphics2D;
31 import java.awt.RenderingHints;
32
33 import java.awt.event.MouseEvent;
34
35 import java.awt.geom.Arc2D;
36 import java.awt.geom.Line2D;
37 import java.awt.geom.Rectangle2D;
38 import java.awt.geom.RoundRectangle2D;
39
40 import javax.swing.ButtonModel;
41 import javax.swing.DefaultButtonModel;
42 import javax.swing.JSlider;
43
44 import javax.swing.event.ChangeEvent;
45 import javax.swing.event.ChangeListener;
46
47 import javax.swing.plaf.basic.BasicSliderUI;
48
49 import org.jvnet.substance.utils.RolloverControlListener;
50 import org.jvnet.substance.utils.Trackable;
51
52 /**
53 *
54 * @author Grigor Iliev
55 */
56 public class FantasiaFaderUI extends BasicSliderUI implements Trackable {
57 private ButtonModel knobModel = new DefaultButtonModel();
58 private RolloverControlListener rolloverListener =
59 new RolloverControlListener(this, knobModel);
60
61 public
62 FantasiaFaderUI(JSlider slider) {
63 super(slider);
64 slider.setOpaque(false);
65 }
66
67 @Override
68 protected void
69 installListeners(JSlider slider) {
70 super.installListeners(slider);
71
72 rolloverListener = new RolloverControlListener(this, knobModel);
73 slider.addMouseListener(rolloverListener);
74 slider.addMouseMotionListener(rolloverListener);
75
76 knobModel.addChangeListener(getHandler());
77 }
78
79 @Override
80 protected void
81 uninstallListeners(JSlider slider) {
82 super.uninstallListeners(slider);
83 slider.removeMouseListener(rolloverListener);
84 slider.removeMouseMotionListener(rolloverListener);
85 rolloverListener = null;
86
87 knobModel.removeChangeListener(getHandler());
88 }
89
90 @Override
91 public void
92 paintTrack(Graphics g) {
93 Graphics2D g2 = (Graphics2D)g;
94
95 if(slider.getOrientation() == JSlider.HORIZONTAL) {
96 int cy = (trackRect.height / 2) - 3;
97 int cw = trackRect.width;
98
99 g.translate(trackRect.x, trackRect.y + cy);
100
101 Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, cw - 1, 3);
102 g2.setPaint(new Color(0x4b4b4b));
103 g2.fill(rect);
104
105 FantasiaPainter.paintBoldInnerBorder(g2, 0, 0, cw - 1, 3);
106
107 g.translate(-trackRect.x, -(trackRect.y + cy));
108
109
110 } else {
111 int cx = (trackRect.width / 2) - 2;
112 int ch = trackRect.height;
113
114 g.translate(trackRect.x + cx, trackRect.y);
115
116 Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, 3, ch - 1);
117 g2.setPaint(new Color(0x4b4b4b));
118 g2.fill(rect);
119
120 FantasiaPainter.paintBoldInnerBorder(g2, 0, 0, 3, ch - 1);
121
122 g.translate(-(trackRect.x + cx), -trackRect.y);
123
124
125 }
126
127 }
128
129 Color c1 = new Color(0x888888);
130 Color c2 = new Color(0x555555);
131 Color c3 = new Color(0xf5f5f5);
132 Color c4 = new Color(0.0f, 0.0f, 0.0f, 0.10f);
133 Color c6 = new Color(0.0f, 0.0f, 0.0f, 0.50f);
134 Color c8 = new Color(0.0f, 0.0f, 0.0f, 0.78f);
135
136 Color c12 = new Color(1.0f, 1.0f, 1.0f, 0.02f);
137 Color c14 = new Color(1.0f, 1.0f, 1.0f, 0.22f);
138 Color c16 = new Color(1.0f, 1.0f, 1.0f, 0.50f);
139 Color c18 = new Color(1.0f, 1.0f, 1.0f, 0.78f);
140
141 public void
142 paintHorizontalLine(Graphics2D g2, double cy, double x1, double x2, Color c) {
143 float r = c.getRed();
144 r /= 255;
145 float g = c.getGreen();
146 g /= 255;
147 float b = c.getBlue();
148 b /= 255;
149
150 GradientPaint gr = new GradientPaint (
151 (float)x1, (float)cy, new Color(r, g, b, 0.40f),
152 (float)x1 + 3, (float)cy, c
153 );
154
155 Line2D.Double l;
156 l = new Line2D.Double(x1, cy, x1 + 3, cy);
157
158 g2.setPaint(gr);
159 g2.draw(l);
160
161 g2.setPaint(c);
162 l = new Line2D.Double(x1 + 4, cy, x2 - 5, cy);
163 g2.draw(l);
164
165 gr = new GradientPaint (
166 (float)x2 - 4, (float)cy, c,
167 (float)x2, (float)cy, new Color(r, g, b, 0.10f)
168 );
169
170 l = new Line2D.Double(x2 - 4, cy, x2, cy);
171 g2.setPaint(gr);
172 g2.draw(l);
173 }
174
175 public void
176 paintVerticalLine(Graphics2D g2, double cx, double y1, double y2, Color c) {
177 float r = c.getRed();
178 r /= 255;
179 float g = c.getGreen();
180 g /= 255;
181 float b = c.getBlue();
182 b /= 255;
183
184 GradientPaint gr = new GradientPaint (
185 (float)cx, (float)y1, new Color(r, g, b, 0.40f),
186 (float)cx, (float)y1 + 3, c
187 );
188
189 Line2D.Double l = new Line2D.Double(cx, y1, cx, y1 + 3);
190 g2.setPaint(gr);
191 g2.draw(l);
192
193 g2.setPaint(c);
194 l = new Line2D.Double(cx, y1 + 4, cx, y2 - 7);
195 g2.draw(l);
196
197 gr = new GradientPaint (
198 (float)cx, (float)y2 - 6, c,
199 (float)cx, (float)y2, new Color(r, g, b, 0.00f)
200 );
201
202 l = new Line2D.Double(cx, y2 - 6, cx, y2);
203 g2.setPaint(gr);
204 g2.draw(l);
205 }
206
207 @Override
208 public void
209 paintThumb(Graphics g) {
210 Graphics2D g2 = (Graphics2D)g;
211
212 g2.setRenderingHint (
213 RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON
214 );
215
216 double h = thumbRect.getHeight();
217 double w = thumbRect.getWidth();
218
219 double x1 = thumbRect.x + 2;
220 double y1 = thumbRect.y + 1;
221 double x2 = thumbRect.x + w - 3;
222 double y2 = thumbRect.y + h - 5;
223
224 // body
225
226 RoundRectangle2D.Double rect = new RoundRectangle2D.Double (
227 x1, y1, x2 - x1 + 1, y2 - y1 + 1, 8, 8
228 );
229
230 Color color = knobModel.isRollover() ? new Color(0x999999) : c1;
231 if(knobModel.isPressed()) color = new Color(0x777777);
232 GradientPaint gr = new GradientPaint (
233 (float)x1, (float)y1, color,
234 (float)x1, (float)y2, c2
235 );
236
237 g2.setPaint(gr);
238 g2.fill(rect);
239
240 //border
241 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50f);
242 g2.setComposite(ac);
243 g2.setPaint(Color.BLACK);
244
245 rect = new RoundRectangle2D.Double (
246 x1 - 1, y1 - 1, x2 - x1 + 2, y2 - y1 + 1, 6, 6
247 );
248 g2.draw(rect);
249
250 g2.setComposite(ac.derive(1.0f));
251 gr = new GradientPaint (
252 (float)x1, (float)y1 + 1, c14, (float)x1, (float)y1 + 3, c12
253 );
254
255 g2.setPaint(gr);
256
257 Arc2D.Double arc = new Arc2D.Double(x1, y1, x2 - x1, 4, 0, 180, Arc2D.OPEN);
258 //g2.setPaint(Color.WHITE);
259 g2.draw(arc);
260 ///////
261
262
263 // Shadow down
264 gr = new GradientPaint (
265 (float)x1, (float)y2 - 4, c6, (float)x1, (float)y2 + 4, c4
266 );
267
268 g2.setPaint(gr);
269
270 g2.setComposite(ac.derive(0.70f));
271 arc = new Arc2D.Double(x1 - 1, y2 - 4, x2 - x1 + 3, 7, 180, 180, Arc2D.PIE);
272 g2.fill(arc);
273
274 g2.setPaint(Color.BLACK);
275 g2.setComposite(ac.derive(0.07f));
276 arc = new Arc2D.Double(x1 - 1, y2 - 3, x2 - x1 + 2, 5, 180, 180, Arc2D.OPEN);
277 g2.draw(arc);
278
279 g2.setPaint(Color.BLACK);
280 g2.setComposite(ac.derive(0.20f));
281 Line2D.Double l = new Line2D.Double(x1 + 3, y2 + 1, x2 - 3, y2 + 1);
282 g2.draw(l); // right
283 ///////
284
285
286
287 g2.setPaint(c3);
288 g2.setComposite(ac.derive(0.06f));
289 l = new Line2D.Double(x1 + 6, y1 - 1, x1 + 8, y1 - 1);
290 g2.draw(l);
291
292
293
294 if(slider.getOrientation() == JSlider.HORIZONTAL) {
295 double cx = (int)thumbRect.x + w / 2;
296
297 // center line
298 g2.setComposite(ac.derive(1.0f));
299 paintVerticalLine(g2, cx, y1, y2, c3);
300
301 // center down line
302 g2.setComposite(ac.derive(0.30f));
303 paintVerticalLine(g2, cx - 1, y1, y2, Color.BLACK);
304 ///
305
306 // center up line
307 g2.setPaint(Color.WHITE);
308 g2.setComposite(ac.derive(0.10f));
309 paintVerticalLine(g2, cx + 1, y1, y2, Color.WHITE);
310 } else {
311 double cy = (int) thumbRect.y + h / 2 - 2;
312 // center line
313 g2.setComposite(ac.derive(1.0f));
314 paintHorizontalLine(g2, cy, x1, x2, c3);
315
316 // center down line
317 g2.setComposite(ac.derive(0.30f));
318 paintHorizontalLine(g2, cy - 1, x1, x2, Color.BLACK);
319 ///
320
321 // center up line
322 g2.setPaint(Color.WHITE);
323 g2.setComposite(ac.derive(0.10f));
324 paintHorizontalLine(g2, cy + 1, x1, x2, Color.WHITE);
325 ///
326 }
327
328 // border shadow
329 g2.setPaint(Color.BLACK);
330 g2.setComposite(ac.derive(0.10f));
331 l = new Line2D.Double(x2, y1 + 1, x2, y2 - 2);
332 g2.draw(l); // right
333
334
335 g2.setComposite(ac.derive(0.06f));
336 l = new Line2D.Double(x1 - 2, y1 + 2, x1 - 2, y2 - 2);
337 g2.draw(l);// left
338
339 l = new Line2D.Double(x2 + 2, y1 + 2, x2 + 2, y2 - 2);
340 g2.draw(l); // right
341 ///
342 }
343
344 @Override
345 public boolean
346 isInside(MouseEvent e) {
347 if(thumbRect == null) return false;
348 return thumbRect.contains(e.getX(), e.getY());
349 }
350
351 private final Handler handler = new Handler();
352
353 private Handler
354 getHandler() { return handler; }
355
356 private class Handler implements ChangeListener {
357 @Override
358 public void stateChanged(ChangeEvent e) {
359 slider.repaint(thumbRect);
360 }
361
362 }
363
364
365 @Override
366 protected Dimension
367 getThumbSize() {
368 Dimension d = (Dimension)slider.getClientProperty("Fader.knobSize");
369 if(d != null) return d;
370 return slider.getOrientation() == JSlider.VERTICAL ?
371 new Dimension(27, 20) : new Dimension(17, 27);
372 }
373 }

  ViewVC Help
Powered by ViewVC