/[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 1872 - (show annotations) (download)
Mon Mar 23 15:34:50 2009 UTC (15 years ago) by iliev
File size: 4593 byte(s)
* Variable number of channel lanes
  (choose Edit/Preferences, then click the `Channels' tab)

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 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 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
60 setButtonNumber(buttonNumber);
61 }
62
63 public void
64 setButtonNumber(int number) {
65 if(number < 1) {
66 throw new IllegalArgumentException("button number should be greater than 0");
67 }
68
69 buttons.removeAllElements();
70 buttons.add(new FirstButton());
71 for(int i = 1; i < number - 1; i++) {
72 buttons.add(new MiddleButton());
73 }
74 if(number > 1) buttons.add(new LastButton());
75
76 removeAll();
77
78 for(JToggleButton btn : buttons) {
79 buttonGroup.add(btn);
80 add(btn);
81 }
82 }
83
84 private class BasicButton extends JToggleButton {
85 BasicButton() {
86 setBorderPainted(false);
87 setContentAreaFilled(false);
88 setRolloverEnabled(true);
89 if(!dark) setForeground(new Color(0xd4d4d4));
90 setFont(getFont().deriveFont(11.0f));
91 //setFont(getFont().deriveFont(Font.BOLD));
92 }
93
94 @Override
95 public void
96 updateUI() { setUI(new BasicButtonUI()); }
97
98 protected void
99 paintButton(Graphics g, FantasiaPainter.RoundCorners rc) {
100 Graphics2D g2 = (Graphics2D)g;
101
102 Paint oldPaint = g2.getPaint();
103 Composite oldComposite = g2.getComposite();
104
105 double w = getSize().getWidth();
106 double h = getSize().getHeight();
107
108 Color c1, c2;
109 if(dark) {
110 c1 = getModel().isRollover() ?
111 FantasiaPainter.color4 : FantasiaPainter.color2;
112
113 c2 = getModel().isRollover() ?
114 FantasiaPainter.color2 : FantasiaPainter.color1;
115
116 if(getModel().isSelected() || getModel().isPressed()) {
117 c1 = FantasiaPainter.color2;
118 c2 = FantasiaPainter.color4;
119 }
120 } else {
121 c1 = getModel().isRollover() ?
122 FantasiaPainter.color6 : FantasiaPainter.color5;
123
124 c2 = getModel().isRollover() ?
125 FantasiaPainter.color5 : FantasiaPainter.color4;
126
127 if(getModel().isSelected() || getModel().isPressed()) {
128 c1 = FantasiaPainter.color6;
129 c2 = FantasiaPainter.color7;
130 }
131 }
132
133 FantasiaPainter.paintGradient(g2, 0, 0, w - 1, h - 1, c1, c2);
134
135
136 if(getModel().isPressed()) {
137 FantasiaPainter.paintInnerBorder(g2, 0, 0, w - 1, h - 1, false, 0.5f, 1.0f);
138 } else {
139 FantasiaPainter.paintOuterBorder(g2, 0, 0, w - 1, h - 1, rc);
140 }
141
142 g2.setComposite(oldComposite);
143 g2.setPaint(oldPaint);
144
145 super.paintComponent(g);
146 }
147 }
148
149 private class FirstButton extends BasicButton {
150 @Override
151 protected void
152 paintComponent(Graphics g) {
153 RoundCorners rc = new RoundCorners(true, true, false, false);
154 paintButton(g, rc);
155 }
156 }
157
158 private class MiddleButton extends BasicButton {
159 @Override
160 protected void
161 paintComponent(Graphics g) {
162 RoundCorners rc = new RoundCorners(false, false, false, false);
163 paintButton(g, rc);
164 }
165 }
166
167 private class LastButton extends BasicButton {
168 @Override
169 protected void
170 paintComponent(Graphics g) {
171 RoundCorners rc = new RoundCorners(false, false, true, true);
172 paintButton(g, rc);
173 }
174 }
175 }

  ViewVC Help
Powered by ViewVC