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