1 |
iliev |
1205 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005-2007 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.Dialog; |
26 |
|
|
import java.awt.Frame; |
27 |
|
|
|
28 |
|
|
import javax.swing.JScrollPane; |
29 |
|
|
import javax.swing.JSplitPane; |
30 |
|
|
import javax.swing.ListSelectionModel; |
31 |
|
|
|
32 |
|
|
import javax.swing.event.ListSelectionEvent; |
33 |
|
|
import javax.swing.event.ListSelectionListener; |
34 |
|
|
|
35 |
|
|
import net.sf.juife.OkCancelDialog; |
36 |
|
|
|
37 |
|
|
import org.jsampler.CC; |
38 |
|
|
|
39 |
|
|
import org.linuxsampler.lscp.DbInstrumentInfo; |
40 |
|
|
|
41 |
|
|
import org.jsampler.view.InstrumentsDbTreeModel; |
42 |
|
|
|
43 |
|
|
import static org.jsampler.view.classic.ClassicI18n.i18n; |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
/** |
47 |
|
|
* |
48 |
|
|
* @author Grigor Iliev |
49 |
|
|
*/ |
50 |
|
|
public class DbInstrumentChooser extends OkCancelDialog implements ListSelectionListener { |
51 |
|
|
private InstrumentsDbTree instrumentsDbTree; |
52 |
|
|
private InstrumentsDbTable instrumentsDbTable; |
53 |
|
|
|
54 |
|
|
/** Creates a new instance of <code>DbInstrumentChooser</code> */ |
55 |
|
|
public DbInstrumentChooser(Frame owner) { |
56 |
|
|
super(owner, i18n.getLabel("DbInstrumentChooser.title")); |
57 |
|
|
initDbInstrumentChooser(); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
/** Creates a new instance of <code>DbInstrumentChooser</code> */ |
61 |
|
|
public DbInstrumentChooser(Dialog owner) { |
62 |
|
|
super(owner, i18n.getLabel("DbInstrumentChooser.title")); |
63 |
|
|
initDbInstrumentChooser(); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
private void |
67 |
|
|
initDbInstrumentChooser() { |
68 |
|
|
btnOk.setEnabled(false); |
69 |
|
|
instrumentsDbTree = new InstrumentsDbTree(CC.getInstrumentsDbTreeModel()); |
70 |
|
|
JScrollPane sp = new JScrollPane(instrumentsDbTree); |
71 |
|
|
|
72 |
|
|
instrumentsDbTable = new InstrumentsDbTable(instrumentsDbTree); |
73 |
|
|
instrumentsDbTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
74 |
|
|
instrumentsDbTable.getSelectionModel().addListSelectionListener(this); |
75 |
|
|
instrumentsDbTable.loadColumnWidths(); |
76 |
|
|
JScrollPane sp2 = new JScrollPane(instrumentsDbTable); |
77 |
|
|
|
78 |
|
|
JSplitPane splitPane = new JSplitPane ( |
79 |
|
|
JSplitPane.HORIZONTAL_SPLIT, |
80 |
|
|
true, // continuousLayout |
81 |
|
|
sp, |
82 |
|
|
sp2 |
83 |
|
|
); |
84 |
|
|
|
85 |
|
|
splitPane.setDividerSize(3); |
86 |
|
|
splitPane.setDividerLocation(200); |
87 |
|
|
|
88 |
|
|
setMainPane(splitPane); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
public String |
92 |
|
|
getSelectedInstrument() { |
93 |
|
|
DbInstrumentInfo[] infos = instrumentsDbTable.getSelectedInstruments(); |
94 |
|
|
if(infos.length == 0) return null; |
95 |
|
|
return infos[0].getInstrumentPath(); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
public void |
99 |
|
|
setSelectedInstrument(String instr) { |
100 |
|
|
String parentDir = InstrumentsDbTreeModel.getParentDirectory(instr); |
101 |
|
|
if(parentDir == null) return; |
102 |
|
|
instrumentsDbTree.setSelectedDirectory(parentDir); |
103 |
|
|
if(instrumentsDbTable.getParentDirectoryNode() == null) return; |
104 |
|
|
|
105 |
|
|
instr = instr.substring(parentDir.length() + 1, instr.length()); |
106 |
|
|
instrumentsDbTable.setSelectedInstrument(instr); |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
protected void |
110 |
|
|
onOk() { |
111 |
|
|
if(!btnOk.isEnabled()) return; |
112 |
|
|
setCancelled(false); |
113 |
|
|
setVisible(false); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
protected void |
117 |
|
|
onCancel() { setVisible(false); } |
118 |
|
|
|
119 |
|
|
public void |
120 |
|
|
valueChanged(ListSelectionEvent e) { |
121 |
|
|
boolean b = instrumentsDbTable.getSelectedInstruments().length > 0; |
122 |
|
|
btnOk.setEnabled(b); |
123 |
|
|
} |
124 |
|
|
} |