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