1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2011 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.Cursor; |
26 |
import java.awt.Dialog; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.Frame; |
29 |
import java.awt.Graphics; |
30 |
import java.awt.Graphics2D; |
31 |
import java.awt.Insets; |
32 |
|
33 |
import javax.swing.Action; |
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.JButton; |
36 |
import javax.swing.JComboBox; |
37 |
import javax.swing.JLabel; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JToolBar; |
40 |
|
41 |
import javax.swing.plaf.basic.BasicButtonUI; |
42 |
import javax.swing.plaf.basic.BasicLabelUI; |
43 |
|
44 |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
45 |
import org.jsampler.view.swing.InstrumentsDbTreeModel; |
46 |
|
47 |
import org.jsampler.view.std.JSDbInstrumentChooser; |
48 |
import org.jsampler.view.std.JSInstrumentChooser; |
49 |
import org.jsampler.view.std.JSInstrumentsDbTree; |
50 |
|
51 |
|
52 |
/** |
53 |
* |
54 |
* @author Grigor Iliev |
55 |
*/ |
56 |
public class FantasiaUtils { |
57 |
|
58 |
/** Forbits the instantiation of the class */ |
59 |
private |
60 |
FantasiaUtils() { } |
61 |
|
62 |
public static JComboBox |
63 |
createEnhancedComboBox() { |
64 |
return new JComboBox(); |
65 |
} |
66 |
|
67 |
public static JSInstrumentChooser |
68 |
createInstrumentChooser(Frame owner) { |
69 |
return new InstrumentChooser(owner); |
70 |
} |
71 |
|
72 |
public static JLabel |
73 |
createScreenLabel(String s) { return new ScreenLabel(s); } |
74 |
|
75 |
public static JButton |
76 |
createScreenButton(String s) { return new ScreenButton(s); } |
77 |
|
78 |
public static JToolBar |
79 |
createSubToolBar() { return new ToolBar(); } |
80 |
|
81 |
public static JPanel |
82 |
createBottomSubPane() { return new BottomSubPane(); } |
83 |
|
84 |
|
85 |
private static class InstrumentChooser extends JSInstrumentChooser { |
86 |
InstrumentChooser(Frame owner) { |
87 |
super(owner); |
88 |
} |
89 |
|
90 |
protected JComboBox |
91 |
createComboBox() { return createEnhancedComboBox(); } |
92 |
|
93 |
@Override |
94 |
protected JSDbInstrumentChooser |
95 |
createDbInstrumentChooser(Dialog owner) { |
96 |
return new DbInstrumentChooser(owner); |
97 |
} |
98 |
} |
99 |
|
100 |
private static class DbInstrumentChooser extends JSDbInstrumentChooser { |
101 |
DbInstrumentChooser(Dialog owner) { |
102 |
super(owner); |
103 |
} |
104 |
|
105 |
@Override |
106 |
protected JButton |
107 |
createToolbarButton(Action a) { return new ToolbarButton(a); } |
108 |
|
109 |
@Override |
110 |
protected JSInstrumentsDbTree |
111 |
createInstrumentsDbTree(InstrumentsDbTreeModel m) { |
112 |
return new FantasiaInstrumentsDbTree(m); |
113 |
} |
114 |
} |
115 |
|
116 |
private static class ScreenLabel extends JLabel { |
117 |
ScreenLabel() { this(""); } |
118 |
|
119 |
ScreenLabel(String s) { |
120 |
super(s); |
121 |
setFont(Res.fontScreen); |
122 |
setForeground(new java.awt.Color(0xFFA300)); |
123 |
} |
124 |
|
125 |
@Override |
126 |
protected void |
127 |
paintComponent(Graphics g) { |
128 |
Graphics2D g2d = (Graphics2D)g; |
129 |
|
130 |
g2d.setRenderingHint ( |
131 |
java.awt.RenderingHints.KEY_TEXT_ANTIALIASING, |
132 |
java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON |
133 |
); |
134 |
|
135 |
super.paintComponent(g2d); |
136 |
} |
137 |
|
138 |
@Override |
139 |
public void |
140 |
updateUI() { setUI(new BasicLabelUI()); } |
141 |
} |
142 |
|
143 |
private static class ScreenButton extends JButton { |
144 |
protected |
145 |
ScreenButton(String s) { |
146 |
super(s); |
147 |
setContentAreaFilled(false); |
148 |
setFocusPainted(false); |
149 |
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
150 |
setMargin(new Insets(0, 0, 0, 0)); |
151 |
|
152 |
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
153 |
setFont(Res.fontScreen); |
154 |
setForeground(new java.awt.Color(0xFFA300)); |
155 |
} |
156 |
|
157 |
@Override |
158 |
protected void |
159 |
paintComponent(Graphics g) { |
160 |
Graphics2D g2d = (Graphics2D)g; |
161 |
|
162 |
g2d.setRenderingHint ( |
163 |
java.awt.RenderingHints.KEY_TEXT_ANTIALIASING, |
164 |
java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON |
165 |
); |
166 |
|
167 |
super.paintComponent(g2d); |
168 |
} |
169 |
|
170 |
@Override |
171 |
public void |
172 |
updateUI() { setUI(new BasicButtonUI()); } |
173 |
} |
174 |
|
175 |
|
176 |
|
177 |
private static class ToolBar extends JToolBar { |
178 |
ToolBar() { |
179 |
setFloatable(false); |
180 |
setOpaque(false); |
181 |
setPreferredSize(new Dimension(77, 29)); |
182 |
setMinimumSize(getPreferredSize()); |
183 |
//setBackground(Color.BLACK); |
184 |
} |
185 |
|
186 |
@Override |
187 |
protected void |
188 |
paintComponent(Graphics g) { |
189 |
super.paintComponent(g); |
190 |
|
191 |
double h = getSize().getHeight(); |
192 |
double w = getSize().getWidth(); |
193 |
|
194 |
FantasiaPainter.paintGradient((Graphics2D)g, 0, 0, w - 1, h - 1); |
195 |
|
196 |
FantasiaPainter.RoundCorners rc = |
197 |
new FantasiaPainter.RoundCorners(true, false, false, true); |
198 |
|
199 |
FantasiaPainter.paintOuterBorder((Graphics2D)g, 0, 0, w - 1, h - 1, rc); |
200 |
} |
201 |
} |
202 |
|
203 |
private static class BottomSubPane extends JPanel { |
204 |
BottomSubPane() { |
205 |
setLayout(new java.awt.BorderLayout()); |
206 |
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
207 |
} |
208 |
|
209 |
@Override |
210 |
protected void |
211 |
paintComponent(Graphics g) { |
212 |
super.paintComponent(g); |
213 |
|
214 |
Graphics2D g2 = (Graphics2D)g; |
215 |
double h = getSize().getHeight(); |
216 |
double w = getSize().getWidth(); |
217 |
|
218 |
FantasiaPainter.paintGradient(g2, 0, 0, w - 1, h - 1); |
219 |
|
220 |
FantasiaPainter.RoundCorners rc = |
221 |
new FantasiaPainter.RoundCorners(false, true, true, false); |
222 |
|
223 |
FantasiaPainter.paintOuterBorder(g2, 0, 0, w - 1, h - 1, rc); |
224 |
|
225 |
FantasiaPainter.paintInnerBorder(g2, 4, 4, w - 5, h - 5, true); |
226 |
} |
227 |
} |
228 |
} |