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

Last change on this file since 177 was 177, checked in by imi, 17 years ago
  • fixed NPE when open the annotation preset plugin with an invalid annotation preset
File size: 4.0 KB
Line 
1package org.openstreetmap.josm.gui.preferences;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.Font;
6import java.awt.GridBagLayout;
7import java.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
9import java.util.Collection;
10import java.util.Iterator;
11import java.util.LinkedList;
12
13import javax.swing.BorderFactory;
14import javax.swing.JLabel;
15import javax.swing.JOptionPane;
16import javax.swing.JPanel;
17import javax.swing.JTabbedPane;
18
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.plugins.PluginProxy;
21import org.openstreetmap.josm.tools.GBC;
22import org.openstreetmap.josm.tools.I18n;
23import org.openstreetmap.josm.tools.ImageProvider;
24
25/**
26 * The preference settings.
27 *
28 * @author imi
29 */
30public class PreferenceDialog extends JTabbedPane {
31
32 public final static Collection<PreferenceSetting> settings = new LinkedList<PreferenceSetting>();
33
34 public boolean requiresRestart = false;
35 public final RequireRestartAction requireRestartAction = new RequireRestartAction();
36
37 // some common tabs
38 public final JPanel display = createPreferenceTab("display", tr("Display Settings"), tr("Various settings that influence the visual representation of the whole program."));
39 public final JPanel connection = createPreferenceTab("connection", I18n.tr("Connection Settings"), I18n.tr("Connection Settings to the OSM server."));
40 public final JPanel map = createPreferenceTab("map", I18n.tr("Map Settings"), I18n.tr("Settings for the map projection and data interpretation."));
41
42 /**
43 * Construct a JPanel for the preference settings. Layout is GridBagLayout
44 * and a centered title label and the description are added.
45 * @param icon The name of the icon.
46 * @param title The title of this preference tab.
47 * @param desc A description in one sentence for this tab. Will be displayed
48 * italic under the title.
49 * @return The created panel ready to add other controls.
50 */
51 public JPanel createPreferenceTab(String icon, String title, String desc) {
52 JPanel p = new JPanel(new GridBagLayout());
53 p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
54 p.add(new JLabel(title), GBC.eol().anchor(GBC.CENTER).insets(0,5,0,10));
55
56 JLabel descLabel = new JLabel("<html>"+desc+"</html>");
57 descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
58 p.add(descLabel, GBC.eol().insets(5,0,5,20).fill(GBC.HORIZONTAL));
59
60 addTab(null, ImageProvider.get("preferences", icon), p);
61 setToolTipTextAt(getTabCount()-1, desc);
62 return p;
63 }
64
65
66
67
68 private final class RequireRestartAction implements ActionListener {
69 public void actionPerformed(ActionEvent e) {
70 requiresRestart = true;
71 }
72 }
73
74 public void ok() {
75 for (PreferenceSetting setting : settings)
76 setting.ok();
77 if (requiresRestart)
78 JOptionPane.showMessageDialog(PreferenceDialog.this,tr("You have to restart JOSM for some settings to take effect."));
79 Main.parent.repaint();
80 }
81
82 /**
83 * If the dialog is closed with Ok, the preferences will be stored to the preferences-
84 * file, otherwise no change of the file happens.
85 */
86 public PreferenceDialog() {
87 super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
88 for (Iterator<PreferenceSetting> it = settings.iterator(); it.hasNext();) {
89 try {
90 it.next().addGui(this);
91 } catch (SecurityException e) {
92 it.remove();
93 }
94 }
95 }
96
97 static {
98 // order is important!
99 settings.add(new LafPreference());
100 settings.add(new DrawingPreference());
101 settings.add(new ColorPreference());
102 settings.add(new ServerAccessPreference());
103 settings.add(new CsvPreference());
104 settings.add(new ProjectionPreference());
105 settings.add(new AnnotationPresetPreference());
106 settings.add(new PluginPreference());
107 settings.add(Main.toolbar);
108
109 for (PluginProxy plugin : Main.plugins) {
110 PreferenceSetting p = plugin.getPreferenceSetting();
111 if (p != null)
112 settings.add(p);
113 }
114
115 // always the last: advanced tab
116 settings.add(new AdvancedPreference());
117 }
118}
Note: See TracBrowser for help on using the repository browser.