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