Changeset 3528 in josm


Ignore:
Timestamp:
Sep 14, 2010 2:11:25 PM (3 years ago)
Author:
stoecker
Message:

improve applet a bit

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

Legend:

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

    r2748 r3528  
    146146 
    147147    public void download(String userName, String password) { 
    148         resetToDefault(); 
    149148        if (!properties.containsKey("osm-server.username") && userName != null) { 
    150149            properties.put("osm-server.username", userName); 
     
    153152            properties.put("osm-server.password", password); 
    154153        } 
     154        download(); 
     155    } 
     156 
     157    public boolean download() { 
     158        resetToDefault(); 
    155159        String cont = connection.download(); 
    156         if (cont == null) return; 
     160        if (cont == null) return false; 
    157161        Reader in = new StringReader(cont); 
     162        boolean res = false; 
    158163        try { 
    159164            XmlObjectParser.Uniform<Prop> parser = new XmlObjectParser.Uniform<Prop>(in, "tag", Prop.class); 
    160165            for (Prop p : parser) { 
     166                res = true; 
    161167                properties.put(p.key, p.value); 
    162168            } 
     
    164170            e.printStackTrace(); 
    165171        } 
     172        return res; 
    166173    } 
    167174 
     
    187194        connection.upload(b.toString()); 
    188195    } 
    189  
    190     @Override public Collection<Bookmark> loadBookmarks() { 
    191         URL url = null; 
    192         try { 
    193             Collection<Bookmark> bookmarks; 
    194             bookmarks = new LinkedList<Bookmark>(); 
    195             url = new URL("http://"+connection.serverUrl.getHost()+"/josm/bookmarks"); 
    196             BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); 
    197  
    198             for (String line = in.readLine(); line != null; line = in.readLine()) { 
    199                 StringTokenizer st = new StringTokenizer(line, ","); 
    200                 if (st.countTokens() != 5) { 
    201                     System.err.println(tr("Error: Unexpected line ''{0}'' in bookmark list from server",line)); 
    202                     continue; 
    203                 } 
    204                 Bookmark b = new Bookmark(); 
    205                 b.setName(st.nextToken()); 
    206                 double[] values= new double[4]; 
    207                 for (int i = 0; i < 4; ++i) { 
    208                     String token = st.nextToken(); 
    209                     try { 
    210                         values[i] = Double.parseDouble(token); 
    211                     } catch(NumberFormatException e) { 
    212                         System.err.println(tr("Error: Illegal double value ''{0}'' on line ''{1}'' in bookmark list from server",token,line)); 
    213                         continue; 
    214                     } 
    215                 } 
    216                 b.setArea(new Bounds(values)); 
    217                 bookmarks.add(b); 
    218             } 
    219             in.close(); 
    220             return bookmarks; 
    221         } catch (MalformedURLException e) { 
    222             e.printStackTrace(); 
    223         } catch (IllegalArgumentException e) { 
    224             e.printStackTrace(); 
    225         } catch (IOException e) { 
    226             e.printStackTrace(); 
    227         } catch(SecurityException e) { 
    228             e.printStackTrace(); 
    229             logger.warning(tr("Failed to load bookmarks from ''{0}'' for security reasons. Exception was: {1}",  url == null ? "null" : url.toExternalForm(), e.toString())); 
    230         } 
    231         return Collections.emptyList(); 
    232     } 
    233  
    234     @Override public void saveBookmarks(Collection<Bookmark> bookmarks) { 
    235     } 
    236196} 
  • trunk/src/org/openstreetmap/josm/gui/MainApplet.java

    r3252 r3528  
    8282 
    8383    @Override public void start() { 
    84         String username = args.containsKey("username") ? args.get("username").iterator().next() : null; 
    85         String password = args.containsKey("password") ? args.get("password").iterator().next() : null; 
    86         if (username == null || password == null) { 
    87             JPanel p = new JPanel(new GridBagLayout()); 
    88             p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,20,0)); 
    89             JTextField user = new JTextField(username == null ? "" : username); 
    90             p.add(user, GBC.eol().fill(GBC.HORIZONTAL)); 
    91             p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,20,0)); 
    92             JPasswordField pass = new JPasswordField(password == null ? "" : password); 
    93             p.add(pass, GBC.eol().fill(GBC.HORIZONTAL)); 
    94             JOptionPane.showMessageDialog(null, p); 
    95             username = user.getText(); 
    96             password = new String(pass.getPassword()); 
    97             args.put("password", Arrays.asList(new String[]{password})); 
    98         } 
    99  
    10084        // initialize the plaform hook, and 
    10185        Main.determinePlatformHook(); 
    102         // call the really early hook before we anything else 
     86        // call the really early hook before we do anything else 
    10387        Main.platform.preStartupHook(); 
    10488 
     
    10690 
    10791        Main.pref = new ServerSidePreferences(getCodeBase()); 
    108         ((ServerSidePreferences)Main.pref).download(username, password); 
     92        if(!((ServerSidePreferences)Main.pref).download()) { 
     93            String username = args.containsKey("username") ? args.get("username").iterator().next() : null; 
     94            String password = args.containsKey("password") ? args.get("password").iterator().next() : null; 
     95            if (username == null || password == null) { 
     96                JPanel p = new JPanel(new GridBagLayout()); 
     97                p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,20,0)); 
     98                JTextField user = new JTextField(username == null ? "" : username); 
     99                p.add(user, GBC.eol().fill(GBC.HORIZONTAL)); 
     100                p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,20,0)); 
     101                JPasswordField pass = new JPasswordField(password == null ? "" : password); 
     102                p.add(pass, GBC.eol().fill(GBC.HORIZONTAL)); 
     103                JOptionPane.showMessageDialog(null, p); 
     104                username = user.getText(); 
     105                password = new String(pass.getPassword()); 
     106                args.put("password", Arrays.asList(new String[]{password})); 
     107            } 
     108            ((ServerSidePreferences)Main.pref).download(username, password); 
     109        } 
     110 
    109111        Main.preConstructorInit(args); 
    110112        Main.parent = frame; 
Note: See TracChangeset for help on using the changeset viewer.