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.view; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
|
27 |
import java.beans.PropertyChangeEvent; |
28 |
import java.beans.PropertyChangeListener; |
29 |
|
30 |
import javax.swing.JPanel; |
31 |
|
32 |
import org.jsampler.SamplerChannelModel; |
33 |
import org.linuxsampler.lscp.SamplerChannel; |
34 |
|
35 |
|
36 |
/** |
37 |
* This class defines the skeleton of a sampler channel. |
38 |
* @author Grigor Iliev |
39 |
*/ |
40 |
public abstract class JSChannel extends JPanel { |
41 |
private SamplerChannelModel model; |
42 |
|
43 |
/** |
44 |
* Creates a new instance of <code>JSChannel</code> using the specified |
45 |
* non-<code>null</code> channel model. |
46 |
* @param model The model to be used by this channel. |
47 |
* @throws IllegalArgumentException If the model is <code>null</code>. |
48 |
*/ |
49 |
public |
50 |
JSChannel(SamplerChannelModel model) { |
51 |
super(new BorderLayout()); |
52 |
|
53 |
if(model == null) throw new IllegalArgumentException("model must be non null"); |
54 |
this.model = model; |
55 |
|
56 |
addPropertyChangeListener("selectionProbablyChanged", new PropertyChangeListener() { |
57 |
public void |
58 |
propertyChange(PropertyChangeEvent e) { |
59 |
boolean b = Boolean.parseBoolean(e.getNewValue().toString()); |
60 |
if(isSelected() == b) return; |
61 |
|
62 |
setSelected(b); |
63 |
} |
64 |
}); |
65 |
} |
66 |
|
67 |
/** |
68 |
* Gets the model that is currently used by this channel. |
69 |
* @return model The <code>SamplerChannelModel</code> instance |
70 |
* which provides information about this channel. |
71 |
*/ |
72 |
public SamplerChannelModel |
73 |
getModel() { return model; } |
74 |
|
75 |
/** |
76 |
* Gets the numerical ID of this sampler channel. |
77 |
* @return The numerical ID of this sampler channel or -1 if the channel's ID is not set. |
78 |
*/ |
79 |
public int |
80 |
getChannelId() { |
81 |
return getChannelInfo() == null ? -1 : getChannelInfo().getChannelId(); |
82 |
} |
83 |
|
84 |
/** |
85 |
* Gets the current settings of this sampler channel. |
86 |
* @return <code>SamplerChannel</code> instance containing |
87 |
* the current settings of this sampler channel. |
88 |
*/ |
89 |
public SamplerChannel |
90 |
getChannelInfo() { return getModel().getChannelInfo(); } |
91 |
|
92 |
/** |
93 |
* Sets the current settings of this sampler channel. |
94 |
* @param chn A <code>SamplerChannel</code> instance containing |
95 |
* the new settings for this sampler channel. |
96 |
* |
97 |
public void |
98 |
setChannelInfo(SamplerChannel chn) { |
99 |
SamplerChannel oldChn = this.chn; |
100 |
this.chn = chn; |
101 |
|
102 |
firePropertyChange("ChannelInfo", oldChn, this.chn); |
103 |
}*/ |
104 |
|
105 |
/** |
106 |
* Determines whether the channel is selected. |
107 |
* @return <code>true</code> if the channel is selected, <code>false</code> otherwise. |
108 |
*/ |
109 |
public abstract boolean isSelected(); |
110 |
|
111 |
/** |
112 |
* Sets the selection state of this channel. |
113 |
* This method is invoked when the selection state of the channel has changed. |
114 |
* @param select Specifies the new selection state of this channel; |
115 |
* <code>true</code> to select the channel, <code>false</code> otherwise. |
116 |
*/ |
117 |
public abstract void setSelected(boolean select); |
118 |
} |