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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1778 - (show annotations) (download)
Sun Sep 28 20:38:36 2008 UTC (15 years, 7 months ago) by iliev
File size: 5812 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.BorderLayout;
26 import java.awt.Color;
27 import java.awt.Composite;
28 import java.awt.Dimension;
29 import java.awt.Graphics;
30 import java.awt.Graphics2D;
31 import java.awt.Paint;
32
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35
36 import javax.swing.Action;
37 import javax.swing.BorderFactory;
38 import javax.swing.Box;
39 import javax.swing.BoxLayout;
40 import javax.swing.JLabel;
41 import javax.swing.JPanel;
42 import javax.swing.JToggleButton;
43 import javax.swing.JToolBar;
44
45 import org.jsampler.CC;
46
47 import static org.jsampler.view.fantasia.A4n.a4n;
48
49 /**
50 *
51 * @author Grigor Iliev
52 */
53 public class StandardBar extends JPanel {
54 private final JToolBar toolbar = new JToolBar();
55 private final JPanel mainPane;
56
57 private final ToolbarButton btnSamplerInfo = new ToolbarButton(a4n.samplerInfo);
58 private final ToolbarButton btnLoadSession = new ToolbarButton(a4n.loadScript);
59 private final ToolbarButton btnExportSession = new ToolbarButton(a4n.exportSamplerConfig);
60 private final ToolbarButton btnRefresh = new ToolbarButton(a4n.refresh);
61 private final ToolbarButton btnResetSampler = new ToolbarButton(a4n.resetSampler);
62
63 protected final ToggleButton btnMidiKeyboard = new ToggleButton();
64 private final ToolbarButton btnLSConsole = new ToolbarButton(a4n.windowLSConsole);
65 private final ToolbarButton btnInstrumentsDb = new ToolbarButton(a4n.windowInstrumentsDb);
66
67 private final ToolbarButton btnPreferences = new ToolbarButton(a4n.editPreferences);
68
69 private final JLabel lLogo = new JLabel(Res.gfxFantasiaLogo);
70
71 /** Creates a new instance of <code>StandardBar</code> */
72 public
73 StandardBar() {
74 //super(Res.gfxToolBarBg);
75 //setPixmapInsets(new Insets(0, 6, 6, 6));
76
77 setLayout(new BorderLayout());
78 setOpaque(false);
79
80 Dimension d = new Dimension(60, 51);
81 setMinimumSize(d);
82 setPreferredSize(d);
83 d = new Dimension(Short.MAX_VALUE, 51);
84 setMaximumSize(d);
85 setBorder(BorderFactory.createEmptyBorder(0, 5, 2, 5));
86
87
88 //mainPane = new PixmapPane(Res.gfxToolBar);
89 //mainPane.setPixmapInsets(Res.insetsToolBar);
90 mainPane = new MainPane();
91 mainPane.setOpaque(false);
92 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.X_AXIS));
93
94 toolbar.setOpaque(false);
95 toolbar.setFloatable(false);
96
97 toolbar.add(btnSamplerInfo);
98 toolbar.addSeparator();
99 toolbar.add(btnLoadSession);
100 toolbar.add(btnExportSession);
101 toolbar.add(btnRefresh);
102 toolbar.add(btnResetSampler);
103 toolbar.addSeparator();
104 btnMidiKeyboard.setIcon(Res.iconMidiKeyboard32);
105 btnMidiKeyboard.addActionListener(new ActionListener() {
106 public void
107 actionPerformed(ActionEvent e) {
108 boolean b = btnMidiKeyboard.isSelected();
109 MainFrame frm = (MainFrame)CC.getMainFrame();
110 if(frm == null) return;
111 frm.setMidiKeyboardVisible(b);
112 }
113 });
114 toolbar.add(btnMidiKeyboard);
115 toolbar.add(btnLSConsole);
116 toolbar.add(btnInstrumentsDb);
117 toolbar.addSeparator();
118 toolbar.add(btnPreferences);
119
120 mainPane.add(toolbar);
121 mainPane.add(Box.createGlue());
122
123 mainPane.add(lLogo);
124 mainPane.add(Box.createRigidArea(new Dimension(17, 0)));
125 FantasiaSubPanel fsp = new FantasiaSubPanel(true, false, false);
126 fsp.add(mainPane);
127 add(fsp);
128 }
129
130 public void
131 showFantasiaLogo(boolean b) { lLogo.setVisible(b); }
132
133 private Color midColor = new Color(0x797979);
134
135 @Override
136 public void
137 paintComponent(Graphics g) {
138 Graphics2D g2 = (Graphics2D)g;
139
140 Paint oldPaint = g2.getPaint();
141 Composite oldComposite = g2.getComposite();
142
143 double h = getSize().getHeight();
144 double w = getSize().getWidth();
145
146 FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color5, midColor);
147
148 FantasiaPainter.Border b = new FantasiaPainter.Border(false, true, false, true);
149 FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 2, b);
150
151 g2.setPaint(oldPaint);
152 g2.setComposite(oldComposite);
153 }
154
155 class ToggleButton extends JToggleButton {
156 /** Creates a new instance of <code>ToolbarButton</code>. */
157 ToggleButton() {
158 setFocusable(false);
159 }
160
161 /** Creates a new instance of <code>ToolbarButton</code>. */
162 public
163 ToggleButton(Action a) {
164 super(a);
165 setFocusable(false);
166 }
167
168 /** This method does nothing. */
169 @Override
170 public void
171 setText(String text) { /* We don't want any text in toolbar buttons */ }
172 }
173
174 class MainPane extends JPanel {
175 private final Color color1 = new Color(0x505050);
176 private final Color color2 = new Color(0x3e3e3e);
177
178 @Override
179 public void
180 paintComponent(Graphics g) {
181 Graphics2D g2 = (Graphics2D)g;
182
183 Paint oldPaint = g2.getPaint();
184 Composite oldComposite = g2.getComposite();
185
186 double h = getSize().getHeight();
187 double w = getSize().getWidth();
188
189 FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, color1, color2);
190
191 FantasiaPainter.paintOuterBorder(g2, 0, 0, w - 1, h - 1, true, 0.5f, 0.3f);
192
193 g2.setPaint(oldPaint);
194 g2.setComposite(oldComposite);
195 }
196 }
197 }

  ViewVC Help
Powered by ViewVC