1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2006 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 |
|
31 |
/** |
32 |
* |
33 |
* @author Grigor Iliev |
34 |
*/ |
35 |
public class Resource { |
36 |
private String name = "Untitled"; |
37 |
private String description = ""; |
38 |
|
39 |
private final Vector<ChangeListener> listeners = new Vector<ChangeListener>(); |
40 |
|
41 |
/** |
42 |
* Creates a new instance of Resource |
43 |
*/ |
44 |
public |
45 |
Resource() { } |
46 |
|
47 |
/** |
48 |
* Registers the specified listener to be notified when the resource info is changed. |
49 |
* @param l The <code>ChangeListener</code> to register. |
50 |
*/ |
51 |
public void |
52 |
addChangeListener(ChangeListener l) { listeners.add(l); } |
53 |
|
54 |
/** |
55 |
* Removes the specified listener. |
56 |
* @param l The <code>ChangeListener</code> to remove. |
57 |
*/ |
58 |
public void |
59 |
removeChangeListener(ChangeListener l) { listeners.remove(l); } |
60 |
|
61 |
/** |
62 |
* Gets the name of this resource. |
63 |
* @return The name of this resource. |
64 |
*/ |
65 |
public String |
66 |
getName() { return name; } |
67 |
|
68 |
/** |
69 |
* Sets the name of this resource. |
70 |
* @param name The new name of this resource. |
71 |
*/ |
72 |
public void |
73 |
setName(String name) { |
74 |
this.name = name; |
75 |
fireChangeEvent(); |
76 |
} |
77 |
|
78 |
/** |
79 |
* Gets a brief description about this resource. |
80 |
* @return A brief description about this resource. |
81 |
*/ |
82 |
public String |
83 |
getDescription() { return description; } |
84 |
|
85 |
/** |
86 |
* Sets a description about this resource. |
87 |
* @param desc A brief description about this resource. |
88 |
*/ |
89 |
public void |
90 |
setDescription(String desc) { |
91 |
description = desc; |
92 |
fireChangeEvent(); |
93 |
} |
94 |
|
95 |
/** Notifies listeners that the recourse properties has changed. */ |
96 |
protected void |
97 |
fireChangeEvent() { |
98 |
ChangeEvent e = new ChangeEvent(this); |
99 |
for(ChangeListener l : listeners) l.stateChanged(e); |
100 |
} |
101 |
} |