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.classic; |
24 |
|
|
|
25 |
|
|
import java.awt.Dimension; |
26 |
|
|
import java.awt.Frame; |
27 |
|
|
|
28 |
|
|
import java.awt.event.ActionEvent; |
29 |
|
|
import java.awt.event.ActionListener; |
30 |
|
|
|
31 |
|
|
import javax.swing.BorderFactory; |
32 |
|
|
import javax.swing.Box; |
33 |
|
|
import javax.swing.BoxLayout; |
34 |
|
|
import javax.swing.ButtonGroup; |
35 |
|
|
import javax.swing.JButton; |
36 |
|
|
import javax.swing.JComboBox; |
37 |
|
|
import javax.swing.JLabel; |
38 |
|
|
import javax.swing.JPanel; |
39 |
|
|
import javax.swing.JRadioButton; |
40 |
|
|
import javax.swing.JSeparator; |
41 |
|
|
import javax.swing.JTextField; |
42 |
|
|
|
43 |
|
|
import org.jsampler.CC; |
44 |
|
|
import org.jsampler.HF; |
45 |
|
|
|
46 |
|
|
import org.jsampler.view.JSChannelsPane; |
47 |
|
|
import org.jsampler.view.JSMainFrame; |
48 |
|
|
|
49 |
|
|
import net.sf.juife.EnhancedDialog; |
50 |
|
|
import net.sf.juife.JuifeUtils; |
51 |
|
|
|
52 |
|
|
import static org.jsampler.view.classic.ClassicI18n.i18n; |
53 |
|
|
|
54 |
|
|
|
55 |
|
|
/** |
56 |
|
|
* |
57 |
|
|
* @author Grigor Iliev |
58 |
|
|
*/ |
59 |
|
|
public class NewChannelsTabDlg extends EnhancedDialog { |
60 |
|
|
private final NewTabPane newTabPane = new NewTabPane(); |
61 |
|
|
private final JButton btnOk = new JButton(i18n.getButtonLabel("ok")); |
62 |
|
|
private final JButton btnCancel = new JButton(i18n.getButtonLabel("cancel")); |
63 |
|
|
|
64 |
|
|
/** Creates a new instance of NewChannelsTabDlg */ |
65 |
|
|
public NewChannelsTabDlg(Frame frm) { |
66 |
|
|
super(frm, i18n.getLabel("NewChannelsTabDlg"), true); |
67 |
|
|
|
68 |
|
|
initNewChannelsTabDlg(); |
69 |
|
|
handleEvents(); |
70 |
|
|
setLocation(JuifeUtils.centerLocation(this, frm)); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
private void |
74 |
|
|
initNewChannelsTabDlg() { |
75 |
|
|
// Set preferred size for Ok & Cancel buttons |
76 |
|
|
Dimension d = JuifeUtils.getUnionSize(btnOk, btnCancel); |
77 |
|
|
btnOk.setPreferredSize(d); |
78 |
|
|
btnOk.setMaximumSize(d); |
79 |
|
|
btnCancel.setPreferredSize(d); |
80 |
|
|
btnCancel.setMaximumSize(d); |
81 |
|
|
|
82 |
|
|
JPanel btnPane = new JPanel(); |
83 |
|
|
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS)); |
84 |
|
|
btnPane.add(btnOk); |
85 |
|
|
btnPane.add(Box.createRigidArea(new Dimension(5, 0))); |
86 |
|
|
btnPane.add(btnCancel); |
87 |
|
|
btnPane.setAlignmentX(RIGHT_ALIGNMENT); |
88 |
|
|
|
89 |
|
|
JPanel mainPane = new JPanel(); |
90 |
|
|
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
91 |
|
|
|
92 |
|
|
newTabPane.setAlignmentX(RIGHT_ALIGNMENT); |
93 |
|
|
mainPane.add(newTabPane); |
94 |
|
|
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
95 |
|
|
mainPane.add(btnPane); |
96 |
|
|
|
97 |
|
|
mainPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); |
98 |
|
|
add(mainPane); |
99 |
|
|
|
100 |
|
|
pack(); |
101 |
|
|
d = getPreferredSize(); |
102 |
|
|
d.width = d.width > 300 ? d.width : 300; |
103 |
|
|
setSize(d); |
104 |
|
|
setResizable(false); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
private void |
108 |
|
|
handleEvents() { |
109 |
|
|
btnCancel.addActionListener(new ActionListener() { |
110 |
|
|
public void |
111 |
|
|
actionPerformed(ActionEvent e) { onCancel(); } |
112 |
|
|
}); |
113 |
|
|
|
114 |
|
|
btnOk.addActionListener(new ActionListener() { |
115 |
|
|
public void |
116 |
|
|
actionPerformed(ActionEvent e) { onOk(); } |
117 |
|
|
}); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
protected void |
121 |
|
|
onOk() { |
122 |
|
|
String title = newTabPane.getTitle().trim(); |
123 |
|
|
ChannelsPane pane = new ChannelsPane(title); |
124 |
|
|
|
125 |
|
|
if(title.length() == 0) { |
126 |
|
|
HF.showErrorMessage(i18n.getError("NewChannelsTabDlg.emptyTitle!"), this); |
127 |
|
|
return; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
for(JSChannelsPane p : CC.getMainFrame().getChannelsPaneList()) { |
131 |
|
|
if(pane.getTitle().equals(p.getTitle())) { |
132 |
|
|
String s; |
133 |
|
|
s = i18n.getError("NewChannelsTabDlg.tabExist!", pane.getTitle()); |
134 |
|
|
HF.showErrorMessage(s, this); |
135 |
|
|
return; |
136 |
|
|
} |
137 |
|
|
} |
138 |
|
|
JSMainFrame frm = CC.getMainFrame(); |
139 |
|
|
if(newTabPane.rbBeginning.isSelected()) frm.insertChannelsPane(pane, 0); |
140 |
|
|
else if(newTabPane.rbAfter.isSelected()) { |
141 |
|
|
int i; |
142 |
|
|
i = frm.getChannelsPaneList().indexOf(newTabPane.cbTabs.getSelectedItem()); |
143 |
|
|
if(i == -1) { |
144 |
|
|
CC.getLogger().warning("ChannelsPane not found in the list!"); |
145 |
|
|
i = frm.getChannelsPaneCount() - 1; |
146 |
|
|
} |
147 |
|
|
frm.insertChannelsPane(pane, i + 1); |
148 |
|
|
} else frm.insertChannelsPane(pane, frm.getChannelsPaneCount()); |
149 |
|
|
|
150 |
|
|
setVisible(false); |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
protected void |
154 |
|
|
onCancel() { |
155 |
|
|
|
156 |
|
|
setVisible(false); |
157 |
|
|
} |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
class NewTabPane extends JPanel { |
161 |
|
|
private final JLabel lTitle = new JLabel(i18n.getLabel("NewTabPane.lTitle")); |
162 |
|
|
private final JTextField tfTitle = new JTextField(); |
163 |
|
|
|
164 |
|
|
protected final JRadioButton rbBeginning = |
165 |
|
|
new JRadioButton(i18n.getButtonLabel("NewTabPane.rbBeginning")); |
166 |
|
|
protected final JRadioButton rbEnd = |
167 |
|
|
new JRadioButton(i18n.getButtonLabel("NewTabPane.rbEnd")); |
168 |
|
|
protected final JRadioButton rbAfter = |
169 |
|
|
new JRadioButton(i18n.getButtonLabel("NewTabPane.rbAfter")); |
170 |
|
|
|
171 |
|
|
protected final JComboBox cbTabs = new JComboBox(); |
172 |
|
|
|
173 |
|
|
private static int count = 2; |
174 |
|
|
|
175 |
|
|
NewTabPane() { |
176 |
|
|
tfTitle.setText("Untitled " + count++); |
177 |
|
|
tfTitle.selectAll(); |
178 |
|
|
|
179 |
|
|
for(JSChannelsPane pane : CC.getMainFrame().getChannelsPaneList()) |
180 |
|
|
cbTabs.addItem(pane); |
181 |
|
|
|
182 |
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
183 |
|
|
|
184 |
|
|
JPanel p1 = new JPanel(); |
185 |
|
|
p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS)); |
186 |
|
|
p1.add(lTitle); |
187 |
|
|
p1.add(Box.createRigidArea(new Dimension(5, 0))); |
188 |
|
|
p1.add(tfTitle); |
189 |
|
|
|
190 |
|
|
ButtonGroup bg = new ButtonGroup(); |
191 |
|
|
bg.add(rbBeginning); |
192 |
|
|
bg.add(rbEnd); |
193 |
|
|
bg.add(rbAfter); |
194 |
|
|
|
195 |
|
|
rbEnd.setSelected(true); |
196 |
|
|
|
197 |
|
|
JPanel p2 = new JPanel(); |
198 |
|
|
p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); |
199 |
|
|
p2.add(rbAfter); |
200 |
|
|
p2.add(Box.createRigidArea(new Dimension(5, 0))); |
201 |
|
|
p2.add(cbTabs); |
202 |
|
|
|
203 |
|
|
p1.setAlignmentX(LEFT_ALIGNMENT); |
204 |
|
|
rbBeginning.setAlignmentX(LEFT_ALIGNMENT); |
205 |
|
|
rbEnd.setAlignmentX(LEFT_ALIGNMENT); |
206 |
|
|
p2.setAlignmentX(LEFT_ALIGNMENT); |
207 |
|
|
|
208 |
|
|
JSeparator sep = new JSeparator(); |
209 |
|
|
|
210 |
|
|
add(p1); |
211 |
|
|
add(Box.createRigidArea(new Dimension(0, 6))); |
212 |
|
|
add(sep); |
213 |
|
|
add(rbBeginning); |
214 |
|
|
add(rbEnd); |
215 |
|
|
add(p2); |
216 |
|
|
|
217 |
|
|
cbTabs.addActionListener(new ActionListener() { |
218 |
|
|
public void |
219 |
|
|
actionPerformed(ActionEvent e) { rbAfter.setSelected(true); } |
220 |
|
|
}); |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
public String |
224 |
|
|
getTitle() { return tfTitle.getText(); } |
225 |
|
|
} |