Changeset 2745 in josm for trunk


Ignore:
Timestamp:
2010-01-06T20:34:54+01:00 (10 years ago)
Author:
Gubaer
Message:

Partial commit due to #4137. Comment to follow in another commit.

Location:
trunk/src/org/openstreetmap/josm/gui/preferences
Files:
10 added
2 deleted
15 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/AdvancedPreference.java

    r2512 r2745  
    4646    protected JTextField txtFilter;
    4747
    48     public void addGui(final PreferenceDialog gui) {
     48    public void addGui(final PreferenceTabbedPane gui) {
    4949        JPanel p = gui.createPreferenceTab("advanced", tr("Advanced Preferences"),
    5050                tr("Setting Preference entries directly. Use with caution!"), false);
     
    215215    }
    216216
    217     private void editPreference(final PreferenceDialog gui, final JTable list) {
     217    private void editPreference(final PreferenceTabbedPane gui, final JTable list) {
    218218        if (list.getSelectedRowCount() != 1) {
    219219            JOptionPane.showMessageDialog(
     
    240240    }
    241241
    242     private void removePreference(final PreferenceDialog gui, final JTable list) {
     242    private void removePreference(final PreferenceTabbedPane gui, final JTable list) {
    243243        if (list.getSelectedRowCount() == 0) {
    244244            JOptionPane.showMessageDialog(
     
    256256    }
    257257
    258     private void addPreference(final PreferenceDialog gui) {
     258    private void addPreference(final PreferenceTabbedPane gui) {
    259259        JPanel p = new JPanel(new GridBagLayout());
    260260        p.add(new JLabel(tr("Key")), GBC.std().insets(0,0,5,0));
  • trunk/src/org/openstreetmap/josm/gui/preferences/AudioPreference.java

    r1742 r2745  
    4848    private JTextField audioCalibration = new JTextField(8);
    4949
    50     public void addGui(PreferenceDialog gui) {
     50    public void addGui(PreferenceTabbedPane gui) {
    5151        // audioMenuVisible
    5252        audioMenuVisible.setSelected(! Main.pref.getBoolean("audio.menuinvisible"));
  • trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java

    r2675 r2745  
    146146    }
    147147
    148     public void addGui(final PreferenceDialog gui) {
     148    public void addGui(final PreferenceTabbedPane gui) {
    149149        fixColorPrefixes();
    150150        setColorModel(Main.pref.getAllColors());
  • trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    r2105 r2745  
    6060    private JCheckBox useAntialiasing = new JCheckBox(tr("Smooth map graphics (antialiasing)"));
    6161
    62     public void addGui(PreferenceDialog gui) {
     62    public void addGui(PreferenceTabbedPane gui) {
    6363        gui.display.setPreferredSize(new Dimension(400,600));
    6464        JPanel panel = new JPanel(new GridBagLayout());
  • trunk/src/org/openstreetmap/josm/gui/preferences/LafPreference.java

    r2428 r2745  
    4242    private JCheckBox modeless = new JCheckBox(tr("Modeless working (Potlatch style)"));
    4343
    44     public void addGui(PreferenceDialog gui) {
     44    public void addGui(PreferenceTabbedPane gui) {
    4545        lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
    4646
  • trunk/src/org/openstreetmap/josm/gui/preferences/LanguagePreference.java

    r2711 r2745  
    4848    private boolean translationsLoaded = false;
    4949
    50     public void addGui(final PreferenceDialog gui) {
     50    public void addGui(final PreferenceTabbedPane gui) {
    5151        model = new LanguageComboBoxModel();
    5252        langCombo = new JComboBox(model);
  • trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java

    r2400 r2745  
    3232    }
    3333
    34     public void addGui(final PreferenceDialog gui) {
     34    public void addGui(final PreferenceTabbedPane gui) {
    3535        enableDefault = new JCheckBox(tr("Enable built-in defaults"),
    3636                Main.pref.getBoolean("mappaint.style.enable-defaults", true));
  • trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r2152 r2745  
    4040    private JPanel plugin;
    4141    private JPanel pluginPanel = new NoHorizontalScrollPanel(new GridBagLayout());
    42     private PreferenceDialog gui;
     42    private PreferenceTabbedPane gui;
    4343    private JScrollPane pluginPane;
    4444    private PluginSelection selection = new PluginSelection();
    4545    private JTextField txtFilter;
    4646
    47     public void addGui(final PreferenceDialog gui) {
     47    public void addGui(final PreferenceTabbedPane gui) {
    4848        this.gui = gui;
    4949        plugin = gui.createPreferenceTab("plugin", tr("Plugins"), tr("Configure available plugins."), false);
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r2641 r2745  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.preferences;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.Font;
    7 import java.awt.GridBagLayout;
    8 import java.awt.ScrollPane;
    9 import java.awt.event.MouseWheelEvent;
    10 import java.awt.event.MouseWheelListener;
    11 import java.util.ArrayList;
    12 import java.util.Collection;
    13 import java.util.Iterator;
    14 import java.util.LinkedList;
    15 import java.util.List;
    16 import java.util.logging.Logger;
     6import java.awt.BorderLayout;
     7import java.awt.Component;
     8import java.awt.Container;
     9import java.awt.Dimension;
     10import java.awt.FlowLayout;
     11import java.awt.event.ActionEvent;
     12import java.awt.event.KeyEvent;
     13import java.awt.event.WindowAdapter;
     14import java.awt.event.WindowEvent;
    1715
     16import javax.swing.AbstractAction;
    1817import javax.swing.BorderFactory;
    1918import javax.swing.JComponent;
    20 import javax.swing.JLabel;
     19import javax.swing.JDialog;
    2120import javax.swing.JOptionPane;
    2221import javax.swing.JPanel;
    23 import javax.swing.JScrollPane;
    24 import javax.swing.JTabbedPane;
     22import javax.swing.KeyStroke;
    2523
    26 import org.openstreetmap.josm.Main;
    27 import org.openstreetmap.josm.plugins.PluginHandler;
    28 import org.openstreetmap.josm.tools.BugReportExceptionHandler;
    29 import org.openstreetmap.josm.tools.GBC;
    30 import org.openstreetmap.josm.tools.I18n;
     24import org.openstreetmap.josm.gui.SideButton;
     25import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
     26import org.openstreetmap.josm.gui.help.HelpUtil;
    3127import org.openstreetmap.josm.tools.ImageProvider;
     28import org.openstreetmap.josm.tools.WindowGeometry;
    3229
    33 /**
    34  * The preference settings.
    35  *
    36  * @author imi
    37  */
    38 public class PreferenceDialog extends JTabbedPane implements MouseWheelListener {
    39     static private final Logger logger = Logger.getLogger(PreferenceDialog.class.getName());
     30public class PreferenceDialog extends JDialog {
    4031
    41     private final static Collection<PreferenceSettingFactory> settingsFactory = new LinkedList<PreferenceSettingFactory>();
    42     private final List<PreferenceSetting> settings = new ArrayList<PreferenceSetting>();
     32    private PreferenceTabbedPane tpPreferences;
     33    private boolean canceled;
    4334
    44     // some common tabs
    45     public final JPanel display = createPreferenceTab("display", tr("Display Settings"), tr("Various settings that influence the visual representation of the whole program."));
    46     public final JPanel connection = createPreferenceTab("connection", I18n.tr("Connection Settings"), I18n.tr("Connection Settings for the OSM server."),false);
    47     public final JPanel map = createPreferenceTab("map", I18n.tr("Map Settings"), I18n.tr("Settings for the map projection and data interpretation."));
    48     public final JPanel audio = createPreferenceTab("audio", I18n.tr("Audio Settings"), I18n.tr("Settings for the audio player and audio markers."));
    49 
    50     public final javax.swing.JTabbedPane displaycontent = new javax.swing.JTabbedPane();
    51     public final javax.swing.JTabbedPane mapcontent = new javax.swing.JTabbedPane();
    52 
    53     /**
    54      * Construct a JPanel for the preference settings. Layout is GridBagLayout
    55      * and a centered title label and the description are added. The panel
    56      * will be shown inside a {@link ScrollPane}
    57      * @param icon The name of the icon.
    58      * @param title The title of this preference tab.
    59      * @param desc A description in one sentence for this tab. Will be displayed
    60      *      italic under the title.
    61      * @return The created panel ready to add other controls.
    62      */
    63     public JPanel createPreferenceTab(String icon, String title, String desc) {
    64         return createPreferenceTab(icon, title, desc, false);
     35    protected JPanel buildActionPanel() {
     36        JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));
     37        pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     38        pnl.add(new SideButton(new OKAction()));
     39        pnl.add(new SideButton(new CancelAction()));
     40        pnl.add(new SideButton(new ContextSensitiveHelpAction(HelpUtil.ht("/Action/Preferences"))));
     41        return pnl;
    6542    }
    6643
    67     /**
    68      * Construct a JPanel for the preference settings. Layout is GridBagLayout
    69      * and a centered title label and the description are added.
    70      * @param icon The name of the icon.
    71      * @param title The title of this preference tab.
    72      * @param desc A description in one sentence for this tab. Will be displayed
    73      *      italic under the title.
    74      * @param inScrollPane if <code>true</code> the added tab will show scroll bars
    75      *        if the panel content is larger than the available space
    76      * @return The created panel ready to add other controls.
    77      */
    78     public JPanel createPreferenceTab(String icon, String title, String desc, boolean inScrollPane) {
    79         JPanel p = new JPanel(new GridBagLayout());
    80         p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    81         p.add(new JLabel(title), GBC.eol().anchor(GBC.CENTER).insets(0,5,0,10));
     44    protected void build() {
     45        Container c = getContentPane();
     46        c.setLayout(new BorderLayout());
     47        c.add(tpPreferences = new PreferenceTabbedPane(), BorderLayout.CENTER);
     48        tpPreferences.buildGui();
     49        tpPreferences.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     50        c.add(buildActionPanel(), BorderLayout.SOUTH);
    8251
    83         JLabel descLabel = new JLabel("<html>"+desc+"</html>");
    84         descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
    85         p.add(descLabel, GBC.eol().insets(5,0,5,20).fill(GBC.HORIZONTAL));
     52        addWindowListener(new WindowEventHandler());
    8653
    87         JComponent tab = p;
    88         if (inScrollPane) {
    89             JScrollPane sp = new JScrollPane(p);
    90             tab = sp;
    91         }
    92         addTab(null, ImageProvider.get("preferences", icon), tab);
    93         setToolTipTextAt(getTabCount()-1, "<html>"+desc+"</html>");
    94         return p;
     54        getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
     55        getRootPane().getActionMap().put("cancel", new CancelAction());
     56        HelpUtil.setHelpContext(getRootPane(), HelpUtil.ht("/Action/Preferences"));
    9557    }
    9658
    97     public void ok() {
    98         boolean requiresRestart = false;
    99         for (PreferenceSetting setting : settings)
    100         {
    101             if(setting.ok()) {
    102                 requiresRestart = true;
    103             }
    104         }
    105         if (requiresRestart) {
    106             JOptionPane.showMessageDialog(
    107                     Main.parent,
    108                     tr("You have to restart JOSM for some settings to take effect."),
    109                     tr("Warning"),
    110                     JOptionPane.WARNING_MESSAGE
    111             );
    112         }
    113         Main.parent.repaint();
     59    public PreferenceDialog(Component parent) {
     60        super(JOptionPane.getFrameForComponent(parent), tr("Preferences"), true /* modal */);
     61        build();
    11462    }
    11563
    116     /**
    117      * If the dialog is closed with Ok, the preferences will be stored to the preferences-
    118      * file, otherwise no change of the file happens.
    119      */
    120     public PreferenceDialog() {
    121         super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
     64    public boolean isCanceled() {
     65        return canceled;
     66    }
    12267
    123         super.addMouseWheelListener(this);
     68    protected void setCanceled(boolean canceled) {
     69        this.canceled = canceled;
     70    }
    12471
    125         for (PreferenceSettingFactory factory:settingsFactory) {
    126             // logger.info("creating settings: " + factory);
    127             PreferenceSetting setting = factory.createPreferenceSetting();
    128             if (setting != null) {
    129                 settings.add(factory.createPreferenceSetting());
    130             }
     72    @Override
     73    public void setVisible(boolean visible) {
     74        if (visible) {
     75            new WindowGeometry(
     76                    getClass().getName() + ".geometry",
     77                    WindowGeometry.centerInWindow(
     78                            getParent(),
     79                            new Dimension(600,800)
     80                    )
     81            ).apply(this);
     82        } else if (!visible && isShowing()){
     83            new WindowGeometry(this).remember(getClass().getName() + ".geometry");
     84        }
     85        super.setVisible(visible);
     86    }
     87
     88    class CancelAction extends AbstractAction {
     89        public CancelAction() {
     90            putValue(NAME, tr("Cancel"));
     91            putValue(SMALL_ICON, ImageProvider.get("cancel"));
     92            putValue(SHORT_DESCRIPTION, tr("Close the prefereces dialog and discard preference updates"));
    13193        }
    13294
    133         display.add(displaycontent, GBC.eol().fill(GBC.BOTH));
    134         map.add(mapcontent, GBC.eol().fill(GBC.BOTH));
    135         for (Iterator<PreferenceSetting> it = settings.iterator(); it.hasNext();) {
    136             try {
    137                 PreferenceSetting settings = it.next();
    138                 //logger.info("adding gui: " + settings);
    139                 settings.addGui(this);
    140             } catch (SecurityException e) {
    141                 it.remove();
    142             } catch (Throwable e) {
    143                 /* allow to change most settings even if e.g. a plugin fails */
    144                 BugReportExceptionHandler.handleException(e);
    145             }
     95        public void cancel() {
     96            setCanceled(true);
     97            setVisible(false);
     98        }
     99
     100        public void actionPerformed(ActionEvent evt) {
     101            cancel();
    146102        }
    147103    }
    148104
    149     public List<PreferenceSetting> getSettings() {
    150         return settings;
     105    class OKAction extends AbstractAction {
     106        public OKAction() {
     107            putValue(NAME, tr("OK"));
     108            putValue(SMALL_ICON, ImageProvider.get("ok"));
     109            putValue(SHORT_DESCRIPTION, tr("Save the preferences and close the dialog"));
     110        }
     111
     112        public void actionPerformed(ActionEvent evt) {
     113            tpPreferences.savePreferences();
     114            setCanceled(false);
     115            setVisible(false);
     116        }
    151117    }
    152118
    153     @SuppressWarnings("unchecked")
    154     public <T>  T getSetting(Class<? extends T> clazz) {
    155         for (PreferenceSetting setting:settings) {
    156             if (clazz.isAssignableFrom(setting.getClass()))
    157                 return (T)setting;
     119    class WindowEventHandler extends WindowAdapter {
     120        @Override
     121        public void windowClosing(WindowEvent arg0) {
     122            new CancelAction().cancel();
    158123        }
    159         return null;
    160     }
    161 
    162     static {
    163         // order is important!
    164         settingsFactory.add(new DrawingPreference.Factory());
    165         settingsFactory.add(new ColorPreference.Factory());
    166         settingsFactory.add(new LafPreference.Factory());
    167         settingsFactory.add(new LanguagePreference.Factory());
    168         settingsFactory.add(new ServerAccessPreference.Factory());
    169         settingsFactory.add(new FilePreferences.Factory());
    170         settingsFactory.add(new ProxyPreferences.Factory());
    171         settingsFactory.add(new ProjectionPreference.Factory());
    172         settingsFactory.add(new MapPaintPreference.Factory());
    173         settingsFactory.add(new TaggingPresetPreference.Factory());
    174         settingsFactory.add(new PluginPreference.Factory());
    175         settingsFactory.add(Main.toolbar);
    176         settingsFactory.add(new AudioPreference.Factory());
    177         settingsFactory.add(new ShortcutPreference.Factory());
    178 
    179         PluginHandler.getPreferenceSetting(settingsFactory);
    180 
    181         // always the last: advanced tab
    182         settingsFactory.add(new AdvancedPreference.Factory());
    183     }
    184 
    185     /**
    186      * This mouse wheel listener reacts when a scroll is carried out over the
    187      * tab strip and scrolls one tab/down or up, selecting it immediately.
    188      */
    189     public void mouseWheelMoved(MouseWheelEvent wev) {
    190         // Ensure the cursor is over the tab strip
    191         if(super.indexAtLocation(wev.getPoint().x, wev.getPoint().y) < 0)
    192             return;
    193 
    194         // Get currently selected tab
    195         int newTab = super.getSelectedIndex() + wev.getWheelRotation();
    196 
    197         // Ensure the new tab index is sound
    198         newTab = newTab < 0 ? 0 : newTab;
    199         newTab = newTab >= super.getTabCount() ? super.getTabCount() - 1 : newTab;
    200 
    201         // select new tab
    202         super.setSelectedIndex(newTab);
    203124    }
    204125}
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceSetting.java

    r2512 r2745  
    77     * the current preferences.
    88     */
    9     void addGui(PreferenceDialog gui);
     9    void addGui(PreferenceTabbedPane gui);
    1010
    1111    /**
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r2741 r2745  
    3636 * @author imi
    3737 */
    38 public class PreferenceDialog extends JTabbedPane implements MouseWheelListener {
    39     static private final Logger logger = Logger.getLogger(PreferenceDialog.class.getName());
     38public class PreferenceTabbedPane extends JTabbedPane implements MouseWheelListener {
     39    static private final Logger logger = Logger.getLogger(PreferenceTabbedPane.class.getName());
    4040
    4141    private final static Collection<PreferenceSettingFactory> settingsFactory = new LinkedList<PreferenceSettingFactory>();
     
    7979        JPanel p = new JPanel(new GridBagLayout());
    8080        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    81         p.add(new JLabel(title), GBC.eol().anchor(GBC.CENTER).insets(0,5,0,10));
     81        p.add(new JLabel(title), GBC.eol().insets(0,5,0,10).anchor(GBC.NORTHWEST));
    8282
    8383        JLabel descLabel = new JLabel("<html>"+desc+"</html>");
     
    9595    }
    9696
    97     public void ok() {
     97    public void savePreferences() {
    9898        boolean requiresRestart = false;
    9999        for (PreferenceSetting setting : settings)
     
    118118     * file, otherwise no change of the file happens.
    119119     */
    120     public PreferenceDialog() {
     120    public PreferenceTabbedPane() {
    121121        super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
    122 
    123122        super.addMouseWheelListener(this);
    124 
     123    }
     124
     125    public void buildGui() {
    125126        for (PreferenceSettingFactory factory:settingsFactory) {
    126127            // logger.info("creating settings: " + factory);
     
    167168        settingsFactory.add(new LanguagePreference.Factory());
    168169        settingsFactory.add(new ServerAccessPreference.Factory());
    169         settingsFactory.add(new FilePreferences.Factory());
    170         settingsFactory.add(new ProxyPreferences.Factory());
    171170        settingsFactory.add(new ProjectionPreference.Factory());
    172171        settingsFactory.add(new MapPaintPreference.Factory());
  • trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java

    r2516 r2745  
    6565    static private GBC projSubPrefPanelGBC = GBC.eol().fill(GBC.BOTH).insets(20,5,5,5);
    6666
    67     public void addGui(PreferenceDialog gui) {
     67    public void addGui(PreferenceTabbedPane gui) {
    6868        setupProjectionCombo();
    6969
  • trunk/src/org/openstreetmap/josm/gui/preferences/ServerAccessPreference.java

    r2650 r2745  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.Font;
    7 import java.net.PasswordAuthentication;
    8 import java.net.Authenticator.RequestorType;
     6import java.awt.BorderLayout;
     7import java.awt.GridBagConstraints;
     8import java.awt.GridBagLayout;
     9import java.awt.Insets;
    910
    10 import javax.swing.JLabel;
    11 import javax.swing.JPasswordField;
    12 import javax.swing.JTextField;
     11import javax.swing.JPanel;
     12import javax.swing.JScrollPane;
     13import javax.swing.JTabbedPane;
    1314
    14 import org.openstreetmap.josm.Main;
    15 import org.openstreetmap.josm.io.auth.CredentialsManager;
    16 import org.openstreetmap.josm.io.auth.CredentialsManagerException;
    17 import org.openstreetmap.josm.io.auth.CredentialsManagerFactory;
    18 import org.openstreetmap.josm.tools.GBC;
    19 
     15import org.openstreetmap.josm.gui.help.HelpUtil;
     16import org.openstreetmap.josm.gui.preferences.server.AuthenticationPreferencesPanel;
     17import org.openstreetmap.josm.gui.preferences.server.BackupPreferencesPanel;
     18import org.openstreetmap.josm.gui.preferences.server.OsmApiUrlInputPanel;
     19import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
     20import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
    2021public class ServerAccessPreference implements PreferenceSetting {
    2122
     
    2627    }
    2728
     29    private OsmApiUrlInputPanel pnlApiUrlPreferences;
     30
     31    private JTabbedPane tpServerPreferences;
     32    /** indicates whether to use the default OSM URL or not */
     33    /** panel for configuring authentication preferences */
     34    private AuthenticationPreferencesPanel pnlAuthPreferences;
     35    /** panel for configuring proxy preferences */
     36    private ProxyPreferencesPanel pnlProxyPreferences;
     37    /** panel for backup preferences */
     38    private BackupPreferencesPanel pnlBackupPreferences;
     39
    2840    /**
    29      * Editfield for the Base url to the REST API from OSM.
     41     * Embeds a vertically scrollable panel in a {@see JScrollPane}
     42     * @param panel the panel
     43     * @return the scroll pane
    3044     */
    31     final private JTextField osmDataServerURL = new JTextField(20);
    32     /**
    33      * Editfield for the username to the OSM account.
    34      */
    35     final private JTextField osmDataUsername = new JTextField(20);
    36     /**
    37      * Passwordfield for the userpassword of the REST API.
    38      */
    39     final private JPasswordField osmDataPassword = new JPasswordField(20);
    40 
    41     public void addGui(PreferenceDialog gui) {
    42         CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
    43         String oldServerURL = Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api");
    44         String oldUsername;
    45         String oldPassword;
    46         try {
    47             PasswordAuthentication credentials =  cm.lookup(RequestorType.SERVER);
    48             oldUsername = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();
    49             oldPassword = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());
    50         } catch(CredentialsManagerException e) {
    51             e.printStackTrace();
    52             oldUsername = "";
    53             oldPassword = "";
    54         }
    55 
    56         osmDataServerURL.setText(oldServerURL);
    57         osmDataUsername.setText(oldUsername);
    58         osmDataPassword.setText(oldPassword);
    59         osmDataServerURL.setToolTipText(tr("The base URL for the OSM server (REST API)"));
    60         osmDataUsername.setToolTipText(tr("Login name (e-mail) to the OSM account."));
    61         osmDataPassword.setToolTipText(tr("Login password to the OSM account. Leave blank to not store any password."));
    62 
    63         gui.connection.add(new JLabel(tr("Base Server URL")), GBC.std());
    64         gui.connection.add(osmDataServerURL, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
    65         gui.connection.add(new JLabel(tr("OSM username (e-mail)")), GBC.std());
    66         gui.connection.add(osmDataUsername, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
    67         gui.connection.add(new JLabel(tr("OSM password")), GBC.std());
    68         gui.connection.add(osmDataPassword, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,0));
    69         JLabel warning = new JLabel(tr("<html>" +
    70                 "WARNING: The password is stored in plain text in the preferences file.<br>" +
    71                 "The password is transferred in plain text to the server, encoded in the URL.<br>" +
    72         "<b>Do not use a valuable Password.</b></html>"));
    73         warning.setFont(warning.getFont().deriveFont(Font.ITALIC));
    74         gui.connection.add(warning, GBC.eop().fill(GBC.HORIZONTAL));
     45    protected JScrollPane wrapVerticallyScrollablePanel(VerticallyScrollablePanel panel) {
     46        JScrollPane sp = new JScrollPane(panel);
     47        sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
     48        sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
     49        return sp;
    7550    }
    7651
     52    /**
     53     * Builds the tabbed pane with the server preferences
     54     *
     55     * @return
     56     */
     57    protected JPanel buildTabbedServerPreferences() {
     58        JPanel pnl = new JPanel(new BorderLayout());
     59
     60        tpServerPreferences = new JTabbedPane();
     61        pnlAuthPreferences = new AuthenticationPreferencesPanel();
     62        tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlAuthPreferences));
     63        pnlProxyPreferences = new ProxyPreferencesPanel();
     64        tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlProxyPreferences));
     65        pnlBackupPreferences = new BackupPreferencesPanel();
     66        tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlBackupPreferences));
     67
     68        tpServerPreferences.setTitleAt(0, tr("Authentication"));
     69        tpServerPreferences.setTitleAt(1, tr("Proxy settings"));
     70        tpServerPreferences.setTitleAt(2, tr("File backup"));
     71        tpServerPreferences.setToolTipTextAt(0, tr("Configure your identity and how to authenticate at the OSM server"));
     72        tpServerPreferences.setToolTipTextAt(1, tr("Configure whether to use a proxy server"));
     73        tpServerPreferences.setToolTipTextAt(2, tr("Configure whether to create backup files"));
     74
     75        pnl.add(tpServerPreferences, BorderLayout.CENTER);
     76        return pnl;
     77    }
     78
     79    /**
     80     * Builds the panel for entering the server access preferences
     81     *
     82     * @return
     83     */
     84    protected JPanel buildContentPanel() {
     85        JPanel pnl = new JPanel(new GridBagLayout());
     86        GridBagConstraints gc = new GridBagConstraints();
     87
     88        // the checkbox for the default UL
     89        gc.fill = GridBagConstraints.HORIZONTAL;
     90        gc.anchor = GridBagConstraints.NORTHWEST;
     91        gc.weightx = 1.0;
     92        gc.insets = new Insets(0,0,0,0);
     93        pnl.add(pnlApiUrlPreferences = new OsmApiUrlInputPanel(), gc);
     94
     95        // the remaining access properties
     96        gc.gridy = 1;
     97        gc.fill = GridBagConstraints.BOTH;
     98        gc.weightx = 1.0;
     99        gc.weighty = 1.0;
     100        gc.insets = new Insets(10,0,3,3);
     101        pnl.add(buildTabbedServerPreferences(), gc);
     102
     103        // let the AuthPreferencesPanel know when the API URL changes
     104        //
     105        pnlApiUrlPreferences.addPropertyChangeListener(pnlAuthPreferences);
     106
     107        HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Preferences/Connection"));
     108        return pnl;
     109    }
     110
     111    public void addGui(PreferenceTabbedPane gui) {
     112        GridBagConstraints gc = new GridBagConstraints();
     113        gc.fill = GridBagConstraints.BOTH;
     114        gc.weightx = 1.0;
     115        gc.weighty = 1.0;
     116        gc.anchor = GridBagConstraints.NORTHWEST;
     117        gui.connection.add(buildContentPanel(), gc);
     118
     119        initFromPreferences();
     120    }
     121
     122    /**
     123     * Initializes the configuration panel with values from the preferences
     124     */
     125    public void initFromPreferences() {
     126        pnlApiUrlPreferences.initFromPreferences();
     127        pnlAuthPreferences.initFromPreferences();
     128        pnlProxyPreferences.initFromPreferences();
     129        pnlBackupPreferences.initFromPreferences();
     130    }
     131
     132    /**
     133     * Saves the values to the preferences
     134     */
    77135    public boolean ok() {
    78         CredentialsManager cm = CredentialsManagerFactory.getCredentialManager();
    79         Main.pref.put("osm-server.url", osmDataServerURL.getText());
    80         try {
    81             cm.store(RequestorType.SERVER, new PasswordAuthentication(
    82                     osmDataUsername.getText(),
    83                     osmDataPassword.getPassword()
    84             ));
    85         } catch(CredentialsManagerException e) {
    86             // FIXME: Message dialog with an error message?
    87             e.printStackTrace();
    88         }
     136        pnlApiUrlPreferences.saveToPreferences();
     137        pnlAuthPreferences.saveToPreferences();
     138        pnlProxyPreferences.saveToPreferences();
     139        pnlBackupPreferences.saveToPreferences();
    89140        return false;
    90141    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/ShortcutPreference.java

    r1742 r2745  
    2020    }
    2121
    22     public void addGui(PreferenceDialog gui) {
     22    public void addGui(PreferenceTabbedPane gui) {
    2323        // icon source: http://www.iconfinder.net/index.php?q=key&page=icondetails&iconid=8553&size=128&q=key&s12=on&s16=on&s22=on&s32=on&s48=on&s64=on&s128=on
    2424        // icon licence: GPL
  • trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java

    r2400 r2745  
    3636    private JCheckBox enableDefault;
    3737
    38     public void addGui(final PreferenceDialog gui) {
     38    public void addGui(final PreferenceTabbedPane gui) {
    3939        sortMenu = new JCheckBox(tr("Sort presets menu"),
    4040                Main.pref.getBoolean("taggingpreset.sortmenu", false));
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r2512 r2745  
    172172        }
    173173
    174         public void addGui(PreferenceDialog gui) {
     174        public void addGui(PreferenceTabbedPane gui) {
    175175            actionsTree.setCellRenderer(new DefaultTreeCellRenderer() {
    176176                @Override
Note: See TracChangeset for help on using the changeset viewer.