Changes in trunk [1738:1732] in josm


Ignore:
Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/PreferencesAction.java

    r1738 r1732  
    3737     */ 
    3838    public void actionPerformed(ActionEvent e) { 
    39         run(); 
     39        new Thread(this).start(); 
    4040    } 
    4141 
     
    7575        dlg.setBounds(targetX, targetY, targetWidth, targetHeight); 
    7676 
    77         dlg.setModal(true); 
    7877        dlg.setVisible(true); 
    7978        if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) 
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r1738 r1732  
    148148 
    149149    public LatLon interpolate(LatLon ll2, double proportion) { 
    150         return new LatLon(this.lat() + proportion * (ll2.lat() - this.lat()), 
    151             this.lon() + proportion * (ll2.lon() - this.lon())); 
     150        return new LatLon(this.x + proportion * (ll2.x - this.x), 
     151            this.y + proportion * (ll2.y - this.y)); 
    152152    } 
    153153 
    154154    public LatLon getCenter(LatLon ll2) { 
    155         return new LatLon((this.lat() + ll2.lat())/2.0, (this.lon() + ll2.lon())/2.0); 
     155        return new LatLon((this.x + ll2.x)/2.0, (this.y + ll2.y)/2.0); 
    156156    } 
    157157 
  • trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java

    r1738 r1732  
    99import java.awt.event.WindowAdapter; 
    1010import java.awt.event.WindowEvent; 
    11 import java.awt.event.WindowListener; 
    1211import java.io.FileNotFoundException; 
    1312import java.io.IOException; 
     
    3736    private final String title; 
    3837 
    39     private ActionListener cancelListener = new ActionListener(){ 
    40         public void actionPerformed(ActionEvent e) { 
    41             if (!cancelled) { 
    42                 cancelled = true; 
    43                 cancel(); 
    44             } 
    45         } 
    46     }; 
    47  
    48     private WindowListener windowListener = new WindowAdapter(){ 
    49         @Override public void windowClosing(WindowEvent e) { 
    50             if (!closeDialogCalled) { 
    51                 if (!cancelled) { 
    52                     cancelled = true; 
    53                     cancel(); 
    54                 } 
    55                 closeDialog(); 
    56             } 
    57         } 
    58     }; 
    59  
    6038    /** 
    6139     * Create the runnable object with a given message for the user. 
     
    7553        this.title = title; 
    7654        this.ignoreException = ignoreException; 
     55        Main.pleaseWaitDlg.cancel.addActionListener(new ActionListener(){ 
     56            public void actionPerformed(ActionEvent e) { 
     57                if (!cancelled) { 
     58                    cancelled = true; 
     59                    cancel(); 
     60                } 
     61            } 
     62        }); 
     63        Main.pleaseWaitDlg.addWindowListener(new WindowAdapter(){ 
     64            @Override public void windowClosing(WindowEvent e) { 
     65                if (!closeDialogCalled) { 
     66                    if (!cancelled) { 
     67                        cancelled = true; 
     68                        cancel(); 
     69                    } 
     70                    closeDialog(); 
     71                } 
     72            } 
     73        }); 
    7774    } 
    7875 
    79     private void prepareDialog() { 
    80         // reset dialog state 
    81         errorMessage = null; 
    82         closeDialogCalled = false; 
    83  
    84         Main.pleaseWaitDlg.setTitle(title); 
    85         Main.pleaseWaitDlg.cancel.setEnabled(true); 
    86         Main.pleaseWaitDlg.setCustomText(""); 
    87         Main.pleaseWaitDlg.cancel.addActionListener(cancelListener); 
    88         Main.pleaseWaitDlg.addWindowListener(windowListener); 
    89         Main.pleaseWaitDlg.setVisible(true); 
    90     } 
    91  
    92     private void doRealRun() { 
     76    public final void run() { 
    9377        try { 
    9478            try { 
     79                if (cancelled) 
     80                    return; // since realRun isn't executed, do not call to finish 
     81 
     82                // reset dialog state 
     83                Main.pleaseWaitDlg.setTitle(title); 
     84                Main.pleaseWaitDlg.cancel.setEnabled(true); 
     85                Main.pleaseWaitDlg.setCustomText(""); 
     86                errorMessage = null; 
     87                closeDialogCalled = false; 
     88 
     89                // show the dialog 
     90                synchronized (this) { 
     91                    EventQueue.invokeLater(new Runnable() { 
     92                        public void run() { 
     93                            synchronized (PleaseWaitRunnable.this) { 
     94                                PleaseWaitRunnable.this.notifyAll(); 
     95                            } 
     96                            Main.pleaseWaitDlg.setVisible(true); 
     97                        } 
     98                    }); 
     99                    try {wait();} catch (InterruptedException e) {} 
     100                } 
     101 
    95102                realRun(); 
    96103            } catch (SAXException x) { 
     
    122129                }); 
    123130            } 
    124         } 
    125     } 
    126  
    127     public final void run() { 
    128         if (cancelled) 
    129             return; // since realRun isn't executed, do not call to finish 
    130  
    131         if (EventQueue.isDispatchThread()) { 
    132             new Thread(new Runnable() { 
    133                 public void run() { 
    134                     doRealRun(); 
    135                 } 
    136             }).start(); 
    137             prepareDialog(); 
    138         } else { 
    139             EventQueue.invokeLater(new Runnable() { 
    140                 public void run() { 
    141                     prepareDialog(); 
    142                 } 
    143             }); 
    144             doRealRun(); 
    145131        } 
    146132    } 
     
    179165                        Main.pleaseWaitDlg.setVisible(false); 
    180166                        Main.pleaseWaitDlg.dispose(); 
    181                         Main.pleaseWaitDlg.removeWindowListener(windowListener); 
    182                         Main.pleaseWaitDlg.cancel.removeActionListener(cancelListener); 
    183167                    } 
    184168                    if (errorMessage != null && !silent) { 
  • trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java

    r1738 r1732  
    686686                Date time = new Date(tp.time.getTime() - (delta+gpstimezone)); 
    687687                if (time.after(e.time) && lastTP != null) { 
    688                     e.pos = new CachedLatLon(lastTP.pos.getCenter(tp.pos)); 
     688                    e.pos.setCoor(lastTP.pos.getCenter(tp.pos)); 
    689689                    break; 
    690690                } 
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r1738 r1732  
    485485                                            hdop = 0; 
    486486                                        } 
    487                                         int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25)); 
     487                                        int hdoplvl = Math.round(hdop * 25); 
    488488                                        // High hdop is bad, but high values in colors are green. 
    489489                                        // Therefore inverse the logic 
     
    10931093                WayPoint R = null; 
    10941094                for (WayPoint S : seg) { 
    1095                     EastNorth c = R.getEastNorth(); 
    10961095                    if (R == null) { 
     1096                        EastNorth c = R.getEastNorth(); 
    10971097                        R = S; 
    10981098                        rx = c.east(); 
     
    11071107                        } 
    11081108                    } else { 
     1109                        EastNorth c = S.getEastNorth(); 
    11091110                        sx = c.east(); 
    11101111                        sy = c.north(); 
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r1738 r1732  
    169169            } 
    170170            for (Entry<String, String> e : osm.keys.entrySet()) { 
    171                 if ((osm instanceof Changeset) || !("created_by".equals(e.getKey()))) 
     171                if (!("created_by".equals(e.getKey()))) 
    172172                    out.println("    <tag k='"+ XmlWriter.encode(e.getKey()) + 
    173173                            "' v='"+XmlWriter.encode(e.getValue())+ "' />"); 
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java

    r1738 r1732  
    1111import java.io.BufferedWriter; 
    1212import java.io.File; 
     13import java.io.FileNotFoundException; 
    1314import java.io.FileOutputStream; 
     15import java.io.FileWriter; 
    1416import java.io.FilenameFilter; 
    1517import java.io.IOException; 
     
    1820import java.io.OutputStream; 
    1921import java.io.OutputStreamWriter; 
     22import java.net.MalformedURLException; 
    2023import java.net.URL; 
    2124import java.util.Arrays; 
     25import java.util.concurrent.Future; 
    2226import java.util.Collection; 
    2327import java.util.LinkedList; 
     
    2529import javax.swing.JOptionPane; 
    2630 
     31import org.openstreetmap.josm.actions.AboutAction; 
    2732import org.openstreetmap.josm.Main; 
    28 import org.openstreetmap.josm.actions.AboutAction; 
    2933import org.openstreetmap.josm.gui.ExtendedDialog; 
    3034import org.openstreetmap.josm.gui.PleaseWaitRunnable; 
     
    6266            if (!pluginDir.exists()) 
    6367                pluginDir.mkdirs(); 
    64             Main.pleaseWaitDlg.progress.setMaximum(toUpdate.size()); 
    65             int progressValue = 0; 
    6668            for (PluginInformation d : toUpdate) { 
    67                 Main.pleaseWaitDlg.progress.setValue(progressValue++); 
    6869                Main.pleaseWaitDlg.currentAction.setText(tr("Downloading Plugin {0}...", d.name)); 
    6970                File pluginFile = new File(pluginDir, d.name + ".jar.new"); 
     
    144145 
    145146    public Collection<PluginInformation> download(Collection<PluginInformation> download) { 
    146         // Execute task in current thread instead of executing it in other thread and waiting for result 
    147         // Waiting for result is not a good idea because the waiting thread will probably be either EDT 
    148         // or worker thread. Blocking one of these threads will cause deadlock 
    149147        UpdateTask t = new UpdateTask(download, false); 
    150         t.run(); 
    151         return t.failed; 
     148        try { 
     149            Future<UpdateTask> ta = Main.worker.submit(t, t); 
     150            t = ta.get(); 
     151            return t.failed; 
     152        } 
     153        catch(java.lang.InterruptedException e) {e.printStackTrace();} 
     154        catch(java.util.concurrent.ExecutionException e) {e.printStackTrace();} 
     155        return download; 
    152156    } 
    153157 
  • trunk/src/org/openstreetmap/josm/plugins/PluginSelection.java

    r1738 r1732  
    99import java.awt.event.ActionEvent; 
    1010import java.awt.event.ActionListener; 
     11 
    1112import java.io.BufferedReader; 
    1213import java.io.ByteArrayInputStream; 
     
    1415import java.io.FileInputStream; 
    1516import java.io.InputStreamReader; 
     17import java.io.IOException; 
    1618import java.util.Arrays; 
    1719import java.util.Collection; 
     
    2325import java.util.Map; 
    2426import java.util.Set; 
     27import java.util.SortedMap; 
    2528import java.util.TreeMap; 
    2629import java.util.Map.Entry; 
     
    6972            PluginInformation description = availablePlugins.get(local.name); 
    7073 
    71             if (description.version != null && !description.version.equals(local.version)) { 
     74            if (description != null && (description.version == null || description.version.equals("")) ? 
     75            (local.version != null && local.version.equals("")) : !description.version.equals(local.version)) { 
    7276                toUpdate.add(description); 
    7377                toUpdateStr.append(description.name+"\n"); 
     
    9397    } 
    9498 
    95     public boolean finish() { 
     99    public Boolean finish() { 
    96100        Collection<PluginInformation> toDownload = new LinkedList<PluginInformation>(); 
    97         Collection<String> installedPlugins = Main.pref.getCollection("plugins", null); 
    98  
    99101        String msg = ""; 
    100102        for (Entry<String, Boolean> entry : pluginMap.entrySet()) { 
    101             if(entry.getValue() && !installedPlugins.contains(entry.getKey())) 
     103            if(entry.getValue()) 
    102104            { 
    103105                String name = entry.getKey(); 
     
    136138    /* return true when plugin list changed */ 
    137139    public void drawPanel(JPanel pluginPanel) { 
    138         loadPlugins(); 
     140        availablePlugins = getAvailablePlugins(); 
    139141        Collection<String> enabledPlugins = Main.pref.getCollection("plugins", null); 
    140142 
     
    222224    } 
    223225 
    224     private void loadPlugins() { 
    225         availablePlugins = new TreeMap<String, PluginInformation>(new Comparator<String>(){ 
     226    /** 
     227     * Return information about a loaded plugin. 
     228     * 
     229     * Note that if you call this in your plugins bootstrap, you may get <code>null</code> if 
     230     * the plugin requested is not loaded yet. 
     231     * 
     232     * @return The PluginInformation to a specific plugin, but only if the plugin is loaded. 
     233     * If it is not loaded, <code>null</code> is returned. 
     234     */ 
     235    private static PluginInformation getLoaded(String pluginName) { 
     236        for (PluginProxy p : PluginHandler.pluginList) 
     237            if (p.info.name.equals(pluginName)) 
     238                return p.info; 
     239        return null; 
     240    } 
     241 
     242    private Map<String, PluginInformation> getAvailablePlugins() { 
     243        SortedMap<String, PluginInformation> availablePlugins = new TreeMap<String, PluginInformation>(new Comparator<String>(){ 
    226244            public int compare(String o1, String o2) { 
    227245                return o1.compareToIgnoreCase(o2); 
     
    330348                localPlugins.put(proxy.info.name, proxy.info); 
    331349        } 
     350        return availablePlugins; 
    332351    } 
    333352} 
Note: See TracChangeset for help on using the changeset viewer.