Changeset 1647 in josm
- Timestamp:
- 2009-06-07T02:56:33+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PreferencesAction.java
r1212 r1647 23 23 * @author imi 24 24 */ 25 public class PreferencesAction extends JosmAction {25 public class PreferencesAction extends JosmAction implements Runnable { 26 26 27 27 /** … … 37 37 */ 38 38 public void actionPerformed(ActionEvent e) { 39 new Thread(this).start(); 40 } 41 42 public void run() { 39 43 PreferenceDialog prefDlg = new PreferenceDialog(); 40 44 prefDlg.setMinimumSize(new Dimension(400,300)); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r1465 r1647 39 39 private int num = 1; 40 40 private String msg = ""; 41 41 42 42 public Task(boolean newLayer, OsmServerReader reader, boolean silent, 43 43 int numLayers, String msg) { … … 65 65 dataSet.dataSources.add(new DataSource(currentBounds, "OpenStreetMap server")); 66 66 } 67 67 68 68 OsmDataLayer layer = new OsmDataLayer(dataSet, tr("Data Layer {0}", num), null); 69 69 if (newLayer) … … 71 71 else 72 72 Main.main.editLayer().mergeFrom(layer); 73 73 74 74 Main.pleaseWaitDlg.setCustomText(""); 75 75 } … … 94 94 double t = minlon; minlon = maxlon; maxlon = t; 95 95 } 96 96 97 97 boolean newLayer = action != null 98 98 && (action.dialog == null || action.dialog.newLayer.isSelected()); … … 104 104 message); 105 105 currentBounds = new Bounds(new LatLon(minlat, minlon), new LatLon(maxlat, maxlon)); 106 // We need submit instead of execute so we can wait for it to finish and get the error 106 // We need submit instead of execute so we can wait for it to finish and get the error 107 107 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. 108 task = Main.worker.submit(t, t); 108 task = Main.worker.submit(t, t); 109 109 } 110 110 111 111 public void download(DownloadAction action, double minlat, double minlon, 112 112 double maxlat, double maxlon) { … … 135 135 return "osm"; 136 136 } 137 137 138 138 /** 139 139 * Finds the number of data layers currently opened … … 149 149 return num; 150 150 } 151 151 152 152 /* 153 153 * (non-Javadoc) … … 156 156 public String getErrorMessage() { 157 157 if(task == null) 158 return ""; 158 return ""; 159 159 160 160 try { -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r1557 r1647 28 28 */ 29 29 public String version; 30 30 31 31 /** 32 32 * All nodes goes here, even when included in other data (ways etc). This enables the instant -
trunk/src/org/openstreetmap/josm/gui/GettingStarted.java
r1562 r1647 99 99 // everytime because of something we can't read. 100 100 return (Main.pref.getInteger("cache.motd.html.version", myVersion) == myVersion) 101 101 && Main.pref.get("cache.motd.html.lang").equals(myLang); 102 102 } 103 103 } -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java
r1465 r1647 54 54 }); 55 55 } 56 57 public void setIndeterminate(boolean newValue) { 56 57 public void setIndeterminate(boolean newValue) { 58 58 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100); 59 59 progressBar.setIndeterminate(newValue); 60 60 } 61 61 62 62 /** 63 63 * Sets a custom text line below currentAction. Can be used to display additional information … … 70 70 return; 71 71 } 72 72 73 73 customText.setVisible(true); 74 74 customText.setText(text); -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java
r1493 r1647 34 34 35 35 private final String title; 36 36 37 37 /** 38 38 * Create the runnable object with a given message for the user. 39 */ 39 */ 40 40 public PleaseWaitRunnable(String title) { 41 41 this(title, false); … … 45 45 * Create the runnable object with a given message for the user. 46 46 * @param title Message for user 47 * @param ignoreException If true, exception will be propaged to calling code. If false then 47 * @param ignoreException If true, exception will be propaged to calling code. If false then 48 48 * exception will be thrown directly in EDT. When this runnable is executed using executor framework 49 49 * then use false unless you read result of task (because exception will get lost if you don't) … … 118 118 public void run() { 119 119 throw new RuntimeException(e); 120 } 120 } 121 121 }); 122 122 } -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java
r1645 r1647 23 23 import java.net.URL; 24 24 import java.util.Arrays; 25 import java.util.concurrent.Future; 25 26 import java.util.Collection; 26 import java.util.regex.Matcher; 27 import java.util.regex.Pattern; 27 import java.util.LinkedList; 28 28 29 29 import javax.swing.JOptionPane; … … 39 39 private static final class UpdateTask extends PleaseWaitRunnable { 40 40 private final Collection<PluginInformation> toUpdate; 41 public final Collection<PluginInformation> failed = new LinkedList<PluginInformation>(); 41 42 private String errors = ""; 42 43 private int count = 0; 44 private boolean update; 43 45 44 private UpdateTask(Collection<PluginInformation> toUpdate) { 45 super(tr("Update Plugins")); 46 private UpdateTask(Collection<PluginInformation> toUpdate, boolean up) { 47 super(up ? tr("Update Plugins") : tr("Download Plugins")); 48 update = up; 46 49 this.toUpdate = toUpdate; 47 50 } … … 52 55 53 56 @Override protected void finish() { 57 Main.pleaseWaitDlg.setVisible(false); 54 58 if (errors.length() > 0) 55 59 JOptionPane.showMessageDialog(Main.parent, tr("There were problems with the following plugins:\n\n {0}",errors)); 56 60 else 57 JOptionPane.showMessageDialog(Main.parent, trn("{0} Plugin successfully updated. Please restart JOSM.", "{0} Plugins successfully updated. Please restart JOSM.", count, count));61 JOptionPane.showMessageDialog(Main.parent, trn("{0} Plugin successfully downloaded. Please restart JOSM.", "{0} Plugins successfully downloaded. Please restart JOSM.", count, count)); 58 62 } 59 63 … … 63 67 pluginDir.mkdirs(); 64 68 for (PluginInformation d : toUpdate) { 69 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading Plugin {0}...", d.name)); 65 70 File pluginFile = new File(pluginDir, d.name + ".jar.new"); 66 71 if (download(d, pluginFile)) 72 { 67 73 count++; 74 failed.add(d); 75 } 68 76 else 69 77 errors += d.name + "\n"; … … 103 111 } 104 112 105 public static boolean downloadPlugin(PluginInformation pd) {106 File file = new File(Main.pref.getPluginsDirFile(), pd.name + ".jar");107 if (!download(pd, file)) {108 JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.downloadlink));109 } else {110 try {111 PluginInformation.findPlugin(pd.name);112 return true;113 } catch (Exception e) {114 e.printStackTrace();115 JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} seems to be broken or could not be downloaded automatically.", pd.name));116 }117 }118 if (file.exists())119 file.delete();120 return false;121 }122 123 113 private static boolean download(PluginInformation pd, File file) { 124 114 if(pd.mainversion > AboutAction.getVersionNumber()) … … 141 131 out.close(); 142 132 in.close(); 133 new PluginInformation(file); 143 134 return true; 144 } catch (MalformedURLException e) { 145 e.printStackTrace(); 146 } catch (FileNotFoundException e) { 147 e.printStackTrace(); 148 } catch (IOException e) { 135 } catch (Exception e) { 149 136 e.printStackTrace(); 150 137 } 138 file.delete(); /* cleanup */ 151 139 return false; 152 140 } 153 141 154 142 public static void update(Collection<PluginInformation> update) { 155 Main.worker.execute(new UpdateTask(update)); 143 Main.worker.execute(new UpdateTask(update, true)); 144 } 145 146 public Collection<PluginInformation> download(Collection<PluginInformation> download) { 147 UpdateTask t = new UpdateTask(download, false); 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) {} 154 catch(java.util.concurrent.ExecutionException e) {} 155 return download; 156 156 } 157 157 -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r1645 r1647 110 110 stage = stageStr == null ? 50 : Integer.parseInt(stageStr); 111 111 version = attr.getValue("Plugin-Version"); 112 try { 113 mainversion = Integer.parseInt(attr.getValue("Plugin-Mainversion")); 114 } catch(NumberFormatException e) { 115 e.printStackTrace(); 116 } 112 try { mainversion = Integer.parseInt(attr.getValue("Plugin-Mainversion")); } 113 catch(NumberFormatException e) {} 117 114 author = attr.getValue("Author"); 118 115 -
trunk/src/org/openstreetmap/josm/plugins/PluginSelection.java
r1623 r1647 98 98 String msg = ""; 99 99 for (Entry<String, Boolean> entry : pluginMap.entrySet()) { 100 if (entry.getValue() && PluginInformation.findPlugin(entry.getKey()) == null) { 101 toDownload.add(availablePlugins.get(entry.getKey())); 102 msg += entry.getKey() + "\n"; 100 if(entry.getValue()) 101 { 102 String name = entry.getKey(); 103 PluginInformation ap = availablePlugins.get(name); 104 PluginInformation pi = PluginInformation.findPlugin(name); 105 boolean add = false; 106 if(pi == null) 107 add = true; 108 else if(!pi.version.equals(ap.version)) 109 { 110 add = true; 111 for (PluginProxy proxy : PluginHandler.pluginList) 112 if(proxy.info.name.equals(ap.name)) 113 add = false; 114 } 115 if(add) 116 { 117 toDownload.add(ap); 118 msg += name + "\n"; 119 } 103 120 } 104 121 } … … 109 126 new String[] {tr("Download Plugins"), tr("Cancel")}, 110 127 new String[] {"download.png", "cancel.png"}).getValue(); 111 if (answer != 1) 112 for (PluginInformation pd : toDownload) 113 pluginMap.put(pd.name, false); 114 else 115 for (PluginInformation pd : toDownload) 116 if (!PluginDownloader.downloadPlugin(pd)) 117 pluginMap.put(pd.name, false); 128 Collection<PluginInformation> error = 129 (answer != 1 ? toDownload : new PluginDownloader().download(toDownload)); 130 for (PluginInformation pd : error) 131 pluginMap.put(pd.name, false); 118 132 119 133 } … … 209 223 pluginCheck.addActionListener(new ActionListener(){ 210 224 public void actionPerformed(ActionEvent e) { 211 // if user enabled a plugin, it is not loaded but found somewhere on disk: offer to delete jar212 if (pluginCheck.isSelected()) {213 PluginInformation plinfo = PluginInformation.findPlugin(plugin.name);214 if ((getLoaded(plugin.name) == null) && (plinfo != null)) {215 try {216 int answer = new ExtendedDialog(Main.parent,217 tr("Plugin already exists"),218 tr("Plugin archive already available. Do you want to download"219 + " the current version by deleting existing archive?\n\n{0}",220 plinfo.file.getCanonicalPath()),221 new String[] {tr("Delete and Download"), tr("Cancel")},222 new String[] {"download.png", "cancel.png"}).getValue();223 224 if (answer == 1) {225 if (!plinfo.file.delete()) {226 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", plinfo.file.getCanonicalPath()));227 }228 }229 } catch (IOException e1) {230 e1.printStackTrace();231 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", e1.getMessage()));232 }233 }234 }235 225 pluginMap.put(plugin.name, pluginCheck.isSelected()); 236 226 }
Note:
See TracChangeset
for help on using the changeset viewer.