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

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

fix bug #1645 (preferences dialog size) Patch by Jan Peter Stotz

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