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