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

Last change on this file since 1180 was 1180, checked in by stoecker, 15 years ago

fixed bug #1871, removed all deprecations

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