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.std; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dimension; |
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.JPanel; |
36 |
import javax.swing.JTable; |
37 |
|
38 |
import net.sf.juife.EnhancedDialog; |
39 |
|
40 |
import org.jsampler.CC; |
41 |
import org.jsampler.JSPrefs; |
42 |
import org.jsampler.Server; |
43 |
|
44 |
import static org.jsampler.view.std.StdI18n.i18n; |
45 |
|
46 |
|
47 |
/** |
48 |
* |
49 |
* @author Grigor Iliev |
50 |
*/ |
51 |
public class JSConnectDlg extends EnhancedDialog { |
52 |
private final JSConnectionPropsPane.ServerListPane serverListPane = |
53 |
new JSConnectionPropsPane.ServerListPane(); |
54 |
|
55 |
private final JButton btnConnect = |
56 |
new JButton(i18n.getButtonLabel("JSConnectDlg.btnConnect")); |
57 |
|
58 |
/** Creates a new instance of <code>JSConnectDlg</code> */ |
59 |
public |
60 |
JSConnectDlg() { |
61 |
super(CC.getMainFrame(), i18n.getLabel("JSConnectDlg.title")); |
62 |
|
63 |
JPanel mainPane = new JPanel(); |
64 |
mainPane.setLayout(new BorderLayout()); |
65 |
|
66 |
mainPane.add(serverListPane); |
67 |
|
68 |
JPanel p = new JPanel(); |
69 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
70 |
p.add(Box.createGlue()); |
71 |
p.add(btnConnect); |
72 |
p.add(Box.createGlue()); |
73 |
p.setBorder(BorderFactory.createEmptyBorder(12, 0, 0, 0)); |
74 |
|
75 |
mainPane.add(p, BorderLayout.SOUTH); |
76 |
mainPane.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
77 |
mainPane.setPreferredSize(new java.awt.Dimension(300, 300)); |
78 |
|
79 |
btnConnect.addActionListener(new ActionListener() { |
80 |
public void |
81 |
actionPerformed(ActionEvent e) { onOk(); } |
82 |
}); |
83 |
|
84 |
getContentPane().add(mainPane); |
85 |
|
86 |
pack(); |
87 |
setMinimumSize(getPreferredSize()); |
88 |
|
89 |
btnConnect.requestFocus(); |
90 |
|
91 |
setLocationRelativeTo(getOwner()); |
92 |
} |
93 |
|
94 |
private static JSPrefs |
95 |
preferences() { return CC.getViewConfig().preferences(); } |
96 |
|
97 |
protected void |
98 |
onOk() { |
99 |
setVisible(false); |
100 |
setCancelled(false); |
101 |
} |
102 |
|
103 |
protected void |
104 |
onCancel() { |
105 |
setVisible(false); |
106 |
} |
107 |
|
108 |
/** Returns the server that is selected by the user to connect. */ |
109 |
public Server |
110 |
getSelectedServer() { |
111 |
if(isCancelled()) return null; |
112 |
return serverListPane.serverTable.getSelectedServer(); |
113 |
} |
114 |
} |