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; |
24 |
|
25 |
import java.awt.Color; |
26 |
import java.awt.Composite; |
27 |
import java.awt.GradientPaint; |
28 |
import java.awt.Graphics; |
29 |
import java.awt.Graphics2D; |
30 |
import java.awt.Paint; |
31 |
|
32 |
import java.awt.geom.Rectangle2D; |
33 |
|
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.JPanel; |
36 |
|
37 |
/** |
38 |
* |
39 |
* @author Grigor Iliev |
40 |
*/ |
41 |
public class FantasiaSubPanel extends JPanel { |
42 |
private boolean dark; |
43 |
private boolean darkParent; |
44 |
private boolean fill; |
45 |
|
46 |
public |
47 |
FantasiaSubPanel() { this(true); } |
48 |
|
49 |
public |
50 |
FantasiaSubPanel(boolean dark) { this(dark, false); } |
51 |
|
52 |
public |
53 |
FantasiaSubPanel(boolean dark, boolean darkParent) { |
54 |
this(dark, darkParent, true); |
55 |
} |
56 |
|
57 |
public |
58 |
FantasiaSubPanel(boolean dark, boolean darkParent, boolean fill) { |
59 |
this.dark = dark; |
60 |
this.darkParent = darkParent; |
61 |
this.fill = fill; |
62 |
|
63 |
setLayout(new java.awt.BorderLayout()); |
64 |
|
65 |
if(fill) setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); |
66 |
else setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
67 |
|
68 |
setOpaque(false); |
69 |
//setBackground(Color.WHITE); |
70 |
} |
71 |
|
72 |
@Override |
73 |
protected void |
74 |
paintComponent(Graphics g) { |
75 |
if(isOpaque()) super.paintComponent(g); |
76 |
|
77 |
double h = getSize().getHeight(); |
78 |
double w = getSize().getWidth(); |
79 |
|
80 |
paintComponent((Graphics2D)g, 0, 0, w, h); |
81 |
} |
82 |
|
83 |
protected void |
84 |
paintComponent(Graphics2D g2, double x1, double y1, double width, double height) { |
85 |
Color c1 = dark ? FantasiaPainter.color2 : FantasiaPainter.color5; |
86 |
Color c2 = dark ? FantasiaPainter.color1 : FantasiaPainter.color4; |
87 |
|
88 |
paintComponent(g2, x1, y1, width, height, c1, c2); |
89 |
} |
90 |
|
91 |
protected void |
92 |
paintComponent ( |
93 |
Graphics2D g2, double x1, double y1, double width, double height, Color c1, Color c2 |
94 |
) { |
95 |
Paint oldPaint = g2.getPaint(); |
96 |
Composite oldComposite = g2.getComposite(); |
97 |
|
98 |
Rectangle2D.Double rect = |
99 |
new Rectangle2D.Double(x1 + 1, y1 + 1, width - 3, height - 3); |
100 |
|
101 |
Color bgColor = dark ? new Color(0x2b2b2b) : new Color(0x323232); |
102 |
g2.setPaint(bgColor); |
103 |
g2.draw(rect); |
104 |
|
105 |
if(fill) { |
106 |
rect = new Rectangle2D.Double(x1 + 2, y1 + 2, width - 4, height - 4); |
107 |
|
108 |
GradientPaint gr = new GradientPaint ( |
109 |
(float)x1, (float)(y1 + 2.0f), c1, |
110 |
(float)x1, (float)(y1 + height - 1), c2 |
111 |
); |
112 |
|
113 |
g2.setPaint(gr); |
114 |
g2.fill(rect); |
115 |
|
116 |
float alpha = dark ? 0.5f : 1.0f; |
117 |
|
118 |
FantasiaPainter.paintOuterBorder ( |
119 |
g2, x1 + 2, y1 + 2, x1 + width - 3, y1 + height - 3, true, alpha, 1.0f |
120 |
); |
121 |
} |
122 |
|
123 |
float alpha = darkParent ? 0.4f : 1.0f; |
124 |
|
125 |
FantasiaPainter.paintInnerBorder ( |
126 |
g2, x1, y1, x1 + width - 1, y1 + height - 1, true, alpha, 1.0f |
127 |
); |
128 |
|
129 |
g2.setPaint(oldPaint); |
130 |
g2.setComposite(oldComposite); |
131 |
} |
132 |
} |