/[svn]/jsampler/trunk/src/org/jsampler/LostFilesModel.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/LostFilesModel.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (show annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 4 months ago) by iliev
File size: 3281 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2008 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;
24
25 import java.util.Vector;
26
27 import net.sf.juife.event.GenericEvent;
28 import net.sf.juife.event.GenericListener;
29 import net.sf.juife.event.TaskEvent;
30 import net.sf.juife.event.TaskListener;
31
32 import org.jsampler.task.InstrumentsDb.FindLostInstrumentFiles;
33
34 /**
35 * A data model providing information about the lost instrument files in the instruments database.
36 * @author Grigor Iliev
37 */
38 public class LostFilesModel {
39 private final Vector<String> lostFiles = new Vector<String>();
40 private final Vector<GenericListener> listeners = new Vector<GenericListener>();
41
42 /** Creates a new instance of <code>LostFilesModel</code> */
43 public
44 LostFilesModel() { }
45
46 /**
47 * Registers the specified listener to be notified when the list
48 * of lost files is updated.
49 * @param l The <code>GenericListener</code> to register.
50 */
51 public void
52 addChangeListener(GenericListener l) { listeners.add(l); }
53
54 /**
55 * Removes the specified listener.
56 * @param l The <code>GenericListener</code> to remove.
57 */
58 public void
59 removeChangeListener(GenericListener l) { listeners.remove(l); }
60
61 /** Returns a list of all lost files. */
62 public String[]
63 getLostFiles() {
64 return lostFiles.toArray(new String[lostFiles.size()]);
65 }
66
67 /**
68 * Gets the absolute pathname of the lost file at the specified position.
69 * @param index The position of the lost file to return.
70 * @return The absolute pathname of the lost file at the specified position.
71 */
72 public String
73 getLostFile(int index) { return lostFiles.get(index); }
74
75 /**
76 * Gets the number of lost files in the instruments database.
77 * @return The number of lost files in the instruments database.
78 */
79 public int
80 getLostFileCount() { return lostFiles.size(); }
81
82 /** Updates the list of lost instrument files. */
83 public void
84 update() {
85 final FindLostInstrumentFiles t = new FindLostInstrumentFiles();
86 t.addTaskListener(new TaskListener() {
87 public void
88 taskPerformed(TaskEvent e) {
89 if(t.doneWithErrors()) return;
90 lostFiles.removeAllElements();
91 for(String s : t.getResult()) lostFiles.add(s);
92 fireLostFileListUpdated();
93 }
94 });
95
96 lostFiles.removeAllElements();
97 fireLostFileListUpdated();
98
99 CC.getTaskQueue().add(t);
100 }
101
102 /**
103 * Notifies listeners that the list of lost files is updated.
104 */
105 private void
106 fireLostFileListUpdated() {
107 GenericEvent e = new GenericEvent(this);
108 for(GenericListener l : listeners) l.jobDone(e);
109 }
110 }

  ViewVC Help
Powered by ViewVC