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