1 |
/* |
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.JButton; |
35 |
import javax.swing.JLabel; |
36 |
import javax.swing.JPanel; |
37 |
import javax.swing.JTextField; |
38 |
|
39 |
import net.sf.juife.EnhancedDialog; |
40 |
import net.sf.juife.JuifeUtils; |
41 |
|
42 |
import org.jsampler.CC; |
43 |
import org.jsampler.HF; |
44 |
import org.jsampler.view.JSChannelsPane; |
45 |
|
46 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
47 |
|
48 |
|
49 |
/** |
50 |
* |
51 |
* @author Grigor Iliev |
52 |
*/ |
53 |
public class ChangeTabTitleDlg extends EnhancedDialog { |
54 |
private final JLabel lTitle = new JLabel(i18n.getLabel("ChangeTabTitleDlg.lTitle")); |
55 |
private final JTextField tfTitle = new JTextField(); |
56 |
|
57 |
private final JButton btnOk = new JButton(i18n.getButtonLabel("ok")); |
58 |
private final JButton btnCancel = new JButton(i18n.getButtonLabel("cancel")); |
59 |
|
60 |
/** Creates a new instance of ChangeTabTitleDlg */ |
61 |
public ChangeTabTitleDlg(Frame frm) { |
62 |
super(frm, i18n.getLabel("ChangeTabTitleDlg"), true); |
63 |
|
64 |
initChangeTabTitleDlg(); |
65 |
setLocation(JuifeUtils.centerLocation(this, frm)); |
66 |
|
67 |
handleEvents(); |
68 |
} |
69 |
|
70 |
private void |
71 |
initChangeTabTitleDlg() { |
72 |
tfTitle.setText(CC.getMainFrame().getSelectedChannelsPane().getTitle()); |
73 |
tfTitle.selectAll(); |
74 |
|
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 pane = new JPanel(); |
90 |
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS)); |
91 |
pane.add(lTitle); |
92 |
pane.add(Box.createRigidArea(new Dimension(5, 0))); |
93 |
pane.add(tfTitle); |
94 |
|
95 |
JPanel mainPane = new JPanel(); |
96 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
97 |
|
98 |
pane.setAlignmentX(RIGHT_ALIGNMENT); |
99 |
mainPane.add(pane); |
100 |
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
101 |
mainPane.add(btnPane); |
102 |
|
103 |
mainPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); |
104 |
add(mainPane); |
105 |
|
106 |
pack(); |
107 |
d = getPreferredSize(); |
108 |
d.width = d.width > 300 ? d.width : 300; |
109 |
setSize(d); |
110 |
setResizable(false); |
111 |
} |
112 |
|
113 |
private void |
114 |
handleEvents() { |
115 |
btnCancel.addActionListener(new ActionListener() { |
116 |
public void |
117 |
actionPerformed(ActionEvent e) { onCancel(); } |
118 |
}); |
119 |
|
120 |
btnOk.addActionListener(new ActionListener() { |
121 |
public void |
122 |
actionPerformed(ActionEvent e) { onOk(); } |
123 |
}); |
124 |
} |
125 |
|
126 |
protected void |
127 |
onOk() { |
128 |
JSChannelsPane pane = CC.getMainFrame().getSelectedChannelsPane(); |
129 |
|
130 |
String title = tfTitle.getText().trim(); |
131 |
|
132 |
if(title.length() == 0) { |
133 |
HF.showErrorMessage(i18n.getError("ChangeTabTitleDlg.emptyTitle!"), this); |
134 |
return; |
135 |
} |
136 |
|
137 |
for(JSChannelsPane p : CC.getMainFrame().getChannelsPaneList()) { |
138 |
if(p != pane && title.equals(p.getTitle())) { |
139 |
String s = i18n.getError("ChangeTabTitleDlg.tabExist!", title); |
140 |
HF.showErrorMessage(s, this); |
141 |
return; |
142 |
} |
143 |
} |
144 |
|
145 |
pane.setTitle(title); |
146 |
((MainFrame)CC.getMainFrame()).updateTabTitle(pane); |
147 |
|
148 |
setVisible(false); |
149 |
} |
150 |
|
151 |
protected void |
152 |
onCancel() { setVisible(false); } |
153 |
} |