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

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/FantasiaUtils.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1778 - (show annotations) (download)
Sun Sep 28 20:38:36 2008 UTC (15 years, 6 months ago) by iliev
File size: 5631 byte(s)
* Fantasia: Improved look and feel
* Fantasia: Added buttons for increasing/decreasing the key number
  of the MIDI keyboard (Ctrl+Up Arrow/Ctrl+Down Arrow)
* Fantasia: Added buttons for scrolling left/right on the MIDI keyboard
  (Ctrl+Left Arrow/Ctrl+Right Arrow)
* Added key bindings for triggering MIDI notes using the computer keyboard
  (from a to ' for the white keys and from 0 to 7 for changing the octaves)
* Notes are now triggered when dragging the mouse over the MIDI keyboard

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

  ViewVC Help
Powered by ViewVC