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.BorderLayout; |
26 |
import java.awt.Color; |
27 |
import java.awt.Container; |
28 |
import java.awt.Cursor; |
29 |
import java.awt.Dialog; |
30 |
import java.awt.Dimension; |
31 |
import java.awt.GraphicsEnvironment; |
32 |
import java.awt.Font; |
33 |
import java.awt.Frame; |
34 |
import java.awt.GridBagConstraints; |
35 |
import java.awt.GridBagLayout; |
36 |
import java.awt.Insets; |
37 |
|
38 |
import java.awt.event.ActionEvent; |
39 |
import java.awt.event.ActionListener; |
40 |
import java.awt.event.ItemEvent; |
41 |
import java.awt.event.ItemListener; |
42 |
import java.awt.event.MouseAdapter; |
43 |
import java.awt.event.MouseEvent; |
44 |
|
45 |
import java.util.Locale; |
46 |
import java.util.Vector; |
47 |
|
48 |
import javax.swing.BorderFactory; |
49 |
import javax.swing.Box; |
50 |
import javax.swing.BoxLayout; |
51 |
import javax.swing.DefaultButtonModel; |
52 |
import javax.swing.JButton; |
53 |
import javax.swing.JCheckBox; |
54 |
import javax.swing.JColorChooser; |
55 |
import javax.swing.JComboBox; |
56 |
import javax.swing.JLabel; |
57 |
import javax.swing.JOptionPane; |
58 |
import javax.swing.JPanel; |
59 |
import javax.swing.JPasswordField; |
60 |
import javax.swing.JTabbedPane; |
61 |
import javax.swing.JTextField; |
62 |
|
63 |
import javax.swing.event.ChangeEvent; |
64 |
import javax.swing.event.ChangeListener; |
65 |
|
66 |
import net.sf.juife.EnhancedDialog; |
67 |
import net.sf.juife.JuifeUtils; |
68 |
import net.sf.juife.LinkButton; |
69 |
import net.sf.juife.OkCancelDialog; |
70 |
|
71 |
import org.jsampler.CC; |
72 |
import org.jsampler.HF; |
73 |
import org.jsampler.JSI18n; |
74 |
import org.jsampler.JSampler; |
75 |
import org.jsampler.Prefs; |
76 |
|
77 |
import org.jsampler.task.SetServerAddress; |
78 |
|
79 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
80 |
|
81 |
|
82 |
/** |
83 |
* |
84 |
* @author Grigor Iliev |
85 |
*/ |
86 |
public class PrefsDlg extends EnhancedDialog { |
87 |
private final ViewPane viewPane = new ViewPane(); |
88 |
private final GeneralPane genPane = new GeneralPane(); |
89 |
private final ConnectionPane conPane = new ConnectionPane(); |
90 |
|
91 |
private final JButton btnApply = new JButton(i18n.getButtonLabel("apply")); |
92 |
private final JButton btnClose = new JButton(i18n.getButtonLabel("close")); |
93 |
|
94 |
|
95 |
public |
96 |
PrefsDlg(Frame frm) { |
97 |
super(frm, i18n.getLabel("PrefsDlg"), true); |
98 |
|
99 |
initPrefsDlg(); |
100 |
handleEvents(); |
101 |
initPrefs(); |
102 |
|
103 |
setLocation(JuifeUtils.centerLocation(this, frm)); |
104 |
} |
105 |
|
106 |
private void |
107 |
initPrefsDlg() { |
108 |
JTabbedPane tp = new JTabbedPane(); |
109 |
tp.addTab(i18n.getLabel("PrefsDlg.tabGeneral"), genPane); |
110 |
tp.addTab(i18n.getLabel("PrefsDlg.tabView"), viewPane); |
111 |
tp.addTab(i18n.getLabel("PrefsDlg.tabConnection"), conPane); |
112 |
tp.setAlignmentX(RIGHT_ALIGNMENT); |
113 |
|
114 |
// Set preferred size for Apply & Exit buttons |
115 |
Dimension d = JuifeUtils.getUnionSize(btnApply, btnClose); |
116 |
btnApply.setPreferredSize(d); |
117 |
btnClose.setPreferredSize(d); |
118 |
|
119 |
JPanel btnPane = new JPanel(); |
120 |
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS)); |
121 |
btnPane.add(btnApply); |
122 |
btnPane.add(Box.createRigidArea(new Dimension(5, 0))); |
123 |
btnPane.add(btnClose); |
124 |
btnPane.setAlignmentX(RIGHT_ALIGNMENT); |
125 |
|
126 |
JPanel mainPane = new JPanel(); |
127 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
128 |
mainPane.add(tp); |
129 |
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
130 |
mainPane.add(btnPane); |
131 |
mainPane.setBorder(BorderFactory.createEmptyBorder(11, 12, 12, 12)); |
132 |
|
133 |
getContentPane().add(mainPane); |
134 |
|
135 |
pack(); |
136 |
setResizable(false); |
137 |
} |
138 |
|
139 |
private void |
140 |
handleEvents() { |
141 |
btnApply.addActionListener(new ActionListener() { |
142 |
public void |
143 |
actionPerformed(ActionEvent e) { onApply(); } |
144 |
}); |
145 |
|
146 |
btnClose.addActionListener(new ActionListener() { |
147 |
public void |
148 |
actionPerformed(ActionEvent e) { onExit(); } |
149 |
}); |
150 |
} |
151 |
|
152 |
protected void |
153 |
onOk() { onApply(); } |
154 |
|
155 |
protected void |
156 |
onCancel() { onExit(); } |
157 |
|
158 |
private void |
159 |
initPrefs() { |
160 |
setLSAddress(Prefs.getLSAddress()); |
161 |
setLSPort(Prefs.getLSPort()); |
162 |
} |
163 |
|
164 |
private void |
165 |
onApply() { |
166 |
genPane.apply(); |
167 |
viewPane.apply(); |
168 |
|
169 |
// CONNECTION |
170 |
Prefs.setLSAddress(getLSAddress()); |
171 |
|
172 |
boolean b = true; |
173 |
String s = getLSPort(); |
174 |
try { |
175 |
if(s.length() > 0) { |
176 |
int port = Integer.parseInt(s); |
177 |
if(port > 0 && port < 0xffff) |
178 |
Prefs.setLSPort(port); |
179 |
else b = false; |
180 |
} else Prefs.setLSPort(-1); // -1 resets to default value |
181 |
} catch(NumberFormatException x) { |
182 |
b = false; |
183 |
} |
184 |
|
185 |
if(!b) { |
186 |
JOptionPane.showMessageDialog ( |
187 |
this, |
188 |
i18n.getError("PrefsDlg.invalidPort", s), |
189 |
i18n.getError("error"), |
190 |
JOptionPane.ERROR_MESSAGE |
191 |
); |
192 |
|
193 |
return; |
194 |
} |
195 |
|
196 |
//CC.getClient().setServerAddress(Prefs.getLSAddress()); |
197 |
//CC.getClient().setServerPort(Prefs.getLSPort()); |
198 |
CC.getTaskQueue().add ( |
199 |
new SetServerAddress(Prefs.getLSAddress(), Prefs.getLSPort()) |
200 |
); |
201 |
|
202 |
setVisible(false); |
203 |
} |
204 |
|
205 |
private void |
206 |
onExit() { setVisible(false); } |
207 |
|
208 |
private String |
209 |
getLSAddress() { return conPane.getLSAddress().trim(); } |
210 |
|
211 |
private void |
212 |
setLSAddress(String s) { conPane.setLSAddress(s); } |
213 |
|
214 |
private String |
215 |
getLSPort() { return conPane.getLSPort().trim(); } |
216 |
|
217 |
private void |
218 |
setLSPort(int port) { conPane.setLSPort(String.valueOf(port)); } |
219 |
} |
220 |
|
221 |
class GeneralPane extends JPanel { |
222 |
private final JCheckBox checkWindowSizeAndLocation = |
223 |
new JCheckBox(i18n.getLabel("GeneralPane.checkWindowSizeAndLocation")); |
224 |
|
225 |
public |
226 |
GeneralPane() { initGeneralPane(); } |
227 |
|
228 |
private void |
229 |
initGeneralPane() { |
230 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
231 |
add(checkWindowSizeAndLocation); |
232 |
|
233 |
checkWindowSizeAndLocation.setSelected(Prefs.getSaveWindowProperties()); |
234 |
|
235 |
checkWindowSizeAndLocation.addItemListener(new ItemListener() { |
236 |
public void |
237 |
itemStateChanged(ItemEvent e) { |
238 |
boolean b = e.getStateChange() == e.SELECTED; |
239 |
checkWindowSizeAndLocation.setEnabled(b); |
240 |
} |
241 |
}); |
242 |
|
243 |
|
244 |
} |
245 |
|
246 |
protected void |
247 |
apply() { |
248 |
Prefs.setSaveWindowProperties(checkWindowSizeAndLocation.isSelected()); |
249 |
} |
250 |
} |
251 |
|
252 |
class ViewPane extends JPanel { |
253 |
private final JLabel lIfaceLanguage = |
254 |
new JLabel(i18n.getLabel("ViewPane.lIfaceLanguage")); |
255 |
private final JComboBox cbIfaceLanguage = new JComboBox(); |
256 |
|
257 |
private final JLabel lIfaceFont = |
258 |
new JLabel(i18n.getLabel("ViewPane.lIfaceFont")); |
259 |
private final JComboBox cbIfaceFont = new JComboBox(); |
260 |
|
261 |
private final JCheckBox checkBorderColor = |
262 |
new JCheckBox(i18n.getLabel("ViewPane.channelBorderColor")); |
263 |
private final ColorButton btnBorderColor = new ColorButton(Color.WHITE); |
264 |
|
265 |
public |
266 |
ViewPane() { initViewPane(); } |
267 |
|
268 |
private void |
269 |
initViewPane() { |
270 |
cbIfaceLanguage.setMaximumSize ( |
271 |
new Dimension(Short.MAX_VALUE, cbIfaceLanguage.getPreferredSize().height) |
272 |
); |
273 |
|
274 |
for(Locale l : JSI18n.getAvailableLocales()) { |
275 |
LocaleBox box = new LocaleBox(l); |
276 |
cbIfaceLanguage.addItem(box); |
277 |
if ( l.getLanguage().equals(Prefs.getInterfaceLanguage()) && |
278 |
l.getCountry().equals(Prefs.getInterfaceCountry()) |
279 |
) cbIfaceLanguage.setSelectedItem(box); |
280 |
} |
281 |
|
282 |
cbIfaceFont.setMaximumSize ( |
283 |
new Dimension(Short.MAX_VALUE, cbIfaceFont.getPreferredSize().height) |
284 |
); |
285 |
|
286 |
cbIfaceFont.addItem("[Default]"); |
287 |
|
288 |
String[] fontS = |
289 |
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); |
290 |
|
291 |
for(String f : fontS) cbIfaceFont.addItem(f); |
292 |
|
293 |
if(Prefs.getInterfaceFont() == null) cbIfaceFont.setSelectedItem("[Default]"); |
294 |
else cbIfaceFont.setSelectedItem(Prefs.getInterfaceFont()); |
295 |
|
296 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
297 |
|
298 |
JPanel ifacePane = new JPanel(); |
299 |
ifacePane.setLayout(new BoxLayout(ifacePane, BoxLayout.X_AXIS)); |
300 |
ifacePane.add(lIfaceLanguage); |
301 |
ifacePane.add(Box.createRigidArea(new Dimension(5, 0))); |
302 |
ifacePane.add(cbIfaceLanguage); |
303 |
|
304 |
add(ifacePane); |
305 |
|
306 |
add(Box.createRigidArea(new Dimension(0, 6))); |
307 |
|
308 |
JPanel fontPane = new JPanel(); |
309 |
fontPane.setLayout(new BoxLayout(fontPane, BoxLayout.X_AXIS)); |
310 |
fontPane.add(lIfaceFont); |
311 |
fontPane.add(Box.createRigidArea(new Dimension(5, 0))); |
312 |
fontPane.add(cbIfaceFont); |
313 |
|
314 |
add(fontPane); |
315 |
add(Box.createRigidArea(new Dimension(0, 6))); |
316 |
add(createCustomColorsPane()); |
317 |
|
318 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
319 |
} |
320 |
|
321 |
private JPanel |
322 |
createCustomColorsPane() { |
323 |
JPanel ccp = new JPanel(); |
324 |
ccp.setAlignmentX(CENTER_ALIGNMENT); |
325 |
ccp.setLayout(new BoxLayout(ccp, BoxLayout.Y_AXIS)); |
326 |
|
327 |
JPanel p = new JPanel(); |
328 |
p.setAlignmentX(LEFT_ALIGNMENT); |
329 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
330 |
p.add(checkBorderColor); |
331 |
|
332 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
333 |
|
334 |
btnBorderColor.setColor(ClassicPrefs.getChannelBorderColor()); |
335 |
btnBorderColor.setEnabled(ClassicPrefs.getCustomChannelBorderColor()); |
336 |
p.add(btnBorderColor); |
337 |
|
338 |
checkBorderColor.setSelected(ClassicPrefs.getCustomChannelBorderColor()); |
339 |
|
340 |
checkBorderColor.addItemListener(new ItemListener() { |
341 |
public void |
342 |
itemStateChanged(ItemEvent e) { |
343 |
boolean b = e.getStateChange() == e.SELECTED; |
344 |
btnBorderColor.setEnabled(b); |
345 |
} |
346 |
}); |
347 |
|
348 |
/*btnBorderColor.addActionListener(new ActionListener() { |
349 |
public void |
350 |
actionPerformed(ActionEvent e) { |
351 |
ClassicPrefs.setChannelBorderColor(btnBorderColor.getColor()); |
352 |
} |
353 |
});*/ |
354 |
|
355 |
ccp.add(p); |
356 |
|
357 |
JButton btnDefaults = new JButton("Reset to defaults"); |
358 |
btnDefaults.addActionListener(new ActionListener() { |
359 |
public void |
360 |
actionPerformed(ActionEvent e) { |
361 |
ClassicPrefs.setChannelBorderColor(null); |
362 |
btnBorderColor.setColor(ClassicPrefs.getChannelBorderColor()); |
363 |
} |
364 |
}); |
365 |
|
366 |
p = new JPanel(); |
367 |
p.setAlignmentX(LEFT_ALIGNMENT); |
368 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
369 |
p.setBorder(BorderFactory.createEmptyBorder(6, 0, 6, 6)); |
370 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
371 |
|
372 |
p.add(Box.createGlue()); |
373 |
p.add(btnDefaults); |
374 |
p.add(Box.createGlue()); |
375 |
|
376 |
ccp.add(p); |
377 |
|
378 |
ccp.setBorder ( |
379 |
BorderFactory.createTitledBorder(i18n.getLabel("ViewPane.CustomColorsPane")) |
380 |
); |
381 |
|
382 |
ccp.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
383 |
|
384 |
return ccp; |
385 |
} |
386 |
|
387 |
private String |
388 |
getInterfaceLanguage() { |
389 |
LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem(); |
390 |
if(box == null) return null; |
391 |
return box.getLocale().getLanguage(); |
392 |
} |
393 |
|
394 |
private String |
395 |
getInterfaceCountry() { |
396 |
LocaleBox box = (LocaleBox)cbIfaceLanguage.getSelectedItem(); |
397 |
if(box == null) return null; |
398 |
return box.getLocale().getCountry(); |
399 |
} |
400 |
|
401 |
private String |
402 |
getInterfaceFontName() { return cbIfaceFont.getSelectedItem().toString(); } |
403 |
|
404 |
protected void |
405 |
apply() { |
406 |
boolean b = Prefs.setInterfaceLanguage(getInterfaceLanguage()); |
407 |
boolean b2 = Prefs.setInterfaceCountry(getInterfaceCountry()); |
408 |
if (b || b2) JOptionPane.showMessageDialog ( |
409 |
this, |
410 |
i18n.getMessage("PrefsDlg.ifaceChangeInfo", "JS Classic"), |
411 |
null, |
412 |
JOptionPane.INFORMATION_MESSAGE |
413 |
); |
414 |
|
415 |
b = false; |
416 |
String fontName = getInterfaceFontName(); |
417 |
if(fontName.equals("[Default]")) { |
418 |
b = Prefs.setInterfaceFont(null); |
419 |
} else if(Prefs.setInterfaceFont(fontName)) { |
420 |
HF.setUIDefaultFont(fontName); |
421 |
b = true; |
422 |
} |
423 |
|
424 |
if(b) JOptionPane.showMessageDialog ( |
425 |
this, |
426 |
i18n.getMessage("PrefsDlg.ifaceFontChangeInfo", "JS Classic"), |
427 |
null, |
428 |
JOptionPane.INFORMATION_MESSAGE |
429 |
); |
430 |
|
431 |
///***/// |
432 |
|
433 |
b = checkBorderColor.isSelected(); |
434 |
ClassicPrefs.setCustomChannelBorderColor(b); |
435 |
if(b) ClassicPrefs.setChannelBorderColor(btnBorderColor.getColor()); |
436 |
|
437 |
Color c; |
438 |
if(b) c = ClassicPrefs.getChannelBorderColor(); |
439 |
else c = ClassicPrefs.getDefaultChannelBorderColor(); |
440 |
Channel.setBorderColor(c); |
441 |
} |
442 |
|
443 |
class LocaleBox { |
444 |
private Locale locale; |
445 |
|
446 |
LocaleBox(Locale locale) { this.locale = locale; } |
447 |
|
448 |
public Locale |
449 |
getLocale() { return locale; } |
450 |
|
451 |
public String |
452 |
toString() { return locale.getDisplayLanguage(JSI18n.i18n.getCurrentLocale()); } |
453 |
} |
454 |
|
455 |
private class ColorButton extends JPanel { |
456 |
private Color color; |
457 |
private final Vector<ActionListener> listeners = new Vector<ActionListener>(); |
458 |
|
459 |
ColorButton(Color c) { |
460 |
color = c; |
461 |
|
462 |
//setBorderPainted(false); |
463 |
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
464 |
setPreferredSize(new Dimension(42, 16)); |
465 |
setMaximumSize(new Dimension(42, 16)); |
466 |
setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
467 |
|
468 |
addMouseListener(new MouseAdapter() { |
469 |
public void |
470 |
mouseClicked(MouseEvent e) { |
471 |
if(!isEnabled()) return; |
472 |
if(e.getButton() == e.BUTTON1) showColorChooser(); |
473 |
} |
474 |
}); |
475 |
} |
476 |
|
477 |
/** |
478 |
* Registers the specified listener to be |
479 |
* notified when the current color is changed. |
480 |
* @param l The <code>ActionListener</code> to register. |
481 |
*/ |
482 |
public void |
483 |
addActionListener(ActionListener l) { listeners.add(l); } |
484 |
|
485 |
/** |
486 |
* Removes the specified listener. |
487 |
* @param l The <code>ActionListener</code> to remove. |
488 |
*/ |
489 |
public void |
490 |
removeActionListener(ActionListener l) { listeners.remove(l); } |
491 |
|
492 |
/** Notifies listeners that the current color is changed. */ |
493 |
private void |
494 |
fireActionPerformed() { |
495 |
ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); |
496 |
for(ActionListener l : listeners) l.actionPerformed(e); |
497 |
} |
498 |
|
499 |
public void |
500 |
setEnabled(boolean b) { |
501 |
setOpaque(b); |
502 |
if(b) setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
503 |
else setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); |
504 |
//setBorderPainted(!b); |
505 |
super.setEnabled(b); |
506 |
} |
507 |
|
508 |
private void |
509 |
showColorChooser() { |
510 |
ColorDlg dlg = new ColorDlg(getColor()); |
511 |
dlg.setVisible(true); |
512 |
if(!dlg.isCancelled()) { |
513 |
setColor(dlg.getColor()); |
514 |
fireActionPerformed(); |
515 |
} |
516 |
} |
517 |
|
518 |
public Color |
519 |
getColor() { return color; } |
520 |
|
521 |
public void |
522 |
setColor(Color c) { |
523 |
color = c; |
524 |
setBackground(color); |
525 |
} |
526 |
} |
527 |
|
528 |
private class ColorDlg extends OkCancelDialog { |
529 |
private final JColorChooser colorChooser = new JColorChooser(); |
530 |
|
531 |
ColorDlg() { this(Color.WHITE); } |
532 |
|
533 |
ColorDlg(Color c) { |
534 |
super((Dialog)JuifeUtils.getWindow(ViewPane.this)); |
535 |
|
536 |
colorChooser.setPreviewPanel(new JPanel()); |
537 |
colorChooser.setColor(c); |
538 |
|
539 |
JPanel mainPane = new JPanel(); |
540 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
541 |
mainPane.add(colorChooser); |
542 |
|
543 |
mainPane.add(Box.createRigidArea(new Dimension(0, 6))); |
544 |
|
545 |
final JPanel p = new JPanel(); |
546 |
p.setBackground(c); |
547 |
p.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
548 |
mainPane.add(p); |
549 |
|
550 |
p.setPreferredSize(new Dimension(48, 8)); |
551 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, 8)); |
552 |
|
553 |
setMainPane(mainPane); |
554 |
|
555 |
colorChooser.getSelectionModel().addChangeListener(new ChangeListener() { |
556 |
public void |
557 |
stateChanged(ChangeEvent e) { p.setBackground(getColor()); } |
558 |
}); |
559 |
} |
560 |
|
561 |
protected void |
562 |
onOk() { setVisible(false); } |
563 |
|
564 |
protected void |
565 |
onCancel() { setVisible(false); } |
566 |
|
567 |
public Color |
568 |
getColor() { return colorChooser.getColor(); } |
569 |
} |
570 |
} |
571 |
|
572 |
class ConnectionPane extends JPanel { |
573 |
final LSPrefsPane lsPrefsPane = new LSPrefsPane(); |
574 |
|
575 |
public |
576 |
ConnectionPane() { initConnectionPane(); } |
577 |
|
578 |
private void |
579 |
initConnectionPane() { |
580 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
581 |
|
582 |
add(lsPrefsPane); |
583 |
add(Box.createGlue()); |
584 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
585 |
} |
586 |
|
587 |
public String |
588 |
getLSAddress() { return lsPrefsPane.getLSAddress(); } |
589 |
|
590 |
public void |
591 |
setLSAddress(String address) { lsPrefsPane.setLSAddress(address); } |
592 |
|
593 |
public String |
594 |
getLSPort() { return lsPrefsPane.getLSPort(); } |
595 |
|
596 |
public void |
597 |
setLSPort(String port) { lsPrefsPane.setLSPort(port); } |
598 |
} |
599 |
|
600 |
class LSPrefsPane extends JPanel { |
601 |
private final JLabel lAddress = new JLabel(i18n.getLabel("LSPrefsPane.Address")); |
602 |
private final JLabel lPort = new JLabel(i18n.getLabel("LSPrefsPane.Port")); |
603 |
private final JTextField tfAddress = new JTextField(); |
604 |
private final JTextField tfPort = new JTextField(); |
605 |
|
606 |
|
607 |
public |
608 |
LSPrefsPane() { initLSPrefsPane(); } |
609 |
|
610 |
private void |
611 |
initLSPrefsPane() { |
612 |
GridBagLayout gridbag = new GridBagLayout(); |
613 |
GridBagConstraints c = new GridBagConstraints(); |
614 |
|
615 |
setLayout(gridbag); |
616 |
|
617 |
// Set preferred size for username & password fields |
618 |
int w1 = (int) tfAddress.getMinimumSize().getWidth(); |
619 |
int h1 = (int) tfAddress.getMinimumSize().getHeight(); |
620 |
Dimension d = new Dimension(w1 > 150 ? w1 : 150, h1); |
621 |
tfAddress.setMinimumSize(d); |
622 |
tfAddress.setPreferredSize(d); |
623 |
|
624 |
w1 = (int) tfPort.getMinimumSize().getWidth(); |
625 |
h1 = (int) tfPort.getMinimumSize().getHeight(); |
626 |
d = new Dimension(w1 > 150 ? w1 : 150, h1); |
627 |
tfPort.setMinimumSize(d); |
628 |
tfPort.setPreferredSize(d); |
629 |
|
630 |
c.fill = GridBagConstraints.NONE; |
631 |
|
632 |
c.gridx = 0; |
633 |
c.gridy = 0; |
634 |
c.anchor = GridBagConstraints.EAST; |
635 |
c.insets = new Insets(3, 3, 3, 3); |
636 |
gridbag.setConstraints(lAddress, c); |
637 |
add(lAddress); |
638 |
|
639 |
c.gridx = 0; |
640 |
c.gridy = 1; |
641 |
gridbag.setConstraints(lPort, c); |
642 |
add(lPort); |
643 |
|
644 |
c.fill = GridBagConstraints.HORIZONTAL; |
645 |
c.gridx = 1; |
646 |
c.gridy = 0; |
647 |
c.weightx = 1.0; |
648 |
c.anchor = GridBagConstraints.WEST; |
649 |
gridbag.setConstraints(tfAddress, c); |
650 |
add(tfAddress); |
651 |
|
652 |
c.gridx = 1; |
653 |
c.gridy = 1; |
654 |
gridbag.setConstraints(tfPort, c); |
655 |
add(tfPort); |
656 |
|
657 |
setBorder(BorderFactory.createTitledBorder(i18n.getLabel("LSPrefsPane"))); |
658 |
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
659 |
} |
660 |
|
661 |
public String |
662 |
getLSAddress() { return tfAddress.getText(); } |
663 |
|
664 |
public void |
665 |
setLSAddress(String address) { tfAddress.setText(address); } |
666 |
|
667 |
public String |
668 |
getLSPort() { return tfPort.getText(); } |
669 |
|
670 |
public void |
671 |
setLSPort(String port) { tfPort.setText(port); } |
672 |
} |