/[svn]/jsampler/trunk/src/org/jsampler/android/view/AndroidChannelsPane.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/android/view/AndroidChannelsPane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2302 - (show annotations) (download)
Thu Dec 15 23:13:30 2011 UTC (12 years, 4 months ago) by iliev
File size: 5489 byte(s)
* Initial support for Android platforms (only sampler channel
  manipulation for now - see the screenshots on the website)

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2011 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.android.view;
24
25 import java.beans.PropertyChangeListener;
26 import java.beans.PropertyChangeSupport;
27 import java.util.ArrayList;
28
29 import org.jsampler.SamplerChannelModel;
30 import org.jsampler.view.JSChannelsPane;
31 import org.jsampler.view.SessionViewConfig.ChannelConfig;
32
33 import android.view.View;
34
35 public abstract class AndroidChannelsPane<C extends AndroidChannel> implements JSChannelsPane<C> {
36 private String title;
37 private View view = null;
38
39 private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
40
41 protected final ArrayList<C> channels = new ArrayList<C>();
42
43 /** Creates a new instance of <code>AndroidChannelsPane</code>. */
44 public
45 AndroidChannelsPane(String title) {
46 this.title = title;
47 }
48
49 public abstract View createView();
50
51 public View
52 getView() {
53 if(view == null) view = createView();
54 return view;
55 }
56
57 /** Add a PropertyChangeListener to the listener list. */
58 public void
59 addPropertyChangeListener(PropertyChangeListener l) {
60 propertyChangeSupport.addPropertyChangeListener(l);
61 }
62
63 /** Remove a PropertyChangeListener from the listener list. */
64 public void
65 removePropertyChangeListener(PropertyChangeListener l) {
66 propertyChangeSupport.removePropertyChangeListener(l);
67 }
68
69 /** Add a PropertyChangeListener for a specific property. */
70 public void
71 addPropertyChangeListener(String propertyName, PropertyChangeListener l) {
72 propertyChangeSupport.addPropertyChangeListener(propertyName, l);
73 }
74
75 /** Remove a PropertyChangeListener for a specific property. */
76 public void
77 removePropertyChangeListener(String propertyName, PropertyChangeListener l) {
78 propertyChangeSupport.removePropertyChangeListener(propertyName, l);
79 }
80
81 /**
82 * Report a bound property update to any registered listeners.
83 * No event is fired if old and new are equal and non-null.
84 */
85 protected void
86 firePropertyChange(String propertyName, Object oldValue, Object newValue) {
87 propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
88 }
89
90 /**
91 * Returns the title of this channels' pane.
92 * @return The title of this channels' pane.
93 */
94 @Override
95 public String
96 getTitle() { return title; }
97
98 /**
99 * Sets the title of this channels' pane.
100 * @param title The new title of this channels' pane.
101 */
102 @Override
103 public void
104 setTitle(String title) {
105 if(this.title.equals(title)) return;
106
107 String oldTitle = this.title;
108 this.title = title;
109 firePropertyChange(TITLE, oldTitle, title);
110 }
111
112 /**
113 * Returns the title of this <code>JSChannelsPane</code>.
114 * @return The title of this <code>JSChannelsPane</code>.
115 */
116 @Override
117 public String
118 toString() { return getTitle(); }
119
120 /**
121 * Adds new channel to this channels pane.
122 * @param channelModel The sampler channel model to be used by the new channel.
123 * @param config The view config of the sampler channel.
124 */
125 @Override
126 public void
127 addChannel(SamplerChannelModel channelModel, ChannelConfig config) {
128 addChannel(channelModel);
129 }
130
131 /**
132 * Adds the specified channels to this channels pane.
133 * @param chns The channels to be added.
134 */
135 @Override
136 public void
137 addChannels(C[] chns) {
138 if(chns == null || chns.length == 0) return;
139
140 for(C c : chns) channels.add(c);
141 firePropertyChange("channelsAdded", null, chns);
142 }
143
144 /**
145 * Removes the specified channel from this channels pane.
146 * This method is invoked when a sampler channel is removed in the back-end.
147 * @param chn The channel to be removed from this channels pane.
148 */
149 @Override
150 public void
151 removeChannel(C chn) {
152 channels.remove(chn);
153 firePropertyChange("channelRemoved", null, chn);
154 }
155
156 /**
157 * Gets the first channel in this channels pane.
158 * @return The first channel in this channels pane or <code>null</code> if
159 * the channels pane is empty.
160 */
161 @Override
162 public C
163 getFirstChannel() { return channels.size() == 0 ? null : channels.get(0); }
164
165 /**
166 * Gets the last channel in this channels pane.
167 * @return The last channel in this channels pane or <code>null</code> if
168 * the channels pane is empty.
169 */
170 @Override
171 public C
172 getLastChannel() {
173 return channels.size() == 0 ? null : channels.get(channels.size() - 1);
174 }
175
176 /**
177 * Gets the channel at the specified index.
178 * @return The channel at the specified index.
179 * @throws ArrayIndexOutOfBoundsException If the index is out of range.
180 */
181 @Override
182 public C
183 getChannel(int idx) { return channels.get(idx); }
184
185 /**
186 * Gets the number of channels in this channels pane.
187 * @return The number of channels in this channels pane.
188 */
189 @Override
190 public int
191 getChannelCount() { return channels.size(); }
192 }

  ViewVC Help
Powered by ViewVC