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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1818 - (show annotations) (download)
Wed Dec 24 17:29:47 2008 UTC (15 years, 4 months ago) by iliev
File size: 10058 byte(s)
* Added support for controlling the global sampler-wide limit of
  maximum voices and disk streams
  (choose Edit/Preferences, then click the `General' tab)
* Fantasia: store the view configuration of audio/MIDI devices and sampler
  channels in the LSCP script when exporting sampler configuration
* Fantasia: Implemented multiple sampler channels' selection
* Fantasia: Added option to move sampler channels up and down
  in the channels list
* Fantasia: Added option to move sampler channels
  to another channels panels

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.Cursor;
26 import java.awt.Dimension;
27 import java.awt.Graphics;
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.Insets;
31 import java.awt.Rectangle;
32
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.HierarchyEvent;
36 import java.awt.event.HierarchyListener;
37 import java.awt.event.MouseAdapter;
38 import java.awt.event.MouseEvent;
39
40 import java.util.Vector;
41
42 import javax.swing.AbstractButton;
43 import javax.swing.BorderFactory;
44 import javax.swing.Box;
45 import javax.swing.BoxLayout;
46 import javax.swing.JPanel;
47 import javax.swing.JScrollPane;
48 import javax.swing.JToggleButton;
49
50 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;
55
56
57 /**
58 *
59 * @author Grigor Iliev
60 */
61 public class MainPane extends FantasiaPanel {
62 private final int CHANNELS_PANEL_NUMBER = 4;
63 private final ChannelsBar channelsBar;
64 private final ButtonsPanel buttonsPanel;
65 private final Vector<ChannelsPanel> channelsPanes = new Vector<ChannelsPanel>();
66
67 final JScrollPane scrollPane = new JScrollPane();
68
69 /** Creates a new instance of <code>MainPane</code> */
70 public MainPane() {
71 setOpaque(false);
72
73 for(int i = 0; i < CHANNELS_PANEL_NUMBER; i++) {
74 String s = i18n.getButtonLabel("MainPane.ButtonsPanel.tt", i + 1);
75 channelsPanes.add(new ChannelsPanel(s));
76 }
77
78 buttonsPanel = new ButtonsPanel();
79 channelsBar = new ChannelsBar(buttonsPanel);
80 GridBagLayout gridbag = new GridBagLayout();
81 GridBagConstraints c = new GridBagConstraints();
82
83 setLayout(gridbag);
84
85 JPanel p = new FantasiaPanel();
86 p.setOpaque(false);
87 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
88 p.add(channelsBar);
89 p.add(Box.createGlue());
90
91 c.gridx = 0;
92 c.gridy = 0;
93 c.weightx = 1.0;
94 c.insets = new Insets(0, 0, 0, 0);
95 c.fill = GridBagConstraints.HORIZONTAL;
96 gridbag.setConstraints(p, c);
97 add(p);
98
99 JScrollPane sp = scrollPane;
100 sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
101 //sp.putClientProperty(SCROLL_PANE_BUTTONS_POLICY, ScrollPaneButtonPolicyKind.NONE);
102 sp.setBorder(BorderFactory.createEmptyBorder());
103 sp.setOpaque(false);
104 javax.swing.JViewport wp = sp.getViewport();
105 wp.setMinimumSize(new Dimension(400, wp.getMinimumSize().height));
106 wp.setOpaque(false);
107 sp.setMaximumSize(new Dimension(sp.getMaximumSize().width, Short.MAX_VALUE));
108 sp.getVerticalScrollBar().setBorder(BorderFactory.createEmptyBorder(7, 4, 0, 1));
109 //sp.getVerticalScrollBar().setUnitIncrement(12);
110 sp.setPreferredSize(new Dimension(420, sp.getPreferredSize().height));
111
112 sp.getVerticalScrollBar().addHierarchyListener(new HierarchyListener() {
113 public void
114 hierarchyChanged(HierarchyEvent e) {
115 if((e.getChangeFlags() & e.SHOWING_CHANGED) != e.SHOWING_CHANGED) {
116 return;
117 }
118
119 onScrollBarVisibilityChanged();
120 }
121 });
122
123 c.gridx = 0;
124 c.gridy = 2;
125 c.weightx = 1.0;
126 c.weighty = 1.0;
127 c.insets = new Insets(0, 0, 0, 0);
128 c.fill = GridBagConstraints.BOTH;
129 gridbag.setConstraints(sp, c);
130 add(sp);
131
132 setMaximumSize(new Dimension(420, Short.MAX_VALUE));
133 }
134
135 private void
136 onScrollBarVisibilityChanged() {
137 int w = 420;
138 int h = scrollPane.getPreferredSize().height;
139 int scrollbarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width;
140
141 if(scrollPane.getVerticalScrollBar().isVisible()) w += scrollbarWidth;
142
143 scrollPane.setMinimumSize(new Dimension(w, scrollPane.getPreferredSize().height));
144 scrollPane.setPreferredSize(new Dimension(w, h));
145 scrollPane.setMaximumSize(new Dimension(w, Short.MAX_VALUE));
146 setMaximumSize(new Dimension(w, Short.MAX_VALUE));
147
148 if(CC.getMainFrame() != null && !CC.getMainFrame().isResizable()) {
149 // this means that there are no visible side panes
150
151 w = CC.getMainFrame().getPreferredSize().width;
152 CC.getMainFrame().setSize(w, CC.getMainFrame().getHeight());
153 }
154
155 revalidate();
156 }
157
158 public void
159 scrollToBottom() {
160 int h = scrollPane.getViewport().getView().getHeight();
161 scrollPane.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1));
162 }
163
164 public JSChannelsPane
165 getChannelsPane(int index) { return channelsPanes.get(index).getChannelsPane(); }
166
167 public int
168 getChannelsPaneCount() { return channelsPanes.size(); }
169
170 public void
171 setSelectedChannelsPane(JSChannelsPane pane) {
172 ChannelsPanel chnPanel = null;
173
174 for(int i = 0; i < getChannelsPaneCount(); i++) {
175 if(channelsPanes.get(i).getChannelsPane() == pane) {
176 chnPanel = channelsPanes.get(i);
177
178 if(!buttonsPanel.buttons.get(i).isSelected()) {
179 buttonsPanel.buttons.get(i).setSelected(true);
180 }
181
182 break;
183 }
184 }
185
186 if(chnPanel == null) {
187 CC.getLogger().warning("Unknown channels pane");
188 return;
189 }
190
191 scrollPane.getViewport().setView(chnPanel);
192 }
193
194 public JSChannelsPane
195 getSelectedChannelsPane() {
196 for(int i = 0; i < getChannelsPaneCount(); i++) {
197 if(buttonsPanel.buttons.get(i).isSelected()) {
198 return channelsPanes.get(i).getChannelsPane();
199 }
200 }
201
202 return null;
203 }
204
205 @Override
206 protected void
207 paintComponent(Graphics g) {
208 super.paintComponent(g);
209 int h = Res.gfxChannelsBg.getIconHeight();
210 if(h < 1) return;
211 int i = 0;
212 while(i < getHeight()) {
213 Res.gfxChannelsBg.paintIcon(this, g, 0, i);
214 i += h;
215 }
216 }
217
218 private final EventHandler eventHandler = new EventHandler();
219
220 private EventHandler
221 getHandler() { return eventHandler; }
222
223 private class EventHandler extends MouseAdapter {
224 @Override
225 public void
226 mousePressed(MouseEvent e) {
227 // TAG: channel selection system
228 CC.getMainFrame().getSelectedChannelsPane().setSelectedChannel(null);
229 ///////
230 }
231 }
232
233 private class ChannelsPanel extends FantasiaPanel {
234 private final JSChannelsPane channelsPane;
235 ChannelsPanel(String title) {
236 ActionListener l = new ActionListener() {
237 public void
238 actionPerformed(ActionEvent e) { scrollToBottom(); }
239 };
240
241 channelsPane = new ChannelsPane(title, 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 {
292 private final PixmapButton btnNew = new PixmapButton(Res.gfxPowerOff);
293
294 NewChannelPane() {
295 super(Res.gfxCreateChannel);
296 setPixmapInsets(new Insets(3, 3, 3, 3));
297
298 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
299 add(Box.createRigidArea(new Dimension(3, 0)));
300 add(btnNew);
301 add(Box.createRigidArea(new Dimension(4, 0)));
302
303 add(createVSeparator());
304
305 add(Box.createRigidArea(new Dimension(275, 0)));
306
307 add(createVSeparator());
308
309 add(Box.createRigidArea(new Dimension(29, 0)));
310
311 add(createVSeparator());
312
313 add(Box.createRigidArea(new Dimension(40, 0)));
314
315 add(createVSeparator());
316
317 setPreferredSize(new Dimension(420, 29));
318 setMinimumSize(getPreferredSize());
319 setMaximumSize(getPreferredSize());
320
321 btnNew.setPressedIcon(Res.gfxPowerOn);
322 btnNew.addActionListener(this);
323
324 addMouseListener(new MouseAdapter() {
325 public void
326 mouseClicked(MouseEvent e) {
327 if(e.getButton() != e.BUTTON1) {
328 return;
329 }
330
331 CC.getSamplerModel().addBackendChannel();
332 }
333 });
334
335 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
336
337 String s = i18n.getLabel("MainPane.NewChannelPane.newChannel");
338 btnNew.setToolTipText(s);
339 setToolTipText(s);
340 }
341
342 @Override
343 public void
344 actionPerformed(ActionEvent e) {
345 CC.getSamplerModel().addBackendChannel();
346 }
347
348 private JPanel
349 createVSeparator() {
350 PixmapPane p = new PixmapPane(Res.gfxVLine);
351 p.setOpaque(false);
352 p.setPreferredSize(new Dimension(2, 29));
353 p.setMinimumSize(p.getPreferredSize());
354 p.setMaximumSize(p.getPreferredSize());
355 return p;
356 }
357 }
358 }

  ViewVC Help
Powered by ViewVC