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

Last change on this file since 938 was 938, checked in by stoecker, 16 years ago

added patches from bug #682 (proxy settings) and #1519 (NMEA)

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