1 |
iliev |
1204 |
/* |
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; |
24 |
|
|
|
25 |
|
|
import java.text.NumberFormat; |
26 |
|
|
|
27 |
|
|
import java.util.Comparator; |
28 |
|
|
import java.util.Date; |
29 |
|
|
import java.util.Vector; |
30 |
|
|
|
31 |
|
|
import javax.swing.table.AbstractTableModel; |
32 |
|
|
|
33 |
|
|
import net.sf.juife.Task; |
34 |
|
|
import net.sf.juife.event.TaskEvent; |
35 |
|
|
import net.sf.juife.event.TaskListener; |
36 |
|
|
|
37 |
|
|
import org.jsampler.CC; |
38 |
|
|
import org.jsampler.task.InstrumentsDb; |
39 |
|
|
|
40 |
|
|
import org.linuxsampler.lscp.DbDirectoryInfo; |
41 |
|
|
import org.linuxsampler.lscp.DbInstrumentInfo; |
42 |
|
|
|
43 |
|
|
import org.linuxsampler.lscp.event.InstrumentsDbEvent; |
44 |
|
|
import org.linuxsampler.lscp.event.InstrumentsDbListener; |
45 |
|
|
|
46 |
|
|
import static org.jsampler.JSI18n.i18n; |
47 |
iliev |
1352 |
import static org.linuxsampler.lscp.Parser.*; |
48 |
iliev |
1204 |
|
49 |
|
|
/** |
50 |
|
|
* |
51 |
|
|
* @author Grigor Iliev |
52 |
|
|
*/ |
53 |
|
|
public class InstrumentsDbTableModel extends AbstractTableModel { |
54 |
|
|
public static enum ColumnType { |
55 |
|
|
NAME (i18n.getLabel("InstrumentsDbTableModel.NAME")), |
56 |
|
|
SIZE (i18n.getLabel("InstrumentsDbTableModel.SIZE")), |
57 |
|
|
FORMAT_FAMILY (i18n.getLabel("InstrumentsDbTableModel.FORMAT_FAMILY")), |
58 |
|
|
FORMAT_VERSION (i18n.getLabel("InstrumentsDbTableModel.FORMAT_VERSION")), |
59 |
|
|
IS_DRUM (i18n.getLabel("InstrumentsDbTableModel.IS_DRUM")), |
60 |
|
|
CREATED (i18n.getLabel("InstrumentsDbTableModel.CREATED")), |
61 |
|
|
MODIFIED (i18n.getLabel("InstrumentsDbTableModel.MODIFIED")), |
62 |
|
|
PRODUCT (i18n.getLabel("InstrumentsDbTableModel.PRODUCT")), |
63 |
|
|
ARTISTS (i18n.getLabel("InstrumentsDbTableModel.ARTISTS")), |
64 |
|
|
INSTRUMENT_FILE (i18n.getLabel("InstrumentsDbTableModel.INSTRUMENT_FILE")), |
65 |
|
|
INSTRUMENT_NR (i18n.getLabel("InstrumentsDbTableModel.INSTRUMENT_NR")), |
66 |
|
|
KEYWORDS (i18n.getLabel("InstrumentsDbTableModel.KEYWORDS")), |
67 |
|
|
DUMMY (""); |
68 |
|
|
|
69 |
|
|
private final String name; |
70 |
|
|
|
71 |
|
|
ColumnType(String name) { this.name = name; } |
72 |
|
|
|
73 |
|
|
public String |
74 |
|
|
toString() { return name; } |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
private Vector<ColumnType> columns = new Vector<ColumnType>(); |
78 |
|
|
|
79 |
|
|
private boolean showSizeColumn = true; |
80 |
|
|
private boolean showFormatFamilyColumn = true; |
81 |
|
|
private boolean showFormatVersionColumn = false; |
82 |
|
|
private boolean showIsDrumColumn = false; |
83 |
|
|
private boolean showCreatedColumn = false; |
84 |
|
|
private boolean showModifiedColumn = true; |
85 |
|
|
private boolean showProductColumn = false; |
86 |
|
|
private boolean showArtistsColumn = false; |
87 |
|
|
private boolean showInstrumentFileColumn = false; |
88 |
|
|
private boolean showInstrumentNrColumn = false; |
89 |
|
|
private boolean showKeywordsColumn = false; |
90 |
iliev |
1285 |
private boolean showDummyColumn = false; |
91 |
iliev |
1204 |
|
92 |
|
|
private DbDirectoryTreeNode directoryNode; |
93 |
|
|
|
94 |
|
|
|
95 |
|
|
/** Creates a new instance of <code>InstrumentsDbTableModel</code>. */ |
96 |
|
|
public |
97 |
|
|
InstrumentsDbTableModel() { |
98 |
|
|
this(null); |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
/** Creates a new instance of <code>InstrumentsDbTableModel</code>. */ |
102 |
|
|
public |
103 |
|
|
InstrumentsDbTableModel(DbDirectoryTreeNode node) { |
104 |
|
|
directoryNode = node; |
105 |
|
|
updateColumns(); |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
/** |
109 |
|
|
* Gets the type of the specified column. |
110 |
|
|
* @param index The index of the column. |
111 |
|
|
*/ |
112 |
|
|
public ColumnType |
113 |
|
|
getColumnType(int index) { return columns.get(index); } |
114 |
|
|
|
115 |
|
|
/** |
116 |
|
|
* Gets the index of the dummy column. |
117 |
|
|
*/ |
118 |
|
|
public int |
119 |
|
|
getDummyColumnIndex() { |
120 |
|
|
return columns.indexOf(ColumnType.DUMMY); |
121 |
|
|
} |
122 |
|
|
|
123 |
iliev |
1729 |
/** Sets only the <b>Name</b> column to be shown. */ |
124 |
|
|
public void |
125 |
|
|
showNameColumnOnly() { |
126 |
|
|
showSizeColumn = false; |
127 |
|
|
showFormatFamilyColumn = false; |
128 |
|
|
showFormatVersionColumn = false; |
129 |
|
|
showIsDrumColumn = false; |
130 |
|
|
showCreatedColumn = false; |
131 |
|
|
showModifiedColumn = false; |
132 |
|
|
showProductColumn = false; |
133 |
|
|
showArtistsColumn = false; |
134 |
|
|
showInstrumentFileColumn = false; |
135 |
|
|
showInstrumentNrColumn = false; |
136 |
|
|
showKeywordsColumn = false; |
137 |
|
|
updateColumns(); |
138 |
|
|
} |
139 |
|
|
|
140 |
iliev |
1204 |
/** Gets whether the <b>Size</b> column is shown. */ |
141 |
|
|
public boolean |
142 |
|
|
getShowSizeColumn() { return showSizeColumn; } |
143 |
|
|
|
144 |
|
|
/** Sets whether the <b>Size</b> column should be shown. */ |
145 |
|
|
public void |
146 |
|
|
setShowSizeColumn(boolean b) { |
147 |
|
|
if(b == showSizeColumn) return; |
148 |
|
|
showSizeColumn = b; |
149 |
|
|
updateColumns(); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
/** Gets whether the <b>Format</b> column is shown. */ |
153 |
|
|
public boolean |
154 |
|
|
getShowFormatFamilyColumn() { return showFormatFamilyColumn; } |
155 |
|
|
|
156 |
|
|
/** Sets whether the <b>Format</b> column should be shown. */ |
157 |
|
|
public void |
158 |
|
|
setShowFormatFamilyColumn(boolean b) { |
159 |
|
|
if(b == showFormatFamilyColumn) return; |
160 |
|
|
showFormatFamilyColumn = b; |
161 |
|
|
updateColumns(); |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
/** Gets whether the <b>Version</b> column is shown. */ |
165 |
|
|
public boolean |
166 |
|
|
getShowFormatVersionColumn() { return showFormatVersionColumn; } |
167 |
|
|
|
168 |
|
|
/** Sets whether the <b>Version</b> column should be shown. */ |
169 |
|
|
public void |
170 |
|
|
setShowFormatVersionColumn(boolean b) { |
171 |
|
|
if(b == showFormatVersionColumn) return; |
172 |
|
|
showFormatVersionColumn = b; |
173 |
|
|
updateColumns(); |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
/** Gets whether the <b>Type</b> column is shown. */ |
177 |
|
|
public boolean |
178 |
|
|
getShowIsDrumColumn() { return showIsDrumColumn; } |
179 |
|
|
|
180 |
|
|
/** Sets whether the <b>Type</b> column should be shown. */ |
181 |
|
|
public void |
182 |
|
|
setShowIsDrumColumn(boolean b) { |
183 |
|
|
if(b == showIsDrumColumn) return; |
184 |
|
|
showIsDrumColumn = b; |
185 |
|
|
updateColumns(); |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
/** Gets whether the <b>Date Created</b> column is shown. */ |
189 |
|
|
public boolean |
190 |
|
|
getShowCreatedColumn() { return showCreatedColumn; } |
191 |
|
|
|
192 |
|
|
/** Sets whether the <b>Date Created</b> column should be shown. */ |
193 |
|
|
public void |
194 |
|
|
setShowCreatedColumn(boolean b) { |
195 |
|
|
if(b == showCreatedColumn) return; |
196 |
|
|
showCreatedColumn = b; |
197 |
|
|
updateColumns(); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
/** Gets whether the <b>Date Modified</b> column is shown. */ |
201 |
|
|
public boolean |
202 |
|
|
getShowModifiedColumn() { return showModifiedColumn; } |
203 |
|
|
|
204 |
|
|
/** Sets whether the <b>Date Modified</b> column should be shown. */ |
205 |
|
|
public void |
206 |
|
|
setShowModifiedColumn(boolean b) { |
207 |
|
|
if(b == showModifiedColumn) return; |
208 |
|
|
showModifiedColumn = b; |
209 |
|
|
updateColumns(); |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
/** Gets whether the <b>Product</b> column is shown. */ |
213 |
|
|
public boolean |
214 |
|
|
getShowProductColumn() { return showProductColumn; } |
215 |
|
|
|
216 |
|
|
/** Sets whether the <b>Product</b> column should be shown. */ |
217 |
|
|
public void |
218 |
|
|
setShowProductColumn(boolean b) { |
219 |
|
|
if(b == showProductColumn) return; |
220 |
|
|
showProductColumn = b; |
221 |
|
|
updateColumns(); |
222 |
|
|
} |
223 |
|
|
|
224 |
|
|
/** Gets whether the <b>Artists</b> column is shown. */ |
225 |
|
|
public boolean |
226 |
|
|
getShowArtistsColumn() { return showArtistsColumn; } |
227 |
|
|
|
228 |
|
|
/** Sets whether the <b>Artists</b> column should be shown. */ |
229 |
|
|
public void |
230 |
|
|
setShowArtistsColumn(boolean b) { |
231 |
|
|
if(b == showArtistsColumn) return; |
232 |
|
|
showArtistsColumn = b; |
233 |
|
|
updateColumns(); |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
/** Gets whether the <b>Instrument File</b> column is shown. */ |
237 |
|
|
public boolean |
238 |
|
|
getShowInstrumentFileColumn() { return showInstrumentFileColumn; } |
239 |
|
|
|
240 |
|
|
/** Sets whether the <b>Instrument File</b> column should be shown. */ |
241 |
|
|
public void |
242 |
|
|
setShowInstrumentFileColumn(boolean b) { |
243 |
|
|
if(b == showInstrumentFileColumn) return; |
244 |
|
|
showInstrumentFileColumn = b; |
245 |
|
|
updateColumns(); |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
/** Gets whether the <b>Index</b> column is shown. */ |
249 |
|
|
public boolean |
250 |
|
|
getShowInstrumentNrColumn() { return showInstrumentNrColumn; } |
251 |
|
|
|
252 |
|
|
/** Sets whether the <b>Index</b> column should be shown. */ |
253 |
|
|
public void |
254 |
|
|
setShowInstrumentNrColumn(boolean b) { |
255 |
|
|
if(b == showInstrumentNrColumn) return; |
256 |
|
|
showInstrumentNrColumn = b; |
257 |
|
|
updateColumns(); |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
/** Gets whether the <b>Keywords</b> column is shown. */ |
261 |
|
|
public boolean |
262 |
|
|
getShowKeywordsColumn() { return showKeywordsColumn; } |
263 |
|
|
|
264 |
|
|
/** Sets whether the <b>Keywords</b> column should be shown. */ |
265 |
|
|
public void |
266 |
|
|
setShowKeywordsColumn(boolean b) { |
267 |
|
|
if(b == showKeywordsColumn) return; |
268 |
|
|
showKeywordsColumn = b; |
269 |
|
|
updateColumns(); |
270 |
|
|
} |
271 |
|
|
|
272 |
iliev |
1285 |
/** Gets whether the <b>Dummy</b> column is shown. */ |
273 |
|
|
public boolean |
274 |
|
|
getShowDummyColumn() { return showDummyColumn; } |
275 |
|
|
|
276 |
|
|
/** Sets whether the <b>Dummy</b> column should be shown. */ |
277 |
|
|
public void |
278 |
|
|
setShowDummyColumn(boolean b) { |
279 |
|
|
if(b == showDummyColumn) return; |
280 |
|
|
showDummyColumn = b; |
281 |
|
|
updateColumns(); |
282 |
|
|
} |
283 |
|
|
|
284 |
iliev |
1204 |
/** |
285 |
|
|
* Returns a comparator for the specified column or <code>null</code> |
286 |
|
|
* if there is no suitable comparator for the specified column. |
287 |
|
|
*/ |
288 |
|
|
public Comparator |
289 |
|
|
getComparator(int col) { |
290 |
|
|
if(columns.get(col) == ColumnType.NAME) return nameComparator; |
291 |
|
|
if(columns.get(col) == ColumnType.CREATED) return dateComparator; |
292 |
|
|
if(columns.get(col) == ColumnType.MODIFIED) return dateComparator; |
293 |
|
|
if(columns.get(col) == ColumnType.SIZE) return sizeComparator; |
294 |
|
|
if(columns.get(col) == ColumnType.INSTRUMENT_NR) return numberComparator; |
295 |
|
|
return null; |
296 |
|
|
} |
297 |
|
|
|
298 |
|
|
/** |
299 |
|
|
* Determines whether the specified column is sortable. |
300 |
|
|
* @return <code>true</code> if the specified column is |
301 |
|
|
* sortable, <code>false</code> otherwise. |
302 |
|
|
*/ |
303 |
|
|
public boolean |
304 |
|
|
isSortable(int col) { |
305 |
|
|
if(columns.get(col) == ColumnType.DUMMY) return false; |
306 |
|
|
return true; |
307 |
|
|
} |
308 |
|
|
|
309 |
|
|
private NameComparator nameComparator = new NameComparator(); |
310 |
|
|
|
311 |
|
|
private class NameComparator implements Comparator { |
312 |
|
|
public int |
313 |
|
|
compare(Object o1, Object o2) { |
314 |
|
|
if (o1 instanceof DbInstrumentInfo && o2 instanceof DbDirectoryInfo) { |
315 |
|
|
return 1; |
316 |
|
|
} |
317 |
|
|
if (o1 instanceof DbDirectoryInfo && o2 instanceof DbInstrumentInfo) { |
318 |
|
|
return -1; |
319 |
|
|
} |
320 |
|
|
|
321 |
|
|
return o1.toString().compareToIgnoreCase(o2.toString()); |
322 |
|
|
} |
323 |
|
|
} |
324 |
|
|
|
325 |
|
|
private DateComparator dateComparator = new DateComparator(); |
326 |
|
|
|
327 |
|
|
private class DateComparator implements Comparator { |
328 |
|
|
public int |
329 |
|
|
compare(Object o1, Object o2) { |
330 |
|
|
if (o1 instanceof Date && o2 instanceof Date) { |
331 |
|
|
return ((Date)o1).compareTo((Date)o2); |
332 |
|
|
} |
333 |
|
|
|
334 |
|
|
return o1.toString().compareToIgnoreCase(o2.toString()); |
335 |
|
|
} |
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
private SizeComparator sizeComparator = new SizeComparator(); |
339 |
|
|
|
340 |
|
|
private class SizeComparator implements Comparator { |
341 |
|
|
public int |
342 |
|
|
compare(Object o1, Object o2) { |
343 |
|
|
if (o1 instanceof InstrumentSize && o2 instanceof InstrumentSize) { |
344 |
|
|
long l1 = ((InstrumentSize)o1).getSize(); |
345 |
|
|
long l2 = ((InstrumentSize)o2).getSize(); |
346 |
|
|
if(l1 < l2) return -1; |
347 |
|
|
if(l1 > l2) return 1; |
348 |
|
|
return 0; |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
return o1.toString().compareToIgnoreCase(o2.toString()); |
352 |
|
|
} |
353 |
|
|
} |
354 |
|
|
|
355 |
|
|
private NumberComparator numberComparator = new NumberComparator(); |
356 |
|
|
|
357 |
|
|
private class NumberComparator implements Comparator { |
358 |
|
|
public int |
359 |
|
|
compare(Object o1, Object o2) { |
360 |
|
|
if (o1 instanceof Integer && o2 instanceof Integer) { |
361 |
|
|
int i1 = (Integer)o1; |
362 |
|
|
int i2 = (Integer)o2; |
363 |
|
|
if(i1 < i2) return -1; |
364 |
|
|
if(i1 > i2) return 1; |
365 |
|
|
return 0; |
366 |
|
|
} |
367 |
|
|
|
368 |
|
|
return o1.toString().compareToIgnoreCase(o2.toString()); |
369 |
|
|
} |
370 |
|
|
} |
371 |
|
|
|
372 |
|
|
private class InstrumentSize { |
373 |
|
|
private DbInstrumentInfo instrument; |
374 |
|
|
|
375 |
|
|
InstrumentSize(DbInstrumentInfo instr) { |
376 |
|
|
instrument = instr; |
377 |
|
|
} |
378 |
|
|
|
379 |
|
|
public long |
380 |
|
|
getSize() { return instrument.getSize(); } |
381 |
|
|
|
382 |
|
|
public String |
383 |
|
|
toString() { return instrument.getFormatedSize(); } |
384 |
|
|
} |
385 |
|
|
|
386 |
|
|
private void |
387 |
|
|
updateColumns() { |
388 |
|
|
columns.removeAllElements(); |
389 |
|
|
columns.add(ColumnType.NAME); |
390 |
|
|
if(showSizeColumn) columns.add(ColumnType.SIZE); |
391 |
|
|
if(showFormatFamilyColumn) columns.add(ColumnType.FORMAT_FAMILY); |
392 |
|
|
if(showFormatVersionColumn) columns.add(ColumnType.FORMAT_VERSION); |
393 |
|
|
if(showIsDrumColumn) columns.add(ColumnType.IS_DRUM); |
394 |
|
|
if(showCreatedColumn) columns.add(ColumnType.CREATED); |
395 |
|
|
if(showModifiedColumn) columns.add(ColumnType.MODIFIED); |
396 |
|
|
if(showProductColumn) columns.add(ColumnType.PRODUCT); |
397 |
|
|
if(showArtistsColumn) columns.add(ColumnType.ARTISTS); |
398 |
|
|
if(showInstrumentFileColumn) columns.add(ColumnType.INSTRUMENT_FILE); |
399 |
|
|
if(showInstrumentNrColumn) columns.add(ColumnType.INSTRUMENT_NR); |
400 |
|
|
if(showKeywordsColumn) columns.add(ColumnType.KEYWORDS); |
401 |
iliev |
1285 |
if(showDummyColumn) columns.add(ColumnType.DUMMY); |
402 |
iliev |
1204 |
|
403 |
|
|
fireTableStructureChanged(); |
404 |
|
|
} |
405 |
|
|
|
406 |
|
|
/** |
407 |
|
|
* Gets the directory node, which |
408 |
|
|
* content is represented by this table model. |
409 |
|
|
*/ |
410 |
|
|
protected DbDirectoryTreeNode |
411 |
|
|
getParentDirectoryNode() { return directoryNode; } |
412 |
|
|
|
413 |
|
|
/** |
414 |
|
|
* Sets the directory node, which |
415 |
|
|
* content will be represented by this table model. |
416 |
|
|
*/ |
417 |
|
|
protected void |
418 |
|
|
setParentDirectoryNode(DbDirectoryTreeNode node) { |
419 |
|
|
if(directoryNode != null) directoryNode.removeInstrumentsDbListener(getHandler()); |
420 |
|
|
directoryNode = node; |
421 |
|
|
if(directoryNode != null) directoryNode.addInstrumentsDbListener(getHandler()); |
422 |
|
|
fireTableDataChanged(); |
423 |
|
|
} |
424 |
|
|
|
425 |
|
|
private String renamedInstrument = null; |
426 |
|
|
|
427 |
|
|
/** |
428 |
|
|
* Gets the name of the last renamed instrument through this table model. |
429 |
|
|
*/ |
430 |
|
|
public String |
431 |
|
|
getRenamedInstrument() { return renamedInstrument; } |
432 |
|
|
|
433 |
|
|
/** |
434 |
|
|
* Sets the name of the last |
435 |
|
|
* renamed instrument through this table model. |
436 |
|
|
*/ |
437 |
|
|
public void |
438 |
|
|
setRenamedInstrument(String instr) { renamedInstrument = instr; } |
439 |
|
|
|
440 |
|
|
private String renamedDirectory = null; |
441 |
|
|
|
442 |
|
|
/** |
443 |
|
|
* Gets the name of the last |
444 |
|
|
* renamed directory through this table model. |
445 |
|
|
*/ |
446 |
|
|
public String |
447 |
|
|
getRenamedDirectory() { return renamedDirectory; } |
448 |
|
|
|
449 |
|
|
/** |
450 |
|
|
* Sets the name of the last |
451 |
|
|
* renamed directory through this table model. |
452 |
|
|
*/ |
453 |
|
|
public void |
454 |
|
|
setRenamedDirectory(String dir) { renamedDirectory = dir; } |
455 |
|
|
|
456 |
|
|
/** |
457 |
|
|
* Gets the number of columns in the model. |
458 |
|
|
* @return The number of columns in the model. |
459 |
|
|
*/ |
460 |
|
|
public int |
461 |
|
|
getColumnCount() { return columns.size(); } |
462 |
|
|
|
463 |
|
|
/** |
464 |
|
|
* Gets the number of rows in the model. |
465 |
|
|
* @return The number of rows in the model. |
466 |
|
|
*/ |
467 |
|
|
public int |
468 |
|
|
getRowCount() { |
469 |
|
|
if(directoryNode == null) return 0; |
470 |
|
|
return directoryNode.getChildCount() + directoryNode.getInstrumentCount(); |
471 |
|
|
} |
472 |
|
|
|
473 |
|
|
/** |
474 |
|
|
* Gets the name of the column at <code>columnIndex</code>. |
475 |
|
|
* @return The name of the column at <code>columnIndex</code>. |
476 |
|
|
*/ |
477 |
|
|
public String |
478 |
|
|
getColumnName(int col) { |
479 |
|
|
return columns.get(col).toString(); |
480 |
|
|
} |
481 |
|
|
|
482 |
|
|
/** |
483 |
|
|
* Gets the directory at the specified row index or |
484 |
|
|
* <code>null</code> there is no directory at the specified index. |
485 |
|
|
*/ |
486 |
|
|
public DbDirectoryTreeNode |
487 |
|
|
getDirectoryNode(int index) { |
488 |
|
|
if(directoryNode == null) return null; |
489 |
|
|
if(index >= directoryNode.getChildCount()) return null; |
490 |
|
|
return directoryNode.getChildAt(index); |
491 |
|
|
} |
492 |
|
|
|
493 |
|
|
/** |
494 |
|
|
* Gets the instrument at the specified row index or |
495 |
|
|
* <code>null</code> there is no instrument at the specified index. |
496 |
|
|
*/ |
497 |
|
|
public DbInstrumentInfo |
498 |
|
|
getInstrument(int index) { |
499 |
|
|
index -= directoryNode.getChildCount(); |
500 |
|
|
if(index < 0) return null; |
501 |
|
|
return directoryNode.getInstrumentAt(index); |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
/** |
505 |
|
|
* Gets the row index of the specified directory. |
506 |
|
|
* @param dir The name of the directory. |
507 |
|
|
* @return The row index of the specified directory or |
508 |
|
|
* <code>-1</code> if the specified directory is not found. |
509 |
|
|
*/ |
510 |
|
|
public int |
511 |
|
|
getDirectoryRowIndex(String dir) { |
512 |
|
|
if(dir == null || dir.length() == 0) return -1; |
513 |
|
|
|
514 |
|
|
for(int i = 0; i < directoryNode.getChildCount(); i++) { |
515 |
|
|
if(dir.equals(directoryNode.getChildAt(i).getInfo().getName())) return i; |
516 |
|
|
} |
517 |
|
|
|
518 |
|
|
return -1; |
519 |
|
|
} |
520 |
|
|
|
521 |
|
|
/** |
522 |
|
|
* Gets the row index of the specified instrument. |
523 |
|
|
* @param instr The name of the instrument. |
524 |
|
|
* @return The row index of the specified instrument or |
525 |
|
|
* <code>-1</code> if the specified instrument is not found. |
526 |
|
|
*/ |
527 |
|
|
public int |
528 |
|
|
getInstrumentRowIndex(String instr) { |
529 |
|
|
if(instr == null || instr.length() == 0) return -1; |
530 |
|
|
|
531 |
|
|
for(int i = 0; i < directoryNode.getInstrumentCount(); i++) { |
532 |
|
|
if(instr.equals(directoryNode.getInstrumentAt(i).getName())) { |
533 |
|
|
return i + directoryNode.getChildCount(); |
534 |
|
|
} |
535 |
|
|
} |
536 |
|
|
|
537 |
|
|
return -1; |
538 |
|
|
} |
539 |
|
|
|
540 |
|
|
/** |
541 |
|
|
* Gets the value for the cell at <code>columnIndex</code> and |
542 |
|
|
* <code>rowIndex</code>. |
543 |
|
|
* @param row The row whose value is to be queried. |
544 |
|
|
* @param col The column whose value is to be queried. |
545 |
|
|
* @return The value for the cell at <code>columnIndex</code> and |
546 |
|
|
* <code>rowIndex</code>. |
547 |
|
|
*/ |
548 |
|
|
public Object |
549 |
|
|
getValueAt(int row, int col) { |
550 |
|
|
if(directoryNode.getChildCount() > row) { |
551 |
|
|
DbDirectoryInfo info = directoryNode.getChildAt(row).getInfo(); |
552 |
|
|
|
553 |
|
|
if(columns.get(col) == ColumnType.NAME) return info; |
554 |
|
|
if(columns.get(col) == ColumnType.MODIFIED) { |
555 |
|
|
return info.getDateModified(); |
556 |
|
|
} |
557 |
|
|
if(columns.get(col) == ColumnType.CREATED) { |
558 |
|
|
return info.getDateCreated(); |
559 |
|
|
} |
560 |
|
|
|
561 |
|
|
return ""; |
562 |
|
|
} |
563 |
|
|
|
564 |
|
|
DbInstrumentInfo instr; |
565 |
|
|
instr = directoryNode.getInstrumentAt(row - directoryNode.getChildCount()); |
566 |
|
|
|
567 |
|
|
switch(columns.get(col)) { |
568 |
|
|
case NAME: |
569 |
|
|
return instr; |
570 |
|
|
|
571 |
|
|
case SIZE: |
572 |
|
|
return new InstrumentSize(instr); |
573 |
|
|
|
574 |
|
|
case FORMAT_FAMILY: |
575 |
|
|
return instr.getFormatFamily(); |
576 |
|
|
|
577 |
|
|
case FORMAT_VERSION: |
578 |
|
|
return instr.getFormatVersion(); |
579 |
|
|
|
580 |
|
|
case IS_DRUM: |
581 |
|
|
if(instr.isDrum()) return i18n.getLabel("InstrumentsDbTableModel.drumkit"); |
582 |
|
|
return i18n.getLabel("InstrumentsDbTableModel.chromatic"); |
583 |
|
|
|
584 |
|
|
case CREATED: |
585 |
|
|
return instr.getDateCreated(); |
586 |
|
|
|
587 |
|
|
case MODIFIED: |
588 |
|
|
return instr.getDateModified(); |
589 |
|
|
|
590 |
|
|
case PRODUCT: |
591 |
|
|
return instr.getProduct(); |
592 |
|
|
|
593 |
|
|
case ARTISTS: |
594 |
|
|
return instr.getArtists(); |
595 |
|
|
|
596 |
|
|
case INSTRUMENT_FILE: |
597 |
|
|
return instr.getFilePath(); |
598 |
|
|
|
599 |
|
|
case INSTRUMENT_NR: |
600 |
|
|
return instr.getInstrumentIndex(); |
601 |
|
|
|
602 |
|
|
case KEYWORDS: |
603 |
|
|
return instr.getKeywords(); |
604 |
|
|
|
605 |
|
|
case DUMMY: |
606 |
|
|
return ""; |
607 |
|
|
|
608 |
|
|
} |
609 |
|
|
|
610 |
|
|
return null; |
611 |
|
|
} |
612 |
|
|
|
613 |
|
|
/** |
614 |
|
|
* Sets the value in the cell at <code>col</code> |
615 |
|
|
* and <code>row</code> to <code>value</code>. |
616 |
|
|
*/ |
617 |
|
|
public void |
618 |
|
|
setValueAt(Object value, final int row, final int col) { |
619 |
|
|
String s = value.toString(); |
620 |
|
|
final String oldName; |
621 |
|
|
final Task t; |
622 |
|
|
if(directoryNode.getChildCount() > row) { |
623 |
|
|
final DbDirectoryInfo info = directoryNode.getChildAt(row).getInfo(); |
624 |
|
|
oldName = info.getName(); |
625 |
|
|
if(oldName.equals(s)) return; |
626 |
|
|
t = new InstrumentsDb.RenameDirectory(info.getDirectoryPath(), s); |
627 |
|
|
info.setName(s); |
628 |
|
|
setRenamedDirectory(info.getName()); |
629 |
|
|
fireTableCellUpdated(row, col); |
630 |
|
|
t.addTaskListener(new TaskListener() { |
631 |
|
|
public void |
632 |
|
|
taskPerformed(TaskEvent e) { |
633 |
|
|
if(!t.doneWithErrors()) return; |
634 |
|
|
info.setName(oldName); |
635 |
|
|
fireTableCellUpdated(row, col); |
636 |
|
|
} |
637 |
|
|
}); |
638 |
|
|
CC.getTaskQueue().add(t); |
639 |
|
|
return; |
640 |
|
|
} |
641 |
|
|
|
642 |
|
|
final DbInstrumentInfo instr; |
643 |
|
|
instr = directoryNode.getInstrumentAt(row - directoryNode.getChildCount()); |
644 |
|
|
oldName = instr.getName(); |
645 |
|
|
if(oldName.equals(s)) return; |
646 |
|
|
t = new InstrumentsDb.RenameInstrument(instr.getInstrumentPath(), s); |
647 |
|
|
instr.setName(s); |
648 |
|
|
setRenamedInstrument(instr.getName()); |
649 |
|
|
fireTableCellUpdated(row, col); |
650 |
|
|
t.addTaskListener(new TaskListener() { |
651 |
|
|
public void |
652 |
|
|
taskPerformed(TaskEvent e) { |
653 |
|
|
if(!t.doneWithErrors()) return; |
654 |
|
|
instr.setName(oldName); |
655 |
|
|
fireTableCellUpdated(row, col); |
656 |
|
|
} |
657 |
|
|
}); |
658 |
|
|
CC.getTaskQueue().add(t); |
659 |
|
|
} |
660 |
|
|
|
661 |
|
|
/** |
662 |
|
|
* Returns <code>true</code> if the cell at |
663 |
|
|
* <code>row</code> and <code>col</code> is editable. |
664 |
|
|
*/ |
665 |
|
|
public boolean |
666 |
|
|
isCellEditable(int row, int col) { |
667 |
|
|
if(columns.get(col) == ColumnType.NAME) return true; |
668 |
|
|
return false; |
669 |
|
|
} |
670 |
|
|
|
671 |
|
|
private final EventHandler eventHandler = new EventHandler(); |
672 |
|
|
|
673 |
|
|
private EventHandler |
674 |
|
|
getHandler() { return eventHandler; } |
675 |
|
|
|
676 |
|
|
private class EventHandler implements InstrumentsDbListener { |
677 |
|
|
/** |
678 |
|
|
* Invoked when the number of instrument |
679 |
|
|
* directories in a specific directory has changed. |
680 |
|
|
*/ |
681 |
|
|
public void |
682 |
|
|
directoryCountChanged(final InstrumentsDbEvent e) { |
683 |
|
|
fireTableDataChanged(); |
684 |
|
|
} |
685 |
|
|
|
686 |
|
|
/** |
687 |
|
|
* Invoked when the settings of an instrument directory are changed. |
688 |
|
|
*/ |
689 |
|
|
public void |
690 |
|
|
directoryInfoChanged(InstrumentsDbEvent e) { |
691 |
|
|
|
692 |
|
|
} |
693 |
|
|
|
694 |
|
|
/** |
695 |
|
|
* Invoked when an instrument directory is renamed. |
696 |
|
|
*/ |
697 |
|
|
public void |
698 |
|
|
directoryNameChanged(InstrumentsDbEvent e) { |
699 |
|
|
String d = e.getPathName(); |
700 |
|
|
DbDirectoryInfo dir = getParentDirectoryNode().getInfo(); |
701 |
|
|
if(dir == null || !d.startsWith(dir.getDirectoryPath())) return; |
702 |
|
|
d = d.substring(dir.getDirectoryPath().length(), d.length()); |
703 |
|
|
if(d.length() == 0) return; |
704 |
|
|
if(d.charAt(0) == '/') d = d.substring(1, d.length()); |
705 |
iliev |
1352 |
int row = getDirectoryRowIndex(toNonEscapedFileName(d)); |
706 |
iliev |
1204 |
if(row == -1) return; |
707 |
|
|
fireTableRowsUpdated(row, row); |
708 |
|
|
} |
709 |
|
|
|
710 |
|
|
/** |
711 |
|
|
* Invoked when the number of instruments |
712 |
|
|
* in a specific directory has changed. |
713 |
|
|
*/ |
714 |
|
|
public void |
715 |
|
|
instrumentCountChanged(final InstrumentsDbEvent e) { |
716 |
|
|
fireTableDataChanged(); |
717 |
|
|
} |
718 |
|
|
|
719 |
|
|
/** |
720 |
|
|
* Invoked when the settings of an instrument are changed. |
721 |
|
|
*/ |
722 |
|
|
public void |
723 |
|
|
instrumentInfoChanged(InstrumentsDbEvent e) { |
724 |
|
|
String instr = e.getPathName(); |
725 |
|
|
DbDirectoryInfo dir = getParentDirectoryNode().getInfo(); |
726 |
|
|
if(dir == null || !instr.startsWith(dir.getDirectoryPath())) return; |
727 |
|
|
instr = instr.substring(dir.getDirectoryPath().length(), instr.length()); |
728 |
|
|
if(instr.length() == 0) return; |
729 |
|
|
if(instr.charAt(0) == '/') instr = instr.substring(1, instr.length()); |
730 |
|
|
int row = getInstrumentRowIndex(instr); |
731 |
|
|
if(row == -1) return; |
732 |
|
|
fireTableRowsUpdated(row, row); |
733 |
|
|
} |
734 |
|
|
|
735 |
|
|
/** |
736 |
|
|
* Invoked when an instrument is renamed. |
737 |
|
|
*/ |
738 |
|
|
public void |
739 |
|
|
instrumentNameChanged(InstrumentsDbEvent e) { |
740 |
|
|
|
741 |
|
|
} |
742 |
|
|
|
743 |
|
|
/** Invoked when the status of particular job has changed. */ |
744 |
|
|
public void |
745 |
|
|
jobStatusChanged(InstrumentsDbEvent e) { } |
746 |
|
|
} |
747 |
|
|
} |