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-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
37 |
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseAdapter; |
38 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
39 |
|
|
40 |
|
import java.util.Vector; |
41 |
|
|
42 |
|
import javax.swing.AbstractButton; |
43 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
44 |
import javax.swing.Box; |
import javax.swing.Box; |
45 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
46 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
47 |
import javax.swing.JScrollPane; |
import javax.swing.JScrollPane; |
48 |
|
import javax.swing.JToggleButton; |
49 |
|
|
50 |
import org.jsampler.CC; |
import org.jsampler.CC; |
51 |
|
import org.jsampler.view.JSChannelsPane; |
52 |
|
import org.jsampler.view.fantasia.basic.*; |
53 |
|
|
54 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
55 |
|
|
59 |
* @author Grigor Iliev |
* @author Grigor Iliev |
60 |
*/ |
*/ |
61 |
public class MainPane extends FantasiaPanel { |
public class MainPane extends FantasiaPanel { |
62 |
private final ChannelsBar channelsBar = new ChannelsBar(); |
private final int CHANNELS_PANEL_NUMBER = 4; |
63 |
private final ChannelsPane channelsPane; |
private final ChannelsBar channelsBar; |
64 |
|
private final ButtonsPanel buttonsPanel; |
65 |
|
private final Vector<ChannelsPanel> channelsPanes = new Vector<ChannelsPanel>(); |
66 |
|
|
67 |
final JScrollPane scrollPane; |
final JScrollPane scrollPane = new JScrollPane(); |
68 |
|
|
69 |
/** Creates a new instance of <code>MainPane</code> */ |
/** Creates a new instance of <code>MainPane</code> */ |
70 |
public MainPane() { |
public MainPane() { |
71 |
setOpaque(false); |
setOpaque(false); |
|
channelsPane = new ChannelsPane("", new ActionListener() { |
|
|
public void |
|
|
actionPerformed(ActionEvent e) { scrollToBottom(); } |
|
|
}); |
|
72 |
|
|
73 |
|
for(int i = 0; i < CHANNELS_PANEL_NUMBER; i++) { |
74 |
|
channelsPanes.add(new ChannelsPanel()); |
75 |
|
} |
76 |
|
|
77 |
|
buttonsPanel = new ButtonsPanel(); |
78 |
|
channelsBar = new ChannelsBar(buttonsPanel); |
79 |
GridBagLayout gridbag = new GridBagLayout(); |
GridBagLayout gridbag = new GridBagLayout(); |
80 |
GridBagConstraints c = new GridBagConstraints(); |
GridBagConstraints c = new GridBagConstraints(); |
81 |
|
|
95 |
gridbag.setConstraints(p, c); |
gridbag.setConstraints(p, c); |
96 |
add(p); |
add(p); |
97 |
|
|
|
p = createChannelsPane(); |
|
|
p.addMouseListener(getHandler()); |
|
|
|
|
|
scrollPane = new JScrollPane(p); |
|
98 |
JScrollPane sp = scrollPane; |
JScrollPane sp = scrollPane; |
99 |
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
100 |
//sp.putClientProperty(SCROLL_PANE_BUTTONS_POLICY, ScrollPaneButtonPolicyKind.NONE); |
//sp.putClientProperty(SCROLL_PANE_BUTTONS_POLICY, ScrollPaneButtonPolicyKind.NONE); |
131 |
setMaximumSize(new Dimension(420, Short.MAX_VALUE)); |
setMaximumSize(new Dimension(420, Short.MAX_VALUE)); |
132 |
} |
} |
133 |
|
|
|
private JPanel |
|
|
createChannelsPane() { |
|
|
JPanel p = new FantasiaPanel(); |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
|
|
channelsPane.setAlignmentX(LEFT_ALIGNMENT); |
|
|
p.add(channelsPane); |
|
|
JPanel p2 = new NewChannelPane(); |
|
|
p2.setAlignmentX(LEFT_ALIGNMENT); |
|
|
p.add(p2); |
|
|
p.add(Box.createGlue()); |
|
|
p.setOpaque(false); |
|
|
p.setBorder(BorderFactory.createEmptyBorder(7, 0, 0, 0)); |
|
|
p.setMinimumSize(new Dimension(420, p.getMinimumSize().height)); |
|
|
p.setAlignmentX(LEFT_ALIGNMENT); |
|
|
return p; |
|
|
} |
|
|
|
|
134 |
private void |
private void |
135 |
onScrollBarVisibilityChanged() { |
onScrollBarVisibilityChanged() { |
136 |
int w = 420; |
int w = 420; |
160 |
scrollPane.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1)); |
scrollPane.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1)); |
161 |
} |
} |
162 |
|
|
163 |
public ChannelsPane |
public JSChannelsPane |
164 |
getChannelsPane() { return channelsPane; } |
getChannelsPane(int index) { return channelsPanes.get(index).getChannelsPane(); } |
165 |
|
|
166 |
|
public int |
167 |
|
getChannelsPaneCount() { return channelsPanes.size(); } |
168 |
|
|
169 |
|
public void |
170 |
|
setSelectedChannelsPane(JSChannelsPane pane) { |
171 |
|
ChannelsPanel chnPanel = null; |
172 |
|
|
173 |
|
for(int i = 0; i < getChannelsPaneCount(); i++) { |
174 |
|
if(channelsPanes.get(i).getChannelsPane() == pane) { |
175 |
|
chnPanel = channelsPanes.get(i); |
176 |
|
|
177 |
|
if(!buttonsPanel.buttons.get(i).isSelected()) { |
178 |
|
buttonsPanel.buttons.get(i).setSelected(true); |
179 |
|
} |
180 |
|
|
181 |
|
break; |
182 |
|
} |
183 |
|
} |
184 |
|
|
185 |
|
if(chnPanel == null) { |
186 |
|
CC.getLogger().warning("Unknown channels pane"); |
187 |
|
return; |
188 |
|
} |
189 |
|
|
190 |
|
scrollPane.getViewport().setView(chnPanel); |
191 |
|
} |
192 |
|
|
193 |
|
public JSChannelsPane |
194 |
|
getSelectedChannelsPane() { |
195 |
|
for(int i = 0; i < getChannelsPaneCount(); i++) { |
196 |
|
if(buttonsPanel.buttons.get(i).isSelected()) { |
197 |
|
return channelsPanes.get(i).getChannelsPane(); |
198 |
|
} |
199 |
|
} |
200 |
|
|
201 |
|
return null; |
202 |
|
} |
203 |
|
|
204 |
|
@Override |
205 |
protected void |
protected void |
206 |
paintComponent(Graphics g) { |
paintComponent(Graphics g) { |
207 |
super.paintComponent(g); |
super.paintComponent(g); |
220 |
getHandler() { return eventHandler; } |
getHandler() { return eventHandler; } |
221 |
|
|
222 |
private class EventHandler extends MouseAdapter { |
private class EventHandler extends MouseAdapter { |
223 |
|
@Override |
224 |
public void |
public void |
225 |
mouseClicked(MouseEvent e) { |
mouseClicked(MouseEvent e) { |
226 |
if(e.getButton() != e.BUTTON1) return; |
if(e.getButton() != MouseEvent.BUTTON1) return; |
227 |
// TAG: channel selection system |
// TAG: channel selection system |
228 |
CC.getMainFrame().getChannelsPane(0).setSelectedChannel(null); |
CC.getMainFrame().getSelectedChannelsPane().setSelectedChannel(null); |
229 |
/////// |
/////// |
230 |
} |
} |
231 |
} |
} |
232 |
|
|
233 |
|
private class ChannelsPanel extends FantasiaPanel { |
234 |
|
private final JSChannelsPane channelsPane; |
235 |
|
ChannelsPanel() { |
236 |
|
ActionListener l = new ActionListener() { |
237 |
|
public void |
238 |
|
actionPerformed(ActionEvent e) { scrollToBottom(); } |
239 |
|
}; |
240 |
|
|
241 |
|
channelsPane = new ChannelsPane("", l); |
242 |
|
|
243 |
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
244 |
|
channelsPane.setAlignmentX(LEFT_ALIGNMENT); |
245 |
|
add(channelsPane); |
246 |
|
JPanel p2 = new NewChannelPane(); |
247 |
|
p2.setAlignmentX(LEFT_ALIGNMENT); |
248 |
|
add(p2); |
249 |
|
add(Box.createGlue()); |
250 |
|
setOpaque(false); |
251 |
|
setBorder(BorderFactory.createEmptyBorder(7, 0, 0, 0)); |
252 |
|
setMinimumSize(new Dimension(420, getMinimumSize().height)); |
253 |
|
setAlignmentX(LEFT_ALIGNMENT); |
254 |
|
|
255 |
|
addMouseListener(getHandler()); |
256 |
|
} |
257 |
|
|
258 |
|
public JSChannelsPane |
259 |
|
getChannelsPane() { return channelsPane; } |
260 |
|
} |
261 |
|
|
262 |
|
private class ButtonsPanel extends FantasiaToggleButtonsPanel implements ActionListener { |
263 |
|
ButtonsPanel() { |
264 |
|
super(CHANNELS_PANEL_NUMBER, true); |
265 |
|
for(int i = 0; i < CHANNELS_PANEL_NUMBER; i++) { |
266 |
|
JToggleButton btn = buttons.get(i); |
267 |
|
btn.setText(String.valueOf(i + 1)); |
268 |
|
btn.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8)); |
269 |
|
btn.addActionListener(this); |
270 |
|
|
271 |
|
String s = "MainPane.ButtonsPanel.tt"; |
272 |
|
btn.setToolTipText(i18n.getButtonLabel(s, i + 1)); |
273 |
|
} |
274 |
|
|
275 |
|
setMaximumSize(getPreferredSize()); |
276 |
|
} |
277 |
|
|
278 |
|
@Override |
279 |
|
public void |
280 |
|
actionPerformed(ActionEvent e) { |
281 |
|
AbstractButton btn = (AbstractButton)e.getSource(); |
282 |
|
if(!btn.isSelected()) return; |
283 |
|
int idx = buttons.indexOf(btn); |
284 |
|
if(idx == -1) return; |
285 |
|
|
286 |
|
ChannelsPanel chnPanel = channelsPanes.get(idx); |
287 |
|
CC.getMainFrame().setSelectedChannelsPane(chnPanel.getChannelsPane()); |
288 |
|
} |
289 |
|
} |
290 |
|
|
291 |
class NewChannelPane extends PixmapPane implements ActionListener { |
class NewChannelPane extends PixmapPane implements ActionListener { |
292 |
private final PixmapButton btnNew = new PixmapButton(Res.gfxPowerOff); |
private final PixmapButton btnNew = new PixmapButton(Res.gfxPowerOff); |
293 |
|
|
339 |
setToolTipText(s); |
setToolTipText(s); |
340 |
} |
} |
341 |
|
|
342 |
|
@Override |
343 |
public void |
public void |
344 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
345 |
CC.getSamplerModel().addBackendChannel(); |
CC.getSamplerModel().addBackendChannel(); |