1 |
iliev |
787 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005 Grigor Kirilov Iliev |
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 |
iliev |
842 |
import java.awt.Dimension; |
26 |
|
|
|
27 |
iliev |
787 |
import java.awt.event.WindowAdapter; |
28 |
|
|
import java.awt.event.WindowEvent; |
29 |
|
|
|
30 |
|
|
import java.util.Vector; |
31 |
|
|
import java.util.logging.Level; |
32 |
|
|
|
33 |
|
|
import javax.swing.JFrame; |
34 |
|
|
|
35 |
|
|
import org.jsampler.CC; |
36 |
|
|
import org.jsampler.JSampler; |
37 |
iliev |
842 |
import org.jsampler.Prefs; |
38 |
iliev |
787 |
|
39 |
|
|
import org.jsampler.event.SamplerChannelListEvent; |
40 |
|
|
import org.jsampler.event.SamplerChannelListListener; |
41 |
|
|
|
42 |
|
|
/** |
43 |
|
|
* |
44 |
|
|
* @author Grigor Iliev |
45 |
|
|
*/ |
46 |
|
|
public abstract class JSMainFrame extends JFrame { |
47 |
|
|
private final Vector<JSChannelsPane> chnPaneList = new Vector<JSChannelsPane>(); |
48 |
|
|
|
49 |
|
|
public |
50 |
|
|
JSMainFrame() { |
51 |
|
|
super(JSampler.NAME + ' ' + JSampler.VERSION); |
52 |
|
|
|
53 |
|
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); |
54 |
|
|
addWindowListener(new WindowAdapter() { |
55 |
|
|
public void |
56 |
iliev |
842 |
windowClosing(WindowEvent we) { onWindowClose(); } |
57 |
iliev |
787 |
}); |
58 |
|
|
|
59 |
|
|
CC.getSamplerModel().addSamplerChannelListListener(new EventHandler()); |
60 |
|
|
} |
61 |
|
|
|
62 |
iliev |
842 |
private void |
63 |
|
|
onWindowClose() { |
64 |
|
|
if(Prefs.getSaveWindowProperties()) { |
65 |
|
|
Prefs.setWindowMaximized ( |
66 |
|
|
(getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH |
67 |
|
|
); |
68 |
|
|
|
69 |
|
|
setVisible(false); |
70 |
|
|
if(Prefs.getWindowMaximized()) { |
71 |
|
|
//setExtendedState(getExtendedState() & ~MAXIMIZED_BOTH); |
72 |
|
|
CC.cleanExit(); |
73 |
|
|
return; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
java.awt.Point p = getLocation(); |
77 |
|
|
Dimension d = getSize(); |
78 |
|
|
StringBuffer sb = new StringBuffer(); |
79 |
|
|
sb.append(p.x).append(',').append(p.y).append(','); |
80 |
|
|
sb.append(d.width).append(',').append(d.height); |
81 |
|
|
Prefs.setWindowSizeAndLocation(sb.toString()); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
CC.cleanExit(); |
85 |
|
|
} |
86 |
|
|
|
87 |
iliev |
787 |
public Vector<JSChannelsPane> |
88 |
|
|
getChannelsPaneList() { return chnPaneList; } |
89 |
|
|
|
90 |
|
|
public JSChannelsPane |
91 |
|
|
getChannelsPane(int idx) { return chnPaneList.get(idx); } |
92 |
|
|
|
93 |
|
|
public void |
94 |
|
|
addChannelsPane(JSChannelsPane chnPane) { chnPaneList.add(chnPane); } |
95 |
|
|
|
96 |
|
|
public boolean |
97 |
|
|
removeChannelsPane(JSChannelsPane chnPane) { return chnPaneList.remove(chnPane); } |
98 |
|
|
|
99 |
|
|
public int |
100 |
|
|
getChannelsPaneCount() { return chnPaneList.size(); } |
101 |
|
|
|
102 |
|
|
public abstract void insertChannelsPane(JSChannelsPane pane, int idx); |
103 |
|
|
public abstract JSChannelsPane getSelectedChannelsPane(); |
104 |
|
|
public abstract void setSelectedChannelsPane(JSChannelsPane pane); |
105 |
|
|
|
106 |
|
|
private class EventHandler implements SamplerChannelListListener { |
107 |
|
|
/** |
108 |
|
|
* Invoked when a new sampler channel is created. |
109 |
|
|
* @param e A <code>SamplerChannelListEvent</code> |
110 |
|
|
* instance providing the event information. |
111 |
|
|
*/ |
112 |
|
|
public void |
113 |
|
|
channelAdded(SamplerChannelListEvent e) { |
114 |
|
|
Integer id = e.getChannelModel().getChannelID(); |
115 |
|
|
if(findChannel(id) != null) { |
116 |
|
|
CC.getLogger().log(Level.WARNING, "JSMainFrame.channelExist!", id); |
117 |
|
|
return; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
getSelectedChannelsPane().addChannel(e.getChannelModel()); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
/** |
124 |
|
|
* Invoked when a sampler channel is removed. |
125 |
|
|
* @param e A <code>SamplerChannelListEvent</code> |
126 |
|
|
* instance providing the event information. |
127 |
|
|
*/ |
128 |
|
|
public void |
129 |
|
|
channelRemoved(SamplerChannelListEvent e) { |
130 |
|
|
removeChannel(e.getChannelModel().getChannelID()); |
131 |
|
|
} |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
/** |
135 |
|
|
* Searches for the first occurence of a channel with numerical ID <code>id</code>. |
136 |
|
|
* @return The first occurence of a channel with numerical ID <code>id</code> or |
137 |
|
|
* <code>null</code> if there is no channel with numerical ID <code>id</code>. |
138 |
|
|
*/ |
139 |
|
|
public JSChannel |
140 |
|
|
findChannel(int id) { |
141 |
|
|
if(id < 0) return null; |
142 |
|
|
|
143 |
|
|
for(JSChannelsPane cp : getChannelsPaneList()) { |
144 |
|
|
for(JSChannel c : cp.getChannels()) if(c.getChannelID() == id) return c; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
return null; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
/** |
151 |
|
|
* Removes the first occurence of a channel with numerical ID <code>id</code>. |
152 |
|
|
* This method is invoked when a sampler channel is removed in the back-end. |
153 |
|
|
* @return The removed channel or <code>null</code> |
154 |
|
|
* if there is no channel with numerical ID <code>id</code>. |
155 |
|
|
*/ |
156 |
|
|
public JSChannel |
157 |
|
|
removeChannel(int id) { |
158 |
|
|
if(id < 0) return null; |
159 |
|
|
|
160 |
|
|
for(JSChannelsPane cp : getChannelsPaneList()) { |
161 |
|
|
for(JSChannel c : cp.getChannels()) { |
162 |
|
|
if(c.getChannelID() == id) { |
163 |
|
|
cp.removeChannel(c); |
164 |
|
|
return c; |
165 |
|
|
} |
166 |
|
|
} |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
return null; |
170 |
|
|
} |
171 |
|
|
} |