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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2146 - (show annotations) (download)
Mon Oct 11 09:31:27 2010 UTC (13 years, 6 months ago) by iliev
File size: 22860 byte(s)
* Fantasia: Migrated to substance 6.1
* Fantasia: Some minor GUI enhancements

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2010 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.Composite;
28 import java.awt.GradientPaint;
29 import java.awt.Graphics;
30 import java.awt.Graphics2D;
31 import java.awt.Insets;
32 import java.awt.Paint;
33 import java.awt.RenderingHints;
34
35 import java.awt.geom.Area;
36 import java.awt.geom.Line2D;
37 import java.awt.geom.Rectangle2D;
38
39 import javax.swing.JComponent;
40
41 /**
42 *
43 * @author Grigor Iliev
44 */
45 public class FantasiaPainter {
46 public static Color color1 = new Color(0x434343);
47 public static Color color2 = new Color(0x535353);
48 public static Color color4 = new Color(0x6e6e6e);
49 public static Color color5 = new Color(0x7a7a7a);
50 public static Color color6 = new Color(0x8a8a8a);
51 public static Color color7 = new Color(0x9a9a9a);
52
53 public static class RoundCorners {
54 public boolean topLeft, bottomLeft, bottomRight, topRight;
55
56 public
57 RoundCorners(boolean round) {
58 this(round, round, round, round);
59 }
60
61 public
62 RoundCorners(boolean topLeft, boolean bottomLeft, boolean bottomRight, boolean topRight) {
63 this.topLeft = topLeft;
64 this.topRight = topRight;
65 this.bottomLeft = bottomLeft;
66 this.bottomRight = bottomRight;
67 }
68 }
69
70 public static class Border {
71 public boolean paintTop, paintLeft, paintBottom, paintRight;
72
73 public
74 Border(boolean paintBorder) {
75 this(paintBorder, paintBorder, paintBorder, paintBorder);
76 }
77
78 public
79 Border(boolean paintTop, boolean paintLeft, boolean paintBottom, boolean paintRight) {
80 this.paintTop = paintTop;
81 this.paintLeft = paintLeft;
82 this.paintBottom = paintBottom;
83 this.paintRight = paintRight;
84 }
85 }
86
87 private
88 FantasiaPainter() { }
89
90 public static void
91 paintGradient(Graphics2D g2, double x1, double y1, double x2, double y2) {
92 paintGradient(g2, x1, y1, x2, y2, color5, color4);
93 }
94
95 public static void
96 paintDarkGradient(Graphics2D g2, double x1, double y1, double x2, double y2) {
97 paintGradient(g2, x1, y1, x2, y2, color2, color1);
98 }
99
100 public static void
101 paintGradient(Graphics2D g2, double x1, double y1, double x2, double y2, Color c1, Color c2) {
102 Paint oldPaint = g2.getPaint();
103
104 Rectangle2D.Double rect = new Rectangle2D.Double(x1, y1, x2 - x1 + 1, y2 -y1 + 1);
105
106 GradientPaint gr = new GradientPaint (
107 (float)x1, (float)y1, c1,
108 (float)x1, (float)y2, c2
109 );
110
111 g2.setPaint(gr);
112 g2.fill(rect);
113
114 g2.setPaint(oldPaint);
115 }
116
117 public static void
118 paintOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
119 paintOuterBorder(g2, x1, y1, x2, y2, false);
120 }
121
122 public static void
123 paintOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2, boolean round) {
124 paintOuterBorder(g2, x1, y1, x2, y2, round, 1.0f, 1.0f);
125 }
126
127 public static void
128 paintOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2, RoundCorners rc) {
129 paintOuterBorder(g2, x1, y1, x2, y2, rc, 1.0f, 1.0f);
130 }
131
132 public static void
133 paintOuterBorder (
134 Graphics2D g2,
135 double x1, double y1, double x2, double y2,
136 boolean round, float alphaWhite, float alphaBlack
137 ) {
138 paintOuterBorder(g2, x1, y1, x2, y2, new RoundCorners(round), alphaWhite, alphaBlack);
139 }
140
141 public static void
142 paintOuterBorder (
143 Graphics2D g2,
144 double x1, double y1, double x2, double y2,
145 boolean round, float alphaTop, float alphaLeft, float alphaBottom, float alphaRight
146 ) {
147 paintOuterBorder (
148 g2, x1, y1, x2, y2, new RoundCorners(round), 1.0f, 1.0f,
149 alphaTop, alphaLeft, alphaBottom, alphaRight
150 );
151 }
152
153 public static void
154 paintOuterBorder (
155 Graphics2D g2,
156 double x1, double y1, double x2, double y2,
157 RoundCorners rc, float alphaWhite, float alphaBlack
158 ) {
159 paintOuterBorder (
160 g2, x1, y1, x2, y2, rc, alphaWhite, alphaBlack,
161 alphaWhite * 0.40f, alphaWhite * 0.255f, alphaBlack * 0.40f, alphaBlack * 0.20f
162 );
163 }
164 public static void
165 paintOuterBorder (
166 Graphics2D g2,
167 double x1, double y1, double x2, double y2, RoundCorners rc,
168 float alphaWhite, float alphaBlack,
169 float alphaTop, float alphaLeft, float alphaBottom, float alphaRight
170 ) {
171
172 Paint oldPaint = g2.getPaint();
173 Composite oldComposite = g2.getComposite();
174
175 AlphaComposite ac;
176 ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaTop);
177 g2.setComposite(ac);
178
179 double x1t = rc.topLeft ? x1 + 2 : x1;
180 double x1b = rc.bottomLeft ? x1 + 2 : x1;
181 double x2t = rc.topRight ? x2 - 2 : x2;
182 double x2b = rc.bottomRight ? x2 - 2 : x2;
183 double y1l = rc.topLeft ? y1 + 2 : y1;
184 double y1r = rc.topRight ? y1 + 2 : y1;
185 double y2l = rc.bottomLeft ? y2 - 2 : y2;
186 double y2r = rc.bottomRight ? y2 - 2 : y2;
187
188 g2.setPaint(Color.WHITE);
189 Line2D.Double l = new Line2D.Double(x1t, y1, x2t, y1);
190 g2.draw(l);
191
192 if(rc.topLeft) {
193 // top-left corner
194 g2.setComposite(ac.derive(0.30f * alphaWhite));
195 l = new Line2D.Double(x1 + 1, y1, x1 + 1, y1);
196 g2.draw(l);
197
198 g2.setComposite(ac.derive(0.20f * alphaWhite));
199 l = new Line2D.Double(x1 + 1, y1 + 1, x1 + 1, y1 + 1);
200 g2.draw(l);
201
202 g2.setComposite(ac.derive(0.15f * alphaWhite));
203 l = new Line2D.Double(x1, y1 + 1, x1, y1 + 1);
204 g2.draw(l);
205
206 g2.setPaint(Color.BLACK);
207 g2.setComposite(ac.derive(0.15f * alphaBlack));
208 l = new Line2D.Double(x1, y1, x1, y1);
209 g2.draw(l);
210
211 g2.setPaint(Color.WHITE);
212 }
213
214 if(rc.topRight) {
215 // top-right corner
216 g2.setPaint(Color.WHITE);
217 g2.setComposite(ac.derive(0.20f * alphaWhite));
218 l = new Line2D.Double(x2 - 1, y1, x2 - 1, y1);
219 g2.draw(l);
220
221 g2.setComposite(ac.derive(0.10f * alphaWhite));
222 l = new Line2D.Double(x2 - 1, y1 + 1, x2 - 1, y1 + 1);
223 g2.draw(l);
224 }
225
226 g2.setComposite(ac.derive(alphaLeft));
227
228 l = new Line2D.Double(x1, y1l, x1, y2l);
229 g2.draw(l);
230
231 g2.setComposite(ac.derive(alphaBottom));
232 g2.setPaint(Color.BLACK);
233
234 l = new Line2D.Double(x1b, y2, x2b, y2);
235 g2.draw(l);
236
237 if(rc.bottomLeft) {
238 // bottom-left corner
239 l = new Line2D.Double(x1, y2, x1, y2);
240 g2.draw(l);
241
242 g2.setComposite(ac.derive(0.30f * alphaBlack));
243 l = new Line2D.Double(x1 + 1, y2, x1 + 1, y2);
244 g2.draw(l);
245
246 g2.setComposite(ac.derive(0.10f * alphaBlack));
247 l = new Line2D.Double(x1 + 1, y2 - 1, x1 + 1, y2 - 1);
248 g2.draw(l);
249
250 g2.setPaint(Color.WHITE);
251 g2.setComposite(ac.derive(0.05f * alphaWhite));
252 l = new Line2D.Double(x1, y2 - 1, x1, y2 - 1);
253 g2.draw(l);
254 g2.setPaint(Color.BLACK);
255 }
256
257 g2.setComposite(ac.derive(alphaRight));
258
259 l = new Line2D.Double(x2, y1r, x2, y2r);
260 g2.draw(l);
261
262 if(rc.topRight) {
263 //top-right corner
264 g2.setComposite(ac.derive(0.15f * alphaBlack));
265 l = new Line2D.Double(x2, y1 + 1, x2, y1 + 1);
266 g2.draw(l);
267
268 g2.setComposite(ac.derive(0.25f * alphaBlack));
269 l = new Line2D.Double(x2, y1, x2, y1);
270 g2.draw(l);
271 }
272
273 if(rc.bottomRight) {
274 //bottom-right corner
275 g2.setComposite(ac.derive(0.30f * alphaBlack));
276 l = new Line2D.Double(x2, y2 - 1, x2, y2 - 1);
277 g2.draw(l);
278
279 g2.setComposite(ac.derive(0.10f * alphaBlack));
280 l = new Line2D.Double(x2 - 1, y2 - 1, x2 - 1, y2 - 1);
281 g2.draw(l);
282
283 g2.setComposite(ac.derive(0.43f * alphaBlack));
284 l = new Line2D.Double(x2, y2, x2, y2);
285 g2.draw(l);
286
287 g2.setComposite(ac.derive(0.38f * alphaBlack));
288 l = new Line2D.Double(x2 - 1, y2, x2 - 1, y2);
289 g2.draw(l);
290 }
291
292 g2.setComposite(oldComposite);
293 g2.setPaint(oldPaint);
294 }
295
296 public static void
297 paintBoldOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
298 paintBoldOuterBorder(g2, x1, y1, x2, y2, new Border(true));
299 }
300
301 public static void
302 paintBoldOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2, Border border) {
303 Paint oldPaint = g2.getPaint();
304 Composite oldComposite = g2.getComposite();
305
306 if(border.paintTop) {
307 paintTopBoldOuterBorder(g2, x1 + 2, y1, x2 - 2, y1);
308 paintTopBoldRoundCorners(g2, x1, y1, x2, y2);
309 }
310
311 if(border.paintLeft) {
312 paintLeftBoldOuterBorder(g2, x1, y1, x2, y2);
313 }
314
315 if(border.paintBottom) {
316 paintBottomBoldOuterBorder(g2, x1, y1, x2, y2);
317 }
318
319 paintBottomLeftBoldRoundCorner(g2, x1, y2);
320
321 if(border.paintRight) {
322 paintRightBoldOuterBorder(g2, x1, y1, x2, y2);
323 }
324
325 paintBottomRightBoldRoundCorner(g2, x2, y2);
326
327 g2.setPaint(oldPaint);
328 g2.setComposite(oldComposite);
329 }
330
331 public static void
332 paintRightBoldOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
333 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.20f);
334 g2.setComposite(ac);
335
336 g2.setPaint(Color.BLACK);
337 Line2D.Double l = new Line2D.Double(x2, y1, x2, y2 - 3);
338 g2.draw(l);
339
340 g2.setComposite(ac.derive(0.10f));
341 l = new Line2D.Double(x2 - 1, y1, x2 - 1, y2 - 1);
342 g2.draw(l);
343 }
344
345 public static void
346 paintBottomBoldOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
347 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.40f);
348 g2.setComposite(ac);
349
350 g2.setPaint(Color.BLACK);
351 Line2D.Double l = new Line2D.Double(x1 + 3, y2, x2 - 2, y2);
352 g2.draw(l);
353
354 g2.setComposite(ac.derive(0.20f));
355 l = new Line2D.Double(x1 + 1, y2 - 1, x2 - 1, y2 - 1);
356 g2.draw(l);
357 }
358
359 public static void
360 paintLeftBoldOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
361 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.255f);
362 g2.setComposite(ac);
363
364 g2.setPaint(Color.WHITE);
365 Line2D.Double l = new Line2D.Double(x1, y1, x1, y2 - 3);
366 g2.draw(l);
367
368 g2.setComposite(ac.derive(0.10f));
369 l = new Line2D.Double(x1 + 1, y1, x1 + 1, y2 - 1);
370 g2.draw(l);
371 }
372
373 public static void
374 paintBottomRightBoldRoundCorner(Graphics2D g2, double x2, double y2) {
375 g2.setPaint(Color.BLACK);
376 // round right-down corner
377 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.37f);
378 g2.setComposite(ac);
379 Line2D.Double l = new Line2D.Double(x2 - 1, y2, x2 - 1, y2);
380 g2.draw(l);
381
382 g2.setComposite(ac.derive(0.34f));
383 l = new Line2D.Double(x2, y2, x2, y2);
384 g2.draw(l);
385 ///////
386
387 // round right corner
388 g2.setComposite(ac.derive(0.25f));
389 l = new Line2D.Double(x2, y2 - 2, x2, y2 - 2);
390 g2.draw(l);
391
392 g2.setComposite(ac.derive(0.30f));
393 l = new Line2D.Double(x2, y2 - 1, x2, y2 - 1);
394 g2.draw(l);
395 ///////
396
397 }
398
399 public static void
400 paintBottomLeftBoldRoundCorner(Graphics2D g2, double x1, double y2) {
401 g2.setPaint(Color.WHITE);
402 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.15f);
403 g2.setComposite(ac);
404 Line2D.Double l = new Line2D.Double(x1, y2 - 2, x1, y2 - 2);
405 g2.draw(l);
406
407 g2.setPaint(Color.BLACK);
408 g2.setComposite(ac.derive(0.27f));
409 l = new Line2D.Double(x1, y2, x1, y2);
410 g2.draw(l);
411
412 g2.setComposite(ac.derive(0.32f));
413 l = new Line2D.Double(x1 + 1, y2, x1 + 1, y2);
414 g2.draw(l);
415
416 g2.setComposite(ac.derive(0.37f));
417 l = new Line2D.Double(x1 + 2, y2, x1 + 2, y2);
418 g2.draw(l);
419 }
420
421 public static void
422 paintTopBoldOuterBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
423 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.40f);
424 g2.setComposite(ac);
425
426 g2.setPaint(Color.WHITE);
427 Line2D.Double l = new Line2D.Double(x1, y1, x2 - 1, y2);
428 g2.draw(l);
429
430 g2.setComposite(ac.derive(0.20f));
431 l = new Line2D.Double(x1, y1 + 1, x2, y2 + 1);
432 g2.draw(l);
433 }
434
435 public static void
436 paintTopBoldRoundCorners(Graphics2D g2, double x1, double y1, double x2, double y2) {
437 paintTopLeftBoldRoundCorner(g2, x1, y1);
438 paintTopRightBoldRoundCorner(g2, y1, x2);
439 }
440
441 public static void
442 paintTopLeftBoldRoundCorner(Graphics2D g2, double x1, double y1) {
443 Paint oldPaint = g2.getPaint();
444 Composite oldComposite = g2.getComposite();
445
446 g2.setPaint(Color.BLACK);
447
448 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.20f);
449 g2.setComposite(ac);
450 Line2D.Double l = new Line2D.Double(x1, y1, x1, y1);
451 g2.draw(l);
452
453 g2.setPaint(Color.WHITE);
454 g2.setComposite(ac.derive(0.20f));
455 l = new Line2D.Double(x1 + 1, y1, x1 + 1, y1);
456 g2.draw(l);
457
458 g2.setComposite(ac.derive(0.15f));
459 l = new Line2D.Double(x1, y1 + 1, x1, y1 + 1);
460 g2.draw(l);
461
462 g2.setComposite(ac.derive(0.30f));
463 l = new Line2D.Double(x1 + 1, y1 + 1, x1 + 1, y1 + 1);
464 g2.draw(l);
465
466 g2.setComposite(ac.derive(0.10f));
467 l = new Line2D.Double(x1, y1 + 2, x1 + 1, y1 + 2);
468 g2.draw(l);
469
470 g2.setPaint(oldPaint);
471 g2.setComposite(oldComposite);
472 }
473
474 public static void
475 paintTopRightBoldRoundCorner(Graphics2D g2, double y1, double x2) {
476 Paint oldPaint = g2.getPaint();
477 Composite oldComposite = g2.getComposite();
478
479 g2.setPaint(Color.WHITE);
480 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.30f);
481 g2.setComposite(ac);
482 Line2D.Double l = new Line2D.Double(x2 - 2, y1, x2 - 2, y1);
483 g2.draw(l);
484
485 g2.setComposite(ac.derive(0.20f));
486 l = new Line2D.Double(x2 - 1, y1, x2 - 1, y1);
487 g2.draw(l);
488
489 g2.setPaint(Color.BLACK);
490 g2.setComposite(ac.derive(0.20f));
491 l = new Line2D.Double(x2, y1, x2, y1);
492 g2.draw(l);
493
494 g2.setPaint(Color.WHITE);
495 g2.setComposite(ac.derive(0.10f));
496 l = new Line2D.Double(x2 - 1, y1 + 1, x2 - 1, y1 + 1);
497 g2.draw(l);
498
499 g2.setPaint(Color.BLACK);
500 g2.setComposite(ac.derive(0.05f));
501 l = new Line2D.Double(x2, y1 + 1, x2, y1 + 1);
502 g2.draw(l);
503
504 g2.setPaint(oldPaint);
505 g2.setComposite(oldComposite);
506 }
507
508 public static void
509 paintInnerBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
510 paintInnerBorder(g2, x1, y1, x2, y2, false);
511 }
512
513 public static void
514 paintInnerBorder(Graphics2D g2, double x1, double y1, double x2, double y2, boolean round) {
515 paintInnerBorder(g2, x1, y1, x2, y2, round, 1.0f, 1.0f);
516 }
517
518 public static void
519 paintInnerBorder (
520 Graphics2D g2,
521 double x1, double y1, double x2, double y2,
522 boolean round, float alphaWhite, float alphaBlack
523 ) {
524 Paint oldPaint = g2.getPaint();
525 Composite oldComposite = g2.getComposite();
526
527 AlphaComposite ac;
528 ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.30f * alphaWhite);
529 g2.setComposite(ac);
530
531 g2.setPaint(Color.WHITE);
532 double x1b = round ? x1 + 3 : x1;
533 double x2b = round ? x2 - 3 : x2;
534 double y1b = round ? y1 + 3 : y1;
535 double y2b = round ? y2 - 3 : y2;
536
537 Line2D.Double l = new Line2D.Double(x1b, y2, x2b, y2);
538 g2.draw(l);
539
540 // bottom-left round border
541 if(round) {
542 g2.setComposite(ac.derive(0.20f * alphaWhite));
543 l = new Line2D.Double(x1 + 2, y2, x1 + 2, y2);
544 g2.draw(l);
545
546 g2.setComposite(ac.derive(0.10f * alphaWhite));
547 l = new Line2D.Double(x1 + 1, y2, x1 + 1, y2);
548 g2.draw(l);
549
550 g2.setComposite(ac.derive(0.05f * alphaWhite));
551 l = new Line2D.Double(x1 + 1, y2 - 1, x1 + 1, y2 - 1);
552 g2.draw(l);
553 }
554 ///////
555
556 g2.setComposite(ac.derive(0.20f * alphaWhite));
557 l = new Line2D.Double(x2, y1b, x2, y2b);
558 g2.draw(l);
559
560 // bottom-right round border
561 if(round) {
562 g2.setComposite(ac.derive(0.15f * alphaWhite));
563 l = new Line2D.Double(x2, y2 - 2, x2, y2 - 2);
564 g2.draw(l);
565
566 g2.setComposite(ac.derive(0.10f * alphaWhite));
567 l = new Line2D.Double(x2, y2 - 1, x2, y2 - 1);
568 g2.draw(l);
569
570 g2.setComposite(ac.derive(0.10f * alphaWhite));
571 l = new Line2D.Double(x2 - 1, y2 - 1, x2 - 1, y2 - 1);
572 g2.draw(l);
573
574 /***/
575
576 g2.setComposite(ac.derive(0.15f * alphaWhite));
577 l = new Line2D.Double(x2 - 2, y2, x2 - 2, y2);
578 g2.draw(l);
579
580 g2.setComposite(ac.derive(0.10f * alphaWhite));
581 l = new Line2D.Double(x2 - 1, y2, x2 - 1, y2);
582 g2.draw(l);
583 }
584 ///////
585
586 g2.setComposite(ac.derive(0.20f * alphaBlack));
587 g2.setPaint(Color.BLACK);
588
589 l = new Line2D.Double(x1b, y1, x2b, y1);
590 g2.draw(l);
591
592 if(round) {
593 // top-left round border
594 g2.setComposite(ac.derive(0.05f * alphaBlack));
595 l = new Line2D.Double(x1, y1, x1, y1);
596 g2.draw(l);
597
598 g2.setComposite(ac.derive(0.10f * alphaBlack));
599 l = new Line2D.Double(x1 + 1, y1, x1 + 1, y1);
600 g2.draw(l);
601
602 g2.setComposite(ac.derive(0.15f * alphaBlack));
603 l = new Line2D.Double(x1 + 2, y1, x1 + 2, y1);
604 g2.draw(l);
605
606 g2.setPaint(Color.WHITE);
607 g2.setComposite(ac.derive(0.15f * alphaWhite));
608 l = new Line2D.Double(x1 + 1, y1 + 1, x1 + 1, y1 + 1);
609 g2.draw(l);
610
611 // top-right round border
612 g2.setComposite(ac.derive(0.05f * alphaWhite));
613 l = new Line2D.Double(x2, y1 + 1, x2, y1 + 1);
614 g2.draw(l);
615
616 g2.setComposite(ac.derive(0.10f * alphaWhite));
617 l = new Line2D.Double(x2, y1 + 2, x2, y1 + 2);
618 g2.draw(l);
619
620 g2.setComposite(ac.derive(0.15f * alphaWhite));
621 l = new Line2D.Double(x2 - 1, y1 + 1, x2 - 1, y1 + 1);
622 g2.draw(l);
623
624 g2.setPaint(Color.BLACK);
625 g2.setComposite(ac.derive(0.10f * alphaBlack));
626 l = new Line2D.Double(x2 - 2, y1, x2 - 2, y1);
627 g2.draw(l);
628
629 g2.setComposite(ac.derive(0.05f * alphaBlack));
630 l = new Line2D.Double(x2 - 1, y1, x2 - 1, y1);
631 g2.draw(l);
632 }
633
634 g2.setComposite(ac.derive(0.20f * alphaBlack));
635 l = new Line2D.Double(x1, y1b, x1, y2b);
636 g2.draw(l);
637
638 if(round) {
639 // top-left round border
640 g2.setComposite(ac.derive(0.10f * alphaBlack));
641 l = new Line2D.Double(x1, y1 + 1, x1, y1 + 1);
642 g2.draw(l);
643
644 g2.setComposite(ac.derive(0.15f * alphaBlack));
645 l = new Line2D.Double(x1, y1 + 2, x1, y1 + 2);
646 g2.draw(l);
647
648 // bottom-left round border
649 g2.setComposite(ac.derive(0.10f * alphaBlack));
650 l = new Line2D.Double(x1, y2 - 2, x1, y2 - 2);
651 g2.draw(l);
652
653 g2.setComposite(ac.derive(0.05f * alphaBlack));
654 l = new Line2D.Double(x1, y2 - 1, x1, y2 - 1);
655 g2.draw(l);
656 }
657 ///////
658
659 g2.setComposite(oldComposite);
660 g2.setPaint(oldPaint);
661 }
662
663 public static void
664 paintBoldInnerBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
665 Paint oldPaint = g2.getPaint();
666 Composite oldComposite = g2.getComposite();
667
668 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.40f);
669 g2.setComposite(ac);
670
671 g2.setPaint(Color.WHITE);
672 Line2D.Double l = new Line2D.Double(x1, y2, x2, y2);
673 g2.draw(l);
674
675 g2.setComposite(ac.derive(0.15f));
676 l = new Line2D.Double(x1 - 1, y2 + 1, x2 + 1, y2 + 1);
677 g2.draw(l);
678
679 g2.setComposite(ac.derive(0.255f));
680 l = new Line2D.Double(x2, y1, x2, y2);
681 g2.draw(l);
682
683 g2.setComposite(ac.derive(0.13f));
684 l = new Line2D.Double(x2 + 1, y1 - 1, x2 + 1, y2 + 1);
685 g2.draw(l);
686
687 g2.setComposite(ac.derive(0.20f));
688 g2.setPaint(Color.BLACK);
689
690 l = new Line2D.Double(x1 - 1, y1 - 1, x2 + 1, y1 - 1);
691 g2.draw(l);
692
693 g2.setComposite(ac.derive(0.40f));
694 g2.setPaint(Color.BLACK);
695
696 l = new Line2D.Double(x1, y1, x2, y1);
697 g2.draw(l);
698
699 g2.setComposite(ac.derive(0.20f));
700
701 l = new Line2D.Double(x1 - 1, y1 - 1, x1 - 1, y2 + 1);
702 g2.draw(l);
703
704 g2.setComposite(ac.derive(0.40f));
705
706 l = new Line2D.Double(x1, y1, x1, y2);
707 g2.draw(l);
708
709 g2.setComposite(oldComposite);
710 g2.setPaint(oldPaint);
711 }
712
713 public static void
714 paintBorder(Graphics2D g2, double x1, double y1, double x2, double y2, double size) {
715 paintBorder(g2, x1, y1, x2, y2, size, true);
716 }
717
718 public static void
719 paintBorder (
720 Graphics2D g2,
721 double x1, double y1, double x2, double y2,
722 double size,
723 boolean paintInnerBorder
724 ) {
725 Paint oldPaint = g2.getPaint();
726 Composite oldComposite = g2.getComposite();
727
728 Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, x2 - x1 + 1, y2 - y1 + 1);
729 Area area = new Area(rect);
730
731 rect = new Rectangle2D.Double (
732 x1 + size, y1 + size, x2 - x1 + 1 - (2 * size), y2 - y1 + 1 - (2 * size)
733 );
734 area.subtract(new Area(rect));
735
736 GradientPaint gr = new GradientPaint (
737 0.0f, (float)y1, FantasiaPainter.color5,
738 0.0f, (float)y2, FantasiaPainter.color4
739 );
740
741 g2.setPaint(gr);
742 g2.fill(area);
743
744 if(paintInnerBorder) {
745 paintInnerBorder (
746 g2, x1 + size - 1, y1 + size - 1, x2 - size + 1, y2 - size + 1, true
747 );
748 }
749
750 paintBoldOuterBorder(g2, x1, y1, x2, y2);
751
752 g2.setPaint(oldPaint);
753 g2.setComposite(oldComposite);
754 }
755
756 private static Color surface1Color1 = new Color(0x7a7a7a);
757 private static Color surface1Color2 = new Color(0x5e5e5e);
758 private static Color surface1Color3 = new Color(0x2e2e2e);
759
760 /**
761 * Used to paint the MIDI keyboard
762 */
763 public static void
764 paintSurface1(JComponent c, Graphics g) {
765 Graphics2D g2 = (Graphics2D)g;
766
767 Paint oldPaint = g2.getPaint();
768 Composite oldComposite = g2.getComposite();
769 Object aa = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
770
771 Insets insets = c.getInsets();
772 double x1 = insets.left;
773 double y1 = insets.top;
774
775 double w = c.getSize().getWidth();
776 double x2 = w - insets.right - 1;
777 double h = c.getSize().getHeight();
778 double y2 = h - insets.bottom - 1;
779
780 g2.setRenderingHint (
781 RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF
782 );
783
784 FantasiaPainter.paintGradient(g2, x1, y1, x2, y2 - 10, surface1Color1, surface1Color2);
785
786 double y3 = y2 - 10;
787 if(y3 < 0) y3 = 0;
788
789 Rectangle2D.Double rect = new Rectangle2D.Double(x1, y3, x2 - x1 + 1, 11);
790
791 GradientPaint gr = new GradientPaint (
792 0.0f, (float)y3, surface1Color2,
793 0.0f, (float)h, surface1Color3
794 );
795
796 g2.setPaint(gr);
797 g2.fill(rect);
798
799 drawSurface1OutBorder(g2, x1, y1, x2, y2);
800
801 g2.setPaint(oldPaint);
802 g2.setComposite(oldComposite);
803 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa);
804 }
805
806 private static void
807 drawSurface1OutBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
808 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.40f);
809 g2.setComposite(ac);
810
811 g2.setPaint(Color.WHITE);
812 Line2D.Double l = new Line2D.Double(x1, y1, x2, y1);
813 g2.draw(l);
814
815 g2.setComposite(ac.derive(0.20f));
816 l = new Line2D.Double(x1, y1 + 1, x2, y1 + 1);
817 g2.draw(l);
818
819 g2.setComposite(ac.derive(0.255f));
820
821 l = new Line2D.Double(x1, y1, x1, y2);
822 g2.draw(l);
823
824 g2.setComposite(ac.derive(0.40f));
825 g2.setPaint(Color.BLACK);
826
827 //l = new Line2D.Double(x1, y2, x2, y2);
828 //g2.draw(l);
829
830 g2.setComposite(ac.derive(0.20f));
831
832 l = new Line2D.Double(x2, y1, x2, y2);
833 g2.draw(l);
834 }
835 }

  ViewVC Help
Powered by ViewVC