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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1540 - (show annotations) (download)
Mon Dec 3 23:22:02 2007 UTC (16 years, 4 months ago) by iliev
File size: 6717 byte(s)
* Fantasia: by default the volume values are now shown in decibels
* Implemented support for retrieving instrument information
  from instrument files
* Some bugfixes and enhancements

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.BorderLayout;
26
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.MouseAdapter;
30 import java.awt.event.MouseEvent;
31
32 import javax.swing.AbstractAction;
33 import javax.swing.Action;
34 import javax.swing.JPanel;
35 import javax.swing.JScrollPane;
36
37 import javax.swing.event.ListSelectionEvent;
38 import javax.swing.event.ListSelectionListener;
39
40 import org.jsampler.CC;
41 import org.jsampler.HF;
42 import org.jsampler.OrchestraModel;
43
44 import org.jsampler.view.OrchestraTable;
45 import org.jsampler.view.OrchestraTableModel;
46
47 import static org.jsampler.view.std.StdI18n.i18n;
48
49 /**
50 *
51 * @author Grigor Iliev
52 */
53 public class JSManageOrchestrasPane extends JPanel {
54 protected final OrchestraTable orchestraTable;
55
56 protected final Action actionAddOrchestra = new AddOrchestraAction();
57 protected final Action actionEditOrchestra = new EditOrchestraAction();
58 protected final Action actionDeleteOrchestra = new DeleteOrchestraAction();
59 protected final Action actionOrchestraUp = new OrchestraUpAction();
60 protected final Action actionOrchestraDown = new OrchestraDownAction();
61
62 /** Creates a new instance of <code>JSManageOrchestrasPane</code> */
63 public
64 JSManageOrchestrasPane() {
65 setLayout(new BorderLayout());
66 orchestraTable = new OrchestraTable(new OrchestraTableModel(CC.getOrchestras()));
67 JScrollPane sp = new JScrollPane(orchestraTable);
68 add(sp);
69
70 installListeneres();
71 }
72
73 private void
74 installListeneres() {
75 OrchestraSelectionHandler l = new OrchestraSelectionHandler();
76 orchestraTable.getSelectionModel().addListSelectionListener(l);
77
78 orchestraTable.addMouseListener(new MouseAdapter() {
79 public void
80 mouseClicked(MouseEvent e) {
81 if(e.getClickCount() < 2) return;
82
83 if(orchestraTable.getSelectedOrchestra() == null) return;
84 editOrchestra(orchestraTable.getSelectedOrchestra());
85 }
86 });
87 }
88
89 /**
90 * Invoked when the user initiates the creation of new orchestra.
91 * @return The model of the orchestra to add
92 * or <code>null</code> if the user cancelled the task.
93 */
94 public OrchestraModel
95 createOrchestra() {
96 JSAddOrEditOrchestraDlg dlg = new JSAddOrEditOrchestraDlg();
97 dlg.setVisible(true);
98
99 if(dlg.isCancelled()) return null;
100
101 return dlg.getOrchestra();
102 }
103
104 public void
105 editOrchestra(OrchestraModel model) {
106 JSAddOrEditOrchestraDlg dlg = new JSAddOrEditOrchestraDlg(model);
107 dlg.setVisible(true);
108 }
109
110 private class OrchestraSelectionHandler implements ListSelectionListener {
111 public void
112 valueChanged(ListSelectionEvent e) {
113 if(e.getValueIsAdjusting()) return;
114
115 if(orchestraTable.getSelectedOrchestra() == null) {
116 actionEditOrchestra.setEnabled(false);
117 actionDeleteOrchestra.setEnabled(false);
118 actionOrchestraUp.setEnabled(false);
119 actionOrchestraDown.setEnabled(false);
120 return;
121 }
122
123 actionEditOrchestra.setEnabled(true);
124 actionDeleteOrchestra.setEnabled(true);
125
126 OrchestraModel orchestraModel = orchestraTable.getSelectedOrchestra();
127 int idx = orchestraTable.getSelectedRow();
128 actionOrchestraUp.setEnabled(idx != 0);
129 actionOrchestraDown.setEnabled(idx != orchestraTable.getRowCount() - 1);
130 }
131 }
132
133 private class AddOrchestraAction extends AbstractAction {
134 AddOrchestraAction() {
135 super("");
136
137 String s = i18n.getLabel("JSManageOrchestrasPane.ttAddOrchestra");
138 putValue(SHORT_DESCRIPTION, s);
139 }
140
141 public void
142 actionPerformed(ActionEvent e) {
143 OrchestraModel newOrch = createOrchestra();
144 if(newOrch == null) return;
145
146 OrchestraModel om = orchestraTable.getSelectedOrchestra();
147 int idx = CC.getOrchestras().getOrchestraIndex(om);
148 if(idx < 0) CC.getOrchestras().addOrchestra(newOrch);
149 else CC.getOrchestras().insertOrchestra(newOrch, idx);
150
151 orchestraTable.setSelectedOrchestra(newOrch);
152 }
153 }
154
155 private class EditOrchestraAction extends AbstractAction {
156 EditOrchestraAction() {
157 super("");
158
159 String s = i18n.getLabel("JSManageOrchestrasPane.ttEditOrchestra");
160 putValue(SHORT_DESCRIPTION, s);
161
162 setEnabled(false);
163 }
164
165 public void
166 actionPerformed(ActionEvent e) {
167 editOrchestra(orchestraTable.getSelectedOrchestra());
168 }
169 }
170
171 private class DeleteOrchestraAction extends AbstractAction {
172 DeleteOrchestraAction() {
173 super("");
174
175 String s = i18n.getLabel("JSManageOrchestrasPane.ttDeleteOrchestra");
176 putValue(SHORT_DESCRIPTION, s);
177
178 setEnabled(false);
179 }
180
181 public void
182 actionPerformed(ActionEvent e) {
183 OrchestraModel om = orchestraTable.getSelectedOrchestra();
184 if(om == null) return;
185 if(om.getInstrumentCount() > 0) {
186 String s;
187 s = i18n.getMessage("JSManageOrchestrasPane.removeOrchestra?");
188 if(!HF.showYesNoDialog(CC.getMainFrame(), s)) return;
189 }
190
191 int i = orchestraTable.getSelectedRow();
192 CC.getOrchestras().removeOrchestra(om);
193 if(orchestraTable.getRowCount() > i) {
194 orchestraTable.getSelectionModel().setSelectionInterval(i, i);
195 }
196 }
197 }
198
199 private class OrchestraUpAction extends AbstractAction {
200 OrchestraUpAction() {
201 super("");
202
203 String s = i18n.getLabel("JSManageOrchestrasPane.ttOrchestraUp");
204 putValue(SHORT_DESCRIPTION, s);
205
206 setEnabled(false);
207 }
208
209 public void
210 actionPerformed(ActionEvent e) {
211 OrchestraModel om = orchestraTable.getSelectedOrchestra();
212 CC.getOrchestras().moveOrchestraUp(om);
213 orchestraTable.setSelectedOrchestra(om);
214 }
215 }
216
217 private class OrchestraDownAction extends AbstractAction {
218 OrchestraDownAction() {
219 super("");
220
221 String s = i18n.getLabel("JSManageOrchestrasPane.ttOrchestraDown");
222 putValue(SHORT_DESCRIPTION, s);
223
224 setEnabled(false);
225 }
226
227 public void
228 actionPerformed(ActionEvent e) {
229 OrchestraModel om = orchestraTable.getSelectedOrchestra();
230 CC.getOrchestras().moveOrchestraDown(om);
231 orchestraTable.setSelectedOrchestra(om);
232 }
233 }
234 }

  ViewVC Help
Powered by ViewVC