Changeset 292 in josm
- Timestamp:
- 2007-07-19T23:19:21+02:00 (17 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/AboutAction.java
r288 r292 23 23 import javax.swing.JTabbedPane; 24 24 import javax.swing.JTextArea; 25 import javax.swing.SwingUtilities;26 25 27 26 import org.openstreetmap.josm.Main; … … 70 69 71 70 JPanel info = new JPanel(new GridBagLayout()); 72 info.add(new JLabel(tr("Java OpenStreetMap Editor Version {0}",version)), GBC.eol()); 73 info.add(new JLabel(tr("last change at {0}",time)), GBC.eol()); 74 info.add(new JLabel(tr("Java Version {0}",System.getProperty("java.version"))), GBC.eol()); 75 info.add(new JLabel(tr("Latest Version on JOSM homepage is")), GBC.std().insets(0,0,5,0)); 76 final JLabel checkVersionLabel = new JLabel("<html><em>"+tr("checking...")+"</em></html>"); 77 info.add(checkVersionLabel, GBC.eol()); 78 new Thread(){ 79 @Override public void run() { 80 final String version = checkLatestVersion(); 81 try { 82 if (version == null) 83 throw new NullPointerException(); 84 SwingUtilities.invokeAndWait(new Runnable(){ 85 public void run() { 86 checkVersionLabel.setText(version); 87 } 88 }); 89 } catch (Exception e) { 90 checkVersionLabel.setText("failed."); 91 } 92 } 93 }.start(); 94 71 info.add(new JLabel(tr("Java OpenStreetMap Editor Version {0}",version)), GBC.eol().fill(GBC.HORIZONTAL)); 72 info.add(new JLabel(tr("last change at {0}",time)), GBC.eol().fill(GBC.HORIZONTAL)); 73 info.add(new JLabel(tr("Java Version {0}",System.getProperty("java.version"))), GBC.eol().fill(GBC.HORIZONTAL)); 95 74 info.add(GBC.glue(0,10), GBC.eol()); 96 97 75 info.add(new JLabel(tr("Homepage")), GBC.std().insets(0,0,10,0)); 98 info.add(new UrlLabel("http://josm.openstreetmap.de"), GBC.eol() );76 info.add(new UrlLabel("http://josm.openstreetmap.de"), GBC.eol().fill(GBC.HORIZONTAL)); 99 77 info.add(new JLabel(tr("Bug Reports")), GBC.std().insets(0,0,10,0)); 100 info.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eol() );78 info.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eol().fill(GBC.HORIZONTAL)); 101 79 info.add(new JLabel(tr("News about JOSM")), GBC.std().insets(0,0,10,0)); 102 info.add(new UrlLabel("http://www.opengeodata.org/?cat=17"), GBC.eol() );80 info.add(new UrlLabel("http://www.opengeodata.org/?cat=17"), GBC.eol().fill(GBC.HORIZONTAL)); 103 81 104 82 StringBuilder pluginsStr = new StringBuilder(); -
src/org/openstreetmap/josm/actions/AutoScaleAction.java
r214 r292 29 29 30 30 public AutoScaleAction(String mode) { 31 super(tr( mode), "dialogs/autoscale/"+mode, tr("Zoom the view to {0}."), 0, 0, true);31 super(tr("Zoom to {0}", mode), "dialogs/autoscale/"+mode, tr("Zoom the view to {0}.", tr(mode)), 0, 0, true); 32 32 String modeHelp = Character.toUpperCase(mode.charAt(0))+mode.substring(1); 33 33 putValue("help", "Action/AutoScale/"+modeHelp); -
src/org/openstreetmap/josm/actions/ExitAction.java
r178 r292 5 5 import java.awt.event.ActionEvent; 6 6 import java.awt.event.KeyEvent; 7 8 import org.openstreetmap.josm.Main; 7 9 8 10 /** … … 18 20 super(tr("Exit"), "exit", tr("Exit the application."), KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK, true); 19 21 } 20 22 21 23 public void actionPerformed(ActionEvent e) { 22 System.exit(0); 24 if (!Main.breakBecauseUnsavedChanges()) 25 System.exit(0); 23 26 } 24 27 } -
src/org/openstreetmap/josm/actions/JosmAction.java
r208 r292 27 27 super(name, ImageProvider.get(iconName)); 28 28 setHelpId(); 29 putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+ShortCutLabel.name(shortCut, modifier)+"</font> </html>"); 30 this.shortCut = KeyStroke.getKeyStroke(shortCut, modifier); 31 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(this.shortCut, name); 32 Main.contentPane.getActionMap().put(name, this); 29 String scl = ShortCutLabel.name(shortCut, modifier); 30 putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+scl+"</font>"+(scl.equals("")?"":" ")+"</html>"); 31 if (shortCut != 0) { 32 this.shortCut = KeyStroke.getKeyStroke(shortCut, modifier); 33 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(this.shortCut, name); 34 Main.contentPane.getActionMap().put(name, this); 35 } 33 36 putValue("toolbar", iconName); 34 37 if (register) … … 37 40 38 41 public void destroy() { 39 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(shortCut); 40 Main.contentPane.getActionMap().remove(shortCut); 42 if (shortCut != null) { 43 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(shortCut); 44 Main.contentPane.getActionMap().remove(shortCut); 45 } 41 46 } 42 47 -
src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r113 r292 44 44 */ 45 45 public ZoomAction(MapFrame mapFrame) { 46 super(tr("Zoom"), "zoom", tr("Zoom in by dragging. (Ctrl+up,left,down,right, +,-)"), KeyEvent.VK_Z, mapFrame, ImageProvider.getCursor("normal", "zoom"));46 super(tr("Zoom"), "zoom", tr("Zoom in by dragging. (Ctrl+up,left,down,right,',','.')"), KeyEvent.VK_Z, mapFrame, ImageProvider.getCursor("normal", "zoom")); 47 47 mv = mapFrame.mapView; 48 48 selectionManager = new SelectionManager(this, true, mv); -
src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r275 r292 196 196 double size = 180.0 / Math.pow(2, Integer.parseInt(map.get("zoom"))); 197 197 b = new Bounds( 198 new LatLon( Double.parseDouble(map.get("mlat")) - size/2, Double.parseDouble(map.get("mlon")) - size),199 new LatLon( Double.parseDouble(map.get("mlat")) + size/2, Double.parseDouble(map.get("mlon")) + size));198 new LatLon(parseDouble(map, "lat") - size/2, parseDouble(map, "lon") - size), 199 new LatLon(parseDouble(map, "lat") + size/2, parseDouble(map, "lon") + size)); 200 200 } 201 201 } catch (NumberFormatException x) { … … 204 204 return b; 205 205 } 206 207 private static double parseDouble(HashMap<String, String> map, String key) { 208 if (map.containsKey(key)) 209 return Double.parseDouble(map.get(key)); 210 return Double.parseDouble(map.get("m"+key)); 211 } 206 212 } -
src/org/openstreetmap/josm/plugins/Plugin.java
r291 r292 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.net.URL;9 import java.net.URLClassLoader;10 8 import java.util.List; 11 9 … … 17 15 /** 18 16 * All plugins *must* have an standard constructor taking no arguments. 17 * 19 18 * This constructor is called at JOSM startup, after all Main-objects have been initialized. 20 19 * For all purposes of loading dynamic resources, the Plugin's class loader should be used 21 20 * (or else, the plugin jar will not be within the class path). 22 21 * 23 * A ll plugins should have at least one class subclassing this abstract base class.22 * A plugin may subclass this abstract base class (but it is optional). 24 23 * 25 * The actual implementation of this interface is optional, as all functions will be called 26 * via reflection. This is to be able to change this interface without the need of recompiling 27 * or even breaking the plugins. If your class does not provide a function here (or does 28 * provide a function with a mismatching signature), it will not be called. That simple. 24 * The actual implementation of this class is optional, as all functions will be called 25 * via reflection. This is to be able to change this interface without the need of 26 * recompiling or even breaking the plugins. If your class does not provide a 27 * function here (or does provide a function with a mismatching signature), it will not 28 * be called. That simple. 29 29 * 30 * Or in other words: See this base class as an documentation of what functions are provided. 31 * Subclassing it and overriding some functions makes it easy for you to keep sync with the 32 * correct actual plugin architecture of JOSM. 33 * 34 * 35 * The pluginname provided to the constructor is also the name of the directory to 36 * store the plugin's own stuff (located under the josm preferences directory) 30 * Or in other words: See this base class as an documentation of what automatic callbacks 31 * are provided (you can register yourself to more callbacks in your plugin class 32 * constructor). 33 * 34 * Subclassing Plugin and overriding some functions makes it easy for you to keep sync 35 * with the correct actual plugin architecture of JOSM. 37 36 * 38 37 * @author Immanuel.Scholz … … 40 39 public abstract class Plugin { 41 40 42 String name; 43 44 public Plugin() { 45 try { 46 URL[] urls = ((URLClassLoader)getClass().getClassLoader()).getURLs(); 47 name = urls[urls.length-1].toString(); 48 if (name.toLowerCase().endsWith(".jar")) { 49 int lastSlash = name.lastIndexOf('/'); 50 name = name.substring(lastSlash+1, name.length()-4); 51 } 52 } catch (RuntimeException e) { 53 name = "unknown"; 54 } 55 } 41 /** 42 * This is the info available for this plugin. You can access this from your 43 * constructor. 44 * 45 * (The actual implementation to request the info from a static variable 46 * is a bit hacky, but it works). 47 */ 48 public final PluginInformation info = PluginInformation.currentPluginInitialization; 56 49 57 50 /** 58 * @return The name of this plugin. This is the name of the .jar file. 59 * @deprecated Plugins have to know their name by themself. 51 * @return The directory for the plugin to store all kind of stuff. 60 52 */ 61 @Deprecated public final String getName() {62 return name;53 public final String getPluginDir() { 54 return Main.pref.getPreferencesDir()+"plugins/"+info.name+"/"; 63 55 } 64 /**65 * @return The directory for the plugin to store all kind of stuff.66 * @deprecated Use <code>Main.pref.getPreferencesDir()+"plugins/"+name+"/";</code> instead.67 */68 @Deprecated public final String getPluginDir() {69 return Main.pref.getPreferencesDir()+"plugins/"+name+"/";70 }71 72 73 56 74 57 /** … … 92 75 93 76 /** 94 * @deprecated Use copy(String pluginName, String from, String to) instead95 */96 @Deprecated public void copy(String from, String to) throws FileNotFoundException, IOException {97 copy(name, from, to);98 }99 100 /**101 77 * Copies the ressource 'from' to the file in the plugin directory named 'to'. 102 78 */ 103 public void copy(String pluginName, Stringfrom, String to) throws FileNotFoundException, IOException {104 String pluginDirName = Main.pref.getPreferencesDir()+"plugins/"+pluginName+"/";105 106 107 108 109 110 111 112 113 114 79 public void copy(String from, String to) throws FileNotFoundException, IOException { 80 String pluginDirName = Main.pref.getPreferencesDir()+"plugins/"+info.name+"/"; 81 File pluginDir = new File(pluginDirName); 82 if (!pluginDir.exists()) 83 pluginDir.mkdirs(); 84 FileOutputStream out = new FileOutputStream(pluginDirName+to); 85 InputStream in = getClass().getResourceAsStream(from); 86 byte[] buffer = new byte[8192]; 87 for(int len = in.read(buffer); len > 0; len = in.read(buffer)) 88 out.write(buffer, 0, len); 89 in.close(); 90 out.close(); 115 91 } 116 92 } -
src/org/openstreetmap/josm/plugins/PluginInformation.java
r291 r292 36 36 37 37 public final Map<String, String> attr = new TreeMap<String, String>(); 38 39 /** 40 * Used in the Plugin constructor to make the information of the plugin 41 * that is currently initializing available. 42 * 43 * If you think this is hacky, you are probably right. But it is 44 * convinient anyway ;-) 45 */ 46 static PluginInformation currentPluginInitialization = null; 38 47 39 48 /** … … 102 111 public PluginProxy load(Class<?> klass) { 103 112 try { 113 currentPluginInitialization = this; 104 114 return new PluginProxy(klass.newInstance(), this); 105 115 } catch (Exception e) { -
src/org/openstreetmap/josm/plugins/PluginProxy.java
r267 r292 19 19 public final Object plugin; 20 20 public final PluginInformation info; 21 public boolean misbehaving = false;22 21 23 22 public PluginProxy(Object plugin, PluginInformation info) { 24 23 this.plugin = plugin; 25 24 this.info = info; 26 27 // setting name of the plugin by reflection28 if (plugin instanceof Plugin) {29 try {30 Plugin.class.getDeclaredField("name").set(plugin, info.name);31 } catch (Exception e) {32 if (e instanceof RuntimeException)33 throw (RuntimeException)e;34 throw new RuntimeException(e);35 }36 }37 25 } 38 26 -
src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r283 r292 4 4 5 5 import java.awt.GridBagLayout; 6 import java.awt.Toolkit; 7 import java.awt.datatransfer.Clipboard; 8 import java.awt.datatransfer.ClipboardOwner; 9 import java.awt.datatransfer.StringSelection; 10 import java.awt.datatransfer.Transferable; 6 11 import java.io.BufferedReader; 7 12 import java.io.File; … … 37 42 if (Main.parent != null) { 38 43 if (e instanceof OutOfMemoryError) { 44 // do not translate the string, as translation may raise an exception 39 45 JOptionPane.showMessageDialog(Main.parent, "You are out of memory. Strange things may happen.\nPlease restart JOSM and load smaller data sets."); 40 46 return; 41 47 } 42 48 49 PluginProxy plugin = null; 50 43 51 // Check for an explicit problem when calling a plugin function 44 if (e instanceof PluginException) { 45 PluginProxy plugin = ((PluginException)e).plugin; 46 if (plugin != null && !plugin.misbehaving) { 47 JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} threw an exception: {1}\nIt may be outdated. Please contact the plugin's author.\nThis message will not shown again until JOSM is restarted.", plugin.info.name, e.getMessage())); 48 plugin.misbehaving = true; 52 if (e instanceof PluginException) 53 plugin = ((PluginException)e).plugin; 54 55 if (plugin == null) 56 plugin = guessPlugin(e); 57 58 if (plugin != null) { 59 int answer = JOptionPane.showConfirmDialog( 60 Main.parent, 61 tr("An unexpected exception occurred, that may come from in the ''{0}'' plugin.", plugin.info.name)+"\n"+ 62 (plugin.info.author != null ? tr("According to the information within the plugin, the author is {0}.", plugin.info.author) : "")+"\n"+ 63 tr("Should the plugin be disabled?"), 64 tr("Disable plugin"), 65 JOptionPane.YES_NO_OPTION); 66 if (answer == JOptionPane.OK_OPTION) { 67 LinkedList<String> plugins = new LinkedList<String>(Arrays.asList(Main.pref.get("plugins").split(","))); 68 if (plugins.contains(plugin.info.name)) { 69 while (plugins.remove(plugin.info.name)) {} 70 String p = ""; 71 for (String s : plugins) 72 p += ","+s; 73 if (p.length() > 0) 74 p = p.substring(1); 75 Main.pref.put("plugins", p); 76 JOptionPane.showMessageDialog(Main.parent, tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin.")); 77 } else { 78 JOptionPane.showMessageDialog(Main.parent, tr("The plugin could not be removed. Please tell the people you got JOSM from about the problem.")); 79 } 49 80 return; 50 }51 }52 53 // Try a heuristic to guess whether the problem may be within a plugin54 String pluginName = guessPlugin(e);55 if (pluginName != null) {56 boolean loaded = false;57 for (PluginProxy p : Main.plugins)58 if (p.info.name.equals(pluginName))59 loaded = true;60 if (loaded) {61 String author = findPluginAuthor(pluginName);62 int answer = JOptionPane.showConfirmDialog(63 Main.parent,64 tr("An unexpected exception occurred, that may come from in the ''{0}'' plugin.", pluginName)+"\n"+65 (author != null ? tr("According to the information within the plugin, the author is {0}.", author) : "")+"\n"+66 tr("Should the plugin be disabled?"),67 tr("Disable plugin"),68 JOptionPane.YES_NO_OPTION);69 if (answer == JOptionPane.OK_OPTION) {70 LinkedList<String> plugins = new LinkedList<String>(Arrays.asList(Main.pref.get("plugins").split(",")));71 if (plugins.contains(pluginName)) {72 while (plugins.remove(pluginName)) {}73 String p = "";74 for (String s : plugins)75 p += ","+s;76 if (p.length() > 0)77 p = p.substring(1);78 Main.pref.put("plugins", p);79 JOptionPane.showMessageDialog(Main.parent, tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."));80 } else {81 JOptionPane.showMessageDialog(Main.parent, tr("The plugin could not be removed. Please tell the people you got JOSM from about the problem."));82 }83 return;84 }85 81 } 86 82 } … … 98 94 99 95 URL revUrl = Main.class.getResource("/REVISION"); 100 StringBuilder sb = new StringBuilder( tr("Please send this to josm@eigenheimstrasse.de\n\n"));96 StringBuilder sb = new StringBuilder(); 101 97 if (revUrl == null) { 102 98 sb.append("Development version. Unknown revision."); … … 121 117 122 118 JPanel p = new JPanel(new GridBagLayout()); 123 p.add(new JLabel(tr("Please send an email with the following information to josm@eigenheimstrasse.de")), GBC.eop()); 119 p.add(new JLabel(tr("Please send an email with the following information to josm@eigenheimstrasse.de")), GBC.eol()); 120 try { 121 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(sb.toString()), new ClipboardOwner(){ 122 public void lostOwnership(Clipboard clipboard, Transferable contents) {} 123 }); 124 p.add(new JLabel(tr("The text has already been copied to your clipboard.")), GBC.eop()); 125 } catch (RuntimeException x) { 126 } 124 127 125 128 JTextArea info = new JTextArea(sb.toString(), 20, 60); … … 136 139 } 137 140 138 /** 139 * Try to find the author of the given plugin. Return <code>null</code> 140 * if no author specified or the plugin is not found. 141 */ 142 private String findPluginAuthor(String pluginName) { 143 for (PluginProxy proxy : Main.plugins) 144 if (pluginName.equals(proxy.info.name)) 145 return proxy.info.author; 141 private PluginProxy guessPlugin(Throwable e) { 142 String name = guessPluginName(e); 143 for (PluginProxy p : Main.plugins) 144 if (p.info.name.equals(name)) 145 return p; 146 146 return null; 147 147 } … … 158 158 * bug reports ;-). 159 159 */ 160 private String guessPlugin (Throwable e) {160 private String guessPluginName(Throwable e) { 161 161 for (StackTraceElement element : e.getStackTrace()) { 162 162 String c = element.getClassName(); 163 163 164 if (c.contains("wmsplugin.") || c.contains(".WMSLayer")) 164 165 return "wmsplugin"; … … 171 172 if (c.contains("annotationtester.")) 172 173 return "annotation-tester"; 174 if (c.startsWith("UtilsPlugin.")) 175 return "UtilsPlugin"; 176 177 if (c.startsWith("org.openstreetmap.josm.plugins.")) { 178 String p = c.substring("org.openstreetmap.josm.plugins.".length()); 179 if (p.indexOf('.') != -1 && p.matches("[a-z].*")) { 180 return p.substring(0,p.indexOf('.')); 181 } 182 } 173 183 } 174 184 return null; -
src/org/openstreetmap/josm/tools/OpenBrowser.java
r200 r292 52 52 53 53 private static void linux(String url) throws IOException { 54 try { 55 Runtime.getRuntime().exec("gnome-open " + url); 56 } catch (IOException e) { 57 Runtime.getRuntime().exec("kfmclient openURL " + url); 54 String[] programs = {"gnome-open", "kfmclient openURL", "firefox"}; 55 for (String program : programs) { 56 try { 57 Runtime.getRuntime().exec(program+" "+url); 58 return; 59 } catch (IOException e) { 60 } 58 61 } 59 62 } -
src/org/openstreetmap/josm/tools/ShortCutLabel.java
r178 r292 8 8 public class ShortCutLabel { 9 9 public static String name(int shortCut, int modifiers) { 10 if (shortCut == 0 && modifiers == 0) 11 return ""; 10 12 String s = ""; 11 13 if ((modifiers & KeyEvent.CTRL_MASK) != 0 || (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0)
Note:
See TracChangeset
for help on using the changeset viewer.