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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1785 - (show annotations) (download)
Tue Oct 7 00:07:14 2008 UTC (15 years, 5 months ago) by iliev
File size: 8617 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.Composite;
28 import java.awt.GradientPaint;
29 import java.awt.Graphics;
30 import java.awt.Graphics2D;
31 import java.awt.Paint;
32 import java.awt.RenderingHints;
33
34 import java.awt.geom.Line2D;
35 import java.awt.geom.Rectangle2D;
36
37 import javax.swing.BorderFactory;
38 import javax.swing.JToggleButton;
39
40 import javax.swing.plaf.basic.BasicButtonUI;
41
42
43 /**
44 *
45 * @author Grigor Iliev
46 */
47 public class FantasiaTabButton extends JToggleButton {
48 private FantasiaTabbedPane tabbedPane;
49 int index = 0;
50
51 public
52 FantasiaTabButton(FantasiaTabbedPane owner) {
53 this(owner, "");
54 }
55
56 public
57 FantasiaTabButton(FantasiaTabbedPane owner, String s) {
58 super(s);
59
60 tabbedPane = owner;
61 setFocusable(false);
62 setContentAreaFilled(false);
63 setFocusPainted(false);
64 setBorder(BorderFactory.createEmptyBorder(5, 3, 5, 3));
65 setRolloverEnabled(true);
66 setForeground(new Color(0xcccccc));
67 //setHorizontalAlignment(LEFT);
68 }
69
70 public int
71 getIndex() { return index; }
72
73 public void
74 setIndex(int idx) { index = idx; }
75
76 public FantasiaTabbedPane
77 getTabbedPane() { return tabbedPane; }
78
79 private Color color3 = new Color(0x5e5e5e);
80 private Color color4 = new Color(0x6e6e6e);
81 private Color color5 = new Color(0x7a7a7a);
82 private Color color6 = new Color(0x8a8a8a);
83
84 @Override
85 protected void
86 paintComponent(Graphics g) {
87 Graphics2D g2 = (Graphics2D)g;
88
89 Paint oldPaint = g2.getPaint();
90 Composite oldComposite = g2.getComposite();
91
92 g2.setRenderingHint (
93 RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF
94 );
95
96 if(isSelected()) paintSelectedButton(g2);
97 else paintUnselectedButton(g2);
98
99 g2.setPaint(oldPaint);
100 g2.setComposite(oldComposite);
101
102 g2.setRenderingHint (
103 RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON
104 );
105
106 super.paintComponent(g);
107 }
108
109 private void
110 paintSelectedButton(Graphics2D g2) {
111 double h = getSize().getHeight();
112 double w = getSize().getWidth();
113
114 double x1 = 0.0;
115 double y2 = getModel().isSelected() ? h : h - 3;
116 double x2 = isLastButton() ? w : w - 1;
117
118 Rectangle2D.Double rect = new Rectangle2D.Double(x1, 0.0, x2, y2);
119
120 GradientPaint gr = new GradientPaint (
121 (float)x1, 0.0f, color6,
122 (float)x1, (float)y2, color5
123 );
124
125 g2.setPaint(gr);
126 g2.fill(rect);
127
128 paintSelectedBorder(g2, x1, 0, x2 - 1, h - 1);
129 }
130
131 private void
132 paintUnselectedButton(Graphics2D g2) {
133 double h = getSize().getHeight();
134 double w = getSize().getWidth();
135
136 double x1 = 0.0;
137 double y1 = 1.0;
138 double y2 = h - 2;
139 double x2 = isLastButton() ? w : w - 1;
140
141 Rectangle2D.Double rect = new Rectangle2D.Double(x1, y1, x2, y2);
142
143 Color c1 = getModel().isRollover() ? color4 : color3;
144 Color c2 = getModel().isRollover() ? color6 : color5;
145
146 GradientPaint gr = new GradientPaint (
147 (float)x1, (float)y1, c1,
148 (float)x1, (float)y2, c2
149 );
150
151 g2.setPaint(gr);
152 g2.fill(rect);
153
154 // draw the bottom component
155 rect = new Rectangle2D.Double(0.0, h - 2, w, y2);
156 g2.setPaint(color5);
157 g2.fill(rect);
158
159 paintUnselectedBorder(g2, x1, y1, x2 - 1, h);
160 }
161
162 private void
163 paintSelectedBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
164 FantasiaPainter.paintTopBoldOuterBorder(g2, x1 + 2, y1, x2 - 2, y1);
165 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.40f);
166
167 FantasiaPainter.paintTopBoldRoundCorners(g2, x1, y1, x2, y2);
168
169 g2.setComposite(ac.derive(0.255f));
170
171 y2 -= 1;
172
173 double y3 = getIndex() == 0 ? y2 + 1 : y2;
174 Line2D.Double l = new Line2D.Double(x1, y1 + 2, x1, y3);
175 g2.draw(l);
176
177 if(getIndex() == 0) {
178 g2.setComposite(ac.derive(0.07f));
179 l = new Line2D.Double(x1 + 1, y1 + 3, x1 + 1, y3);
180 g2.draw(l);
181 }
182
183 g2.setComposite(ac.derive(0.40f));
184 g2.setPaint(Color.BLACK);
185
186 g2.setComposite(ac.derive(0.20f));
187
188 y3 = getIndex() == getTabbedPane().getTabCount() - 1 ? y2 + 1 : y2;
189 l = new Line2D.Double(x2, y1 + 2, x2, y3);
190 g2.draw(l);
191
192 if(getIndex() == getTabbedPane().getTabCount() - 1) {
193 g2.setComposite(ac.derive(0.07f));
194 l = new Line2D.Double(x2 - 1, y1 + 3, x2 - 1, y3);
195 g2.draw(l);
196 }
197
198 // draw bottom component right border
199 if(getIndex() != getTabbedPane().getTabCount() - 1) {
200 g2.setPaint(color5);
201 g2.setComposite(ac.derive(1.0f));
202 l = new Line2D.Double(x2 + 1, y2, x2 + 1, y2 + 1);
203 g2.draw(l);
204
205 g2.setPaint(Color.WHITE);
206
207 g2.setComposite(ac.derive(0.10f));
208 l = new Line2D.Double(x2, y2, x2, y2);
209 g2.draw(l);
210
211 g2.setComposite(ac.derive(0.20f));
212 l = new Line2D.Double(x2 + 1, y2, x2 + 1, y2);
213 g2.draw(l);
214
215 // draw bottom component border
216 g2.setComposite(ac.derive(0.10f));
217 l = new Line2D.Double(x2 + 1, y2 + 1, x2 + 1, y2 + 1);
218 g2.draw(l);
219 }
220 }
221
222 public boolean
223 isLastButton() { return getIndex() == getTabbedPane().getTabCount() - 1; }
224
225 private void
226 paintUnselectedBorder(Graphics2D g2, double x1, double y1, double x2, double y2) {
227 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.40f);
228 g2.setComposite(ac);
229
230 g2.setPaint(Color.WHITE);
231 Line2D.Double l = new Line2D.Double(x1 + 2, y1, x2 - 3, y1);
232 g2.draw(l);
233
234 double h = getSize().getHeight();
235
236 // draw bottom component border
237 double x0 = getIndex() == 0 ? 2 : 0;
238 double x3 = isLastButton() ? x2 - 3 : x2 + 1;
239 l = new Line2D.Double(x0, h - 2, x3, h - 2);
240 g2.draw(l);
241
242 g2.setComposite(ac.derive(0.20f));
243 l = new Line2D.Double(x1, y1 + 1, x2 - 2, y1 + 1);
244 g2.draw(l);
245
246 // draw bottom component border
247 l = new Line2D.Double(x0, h - 1, x3, h - 1);
248 g2.draw(l);
249
250 paintRoundCorners(g2, x1, y1, x2, y2);
251
252 if(getIndex() == 0) {
253 FantasiaPainter.paintTopLeftBoldRoundCorner(g2, 0.0, h - 2);
254 } else if(isLastButton()) {
255 FantasiaPainter.paintTopRightBoldRoundCorner(g2, y2 - 2, x2);
256 }
257 g2.setComposite(ac.derive(0.255f));
258
259 y2 -= 3;
260
261 l = new Line2D.Double(x1, y1 + 2, x1, y2);
262 g2.draw(l);
263
264 g2.setComposite(ac.derive(0.30f));
265 g2.setPaint(Color.BLACK);
266
267 l = new Line2D.Double(x1, y2, x2, y2);
268 g2.draw(l);
269
270 g2.setComposite(ac.derive(0.20f));
271
272 l = new Line2D.Double(x2, y1 + 2, x2, y2);
273 g2.draw(l);
274 }
275
276 private void
277 paintRoundCorners(Graphics2D g2, double x1, double y1, double x2, double y2) {
278 Paint oldPaint = g2.getPaint();
279
280 g2.setPaint(Color.WHITE);
281
282 // Round corner - left
283 AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.10f);
284 g2.setComposite(ac);
285 Line2D.Double l = new Line2D.Double(x1, y1, x1, y1);
286 g2.draw(l);
287
288 g2.setPaint(Color.WHITE);
289 g2.setComposite(ac.derive(0.37f));
290 l = new Line2D.Double(x1 + 1, y1, x1 + 1, y1);
291 g2.draw(l);
292
293 g2.setComposite(ac.derive(0.15f));
294 l = new Line2D.Double(x1, y1 + 1, x1, y1 + 1);
295 g2.draw(l);
296
297 g2.setComposite(ac.derive(0.20f));
298 l = new Line2D.Double(x1 + 1, y1 + 1, x1 + 1, y1 + 1);
299 g2.draw(l);
300
301 g2.setComposite(ac.derive(0.10f));
302 l = new Line2D.Double(x1, y1 + 2, x1 + 1, y1 + 2);
303 g2.draw(l);
304 // Round corner - right
305 g2.setPaint(Color.WHITE);
306 g2.setComposite(ac.derive(0.30f));
307 l = new Line2D.Double(x2 - 2, y1, x2 - 2, y1);
308 g2.draw(l);
309
310 g2.setComposite(ac.derive(0.20f));
311 l = new Line2D.Double(x2 - 1, y1, x2 - 1, y1);
312 g2.draw(l);
313
314 g2.setPaint(Color.BLACK);
315 g2.setComposite(ac.derive(0.10f));
316 l = new Line2D.Double(x2, y1, x2, y1);
317 g2.draw(l);
318
319 g2.setPaint(Color.WHITE);
320 l = new Line2D.Double(x2 - 1, y1 + 1, x2 - 1, y1 + 1);
321 g2.draw(l);
322
323 g2.setPaint(Color.BLACK);
324 g2.setComposite(ac.derive(0.05f));
325 l = new Line2D.Double(x2, y1 + 1, x2, y1 + 1);
326 g2.draw(l);
327
328 g2.setPaint(oldPaint);
329 }
330
331 @Override
332 public void
333 updateUI() { setUI(new BasicButtonUI()); }
334 }

  ViewVC Help
Powered by ViewVC