source: josm/src/org/openstreetmap/josm/gui/PreferenceDialog.java@ 150

Last change on this file since 150 was 150, checked in by imi, 18 years ago
  • fixed saving of plugins
File size: 22.8 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.Color;
6import java.awt.Component;
7import java.awt.Dimension;
8import java.awt.Font;
9import java.awt.GridBagLayout;
10import java.awt.event.ActionEvent;
11import java.awt.event.ActionListener;
12import java.io.File;
13import java.util.Arrays;
14import java.util.Collection;
15import java.util.HashMap;
16import java.util.HashSet;
17import java.util.Locale;
18import java.util.Map;
19import java.util.StringTokenizer;
20import java.util.TreeMap;
21import java.util.Vector;
22import java.util.Map.Entry;
23
24import javax.swing.AbstractAction;
25import javax.swing.BorderFactory;
26import javax.swing.Box;
27import javax.swing.DefaultListCellRenderer;
28import javax.swing.DefaultListModel;
29import javax.swing.JButton;
30import javax.swing.JCheckBox;
31import javax.swing.JColorChooser;
32import javax.swing.JComboBox;
33import javax.swing.JDialog;
34import javax.swing.JLabel;
35import javax.swing.JList;
36import javax.swing.JOptionPane;
37import javax.swing.JPanel;
38import javax.swing.JPasswordField;
39import javax.swing.JScrollPane;
40import javax.swing.JTabbedPane;
41import javax.swing.JTable;
42import javax.swing.JTextField;
43import javax.swing.ListCellRenderer;
44import javax.swing.ListSelectionModel;
45import javax.swing.UIManager;
46import javax.swing.UIManager.LookAndFeelInfo;
47import javax.swing.table.TableCellRenderer;
48
49import org.openstreetmap.josm.Main;
50import org.openstreetmap.josm.data.projection.Projection;
51import org.openstreetmap.josm.plugins.PluginProxy;
52import org.openstreetmap.josm.tools.ColorHelper;
53import org.openstreetmap.josm.tools.GBC;
54import org.openstreetmap.josm.tools.ImageProvider;
55import org.openstreetmap.josm.tools.UrlLabel;
56
57/**
58 * The preference settings.
59 *
60 * @author imi
61 */
62public class PreferenceDialog extends JDialog {
63
64 private final class RequireRestartAction implements ActionListener {
65 public void actionPerformed(ActionEvent e) {
66 requiresRestart = true;
67 }
68 }
69 private RequireRestartAction requireRestartAction = new RequireRestartAction();
70
71 /**
72 * Action to take place when user pressed the ok button.
73 */
74 class OkAction extends AbstractAction {
75 private static final String OKBUTTON_PROP = "OptionPane.okButtonText";
76
77 public OkAction() {
78 super(UIManager.getString(OKBUTTON_PROP), UIManager.getIcon("OptionPane.okIcon"));
79 try {
80 putValue(MNEMONIC_KEY, new Integer((String)UIManager.get("OptionPane.okButtonMnemonic")));
81 } catch (NumberFormatException e) {
82 // just don't set the mnemonic
83 }
84 }
85 public void actionPerformed(ActionEvent e) {
86 Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName());
87 Main.pref.put("language", languages.getSelectedItem().toString());
88 Main.pref.put("projection", projectionCombo.getSelectedItem().getClass().getName());
89 Main.pref.put("osm-server.url", osmDataServer.getText());
90 Main.pref.put("osm-server.username", osmDataUsername.getText());
91 String pwd = String.valueOf(osmDataPassword.getPassword());
92 if (pwd.equals(""))
93 pwd = null;
94 Main.pref.put("osm-server.password", pwd);
95 Main.pref.put("wms.baseurl", wmsServerBaseUrl.getText());
96 Main.pref.put("csv.importstring", csvImportString.getText());
97 Main.pref.put("draw.rawgps.lines", drawRawGpsLines.isSelected());
98 Main.pref.put("draw.rawgps.lines.force", forceRawGpsLines.isSelected());
99 Main.pref.put("draw.rawgps.large", largeGpsPoints.isSelected());
100 Main.pref.put("draw.segment.direction", directionHint.isSelected());
101
102 if (annotationSources.getModel().getSize() > 0) {
103 StringBuilder sb = new StringBuilder();
104 for (int i = 0; i < annotationSources.getModel().getSize(); ++i)
105 sb.append(";"+annotationSources.getModel().getElementAt(i));
106 Main.pref.put("annotation.sources", sb.toString().substring(1));
107 } else
108 Main.pref.put("annotation.sources", null);
109
110 String plugins = "";
111 for (Entry<String, Boolean> entry : pluginMap.entrySet())
112 if (entry.getValue())
113 plugins += entry.getKey() + ",";
114 if (plugins.endsWith(","))
115 plugins = plugins.substring(0, plugins.length()-1);
116 Main.pref.put("plugins", plugins);
117
118 for (int i = 0; i < colors.getRowCount(); ++i) {
119 String name = (String)colors.getValueAt(i, 0);
120 Color col = (Color)colors.getValueAt(i, 1);
121 Main.pref.put("color."+name, ColorHelper.color2html(col));
122 }
123
124 if (requiresRestart)
125 JOptionPane.showMessageDialog(PreferenceDialog.this,tr("You have to restart JOSM for some settings to take effect."));
126 Main.parent.repaint();
127 setVisible(false);
128 }
129 }
130
131 /**
132 * Action to take place when user pressed the cancel button.
133 */
134 class CancelAction extends AbstractAction {
135 private static final String CANCELBUTTON_PROP = "OptionPane.cancelButtonText";
136 public CancelAction() {
137 super(UIManager.getString(CANCELBUTTON_PROP),
138 UIManager.getIcon("OptionPane.cancelIcon"));
139 try {
140 putValue(MNEMONIC_KEY, new Integer((String)UIManager.get("OptionPane.cancelButtonMnemonic")));
141 } catch (NumberFormatException e) {
142 // just don't set the mnemonic
143 }
144 }
145 public void actionPerformed(ActionEvent e) {
146 setVisible(false);
147 }
148 }
149
150 /**
151 * Indicate, that the application has to be restarted for the settings to take effect.
152 */
153 private boolean requiresRestart = false;
154 /**
155 * ComboBox with all look and feels.
156 */
157 private JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
158 private JComboBox languages = new JComboBox(new Locale[]{
159 new Locale("en", "US"),
160 new Locale("en", "GB"),
161 Locale.GERMAN,
162 Locale.FRENCH,
163 new Locale("ro", "RO")});
164 /**
165 * The main tab panel.
166 */
167 private JTabbedPane tabPane = new JTabbedPane(JTabbedPane.LEFT);
168
169 /**
170 * Editfield for the Base url to the REST API from OSM.
171 */
172 private JTextField osmDataServer = new JTextField(20);
173 /**
174 * Editfield for the username to the OSM account.
175 */
176 private JTextField osmDataUsername = new JTextField(20);
177 /**
178 * Passwordfield for the userpassword of the REST API.
179 */
180 private JPasswordField osmDataPassword = new JPasswordField(20);
181 /**
182 * Base url of the WMS server. Holds everything except the bbox= argument.
183 */
184 private JTextField wmsServerBaseUrl = new JTextField(20);
185 /**
186 * Comma seperated import string specifier or <code>null</code> if the first
187 * data line should be interpreted as one.
188 */
189 private JTextField csvImportString = new JTextField(20);
190 /**
191 * The checkbox stating whether nodes should be merged together.
192 */
193 private JCheckBox drawRawGpsLines = new JCheckBox(tr("Draw lines between raw gps points."));
194 /**
195 * The checkbox stating whether raw gps lines should be forced.
196 */
197 private JCheckBox forceRawGpsLines = new JCheckBox(tr("Force lines if no segments imported."));
198 private JCheckBox largeGpsPoints = new JCheckBox(tr("Draw large GPS points."));
199 private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows"));
200 private JTable colors;
201
202 /**
203 * Combobox with all projections available
204 */
205 private JComboBox projectionCombo = new JComboBox(Projection.allProjections);
206 private JList annotationSources = new JList(new DefaultListModel());
207 private Map<String, Boolean> pluginMap = new HashMap<String, Boolean>();
208
209
210 /**
211 * Create a preference setting dialog from an preferences-file. If the file does not
212 * exist, it will be created.
213 * If the dialog is closed with Ok, the preferences will be stored to the preferences-
214 * file, otherwise no change of the file happens.
215 */
216 public PreferenceDialog() {
217 super(JOptionPane.getFrameForComponent(Main.parent), tr("Preferences"));
218
219 // look and feel combo box
220 String laf = Main.pref.get("laf");
221 for (int i = 0; i < lafCombo.getItemCount(); ++i) {
222 if (((LookAndFeelInfo)lafCombo.getItemAt(i)).getClassName().equals(laf)) {
223 lafCombo.setSelectedIndex(i);
224 break;
225 }
226 }
227 final ListCellRenderer oldRenderer = lafCombo.getRenderer();
228 lafCombo.setRenderer(new DefaultListCellRenderer(){
229 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
230 return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus);
231 }
232 });
233 lafCombo.addActionListener(requireRestartAction);
234
235 // language
236 String lang = Main.pref.get("language");
237 for (int i = 0; i < languages.getItemCount(); ++i) {
238 if (languages.getItemAt(i).toString().equals(lang)) {
239 languages.setSelectedIndex(i);
240 break;
241 }
242 }
243 languages.setRenderer(new DefaultListCellRenderer(){
244 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
245 return super.getListCellRendererComponent(list, ((Locale)value).getDisplayName(), index, isSelected, cellHasFocus);
246 }
247 });
248 languages.addActionListener(requireRestartAction);
249
250 // projection combo box
251 for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
252 if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection"))) {
253 projectionCombo.setSelectedIndex(i);
254 break;
255 }
256 }
257 projectionCombo.addActionListener(requireRestartAction);
258
259 drawRawGpsLines.addActionListener(new ActionListener(){
260 public void actionPerformed(ActionEvent e) {
261 if (!drawRawGpsLines.isSelected())
262 forceRawGpsLines.setSelected(false);
263 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
264 }
265 });
266
267 osmDataServer.setText(Main.pref.get("osm-server.url"));
268 osmDataUsername.setText(Main.pref.get("osm-server.username"));
269 osmDataPassword.setText(Main.pref.get("osm-server.password"));
270 wmsServerBaseUrl.setText(Main.pref.get("wms.baseurl", "http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&width=512&height=512&layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg&"));
271 csvImportString.setText(Main.pref.get("csv.importstring"));
272 drawRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines"));
273 forceRawGpsLines.setToolTipText(tr("Force drawing of lines if the imported data contain no line information."));
274 forceRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines.force"));
275 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
276 largeGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.large"));
277 largeGpsPoints.setToolTipText(tr("Draw larger dots for the GPS points."));
278 directionHint.setToolTipText(tr("Draw direction hints for all segments."));
279 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction"));
280
281 String annos = Main.pref.get("annotation.sources");
282 StringTokenizer st = new StringTokenizer(annos, ";");
283 while (st.hasMoreTokens())
284 ((DefaultListModel)annotationSources.getModel()).addElement(st.nextToken());
285
286 Box pluginPanel = Box.createVerticalBox();
287 Collection<String> availablePlugins = new HashSet<String>();
288 File[] pluginFiles = new File(Main.pref.getPreferencesDir()+"plugins").listFiles();
289 if (pluginFiles != null) {
290 for (File f : pluginFiles) {
291 if (!f.isFile() || !f.getName().endsWith(".jar"))
292 continue;
293 availablePlugins.add(f.getName().substring(0, f.getName().length()-4));
294 }
295 }
296 Collection<String> enabledPlugins = Arrays.asList(Main.pref.get("plugins").split(","));
297 for (final String plugin : availablePlugins) {
298 boolean enabled = enabledPlugins.contains(plugin);
299 String desc = null;
300 for (PluginProxy p : Main.plugins) {
301 if (p.name.equals(plugin)) {
302 desc = p.getDescription();
303 break;
304 }
305 }
306
307 final JCheckBox pluginCheck = new JCheckBox(plugin, enabled);
308 pluginPanel.add(pluginCheck);
309 if (desc != null) {
310 pluginCheck.setToolTipText(desc);
311 JLabel label = new JLabel("<html><i>"+desc+"</i></html>");
312 label.setBorder(BorderFactory.createEmptyBorder(0,20,0,0));
313 pluginPanel.add(label);
314 pluginPanel.add(Box.createVerticalStrut(5));
315 }
316 pluginMap.put(plugin, enabled);
317 pluginCheck.addActionListener(new ActionListener(){
318 public void actionPerformed(ActionEvent e) {
319 pluginMap.put(plugin, pluginCheck.isSelected());
320 requiresRestart = true;
321 }
322 });
323 }
324 JScrollPane pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
325 pluginPane.setBorder(null);
326
327 Map<String,String> allColors = new TreeMap<String, String>(Main.pref.getAllPrefix("color."));
328
329 Vector<Vector<Object>> rows = new Vector<Vector<Object>>();
330 for (Entry<String,String> e : allColors.entrySet()) {
331 Vector<Object> row = new Vector<Object>(2);
332 row.add(tr(e.getKey().substring("color.".length())));
333 row.add(ColorHelper.html2color(e.getValue()));
334 rows.add(row);
335 }
336 Vector<Object> cols = new Vector<Object>(2);
337 cols.add(tr("Color"));
338 cols.add(tr("Name"));
339 colors = new JTable(rows, cols){
340 @Override public boolean isCellEditable(int row, int column) {
341 return false;
342 }
343 };
344 colors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
345 final TableCellRenderer oldColorsRenderer = colors.getDefaultRenderer(Object.class);
346 colors.setDefaultRenderer(Object.class, new TableCellRenderer(){
347 public Component getTableCellRendererComponent(JTable t, Object o, boolean selected, boolean focus, int row, int column) {
348 if (column == 1) {
349 JLabel l = new JLabel(ColorHelper.color2html((Color)o));
350 l.setBackground((Color)o);
351 l.setOpaque(true);
352 return l;
353 }
354 return oldColorsRenderer.getTableCellRendererComponent(t,o,selected,focus,row,column);
355 }
356 });
357 colors.getColumnModel().getColumn(1).setWidth(100);
358
359 JButton colorEdit = new JButton(tr("Choose"));
360 colorEdit.addActionListener(new ActionListener(){
361 public void actionPerformed(ActionEvent e) {
362 if (colors.getSelectedRowCount() == 0) {
363 JOptionPane.showMessageDialog(PreferenceDialog.this, tr("Please select a color."));
364 return;
365 }
366 int sel = colors.getSelectedRow();
367 JColorChooser chooser = new JColorChooser((Color)colors.getValueAt(sel, 1));
368 int answer = JOptionPane.showConfirmDialog(PreferenceDialog.this, chooser, tr("Choose a color for {0}", colors.getValueAt(sel, 0)), JOptionPane.OK_CANCEL_OPTION);
369 if (answer == JOptionPane.OK_OPTION)
370 colors.setValueAt(chooser.getColor(), sel, 1);
371 }
372 });
373
374 // Annotation source panels
375 JButton addAnno = new JButton(tr("Add"));
376 addAnno.addActionListener(new ActionListener(){
377 public void actionPerformed(ActionEvent e) {
378 String source = JOptionPane.showInputDialog(Main.parent, tr("Annotation preset source"));
379 if (source == null)
380 return;
381 ((DefaultListModel)annotationSources.getModel()).addElement(source);
382 requiresRestart = true;
383 }
384 });
385
386 JButton editAnno = new JButton(tr("Edit"));
387 editAnno.addActionListener(new ActionListener(){
388 public void actionPerformed(ActionEvent e) {
389 if (annotationSources.getSelectedIndex() == -1)
390 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit."));
391 else {
392 String source = JOptionPane.showInputDialog(Main.parent, tr("Annotation preset source"), annotationSources.getSelectedValue());
393 if (source == null)
394 return;
395 ((DefaultListModel)annotationSources.getModel()).setElementAt(source, annotationSources.getSelectedIndex());
396 requiresRestart = true;
397 }
398 }
399 });
400
401 JButton deleteAnno = new JButton(tr("Delete"));
402 deleteAnno.addActionListener(new ActionListener(){
403 public void actionPerformed(ActionEvent e) {
404 if (annotationSources.getSelectedIndex() == -1)
405 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete."));
406 else {
407 ((DefaultListModel)annotationSources.getModel()).remove(annotationSources.getSelectedIndex());
408 requiresRestart = true;
409 }
410 }
411 });
412 annotationSources.setVisibleRowCount(3);
413
414
415
416 // setting tooltips
417 osmDataServer.setToolTipText(tr("The base URL to the OSM server (REST API)"));
418 osmDataUsername.setToolTipText(tr("Login name (email) to the OSM account."));
419 osmDataPassword.setToolTipText(tr("Login password to the OSM account. Leave blank to not store any password."));
420 wmsServerBaseUrl.setToolTipText(tr("The base URL to the server retrieving WMS background pictures from."));
421 csvImportString.setToolTipText(tr("<html>Import string specification. lat/lon and time are imported.<br>" +
422 "<b>lat</b>: The latitude coordinate<br>" +
423 "<b>lon</b>: The longitude coordinate<br>" +
424 "<b>time</b>: The measured time as string<br>" +
425 "<b>ignore</b>: Skip this field<br>" +
426 "An example: \"ignore ignore lat lon\" will use ' ' as delimiter, skip the first two values and read then lat/lon.<br>" +
427 "Other example: \"lat,lon\" will just read lat/lon values comma seperated.</html>"));
428 drawRawGpsLines.setToolTipText(tr("If your gps device draw to few lines, select this to draw lines along your way."));
429 colors.setToolTipText(tr("Colors used by different objects in JOSM."));
430 annotationSources.setToolTipText(tr("The sources (url or filename) of annotation preset definition files. See http://josm.eigenheimstrasse.de/wiki/AnnotationPresets for help."));
431 addAnno.setToolTipText(tr("Add a new annotation preset source to the list."));
432 deleteAnno.setToolTipText(tr("Delete the selected source from the list."));
433
434 // creating the gui
435
436 // Display tab
437 JPanel display = createPreferenceTab("display", tr("Display Settings"), tr("Various settings that influence the visual representation of the whole program."));
438 display.add(new JLabel(tr("Look and Feel")), GBC.std());
439 display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
440 display.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL));
441 display.add(new JLabel(tr("Language")), GBC.std());
442 display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
443 display.add(languages, GBC.eol().fill(GBC.HORIZONTAL));
444 display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0));
445 display.add(forceRawGpsLines, GBC.eop().insets(40,0,0,0));
446 display.add(largeGpsPoints, GBC.eop().insets(20,0,0,0));
447 display.add(directionHint, GBC.eop().insets(20,0,0,0));
448 display.add(new JLabel(tr("Colors")), GBC.eol());
449 colors.setPreferredScrollableViewportSize(new Dimension(100,112));
450 display.add(new JScrollPane(colors), GBC.eol().fill(GBC.BOTH));
451 display.add(colorEdit, GBC.eol().anchor(GBC.EAST));
452 //display.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
453
454 // Connection tab
455 JPanel con = createPreferenceTab("connection", tr("Connection Settings"), tr("Connection Settings to the OSM server."));
456 con.add(new JLabel(tr("Base Server URL")), GBC.std());
457 con.add(osmDataServer, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
458 con.add(new JLabel(tr("OSM username (email)")), GBC.std());
459 con.add(osmDataUsername, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
460 con.add(new JLabel(tr("OSM password")), GBC.std());
461 con.add(osmDataPassword, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,0));
462 JLabel warning = new JLabel(tr("<html>" +
463 "WARNING: The password is stored in plain text in the preferences file.<br>" +
464 "The password is transfered in plain text to the server, encoded in the url.<br>" +
465 "<b>Do not use a valuable Password.</b></html>"));
466 warning.setFont(warning.getFont().deriveFont(Font.ITALIC));
467 con.add(warning, GBC.eop().fill(GBC.HORIZONTAL));
468 //con.add(new JLabel("WMS server base url (everything except bbox-parameter)"), GBC.eol());
469 //con.add(wmsServerBaseUrl, GBC.eop().fill(GBC.HORIZONTAL));
470 //con.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
471 con.add(new JLabel(tr("CSV import specification (empty: read from first line in data)")), GBC.eol());
472 con.add(csvImportString, GBC.eop().fill(GBC.HORIZONTAL));
473 con.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
474
475 // Map tab
476 JPanel map = createPreferenceTab("map", tr("Map Settings"), tr("Settings for the map projection and data interpretation."));
477 map.add(new JLabel(tr("Projection method")), GBC.std());
478 map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
479 map.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,0,0,5));
480 map.add(new JLabel(tr("Annotation preset sources")), GBC.eol().insets(0,5,0,0));
481 map.add(new JScrollPane(annotationSources), GBC.eol().fill(GBC.BOTH));
482 map.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
483 map.add(addAnno, GBC.std());
484 map.add(editAnno, GBC.std().insets(5,0,5,0));
485 map.add(deleteAnno, GBC.std());
486
487 // I HATE SWING!
488 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
489 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
490 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
491 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
492 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
493
494
495 // Plugin tab
496 JPanel plugin = createPreferenceTab("plugin", tr("Plugins"), tr("Configure available Plugins."));
497 plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH));
498 plugin.add(GBC.glue(0,10), GBC.eol());
499 plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", "Get more plugins"), GBC.std().fill(GBC.HORIZONTAL));
500
501 tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
502
503 // OK/Cancel panel at bottom
504 JPanel okPanel = new JPanel(new GridBagLayout());
505 okPanel.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
506 okPanel.add(new JButton(new OkAction()), GBC.std());
507 okPanel.add(new JButton(new CancelAction()), GBC.std());
508 okPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
509
510 // merging all in the content pane
511 getContentPane().setLayout(new GridBagLayout());
512 getContentPane().add(tabPane, GBC.eol().fill());
513 getContentPane().add(okPanel, GBC.eol().fill(GBC.HORIZONTAL));
514
515 setModal(true);
516 pack();
517 setLocationRelativeTo(Main.parent);
518 }
519
520 /**
521 * Construct a JPanel for the preference settings. Layout is GridBagLayout
522 * and a centered title label and the description are added.
523 * @param icon The name of the icon.
524 * @param title The title of this preference tab.
525 * @param desc A description in one sentence for this tab. Will be displayed
526 * italic under the title.
527 * @return The created panel ready to add other controls.
528 */
529 private JPanel createPreferenceTab(String icon, String title, String desc) {
530 JPanel p = new JPanel(new GridBagLayout());
531 p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
532 p.add(new JLabel(title), GBC.eol().anchor(GBC.CENTER).insets(0,5,0,10));
533
534 JLabel descLabel = new JLabel("<html>"+desc+"</html>");
535 descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
536 p.add(descLabel, GBC.eol().insets(5,0,5,20).fill(GBC.HORIZONTAL));
537
538 tabPane.addTab(null, ImageProvider.get("preferences", icon), p);
539 tabPane.setToolTipTextAt(tabPane.getTabCount()-1, desc);
540 return p;
541 }
542}
Note: See TracBrowser for help on using the repository browser.