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

Last change on this file since 298 was 298, checked in by imi, 17 years ago
  • added license description to head of each source file
File size: 3.9 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
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 ServerAccessPreference());
104 settings.add(new CsvPreference());
105 settings.add(new ProjectionPreference());
106 settings.add(new TaggingPresetPreference());
107 settings.add(new PluginPreference());
108 settings.add(Main.toolbar);
109
110 for (PluginProxy plugin : Main.plugins) {
111 PreferenceSetting p = plugin.getPreferenceSetting();
112 if (p != null)
113 settings.add(p);
114 }
115
116 // always the last: advanced tab
117 settings.add(new AdvancedPreference());
118 }
119}
Note: See TracBrowser for help on using the repository browser.