/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSDbInstrumentChooser.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/std/JSDbInstrumentChooser.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1286 - (show annotations) (download)
Fri Aug 10 20:24:23 2007 UTC (16 years, 8 months ago) by iliev
File size: 5494 byte(s)
- Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

1 /*
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.std;
24
25 import java.awt.Dialog;
26 import java.awt.Frame;
27
28 import java.awt.event.ActionEvent;
29 import java.awt.event.KeyEvent;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32
33 import javax.swing.AbstractAction;
34 import javax.swing.JComponent;
35 import javax.swing.JScrollPane;
36 import javax.swing.JSplitPane;
37 import javax.swing.KeyStroke;
38 import javax.swing.ListSelectionModel;
39
40 import javax.swing.event.ListSelectionEvent;
41 import javax.swing.event.ListSelectionListener;
42
43 import net.sf.juife.OkCancelDialog;
44
45 import org.jsampler.CC;
46
47 import org.jsampler.view.DbDirectoryTreeNode;
48 import org.jsampler.view.InstrumentsDbTreeModel;
49
50 import org.linuxsampler.lscp.DbInstrumentInfo;
51
52 import static org.jsampler.view.std.StdI18n.i18n;
53
54
55 /**
56 *
57 * @author Grigor Iliev
58 */
59 public class JSDbInstrumentChooser extends OkCancelDialog implements ListSelectionListener {
60 protected JSInstrumentsDbTree instrumentsDbTree;
61 protected JSInstrumentsDbTable instrumentsDbTable;
62
63 /**
64 * Creates a new instance of <code>JSDbInstrumentChooser</code>
65 */
66 public JSDbInstrumentChooser(Frame owner) {
67 super(owner, i18n.getLabel("JSDbInstrumentChooser.title"));
68 initDbInstrumentChooser();
69 }
70
71 /**
72 * Creates a new instance of <code>JSDbInstrumentChooser</code>
73 */
74 public JSDbInstrumentChooser(Dialog owner) {
75 super(owner, i18n.getLabel("JSDbInstrumentChooser.title"));
76 initDbInstrumentChooser();
77 }
78
79 private void
80 initDbInstrumentChooser() {
81 btnOk.setEnabled(false);
82 instrumentsDbTree = new JSInstrumentsDbTree(CC.getInstrumentsDbTreeModel());
83 JScrollPane sp = new JScrollPane(instrumentsDbTree);
84
85 instrumentsDbTable = new JSInstrumentsDbTable(instrumentsDbTree);
86 instrumentsDbTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
87 instrumentsDbTable.getSelectionModel().addListSelectionListener(this);
88 instrumentsDbTable.loadColumnWidths();
89 JScrollPane sp2 = new JScrollPane(instrumentsDbTable);
90
91 JSplitPane splitPane = new JSplitPane (
92 JSplitPane.HORIZONTAL_SPLIT,
93 true, // continuousLayout
94 sp,
95 sp2
96 );
97
98 splitPane.setDividerSize(3);
99 splitPane.setDividerLocation(200);
100
101 setMainPane(splitPane);
102
103 instrumentsDbTable.addMouseListener(new MouseAdapter() {
104 public void
105 mouseClicked(MouseEvent e) {
106 if(e.getButton() != e.BUTTON1 || e.getClickCount() < 2) return;
107 DbInstrumentInfo infos[];
108 infos = instrumentsDbTable.getSelectedInstruments();
109 if(infos.length == 0) return;
110 onOk();
111 }
112 });
113
114 installKeyboardListeners();
115 }
116
117 private void
118 installKeyboardListeners() {
119 getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put (
120 KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
121 "goUp"
122 );
123
124 getRootPane().getActionMap().put ("goUp", new GoUp());
125
126 instrumentsDbTable.getInputMap().put (
127 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
128 "Select"
129 );
130
131 instrumentsDbTable.getActionMap().put ("Select", new AbstractAction() {
132 public void
133 actionPerformed(ActionEvent e) {
134 DbDirectoryTreeNode node;
135 node = instrumentsDbTable.getSelectedDirectoryNode();
136 if(node != null) {
137 instrumentsDbTree.setSelectedDirectoryNode(node);
138 return;
139 }
140
141 if(instrumentsDbTable.getSelectedInstruments().length > 0) {
142 onOk();
143 }
144
145 }
146 });
147 }
148
149 public String
150 getSelectedInstrument() {
151 DbInstrumentInfo[] infos = instrumentsDbTable.getSelectedInstruments();
152 if(infos.length == 0) return null;
153 return infos[0].getInstrumentPath();
154 }
155
156 public void
157 setSelectedInstrument(String instr) {
158 String parentDir = InstrumentsDbTreeModel.getParentDirectory(instr);
159 if(parentDir == null) return;
160 instrumentsDbTree.setSelectedDirectory(parentDir);
161 if(instrumentsDbTable.getParentDirectoryNode() == null) return;
162
163 instr = instr.substring(parentDir.length() + 1, instr.length());
164 instrumentsDbTable.setSelectedInstrument(instr);
165 }
166
167 public void
168 setSelectedDirectory(String dir) {
169 instrumentsDbTree.setSelectedDirectory(dir);
170 }
171
172 protected void
173 onOk() {
174 if(!btnOk.isEnabled()) return;
175 setCancelled(false);
176 setVisible(false);
177 }
178
179 protected void
180 onCancel() { setVisible(false); }
181
182 public void
183 valueChanged(ListSelectionEvent e) {
184 boolean b = instrumentsDbTable.getSelectedInstruments().length > 0;
185 btnOk.setEnabled(b);
186 }
187
188 private class GoUp extends AbstractAction {
189 GoUp() { }
190
191 public void
192 actionPerformed(ActionEvent e) {
193 DbDirectoryTreeNode node = instrumentsDbTree.getSelectedDirectoryNode();
194 if(node == null) return;
195 if(node.getParent() == null) return;
196 instrumentsDbTree.setSelectedDirectoryNode(node.getParent());
197 }
198 }
199 }

  ViewVC Help
Powered by ViewVC