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.view.fantasia; |
24 |
|
25 |
import java.awt.event.ActionListener; |
26 |
|
27 |
import javax.swing.BorderFactory; |
28 |
import javax.swing.BoxLayout; |
29 |
|
30 |
import org.jsampler.CC; |
31 |
import org.jsampler.SamplerChannelModel; |
32 |
|
33 |
import org.jsampler.view.JSChannel; |
34 |
import org.jsampler.view.SessionViewConfig.ChannelConfig; |
35 |
|
36 |
import org.jsampler.view.std.StdChannelsPane; |
37 |
|
38 |
|
39 |
/** |
40 |
* |
41 |
* @author Grigor Iliev |
42 |
*/ |
43 |
public class ChannelsPane extends StdChannelsPane { |
44 |
private ActionListener listener; |
45 |
|
46 |
/** |
47 |
* Creates a new instance of <code>ChannelsPane</code> with |
48 |
* the specified <code>title</code>. |
49 |
* @param title The title of this <code>ChannelsPane</code> |
50 |
*/ |
51 |
public |
52 |
ChannelsPane(String title) { |
53 |
this(title, null); |
54 |
} |
55 |
|
56 |
/** |
57 |
* Creates a new instance of <code>ChannelsPane</code> with |
58 |
* the specified <code>title</code>. |
59 |
* @param title The title of this <code>ChannelsPane</code> |
60 |
* @param l A listener which is notified when a newly created |
61 |
* channel is fully expanded on the screen. |
62 |
*/ |
63 |
public |
64 |
ChannelsPane(String title, ActionListener l) { |
65 |
super(title); |
66 |
|
67 |
listener = l; |
68 |
|
69 |
removeAll(); |
70 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
71 |
|
72 |
add(chnList); |
73 |
setBorder(BorderFactory.createEmptyBorder()); |
74 |
} |
75 |
|
76 |
@Override |
77 |
protected ChannelList |
78 |
createChannelList() { return new FantasiaChannelList(); } |
79 |
|
80 |
@Override |
81 |
protected ChannelListModel |
82 |
createChannelListModel() { return new FantasiaChannelListModel(); } |
83 |
|
84 |
class FantasiaChannelList extends ChannelList { |
85 |
@Override |
86 |
public java.awt.Dimension |
87 |
getMaximumSize() { return getPreferredSize(); } |
88 |
} |
89 |
|
90 |
class FantasiaChannelListModel extends ChannelListModel { |
91 |
@Override |
92 |
public boolean |
93 |
getComponentListIsAdjusting() { |
94 |
boolean b = CC.getSamplerModel().getChannelListIsAdjusting(); |
95 |
return super.getComponentListIsAdjusting() || b; |
96 |
} |
97 |
} |
98 |
|
99 |
@Override |
100 |
protected JSChannel |
101 |
createChannel(SamplerChannelModel channelModel) { |
102 |
return new Channel(channelModel, listener); |
103 |
} |
104 |
|
105 |
/** |
106 |
* Adds new channel to this channels pane. |
107 |
* @param channelModel The sampler channel model to be used by the new channel. |
108 |
*/ |
109 |
@Override |
110 |
public void |
111 |
addChannel(SamplerChannelModel channelModel) { |
112 |
addChannel(channelModel, null); |
113 |
} |
114 |
|
115 |
@Override |
116 |
public void |
117 |
addChannel(SamplerChannelModel channelModel, ChannelConfig config) { |
118 |
Channel channel = null; |
119 |
|
120 |
if(config != null) { |
121 |
switch(config.type) { |
122 |
case SMALL: |
123 |
channel = new Channel(channelModel, listener, ChannelView.Type.SMALL); |
124 |
break; |
125 |
case NORMAL: |
126 |
channel = new Channel(channelModel, listener, ChannelView.Type.NORMAL); |
127 |
break; |
128 |
} |
129 |
} |
130 |
if(channel == null) channel = new Channel(channelModel, listener); |
131 |
if(config != null) { |
132 |
if(config.expanded) channel.expandChannel(false); |
133 |
} else { |
134 |
if(channel.getChannelInfo().getEngine() == null) { |
135 |
channel.expandChannel(false); |
136 |
} |
137 |
} |
138 |
listModel.add(channel); |
139 |
chnList.setSelectedComponent(channel, true); |
140 |
|
141 |
firePropertyChange("channelAdded", null, channelModel); |
142 |
} |
143 |
} |