/[svn]/jsampler/trunk/src/org/jsampler/view/classic/ManageOrchestrasPage.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/classic/ManageOrchestrasPage.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1143 - (show annotations) (download)
Mon Apr 2 21:18:31 2007 UTC (17 years, 1 month ago) by iliev
File size: 15012 byte(s)
* upgrading to version 0.4a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2006 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.classic;
24
25 import java.awt.Dimension;
26
27 import java.awt.datatransfer.DataFlavor;
28
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
33
34 import java.util.logging.Level;
35
36 import javax.swing.AbstractAction;
37 import javax.swing.Action;
38 import javax.swing.Box;
39 import javax.swing.BoxLayout;
40 import javax.swing.JComponent;
41 import javax.swing.JPanel;
42 import javax.swing.JScrollPane;
43 import javax.swing.JSplitPane;
44 import javax.swing.JToolBar;
45 import javax.swing.ListSelectionModel;
46 import javax.swing.TransferHandler;
47
48 import javax.swing.event.ListSelectionEvent;
49 import javax.swing.event.ListSelectionListener;
50
51 import net.sf.juife.JuifeUtils;
52 import net.sf.juife.LinkButton;
53 import net.sf.juife.NavigationPage;
54
55 import org.jsampler.CC;
56 import org.jsampler.DOMUtils;
57 import org.jsampler.DefaultOrchestraModel;
58 import org.jsampler.HF;
59 import org.jsampler.Instrument;
60 import org.jsampler.OrchestraListModel;
61 import org.jsampler.OrchestraModel;
62
63 import org.jsampler.view.InstrumentTable;
64 import org.jsampler.view.InstrumentTableModel;
65 import org.jsampler.view.OrchestraTable;
66 import org.jsampler.view.OrchestraTableModel;
67
68 import static org.jsampler.view.classic.ClassicI18n.i18n;
69
70
71 /**
72 *
73 * @author Grigor Iliev
74 */
75 public class ManageOrchestrasPage extends NavigationPage {
76 private final JComponent manageOrchestrasPane;
77
78 // Manage Orchestra
79 private final ToolbarButton btnAddOrchestra = new ToolbarButton(new AddOrchestra());
80 private final ToolbarButton btnEditOrchestra = new ToolbarButton(new EditOrchestra());
81 private final ToolbarButton btnDeleteOrchestra = new ToolbarButton(new DeleteOrchestra());
82 private final ToolbarButton btnOrchestraUp = new ToolbarButton(new OrchestraUp());
83 private final ToolbarButton btnOrchestraDown = new ToolbarButton(new OrchestraDown());
84
85 private OrchestraTable orchestraTable;
86
87 private final ToolbarButton btnAddInstrument = new ToolbarButton(new AddInstrument());
88 private final ToolbarButton btnEditInstrument = new ToolbarButton(new EditInstrument());
89 private final ToolbarButton btnDeleteInstrument = new ToolbarButton(new DeleteInstrument());
90 private final ToolbarButton btnInstrumentUp = new ToolbarButton(new InstrumentUp());
91 private final ToolbarButton btnInstrumentDown = new ToolbarButton(new InstrumentDown());
92
93 private LinkButton lnkOrchestras =
94 new LinkButton(i18n.getButtonLabel("ManageOrchestrasPage.lnkOrchestras"));
95
96 private InstrumentTable instrumentTable;
97 private OrchestraModel orchestraModel;
98
99
100 /** Creates a new instance of <code>ManageOrchestrasPage</code>. */
101 public ManageOrchestrasPage() {
102 setTitle(i18n.getLabel("ManageOrchestrasPage.title"));
103
104 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
105
106 manageOrchestrasPane = createManageOrchestrasPane();
107 add(manageOrchestrasPane);
108
109 installListeneres();
110 }
111
112 private JComponent
113 createManageOrchestrasPane() {
114 JPanel p = new JPanel();
115 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
116 //p.add(Box.createRigidArea(new Dimension(0, 5)));
117
118 JToolBar tb = new JToolBar();
119 tb.add(btnAddOrchestra);
120 tb.add(btnEditOrchestra);
121 tb.add(btnDeleteOrchestra);
122
123 tb.addSeparator();
124
125 tb.add(btnOrchestraUp);
126 tb.add(btnOrchestraDown);
127
128 tb.setMaximumSize(new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height));
129 tb.setFloatable(false);
130 tb.setAlignmentX(LEFT_ALIGNMENT);
131
132 p.add(tb);
133
134 orchestraTable = new OrchestraTable(new OrchestraTableModel(CC.getOrchestras()));
135 JScrollPane sp = new JScrollPane(orchestraTable);
136
137 sp.getViewport().addMouseListener(new MouseAdapter() {
138 public void
139 mouseClicked(MouseEvent e) { orchestraTable.clearSelection(); }
140 });
141
142 Dimension d;
143 d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height);
144 sp.setPreferredSize(d);
145
146 sp.setAlignmentX(LEFT_ALIGNMENT);
147 p.add(sp);
148
149 JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
150 splitPane.setContinuousLayout(true);
151 splitPane.setTopComponent(p);
152
153 p = new JPanel();
154 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
155 //p.add(Box.createRigidArea(new Dimension(0, 5)));
156
157 tb = new JToolBar();
158 btnAddInstrument.setEnabled(false);
159 tb.add(btnAddInstrument);
160 tb.add(btnEditInstrument);
161 tb.add(btnDeleteInstrument);
162
163 tb.addSeparator();
164
165 tb.add(btnInstrumentUp);
166 tb.add(btnInstrumentDown);
167
168 tb.setMaximumSize(new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height));
169 tb.setFloatable(false);
170 tb.setAlignmentX(JPanel.LEFT_ALIGNMENT);
171
172 p.add(tb);
173
174 orchestraModel = new DefaultOrchestraModel();
175 instrumentTable = new InstrumentTable(new InstrumentTableModel(orchestraModel));
176 sp = new DnDScrollPane(instrumentTable);
177 sp.setAlignmentX(LEFT_ALIGNMENT);
178 p.add(sp);
179
180 //p.add(lnkOrchestras);
181 //p.add(Box.createRigidArea(new Dimension(0, 5)));
182
183 splitPane.setBottomComponent(p);
184 splitPane.setDividerSize(3);
185 splitPane.setDividerLocation(180);
186
187 return splitPane;
188 }
189
190 private void
191 installListeneres() {
192 lnkOrchestras.addActionListener(new ActionListener() {
193 public void
194 actionPerformed(ActionEvent e) {
195 LeftPane.getLeftPane().showOrchestrasPage();
196 }
197 });
198
199 OrchestraSelectionHandler l = new OrchestraSelectionHandler();
200 orchestraTable.getSelectionModel().addListSelectionListener(l);
201
202 orchestraTable.addMouseListener(new MouseAdapter() {
203 public void
204 mouseClicked(MouseEvent e) {
205 if(e.getClickCount() < 2) return;
206
207 if(orchestraTable.getSelectedOrchestra() == null) return;
208 btnEditOrchestra.doClick(0);
209 }
210 });
211
212 InstrumentSelectionHandler l2 = new InstrumentSelectionHandler();
213 instrumentTable.getSelectionModel().addListSelectionListener(l2);
214
215 instrumentTable.addMouseListener(new MouseAdapter() {
216 public void
217 mouseClicked(MouseEvent e) {
218 if(e.getClickCount() < 2) return;
219
220 if(instrumentTable.getSelectedInstrument() == null) return;
221 btnEditInstrument.doClick(0);
222 }
223 });
224 }
225
226 public class DnDScrollPane extends JScrollPane {
227 private InstrumentTable instrumentTable;
228
229 private
230 DnDScrollPane(InstrumentTable table) {
231 instrumentTable = table;
232 setViewport(new DnDViewPort());
233 setViewportView(instrumentTable);
234
235 Dimension d;
236 d = new Dimension(getMinimumSize().width, getPreferredSize().height);
237 setPreferredSize(d);
238 }
239
240 public class DnDViewPort extends javax.swing.JViewport {
241 private
242 DnDViewPort() {
243 setTransferHandler(new TransferHandler("instrument") {
244 public boolean
245 canImport(JComponent comp, DataFlavor[] flavors) {
246 if(instrumentTable.isPerformingDnD()) return false;
247 if(!btnAddInstrument.isEnabled()) return false;
248
249 return super.canImport(comp, flavors);
250 }
251 });
252
253 addMouseListener(new MouseAdapter() {
254 public void
255 mouseClicked(MouseEvent e) {
256 instrumentTable.clearSelection();
257 }
258 });
259 }
260
261 public String
262 getInstrument() { return null; }
263
264 public void
265 setInstrument(String instr) {
266 instrumentTable.setSelectedInstrument(null);
267 instrumentTable.setInstrument(instr);
268 }
269 }
270 }
271
272 private class OrchestraSelectionHandler implements ListSelectionListener {
273 public void
274 valueChanged(ListSelectionEvent e) {
275 if(e.getValueIsAdjusting()) return;
276
277 if(orchestraTable.getSelectedOrchestra() == null) {
278 btnEditOrchestra.setEnabled(false);
279 btnDeleteOrchestra.setEnabled(false);
280 btnAddInstrument.setEnabled(false);
281 btnOrchestraUp.setEnabled(false);
282 btnOrchestraDown.setEnabled(false);
283 instrumentTable.setModel(new InstrumentTableModel());
284 return;
285 }
286
287 btnEditOrchestra.setEnabled(true);
288 btnDeleteOrchestra.setEnabled(true);
289 btnAddInstrument.setEnabled(true);
290
291 orchestraModel = orchestraTable.getSelectedOrchestra();
292 int idx = orchestraTable.getSelectedRow();
293 btnOrchestraUp.setEnabled(idx != 0);
294 btnOrchestraDown.setEnabled(idx != orchestraTable.getRowCount() - 1);
295
296 instrumentTable.getModel().setOrchestraModel(orchestraModel);
297 }
298 }
299
300 private class InstrumentSelectionHandler implements ListSelectionListener {
301 public void
302 valueChanged(ListSelectionEvent e) {
303 if(e.getValueIsAdjusting()) return;
304
305 if(instrumentTable.getSelectedInstrument() == null) {
306 btnEditInstrument.setEnabled(false);
307 btnDeleteInstrument.setEnabled(false);
308 btnInstrumentUp.setEnabled(false);
309 btnInstrumentDown.setEnabled(false);
310 return;
311 }
312
313 btnEditInstrument.setEnabled(true);
314 btnDeleteInstrument.setEnabled(true);
315
316 int idx = instrumentTable.getSelectedRow();
317 btnInstrumentUp.setEnabled(idx != 0);
318 btnInstrumentDown.setEnabled(idx != instrumentTable.getRowCount() - 1);
319 }
320 }
321
322 private class AddOrchestra extends AbstractAction {
323 AddOrchestra() {
324 super("");
325
326 String s = i18n.getLabel("ManageOrchestrasPage.ttAddOrchestra");
327 putValue(SHORT_DESCRIPTION, s);
328 putValue(Action.SMALL_ICON, Res.iconNew16);
329 }
330
331 public void
332 actionPerformed(ActionEvent e) {
333 AddOrchestraDlg dlg = new AddOrchestraDlg();
334 dlg.setVisible(true);
335
336 if(dlg.isCancelled()) return;
337
338 OrchestraModel om = orchestraTable.getSelectedOrchestra();
339 int idx = CC.getOrchestras().getOrchestraIndex(om);
340 if(idx < 0) CC.getOrchestras().addOrchestra(dlg.getOrchestra());
341 else CC.getOrchestras().insertOrchestra(dlg.getOrchestra(), idx);
342
343 orchestraTable.setSelectedOrchestra(dlg.getOrchestra());
344 }
345 }
346
347 private class EditOrchestra extends AbstractAction {
348 EditOrchestra() {
349 super("");
350
351 String s = i18n.getLabel("ManageOrchestrasPage.ttEditOrchestra");
352 putValue(SHORT_DESCRIPTION, s);
353 putValue(Action.SMALL_ICON, Res.iconEdit16);
354
355 setEnabled(false);
356 }
357
358 public void
359 actionPerformed(ActionEvent e) {
360 OrchestraModel m = orchestraTable.getSelectedOrchestra();
361 AddOrchestraDlg dlg = new AddOrchestraDlg(m);
362 dlg.setVisible(true);
363 }
364 }
365
366 private class DeleteOrchestra extends AbstractAction {
367 DeleteOrchestra() {
368 super("");
369
370 String s = i18n.getLabel("ManageOrchestrasPage.ttDeleteOrchestra");
371 putValue(SHORT_DESCRIPTION, s);
372 putValue(Action.SMALL_ICON, Res.iconDelete16);
373
374 setEnabled(false);
375 }
376
377 public void
378 actionPerformed(ActionEvent e) {
379 OrchestraModel om = orchestraTable.getSelectedOrchestra();
380 if(om == null) return;
381 if(om.getInstrumentCount() > 0) {
382 String s = i18n.getMessage("ManageOrchestrasPage.removeOrchestra?");
383 if(!HF.showYesNoDialog(CC.getMainFrame(), s)) return;
384 }
385
386 CC.getOrchestras().removeOrchestra(om);
387 }
388 }
389
390 private class OrchestraUp extends AbstractAction {
391 OrchestraUp() {
392 super("");
393
394 String s = i18n.getLabel("ManageOrchestrasPage.OrchestraUp");
395 putValue(SHORT_DESCRIPTION, s);
396 putValue(Action.SMALL_ICON, Res.iconUp16);
397
398 setEnabled(false);
399 }
400
401 public void
402 actionPerformed(ActionEvent e) {
403 OrchestraModel om = orchestraTable.getSelectedOrchestra();
404 CC.getOrchestras().moveOrchestraUp(om);
405 orchestraTable.setSelectedOrchestra(om);
406 }
407 }
408
409 private class OrchestraDown extends AbstractAction {
410 OrchestraDown() {
411 super("");
412
413 String s = i18n.getLabel("ManageOrchestrasPage.OrchestraDown");
414 putValue(SHORT_DESCRIPTION, s);
415 putValue(Action.SMALL_ICON, Res.iconDown16);
416
417 setEnabled(false);
418 }
419
420 public void
421 actionPerformed(ActionEvent e) {
422 OrchestraModel om = orchestraTable.getSelectedOrchestra();
423 CC.getOrchestras().moveOrchestraDown(om);
424 orchestraTable.setSelectedOrchestra(om);
425 }
426 }
427
428 private class AddInstrument extends AbstractAction {
429 AddInstrument() {
430 super("");
431
432 String s = i18n.getLabel("ManageOrchestrasPage.ttAddInstrument");
433 putValue(SHORT_DESCRIPTION, s);
434
435 try {
436 putValue(Action.SMALL_ICON, Res.iconNew16);
437 } catch(Exception x) {
438 CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
439 }
440 }
441
442 public void
443 actionPerformed(ActionEvent e) {
444 AddInstrumentDlg dlg = new AddInstrumentDlg();
445 dlg.setVisible(true);
446
447 if(dlg.isCancelled()) return;
448
449 orchestraModel.addInstrument(dlg.getInstrument());
450 }
451 }
452
453 private class EditInstrument extends AbstractAction {
454 EditInstrument() {
455 super("");
456
457 String s = i18n.getLabel("ManageOrchestrasPage.ttEditInstrument");
458 putValue(SHORT_DESCRIPTION, s);
459 putValue(Action.SMALL_ICON, Res.iconEdit16);
460
461 setEnabled(false);
462 }
463
464 public void
465 actionPerformed(ActionEvent e) {
466 Instrument instr = instrumentTable.getSelectedInstrument();
467 AddInstrumentDlg dlg = new AddInstrumentDlg(instr);
468 dlg.setVisible(true);
469 }
470 }
471
472 private class DeleteInstrument extends AbstractAction {
473 DeleteInstrument() {
474 super("");
475
476 String s = i18n.getLabel("ManageOrchestrasPage.ttDeleteInstrument");
477 putValue(SHORT_DESCRIPTION, s);
478 putValue(Action.SMALL_ICON, Res.iconDelete16);
479
480 setEnabled(false);
481 }
482
483 public void
484 actionPerformed(ActionEvent e) {
485 Instrument instr = instrumentTable.getSelectedInstrument();
486 if(instr == null) return;
487 orchestraModel.removeInstrument(instr);
488 }
489 }
490
491 private class InstrumentUp extends AbstractAction {
492 InstrumentUp() {
493 super("");
494
495 String s = i18n.getLabel("ManageOrchestrasPage.InstrumentUp");
496 putValue(SHORT_DESCRIPTION, s);
497 putValue(Action.SMALL_ICON, Res.iconUp16);
498
499 setEnabled(false);
500 }
501
502 public void
503 actionPerformed(ActionEvent e) {
504 Instrument instr = instrumentTable.getSelectedInstrument();
505 instrumentTable.getModel().getOrchestraModel().moveInstrumentUp(instr);
506 instrumentTable.setSelectedInstrument(instr);
507 }
508 }
509
510 private class InstrumentDown extends AbstractAction {
511 InstrumentDown() {
512 super("");
513
514 String s = i18n.getLabel("ManageOrchestrasPage.InstrumentDown");
515 putValue(SHORT_DESCRIPTION, s);
516 putValue(Action.SMALL_ICON, Res.iconDown16);
517
518 setEnabled(false);
519 }
520
521 public void
522 actionPerformed(ActionEvent e) {
523 Instrument instr = instrumentTable.getSelectedInstrument();
524 instrumentTable.getModel().getOrchestraModel().moveInstrumentDown(instr);
525 instrumentTable.setSelectedInstrument(instr);
526 }
527 }
528 }

  ViewVC Help
Powered by ViewVC