/[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 1729 - (show annotations) (download)
Tue Apr 29 22:22:40 2008 UTC (15 years, 11 months ago) by iliev
File size: 3274 byte(s)
* Added support for handling lost files in the Instruments Database
  (In the Instruments Database window choose Actions/Check For Lost Files)
* Fantasia: Added option to show the Instruments Database
  on the Right-Side Pane of the Fantasia's main window
  (choose Edit/Preferences, then click the `View' tab)
* Added new menu item in the Instruments Database window: Edit/Find
* Some minor bugfixes and enhancements

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

  ViewVC Help
Powered by ViewVC