Changeset 431 in josm


Ignore:
Timestamp:
26.10.2007 21:58:25 (5 years ago)
Author:
gebner
Message:

Make the applet code work again.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java

    r343 r431  
    1212import java.io.StringReader; 
    1313import java.net.HttpURLConnection; 
     14import java.net.URLConnection; 
    1415import java.net.MalformedURLException; 
    1516import java.net.URL; 
     
    4647                        try { 
    4748                                System.out.println("reading preferences from "+serverUrl); 
    48                                 HttpURLConnection con = (HttpURLConnection)serverUrl.openConnection(); 
    49                                 addAuth(con); 
     49                                URLConnection con = serverUrl.openConnection(); 
     50                                if (con instanceof HttpURLConnection) addAuth((HttpURLConnection) con); 
    5051                                con.connect(); 
    5152                                BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); 
     
    5556                                        b.append("\n"); 
    5657                                } 
    57                                 con.disconnect(); 
     58                                if (con instanceof HttpURLConnection) ((HttpURLConnection) con).disconnect(); 
    5859                                return b.toString(); 
    5960                        } catch (IOException e) { 
     
    122123                if (!properties.containsKey("osm-server.password") && password != null) 
    123124                        properties.put("osm-server.password", password); 
    124                 Reader in = new StringReader(connection.download()); 
     125                String cont = connection.download(); 
     126                if (cont == null) return; 
     127                Reader in = new StringReader(cont); 
    125128                try { 
    126129                        XmlObjectParser.Uniform<Prop> parser = new XmlObjectParser.Uniform<Prop>(in, "tag", Prop.class); 
     
    176179                } catch (MalformedURLException e) { 
    177180                        e.printStackTrace(); 
     181                } catch (IllegalArgumentException e) { 
     182                        e.printStackTrace(); 
    178183                } catch (IOException e) { 
    179184                        e.printStackTrace(); 
  • trunk/src/org/openstreetmap/josm/gui/MainApplet.java

    r298 r431  
    44import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
     6import java.applet.AppletStub; 
     7import java.applet.AppletContext; 
    68import java.awt.GridBagLayout; 
    79import java.awt.event.ActionEvent; 
    810import java.awt.event.KeyEvent; 
     11import java.io.File; 
     12import java.net.URL; 
    913import java.util.Arrays; 
    1014import java.util.Collection; 
     
    1418 
    1519import javax.swing.JApplet; 
     20import javax.swing.JFrame; 
    1621import javax.swing.JLabel; 
    1722import javax.swing.JOptionPane; 
     
    5560 
    5661        private Map<String, Collection<String>> args = new HashMap<String, Collection<String>>(); 
    57         private UploadPreferencesAction uploadPreferences = new UploadPreferencesAction();  
    5862 
    5963        @Override public String[][] getParameterInfo() { 
     
    101105                // remove offending stuff from JOSM (that would break the SecurityManager) 
    102106                m.remove(m.fileMenu); 
    103                 m.editMenu.add(uploadPreferences); 
     107                m.editMenu.add(new UploadPreferencesAction()); 
    104108                m.open.setEnabled(false); 
    105109                m.exit.setEnabled(false); 
     
    118122                return v; 
    119123        } 
     124 
     125        public static void main(String[] args) { 
     126                final JFrame frame = new JFrame("Java OpenStreetMap Applet"); 
     127                MainApplet applet = new MainApplet(); 
     128                applet.setStub(new AppletStub() { 
     129                        public void appletResize(int w, int h) { 
     130                                frame.resize(w, h); 
     131                        } 
     132 
     133                        public AppletContext getAppletContext() { 
     134                                return null; 
     135                        } 
     136 
     137                        public URL getCodeBase() { 
     138                                try { 
     139                                        return new File(".").toURI().toURL(); 
     140                                } catch (Exception e) { 
     141                                        e.printStackTrace(); 
     142                                        return null; 
     143                                } 
     144                        } 
     145 
     146                        public URL getDocumentBase() { 
     147                                return getCodeBase(); 
     148                        } 
     149 
     150                        public String getParameter(String k) { 
     151                                return null; 
     152                        } 
     153 
     154                        public boolean isActive() { 
     155                                return true; 
     156                        } 
     157                }); 
     158                applet.init(); 
     159                applet.start(); 
     160                frame.setContentPane(applet); 
     161                frame.setVisible(true); 
     162        } 
    120163} 
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r373 r431  
    101101 
    102102                // status line below the map 
    103                 if (!Main.applet) 
    104                 statusLine = new MapStatus(this); 
     103                statusLine = new MapStatus(this); 
    105104        } 
    106105 
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r373 r431  
    1717import java.awt.event.MouseEvent; 
    1818import java.awt.event.MouseMotionListener; 
     19import java.awt.event.KeyAdapter; 
     20import java.awt.event.KeyEvent; 
    1921import java.lang.reflect.InvocationTargetException; 
    2022import java.text.DecimalFormat; 
     
    270272                // Listen to keyboard/mouse events for pressing/releasing alt key and 
    271273                // inform the collector. 
    272         Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener(){ 
    273                 public void eventDispatched(AWTEvent event) { 
    274                         synchronized (collector) { 
    275                                 mouseState.modifiers = ((InputEvent)event).getModifiersEx(); 
    276                                 if (event instanceof MouseEvent) 
    277                                         mouseState.mousePos = ((MouseEvent)event).getPoint(); 
    278                                 collector.notify(); 
    279                         } 
    280                 } 
    281         }, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); 
     274                try { 
     275                        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener(){ 
     276                                public void eventDispatched(AWTEvent event) { 
     277                                        synchronized (collector) { 
     278                                                mouseState.modifiers = ((InputEvent)event).getModifiersEx(); 
     279                                                if (event instanceof MouseEvent) 
     280                                                        mouseState.mousePos = ((MouseEvent)event).getPoint(); 
     281                                                collector.notify(); 
     282                                        } 
     283                                } 
     284                        }, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); 
     285                } catch (SecurityException ex) { 
     286                        mapFrame.mapView.addMouseMotionListener(new MouseMotionListener() { 
     287                                public void mouseMoved(MouseEvent e) { 
     288                                        synchronized (collector) { 
     289                                                mouseState.modifiers = e.getModifiersEx(); 
     290                                                mouseState.mousePos = e.getPoint(); 
     291                                                collector.notify(); 
     292                                        } 
     293                                } 
     294 
     295                                public void mouseDragged(MouseEvent e) { 
     296                                        mouseMoved(e); 
     297                                } 
     298                        }); 
     299 
     300                        mapFrame.mapView.addKeyListener(new KeyAdapter() { 
     301                                public void keyPressed(KeyEvent e) { 
     302                                        synchronized (collector) { 
     303                                                mouseState.modifiers = e.getModifiersEx(); 
     304                                                collector.notify(); 
     305                                        } 
     306                                } 
     307 
     308                                public void keyReleased(KeyEvent e) { 
     309                                        keyReleased(e); 
     310                                } 
     311                        }); 
     312                } 
    282313        } 
    283314 
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r298 r431  
    167167 
    168168        static { 
    169                 sources.add(ClassLoader.getSystemClassLoader()); 
     169                try { 
     170                        sources.add(ClassLoader.getSystemClassLoader()); 
     171                } catch (SecurityException ex) { 
     172                        sources.add(ImageProvider.class.getClassLoader()); 
     173                } 
    170174        } 
    171175} 
  • trunk/start.html

    r321 r431  
    11<applet  
    22  code="org/openstreetmap/josm/gui/MainApplet.class"  
    3   archive="dist/josm-custom.jar,lib/gettext-commons-0.9.jar,lib/metadata-extractor-2.3.1.jar,lib/MinML2.jar"  
     3  archive="dist/josm-custom.jar"  
    44  width="800"  
    5   height="600" 
    6   username="foo" 
    7   password="bar" 
    8 /> 
     5  height="600"> 
     6</applet> 
Note: See TracChangeset for help on using the changeset viewer.