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

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/basic/FantasiaToggleButtonsPanel.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: 4496 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.Color;
26 import java.awt.Composite;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29
30 import java.awt.Paint;
31 import java.util.Vector;
32
33 import javax.swing.BoxLayout;
34 import javax.swing.ButtonGroup;
35 import javax.swing.JToggleButton;
36 import javax.swing.plaf.basic.BasicButtonUI;
37
38 import org.jsampler.view.fantasia.basic.FantasiaPainter.RoundCorners;
39
40
41 /**
42 *
43 * @author Grigor Iliev
44 */
45 public class FantasiaToggleButtonsPanel extends FantasiaSubPanel {
46 public final Vector<JToggleButton> buttons = new Vector<JToggleButton>();
47 protected final ButtonGroup buttonGroup = new ButtonGroup();
48 protected boolean dark;
49
50 public
51 FantasiaToggleButtonsPanel(int buttonNumber) {
52 this(buttonNumber, true);
53 }
54
55 public
56 FantasiaToggleButtonsPanel(int buttonNumber, boolean dark) {
57 super(true, false, false);
58 this.dark = dark;
59
60 if(buttonNumber < 2) {
61 throw new IllegalArgumentException("buttonNumber should be greater than 1");
62 }
63
64 buttons.add(new FirstButton());
65 for(int i = 1; i < buttonNumber - 1; i++) {
66 buttons.add(new MiddleButton());
67 }
68 buttons.add(new LastButton());
69
70 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
71
72 for(JToggleButton btn : buttons) {
73 btn.setText(" 3 ");
74 buttonGroup.add(btn);
75 add(btn);
76 }
77 }
78
79 private class BasicButton extends JToggleButton {
80 BasicButton() {
81 setBorderPainted(false);
82 setContentAreaFilled(false);
83 setRolloverEnabled(true);
84 if(!dark) setForeground(new Color(0xd4d4d4));
85 setFont(getFont().deriveFont(11.0f));
86 //setFont(getFont().deriveFont(Font.BOLD));
87 }
88
89 @Override
90 public void
91 updateUI() { setUI(new BasicButtonUI()); }
92
93 protected void
94 paintButton(Graphics g, FantasiaPainter.RoundCorners rc) {
95 Graphics2D g2 = (Graphics2D)g;
96
97 Paint oldPaint = g2.getPaint();
98 Composite oldComposite = g2.getComposite();
99
100 double w = getSize().getWidth();
101 double h = getSize().getHeight();
102
103 Color c1, c2;
104 if(dark) {
105 c1 = getModel().isRollover() ?
106 FantasiaPainter.color4 : FantasiaPainter.color2;
107
108 c2 = getModel().isRollover() ?
109 FantasiaPainter.color2 : FantasiaPainter.color1;
110
111 if(getModel().isSelected() || getModel().isPressed()) {
112 c1 = FantasiaPainter.color2;
113 c2 = FantasiaPainter.color4;
114 }
115 } else {
116 c1 = getModel().isRollover() ?
117 FantasiaPainter.color6 : FantasiaPainter.color5;
118
119 c2 = getModel().isRollover() ?
120 FantasiaPainter.color5 : FantasiaPainter.color4;
121
122 if(getModel().isSelected() || getModel().isPressed()) {
123 c1 = FantasiaPainter.color6;
124 c2 = FantasiaPainter.color7;
125 }
126 }
127
128 FantasiaPainter.paintGradient(g2, 0, 0, w - 1, h - 1, c1, c2);
129
130
131 if(getModel().isPressed()) {
132 FantasiaPainter.paintInnerBorder(g2, 0, 0, w - 1, h - 1, false, 0.5f, 1.0f);
133 } else {
134 FantasiaPainter.paintOuterBorder(g2, 0, 0, w - 1, h - 1, rc);
135 }
136
137 g2.setComposite(oldComposite);
138 g2.setPaint(oldPaint);
139
140 super.paintComponent(g);
141 }
142 }
143
144 private class FirstButton extends BasicButton {
145 @Override
146 protected void
147 paintComponent(Graphics g) {
148 RoundCorners rc = new RoundCorners(true, true, false, false);
149 paintButton(g, rc);
150 }
151 }
152
153 private class MiddleButton extends BasicButton {
154 @Override
155 protected void
156 paintComponent(Graphics g) {
157 RoundCorners rc = new RoundCorners(false, false, false, false);
158 paintButton(g, rc);
159 }
160 }
161
162 private class LastButton extends BasicButton {
163 @Override
164 protected void
165 paintComponent(Graphics g) {
166 RoundCorners rc = new RoundCorners(false, false, true, true);
167 paintButton(g, rc);
168 }
169 }
170 }

  ViewVC Help
Powered by ViewVC