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

Last change on this file since 1415 was 1415, checked in by stoecker, 17 years ago

applied patch #2185 by bruce89

  • Property svn:eol-style set to native
File size: 5.7 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.ScrollPane;
9import java.util.Collection;
10import java.util.Iterator;
11import java.util.LinkedList;
12
13import javax.swing.BorderFactory;
14import javax.swing.JComponent;
15import javax.swing.JLabel;
16import javax.swing.JOptionPane;
17import javax.swing.JPanel;
18import javax.swing.JScrollPane;
19import javax.swing.JTabbedPane;
20
21import org.openstreetmap.josm.Main;
22import org.openstreetmap.josm.plugins.PluginHandler;
23import org.openstreetmap.josm.tools.BugReportExceptionHandler;
24import org.openstreetmap.josm.tools.GBC;
25import org.openstreetmap.josm.tools.I18n;
26import org.openstreetmap.josm.tools.ImageProvider;
27
28/**
29 * The preference settings.
30 *
31 * @author imi
32 */
33public class PreferenceDialog extends JTabbedPane {
34
35 public final static Collection<PreferenceSetting> settings = new LinkedList<PreferenceSetting>();
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 for 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 public final JPanel audio = createPreferenceTab("audio", I18n.tr("Audio Settings"), I18n.tr("Settings for the audio player and audio markers."));
42
43 public final javax.swing.JTabbedPane displaycontent = new javax.swing.JTabbedPane();
44
45 /**
46 * Construct a JPanel for the preference settings. Layout is GridBagLayout
47 * and a centered title label and the description are added. The panel
48 * will be shown inside a {@link ScrollPane}
49 * @param icon The name of the icon.
50 * @param title The title of this preference tab.
51 * @param desc A description in one sentence for this tab. Will be displayed
52 * italic under the title.
53 * @return The created panel ready to add other controls.
54 */
55 public JPanel createPreferenceTab(String icon, String title, String desc) {
56 return createPreferenceTab(icon, title, desc, false);
57 }
58
59 /**
60 * Construct a JPanel for the preference settings. Layout is GridBagLayout
61 * and a centered title label and the description are added.
62 * @param icon The name of the icon.
63 * @param title The title of this preference tab.
64 * @param desc A description in one sentence for this tab. Will be displayed
65 * italic under the title.
66 * @param inScrollPane if <code>true</code> the added tab will show scroll bars
67 * if the panel content is larger than the available space
68 * @return The created panel ready to add other controls.
69 */
70 public JPanel createPreferenceTab(String icon, String title, String desc, boolean inScrollPane) {
71 JPanel p = new JPanel(new GridBagLayout());
72 p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
73 p.add(new JLabel(title), GBC.eol().anchor(GBC.CENTER).insets(0,5,0,10));
74
75 JLabel descLabel = new JLabel("<html>"+desc+"</html>");
76 descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
77 p.add(descLabel, GBC.eol().insets(5,0,5,20).fill(GBC.HORIZONTAL));
78
79 JComponent tab = p;
80 if (inScrollPane) {
81 JScrollPane sp = new JScrollPane(p);
82 tab = sp;
83 }
84 addTab(null, ImageProvider.get("preferences", icon), tab);
85 setToolTipTextAt(getTabCount()-1, "<html>"+desc+"</html>");
86 return p;
87 }
88
89 public void ok() {
90 boolean requiresRestart = false;
91 for (PreferenceSetting setting : settings)
92 {
93 if(setting.ok())
94 requiresRestart = true;
95 }
96 if (requiresRestart)
97 JOptionPane.showMessageDialog(Main.parent,tr("You have to restart JOSM for some settings to take effect."));
98 Main.parent.repaint();
99 }
100
101 /**
102 * If the dialog is closed with Ok, the preferences will be stored to the preferences-
103 * file, otherwise no change of the file happens.
104 */
105 public PreferenceDialog() {
106 super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
107 display.add(displaycontent, GBC.eol().fill(GBC.BOTH));
108 for (Iterator<PreferenceSetting> it = settings.iterator(); it.hasNext();) {
109 try {
110 it.next().addGui(this);
111 } catch (SecurityException e) {
112 it.remove();
113 } catch (Throwable e) {
114 /* allow to change most settings even if e.g. a plugin fails */
115 BugReportExceptionHandler.handleException(e);
116 }
117 }
118 }
119
120 static {
121 // order is important!
122 settings.add(new DrawingPreference());
123 settings.add(new ColorPreference());
124 settings.add(new LafPreference());
125 settings.add(new LanguagePreference());
126 settings.add(new MapPaintPreference());
127 settings.add(new ServerAccessPreference());
128 settings.add(new FilePreferences());
129 settings.add(new ProxyPreferences());
130 settings.add(new ProjectionPreference());
131 settings.add(new TaggingPresetPreference());
132 settings.add(new PluginPreference());
133 settings.add(Main.toolbar);
134 settings.add(new AudioPreference());
135 settings.add(new ShortcutPreference());
136
137 PluginHandler.getPreferenceSetting(settings);
138
139 // always the last: advanced tab
140 settings.add(new AdvancedPreference());
141 }
142}
Note: See TracBrowser for help on using the repository browser.