46 |
private String name = ""; |
private String name = ""; |
47 |
private String description = ""; |
private String description = ""; |
48 |
|
|
49 |
private final Vector<Instrument> instruments = new Vector<Instrument>(); |
private final Vector<OrchestraInstrument> instruments = new Vector<OrchestraInstrument>(); |
50 |
|
|
51 |
private final Vector<OrchestraListener> listeners = new Vector<OrchestraListener>(); |
private final Vector<OrchestraListener> listeners = new Vector<OrchestraListener>(); |
52 |
|
|
123 |
* @param idx The index of the instrument to be returned. |
* @param idx The index of the instrument to be returned. |
124 |
* @return The instrument at the specified position. |
* @return The instrument at the specified position. |
125 |
*/ |
*/ |
126 |
public Instrument |
public OrchestraInstrument |
127 |
getInstrument(int idx) { return instruments.get(idx); } |
getInstrument(int idx) { return instruments.get(idx); } |
128 |
|
|
129 |
/** |
/** |
132 |
* @throws IllegalArgumentException If <code>instr</code> is <code>null</code>. |
* @throws IllegalArgumentException If <code>instr</code> is <code>null</code>. |
133 |
*/ |
*/ |
134 |
public void |
public void |
135 |
addInstrument(Instrument instr) { |
addInstrument(OrchestraInstrument instr) { |
136 |
insertInstrument(instr, getInstrumentCount()); |
insertInstrument(instr, getInstrumentCount()); |
137 |
} |
} |
138 |
|
|
144 |
* @throws ArrayIndexOutOfBoundsException If the specified index is invalid. |
* @throws ArrayIndexOutOfBoundsException If the specified index is invalid. |
145 |
*/ |
*/ |
146 |
public void |
public void |
147 |
insertInstrument(Instrument instr, int idx) { |
insertInstrument(OrchestraInstrument instr, int idx) { |
148 |
if(instr == null) throw new IllegalArgumentException("instr should be non-null!"); |
if(instr == null) throw new IllegalArgumentException("instr should be non-null!"); |
149 |
instruments.insertElementAt(instr, idx); |
instruments.insertElementAt(instr, idx); |
150 |
fireInstrumentAdded(instr); |
fireInstrumentAdded(instr); |
156 |
*/ |
*/ |
157 |
public void |
public void |
158 |
removeInstrument(int idx) { |
removeInstrument(int idx) { |
159 |
Instrument instr = instruments.get(idx); |
OrchestraInstrument instr = instruments.get(idx); |
160 |
instruments.removeElementAt(idx); |
instruments.removeElementAt(idx); |
161 |
fireInstrumentRemoved(instr); |
fireInstrumentRemoved(instr); |
162 |
} |
} |
168 |
* <code>false</code> otherwise. |
* <code>false</code> otherwise. |
169 |
*/ |
*/ |
170 |
public boolean |
public boolean |
171 |
removeInstrument(Instrument instr) { |
removeInstrument(OrchestraInstrument instr) { |
172 |
boolean b = instruments.removeElement(instr); |
boolean b = instruments.removeElement(instr); |
173 |
if(b) fireInstrumentRemoved(instr); |
if(b) fireInstrumentRemoved(instr); |
174 |
return b; |
return b; |
182 |
* the orchestra does not contain the specified instrument. |
* the orchestra does not contain the specified instrument. |
183 |
*/ |
*/ |
184 |
public int |
public int |
185 |
getInstrumentIndex(Instrument instr) { |
getInstrumentIndex(OrchestraInstrument instr) { |
186 |
if(instr == null) return -1; |
if(instr == null) return -1; |
187 |
|
|
188 |
for(int i = 0; i < getInstrumentCount(); i++) { |
for(int i = 0; i < getInstrumentCount(); i++) { |
200 |
* @param instr The instrument to move on top. |
* @param instr The instrument to move on top. |
201 |
*/ |
*/ |
202 |
public void |
public void |
203 |
moveInstrumentOnTop(Instrument instr) { |
moveInstrumentOnTop(OrchestraInstrument instr) { |
204 |
if(instr == null) return; |
if(instr == null) return; |
205 |
|
|
206 |
int idx = getInstrumentIndex(instr); |
int idx = getInstrumentIndex(instr); |
218 |
* @param instr The instrument to move up. |
* @param instr The instrument to move up. |
219 |
*/ |
*/ |
220 |
public void |
public void |
221 |
moveInstrumentUp(Instrument instr) { |
moveInstrumentUp(OrchestraInstrument instr) { |
222 |
if(instr == null) return; |
if(instr == null) return; |
223 |
|
|
224 |
int idx = getInstrumentIndex(instr); |
int idx = getInstrumentIndex(instr); |
237 |
* @param instr The instrument to move down. |
* @param instr The instrument to move down. |
238 |
*/ |
*/ |
239 |
public void |
public void |
240 |
moveInstrumentDown(Instrument instr) { |
moveInstrumentDown(OrchestraInstrument instr) { |
241 |
if(instr == null) return; |
if(instr == null) return; |
242 |
|
|
243 |
int idx = getInstrumentIndex(instr); |
int idx = getInstrumentIndex(instr); |
254 |
* @param instr The instrument to move at bottom. |
* @param instr The instrument to move at bottom. |
255 |
*/ |
*/ |
256 |
public void |
public void |
257 |
moveInstrumentAtBottom(Instrument instr) { |
moveInstrumentAtBottom(OrchestraInstrument instr) { |
258 |
if(instr == null) return; |
if(instr == null) return; |
259 |
|
|
260 |
int idx = getInstrumentIndex(instr); |
int idx = getInstrumentIndex(instr); |
302 |
setDescription(node.getFirstChild().getNodeValue()); |
setDescription(node.getFirstChild().getNodeValue()); |
303 |
} |
} |
304 |
} else if(s.equals("instrument")) { |
} else if(s.equals("instrument")) { |
305 |
Instrument instr = new Instrument(); |
OrchestraInstrument instr = new OrchestraInstrument(); |
306 |
instr.readObject(node); |
instr.readObject(node); |
307 |
addInstrument(instr); |
addInstrument(instr); |
308 |
} else { // Unknown content |
} else { // Unknown content |
351 |
|
|
352 |
/** Notifies listeners that an instrument has been added to this orchestra. */ |
/** Notifies listeners that an instrument has been added to this orchestra. */ |
353 |
private void |
private void |
354 |
fireInstrumentAdded(Instrument instr) { |
fireInstrumentAdded(OrchestraInstrument instr) { |
355 |
OrchestraEvent e = new OrchestraEvent(this, instr); |
OrchestraEvent e = new OrchestraEvent(this, instr); |
356 |
for(OrchestraListener l : listeners) l.instrumentAdded(e); |
for(OrchestraListener l : listeners) l.instrumentAdded(e); |
357 |
} |
} |
358 |
|
|
359 |
/** Notifies listeners that an instrument has been removed from this orchestra. */ |
/** Notifies listeners that an instrument has been removed from this orchestra. */ |
360 |
private void |
private void |
361 |
fireInstrumentRemoved(Instrument instr) { |
fireInstrumentRemoved(OrchestraInstrument instr) { |
362 |
OrchestraEvent e = new OrchestraEvent(this, instr); |
OrchestraEvent e = new OrchestraEvent(this, instr); |
363 |
for(OrchestraListener l : listeners) l.instrumentRemoved(e); |
for(OrchestraListener l : listeners) l.instrumentRemoved(e); |
364 |
} |
} |
368 |
* @param instr The instrument whose settings has been changed. |
* @param instr The instrument whose settings has been changed. |
369 |
*/ |
*/ |
370 |
private void |
private void |
371 |
fireInstrumentChanged(Instrument instr) { |
fireInstrumentChanged(OrchestraInstrument instr) { |
372 |
OrchestraEvent e = new OrchestraEvent(this, instr); |
OrchestraEvent e = new OrchestraEvent(this, instr); |
373 |
for(OrchestraListener l : listeners) l.instrumentChanged(e); |
for(OrchestraListener l : listeners) l.instrumentChanged(e); |
374 |
} |
} |
382 |
/** Invoked when the settings of an instrument are changed. */ |
/** Invoked when the settings of an instrument are changed. */ |
383 |
public void |
public void |
384 |
stateChanged(ChangeEvent e) { |
stateChanged(ChangeEvent e) { |
385 |
fireInstrumentChanged((Instrument)e.getSource()); |
fireInstrumentChanged((OrchestraInstrument)e.getSource()); |
386 |
} |
} |
387 |
|
|
388 |
/** Invoked when an instrument is added to the orchestra. */ |
/** Invoked when an instrument is added to the orchestra. */ |