1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.displayers.selector;
24
25 import java.awt.BorderLayout;
26 import java.awt.Component;
27 import java.awt.GridBagConstraints;
28 import java.awt.GridBagLayout;
29 import java.awt.Insets;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32 import java.awt.event.WindowAdapter;
33 import java.awt.event.WindowEvent;
34
35 import javax.swing.JButton;
36 import javax.swing.JDialog;
37 import javax.swing.JLabel;
38 import javax.swing.JOptionPane;
39 import javax.swing.JPanel;
40 import javax.swing.JTabbedPane;
41 import javax.swing.border.EmptyBorder;
42
43 import com.cosylab.gui.adapters.ConverterCustomizer;
44
45 import de.desy.acop.displayers.tools.AcopDisplayerParameters;
46 import de.desy.acop.transport.ConnectionParameters;
47
48
49
50
51
52
53
54
55
56 public abstract class AcopDisplayerParametersDialog<T extends AcopDisplayerParameters> extends JDialog {
57
58 private static final long serialVersionUID = 1L;
59
60 private JPanel contentPanel;
61 private JPanel labelPanel;
62 private JLabel connectionLabel;
63 private JPanel buttonPanel;
64 private JButton addButton;
65 private JButton cancelButton;
66
67 private AcopDisplayerParameters parameters;
68 private T result;
69 private ConverterCustomizer converterCustomizer;
70 private JTabbedPane customizerTab;
71
72
73
74
75
76
77 public AcopDisplayerParametersDialog(Component comp) {
78 super(JOptionPane.getFrameForComponent(comp), "Adding New Parameters", true);
79 initialize();
80 }
81
82 private void initialize() {
83 this.setLayout(new GridBagLayout());
84 this.add(getContentPanel(), new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11,11,11,11),1,1));
85 this.setSize(330, 300);
86 this.addWindowListener(new WindowCloser());
87 }
88
89 private JPanel getContentPanel() {
90 if (contentPanel == null) {
91 contentPanel = new JPanel();
92 contentPanel.setLayout(new BorderLayout());
93 contentPanel.add(getCustomizerTabPane(), BorderLayout.CENTER);
94 contentPanel.add(getLabelPanel(), BorderLayout.NORTH);
95 contentPanel.add(getButtonPanel(), BorderLayout.SOUTH);
96
97 }
98 return contentPanel;
99 }
100
101 private JTabbedPane getCustomizerTabPane() {
102 if (customizerTab == null) {
103 customizerTab = new JTabbedPane();
104 customizerTab.add(getCustomizerPanel(), "Properties");
105 customizerTab.add(getConverterPanel(), "Converter");
106 }
107 return customizerTab;
108 }
109
110 protected ConverterCustomizer getConverterPanel() {
111 if (converterCustomizer == null) {
112 converterCustomizer = new ConverterCustomizer();
113 }
114 return converterCustomizer;
115 }
116
117 private JPanel getLabelPanel() {
118 if (labelPanel == null) {
119 labelPanel = new JPanel();
120 labelPanel.setBorder(new EmptyBorder(new Insets(0,0,5,0)));
121 labelPanel.add(getConnectionLabel());
122 }
123 return labelPanel;
124 }
125
126 private JLabel getConnectionLabel() {
127 if (connectionLabel == null) {
128 connectionLabel = new JLabel("Connection");
129 connectionLabel.setToolTipText("Connection");
130 }
131 return connectionLabel;
132 }
133
134 private void setConnectionLabel(String connection) {
135 getConnectionLabel().setText(connection);
136 getConnectionLabel().setToolTipText(connection);
137 }
138
139 private JPanel getButtonPanel() {
140 if (buttonPanel == null) {
141 buttonPanel = new JPanel();
142 buttonPanel.add(getAddButton());
143 buttonPanel.add(getCancelButton());
144 }
145 return buttonPanel;
146 }
147
148 protected abstract MultipleDisplayerAbstractSettingsPanel<T> getCustomizerPanel();
149
150 protected abstract T generateParameters();
151
152 private JButton getAddButton() {
153 if (addButton == null) {
154 addButton = new JButton("Add");
155 addButton.addActionListener(new ActionListener() {
156 public void actionPerformed(ActionEvent e) {
157 result = generateParameters();
158 closeDialog();
159 }
160 });
161
162 }
163 return addButton;
164 }
165
166 private JButton getCancelButton() {
167 if (cancelButton == null) {
168 cancelButton = new JButton("Cancel");
169 cancelButton.addActionListener(new ActionListener() {
170 public void actionPerformed(ActionEvent e) {
171 result = null;
172 closeDialog();
173 }
174 });
175 }
176 return cancelButton;
177 }
178
179 private void closeDialog() {
180 this.setVisible(false);
181 }
182
183
184
185
186
187
188
189
190 public T showDialog(Component component, AcopDisplayerParameters adp) {
191 parameters= adp;
192 getCustomizerTabPane().setSelectedIndex(0);
193 getConverterPanel().setConverter(null);
194 this.setConnectionLabel(adp.getConnectionParameters().getRemoteName());
195 this.setLocationRelativeTo(component);
196 this.setVisible(true);
197 return result;
198 }
199
200
201
202
203
204
205
206
207 public T showDialog(Component component, ConnectionParameters cp) {
208 parameters = new AcopDisplayerParameters(cp);
209 getCustomizerTabPane().setSelectedIndex(0);
210 this.getConverterPanel().setConverter(null);
211 this.setConnectionLabel(parameters.getConnectionParameters().getRemoteName());
212 this.setLocationRelativeTo(component);
213 this.setVisible(true);
214 return result;
215 }
216
217 private class WindowCloser extends WindowAdapter {
218
219
220
221
222 @Override
223 public void windowClosing(WindowEvent e) {
224 parameters = null;
225 super.windowClosed(e);
226 }
227
228 }
229
230 protected AcopDisplayerParameters getDisplayerParameters() {
231 return parameters;
232 }
233
234
235
236 }