Changeset 6525 in josm for trunk


Ignore:
Timestamp:
2013-12-24T23:40:10+01:00 (10 years ago)
Author:
Don-vip
Message:

fix server preferences dialog broken in r6523 + reload MOTD after proxy update if it fails because of a proxy error

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
6 edited

Legend:

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

    r6296 r6525  
    2525import org.openstreetmap.josm.Main;
    2626import org.openstreetmap.josm.data.Version;
     27import org.openstreetmap.josm.gui.preferences.server.ProxyPreference;
     28import org.openstreetmap.josm.gui.preferences.server.ProxyPreferenceListener;
    2729import org.openstreetmap.josm.gui.widgets.JosmEditorPane;
    2830import org.openstreetmap.josm.io.CacheCustomContent;
     
    3133import org.openstreetmap.josm.tools.WikiReader;
    3234
    33 public final class GettingStarted extends JPanel {
     35public final class GettingStarted extends JPanel implements ProxyPreferenceListener {
     36
     37    private final LinkGeneral lg;
    3438    private String content = "";
     39    private boolean contentInitialized = false;
     40
    3541    private static final String STYLE = "<style type=\"text/css\">\n"
    3642            + "body {font-family: sans-serif; font-weight: bold; }\n"
     
    113119    public GettingStarted() {
    114120        super(new BorderLayout());
    115         final LinkGeneral lg = new LinkGeneral("<html>" + STYLE + "<h1>" + "JOSM - " + tr("Java OpenStreetMap Editor")
     121        lg = new LinkGeneral("<html>" + STYLE + "<h1>" + "JOSM - " + tr("Java OpenStreetMap Editor")
    116122                + "</h1><h2 align=\"center\">" + tr("Downloading \"Message of the day\"") + "</h2></html>");
    117123        // clear the build-in command ctrl+shift+O, because it is used as shortcut in JOSM
     
    122128        add(scroller, BorderLayout.CENTER);
    123129
     130        getMOTD();
     131
     132        new FileDrop(scroller);
     133    }
     134
     135    private void getMOTD() {
    124136        // Asynchronously get MOTD to speed-up JOSM startup
    125137        Thread t = new Thread(new Runnable() {
    126138            @Override
    127139            public void run() {
    128                 if (content.isEmpty() && Main.pref.getBoolean("help.displaymotd", true)) {
     140                if (!contentInitialized && Main.pref.getBoolean("help.displaymotd", true)) {
    129141                    try {
    130142                        content = new MotdContent().updateIfRequiredString();
     143                        contentInitialized = true;
     144                        ProxyPreference.removeProxyPreferenceListener(GettingStarted.this);
    131145                    } catch (IOException ex) {
    132146                        Main.warn(tr("Failed to read MOTD. Exception was: {0}", ex.toString()));
    133147                        content = "<html>" + STYLE + "<h1>" + "JOSM - " + tr("Java OpenStreetMap Editor")
    134148                                + "</h1>\n<h2 align=\"center\">(" + tr("Message of the day not available") + ")</h2></html>";
     149                        // In case of MOTD not loaded because of proxy error, listen to preference changes to retry after update
     150                        ProxyPreference.addProxyPreferenceListener(GettingStarted.this);
    135151                    }
    136152                }
     
    146162        t.setDaemon(true);
    147163        t.start();
    148 
    149         new FileDrop(scroller);
    150164    }
    151165
     
    163177        return sb.toString();
    164178    }
     179
     180    @Override
     181    public void proxyPreferenceChanged() {
     182        getMOTD();
     183    }
    165184}
  • trunk/src/org/openstreetmap/josm/gui/preferences/ServerAccessPreference.java

    r6523 r6525  
    4545     * @return the scroll pane
    4646     */
    47     protected JScrollPane wrapVerticallyScrollablePanel(VerticallyScrollablePanel panel) {
     47    public static JScrollPane wrapVerticallyScrollablePanel(VerticallyScrollablePanel panel) {
    4848        JScrollPane sp = new JScrollPane(panel);
    4949        sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
     
    109109        gui.createPreferenceTab(this).add(buildContentPanel(), gc);
    110110
    111         initFromPreferences();
    112     }
    113 
    114     /**
    115      * Initializes the configuration panel with values from the preferences
    116      */
    117     public void initFromPreferences() {
    118111        pnlApiUrlPreferences.initFromPreferences();
    119112    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreference.java

    r6523 r6525  
    77import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
    88import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
     9import org.openstreetmap.josm.gui.preferences.ServerAccessPreference;
    910import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
    1011import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
     
    3637        pnlAuthPreferences = new AuthenticationPreferencesPanel();
    3738        gui.getServerPreference().addApiUrlChangeListener(pnlAuthPreferences);
    38         gui.getServerPreference().addSubTab(this, tr("Authentication"), pnlAuthPreferences,
     39        gui.getServerPreference().addSubTab(this, tr("Authentication"),
     40                ServerAccessPreference.wrapVerticallyScrollablePanel(pnlAuthPreferences),
    3941                tr("Configure your identity and how to authenticate at the OSM server"));
    4042    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java

    r6365 r6525  
    106106    public AuthenticationPreferencesPanel() {
    107107        build();
     108        initFromPreferences();
    108109        HelpUtil.setHelpContext(this, HelpUtil.ht("/Preferences/Connection#AuthenticationSettings"));
    109110    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreference.java

    r6523 r6525  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.util.HashSet;
     7import java.util.Set;
     8
    69import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    710import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
    811import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
     12import org.openstreetmap.josm.gui.preferences.ServerAccessPreference;
    913import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
    1014import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
     
    2630    }
    2731
    28     ProxyPreferencesPanel pnlProxyPreferences;
     32    private static Set<ProxyPreferenceListener> listeners = new HashSet<ProxyPreferenceListener>();
     33   
     34    private ProxyPreferencesPanel pnlProxyPreferences;
    2935
    3036    private ProxyPreference() {
     
    3541    public void addGui(PreferenceTabbedPane gui) {
    3642        pnlProxyPreferences = new ProxyPreferencesPanel();
    37         gui.getServerPreference().addSubTab(this, tr("Proxy settings"), pnlProxyPreferences,
     43        gui.getServerPreference().addSubTab(this, tr("Proxy settings"),
     44                ServerAccessPreference.wrapVerticallyScrollablePanel(pnlProxyPreferences),
    3845                tr("Configure whether to use a proxy server"));
    3946    }
     
    4249    public boolean ok() {
    4350        pnlProxyPreferences.saveToPreferences();
     51        for (ProxyPreferenceListener listener : listeners) {
     52            listener.proxyPreferenceChanged();
     53        }
    4454        return false;
    4555    }
     
    5464        return gui.getServerPreference();
    5565    }
     66   
     67    /**
     68     * Adds a new ProxyPreferenceListener.
     69     * @param listener the listener to add
     70     * @return {@code true} if the listener has been added, {@code false} otherwise
     71     * @since 6525
     72     */
     73    public static boolean addProxyPreferenceListener(ProxyPreferenceListener listener) {
     74        if (listener != null) {
     75            return listeners.add(listener);
     76        }
     77        return false;
     78    }
     79
     80    /**
     81     * Removes a ProxyPreferenceListener.
     82     * @param listener the listener to remove
     83     * @return {@code true} if the listener has been removed, {@code false} otherwise
     84     * @since 6525
     85     */
     86    public static boolean removeProxyPreferenceListener(ProxyPreferenceListener listener) {
     87        if (listener != null) {
     88            return listeners.remove(listener);
     89        }
     90        return false;
     91    }
    5692}
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java

    r6340 r6525  
    360360    }
    361361
     362    /**
     363     * Constructs a new {@code ProxyPreferencesPanel}.
     364     */
    362365    public ProxyPreferencesPanel() {
    363366        setLayout(new GridBagLayout());
Note: See TracChangeset for help on using the changeset viewer.