Changeset 5887 in josm


Ignore:
Timestamp:
2013-04-20T02:24:00+02:00 (7 years ago)
Author:
Don-vip
Message:

see #8606 - Fix user-agent used with JEditorPage.setPage() or JEditorPane(URL) + fix version number from previous commit

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

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

    r5886 r5887  
    33
    44import java.io.IOException;
     5import java.io.InputStream;
    56import java.net.URL;
     7import java.net.URLConnection;
    68
    79import javax.swing.JEditorPane;
    810
     11import org.openstreetmap.josm.tools.Utils;
     12
    913/**
    10  * Subclass of {@link JEditorPane} that adds a "native" context menu (cut/copy/paste/select all).
    11  * @since 5885
     14 * Subclass of {@link JEditorPane} that adds a "native" context menu (cut/copy/paste/select all)
     15 * and effectively uses JOSM user agent when performing HTTP request in {@link #setPage(URL)} method.
     16 * @since 5886
    1217 */
    1318public class JosmEditorPane extends JEditorPane {
     
    5964        setText(text);
    6065    }
     66
     67    @Override
     68    protected InputStream getStream(URL page) throws IOException {
     69        URLConnection conn = Utils.setupURLConnection(page.openConnection());
     70        InputStream result = conn.getInputStream();
     71        String type = conn.getContentType();
     72        if (type != null) {
     73            setContentType(type);
     74        }
     75        return result;
     76    }
    6177}
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextArea.java

    r5886 r5887  
    77/**
    88 * Subclass of {@link JTextArea} that adds a "native" context menu (cut/copy/paste/select all).
    9  * @since 5885
     9 * @since 5886
    1010 */
    1111public class JosmTextArea extends JTextArea {
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTextField.java

    r5886 r5887  
    77/**
    88 * Subclass of {@link JTextField} that adds a "native" context menu (cut/copy/paste/select all).
    9  * @since 5885
     9 * @since 5886
    1010 */
    1111public class JosmTextField extends JTextField {
  • trunk/src/org/openstreetmap/josm/gui/widgets/PopupMenuLauncher.java

    r5886 r5887  
    3939     * @param menu The popup menu to display
    4040     * @param checkEnabled if {@code true}, the popup menu will only be displayed if the component triggering the mouse event is enabled
    41      * @since 5885
     41     * @since 5886
    4242     */
    4343    public PopupMenuLauncher(JPopupMenu menu, boolean checkEnabled) {
  • trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java

    r5886 r5887  
    3434 * <li>Select All</li>
    3535 * </ul>
    36  * @since 5885
     36 * @since 5886
    3737 */
    3838public class TextContextualPopupMenu extends JPopupMenu {
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r5881 r5887  
    586586     */
    587587    public static InputStream openURL(URL url) throws IOException {
    588         URLConnection connection = url.openConnection();
    589         connection.setRequestProperty("User-Agent", Version.getInstance().getFullAgentString());
    590         connection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000);
    591         connection.setReadTimeout(Main.pref.getInteger("socket.timeout.read",30)*1000);
    592         return connection.getInputStream();
     588        return setupURLConnection(url.openConnection()).getInputStream();
     589    }
     590
     591    /***
     592     * Setups the given URL connection to match JOSM needs by setting its User-Agent and timeout properties.
     593     * @param connection The connection to setup
     594     * @return {@code connection}, with updated properties
     595     * @since 5887
     596     */
     597    public static URLConnection setupURLConnection(URLConnection connection) {
     598        if (connection != null) {
     599            connection.setRequestProperty("User-Agent", Version.getInstance().getFullAgentString());
     600            connection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000);
     601            connection.setReadTimeout(Main.pref.getInteger("socket.timeout.read",30)*1000);
     602        }
     603        return connection;
    593604    }
    594605
Note: See TracChangeset for help on using the changeset viewer.