- Timestamp:
- 2006-10-13T13:02:57+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r155 r159 7 7 import java.awt.Rectangle; 8 8 import java.awt.Toolkit; 9 import java.awt.event.ActionEvent;10 9 import java.awt.event.KeyEvent; 11 10 import java.io.File; … … 21 20 import java.util.regex.Pattern; 22 21 23 import javax.swing.AbstractAction;24 import javax.swing.Action;25 22 import javax.swing.JComponent; 26 import javax.swing.JMenu;27 import javax.swing.JMenuBar;28 23 import javax.swing.JOptionPane; 29 24 import javax.swing.JPanel; 30 import javax.swing.JSeparator;31 25 import javax.swing.JToolBar; 32 26 import javax.swing.KeyStroke; … … 34 28 35 29 import org.openstreetmap.josm.actions.AboutAction; 36 import org.openstreetmap.josm.actions.AlignInCircleAction;37 30 import org.openstreetmap.josm.actions.DownloadAction; 38 import org.openstreetmap.josm.actions.ExitAction;39 import org.openstreetmap.josm.actions.ExternalToolsAction;40 import org.openstreetmap.josm.actions.GpxExportAction;41 import org.openstreetmap.josm.actions.HelpAction;42 import org.openstreetmap.josm.actions.OpenAction;43 import org.openstreetmap.josm.actions.PreferencesAction;44 import org.openstreetmap.josm.actions.RedoAction;45 import org.openstreetmap.josm.actions.ReverseSegmentAction;46 import org.openstreetmap.josm.actions.SaveAction;47 import org.openstreetmap.josm.actions.SaveAsAction;48 import org.openstreetmap.josm.actions.UndoAction;49 import org.openstreetmap.josm.actions.UploadAction;50 31 import org.openstreetmap.josm.actions.DownloadAction.DownloadTask; 51 32 import org.openstreetmap.josm.actions.mapmode.MapMode; … … 55 36 import org.openstreetmap.josm.data.projection.Epsg4326; 56 37 import org.openstreetmap.josm.data.projection.Projection; 38 import org.openstreetmap.josm.gui.MainMenu; 57 39 import org.openstreetmap.josm.gui.MapFrame; 58 40 import org.openstreetmap.josm.gui.PleaseWaitDialog; 59 41 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 60 import org.openstreetmap.josm.gui.annotation.AnnotationTester;61 42 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 62 43 import org.openstreetmap.josm.gui.layer.Layer; … … 107 88 */ 108 89 public static PleaseWaitDialog pleaseWaitDlg; 109 /** 110 * The access to the help subsystem 111 */ 112 public HelpAction help; 90 91 92 /** 93 * The main menu bar at top of screen. 94 */ 95 public final MainMenu menu; 113 96 114 97 … … 153 136 public final void setLayerMenu(Component[] entries) { 154 137 if (entries == null || entries.length == 0) 155 layerMenu.setVisible(false);138 menu.layerMenu.setVisible(false); 156 139 else { 157 layerMenu.removeAll();140 menu.layerMenu.removeAll(); 158 141 for (Component c : entries) 159 layerMenu.add(c);160 layerMenu.setVisible(true);142 menu.layerMenu.add(c); 143 menu.layerMenu.setVisible(true); 161 144 } 162 145 } … … 177 160 main = this; 178 161 contentPane.add(panel, BorderLayout.CENTER); 179 180 final Action annotationTesterAction = new AbstractAction(){ 181 public void actionPerformed(ActionEvent e) { 182 String annotationSources = pref.get("annotation.sources"); 183 if (annotationSources.equals("")) { 184 JOptionPane.showMessageDialog(Main.parent, tr("You have to specify annotation sources in the preferences first.")); 185 return; 186 } 187 String[] args = annotationSources.split(";"); 188 new AnnotationTester(args); 189 } 190 }; 191 annotationTesterAction.putValue(Action.NAME, tr("Annotation Preset Tester")); 192 annotationTesterAction.putValue(Action.SMALL_ICON, ImageProvider.get("annotation-tester")); 193 final Action reverseSegmentAction = new ReverseSegmentAction(); 194 final Action alignInCircleAction = new AlignInCircleAction(); 195 final Action uploadAction = new UploadAction(); 196 final Action saveAction = new SaveAction(); 197 final Action saveAsAction = new SaveAsAction(); 198 final Action gpxExportAction = new GpxExportAction(null); 199 final Action exitAction = new ExitAction(); 200 final Action preferencesAction = new PreferencesAction(); 201 help = new HelpAction(); 202 final Action aboutAction = new AboutAction(); 203 204 final JMenu fileMenu = new JMenu(tr("Files")); 205 fileMenu.setMnemonic('F'); 206 fileMenu.add(openAction); 207 fileMenu.add(saveAction); 208 fileMenu.add(saveAsAction); 209 fileMenu.add(gpxExportAction); 210 fileMenu.addSeparator(); 211 fileMenu.add(exitAction); 212 mainMenu.add(fileMenu); 213 214 215 final JMenu connectionMenu = new JMenu(tr("Connection")); 216 connectionMenu.setMnemonic('C'); 217 connectionMenu.add(downloadAction); 218 //connectionMenu.add(new DownloadIncompleteAction()); 219 connectionMenu.add(uploadAction); 220 mainMenu.add(connectionMenu); 221 222 layerMenu = new JMenu(tr("Layer")); 223 layerMenu.setMnemonic('L'); 224 mainMenu.add(layerMenu); 225 layerMenu.setVisible(false); 226 227 final JMenu editMenu = new JMenu(tr("Edit")); 228 editMenu.setMnemonic('E'); 229 editMenu.add(undoAction); 230 editMenu.add(redoAction); 231 editMenu.addSeparator(); 232 editMenu.add(reverseSegmentAction); 233 editMenu.add(alignInCircleAction); 234 editMenu.addSeparator(); 235 editMenu.add(preferencesAction); 236 mainMenu.add(editMenu); 237 238 JMenu externalMenu = ExternalToolsAction.buildMenu(); 239 if (externalMenu != null) 240 mainMenu.add(externalMenu); 241 242 mainMenu.add(new JSeparator()); 243 final JMenu helpMenu = new JMenu(tr("Help")); 244 helpMenu.setMnemonic('H'); 245 helpMenu.add(help); 246 helpMenu.add(aboutAction); 247 helpMenu.addSeparator(); 248 helpMenu.add(annotationTesterAction); 249 mainMenu.add(helpMenu); 162 menu = new MainMenu(); 250 163 251 164 // creating toolbar 252 165 final JToolBar toolBar = new JToolBar(); 253 166 toolBar.setFloatable(false); 254 toolBar.add( downloadAction);255 toolBar.add( uploadAction);167 toolBar.add(menu.download); 168 toolBar.add(menu.upload); 256 169 toolBar.addSeparator(); 257 toolBar.add( openAction);258 toolBar.add( saveAction);259 toolBar.add( gpxExportAction);170 toolBar.add(menu.open); 171 toolBar.add(menu.save); 172 toolBar.add(menu.gpxExport); 260 173 toolBar.addSeparator(); 261 toolBar.add( undoAction);262 toolBar.add( redoAction);174 toolBar.add(menu.undo); 175 toolBar.add(menu.redo); 263 176 toolBar.addSeparator(); 264 toolBar.add( preferencesAction);177 toolBar.add(menu.preferences); 265 178 contentPane.add(toolBar, BorderLayout.NORTH); 266 179 267 180 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "Help"); 268 contentPane.getActionMap().put("Help", help);181 contentPane.getActionMap().put("Help", menu.help); 269 182 270 183 contentPane.updateUI(); … … 280 193 try { 281 194 File pluginFile = new File(pref.getPreferencesDir()+"plugins/"+pluginName+".jar"); 282 if (pluginFile.exists()) 283 plugins.add(new PluginInformation(pluginFile).load()); 284 else 195 if (pluginFile.exists()) { 196 PluginInformation info = new PluginInformation(pluginFile); 197 Class<?> klass = info.loadClass(); 198 ImageProvider.sources.add(0, klass); 199 plugins.add(info.load(klass)); 200 } else 285 201 JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName)); 286 202 } catch (PluginException e) { … … 327 243 //////////////////////////////////////////////////////////////////////////////////////// 328 244 329 330 245 public static JPanel panel = new JPanel(new BorderLayout()); 331 246 332 public final JMenuBar mainMenu = new JMenuBar();333 247 protected static Rectangle bounds; 334 248 335 public final UndoAction undoAction = new UndoAction();336 public final RedoAction redoAction = new RedoAction();337 public final OpenAction openAction = new OpenAction();338 public final DownloadAction downloadAction = new DownloadAction();339 249 340 250 private final CommandQueueListener redoUndoListener = new CommandQueueListener(){ 341 251 public void commandChanged(final int queueSize, final int redoSize) { 342 undoAction.setEnabled(queueSize > 0);343 redoAction.setEnabled(redoSize > 0);252 menu.undo.setEnabled(queueSize > 0); 253 menu.redo.setEnabled(redoSize > 0); 344 254 } 345 255 }; 346 private JMenu layerMenu;347 256 348 257 /** … … 420 329 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed url: \"{0}\"", s)); 421 330 else { 422 DownloadTask osmTask = main. downloadAction.downloadTasks.get(0);423 osmTask.download(main. downloadAction, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon());331 DownloadTask osmTask = main.menu.download.downloadTasks.get(0); 332 osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon()); 424 333 } 425 334 return; … … 428 337 if (s.startsWith("file:")) { 429 338 try { 430 main. openAction.openFile(new File(new URI(s)));339 main.menu.open.openFile(new File(new URI(s))); 431 340 } catch (URISyntaxException e) { 432 341 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed file url: \"{0}\"", s)); … … 438 347 if (st.countTokens() == 4) { 439 348 try { 440 DownloadTask task = main. downloadAction.downloadTasks.get(rawGps ? 1 : 0);441 task.download(main. downloadAction, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));349 DownloadTask task = main.menu.download.downloadTasks.get(rawGps ? 1 : 0); 350 task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())); 442 351 return; 443 352 } catch (final NumberFormatException e) { … … 445 354 } 446 355 447 main. openAction.openFile(new File(s));356 main.menu.open.openFile(new File(s)); 448 357 } 449 358 } -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r103 r159 88 88 89 89 /** 90 * Return the id as hashcode or supers hashcode if0.90 * Return the id plus the class type encoded as hashcode or supers hashcode if id is 0. 91 91 * 92 92 * An primitive has the same hashcode as its incomplete counter part. 93 93 */ 94 94 @Override public final int hashCode() { 95 return id == 0 ? super.hashCode() : (int)id; 95 if (id == 0) 96 return super.hashCode(); 97 final int[] ret = new int[1]; 98 Visitor v = new Visitor(){ 99 public void visit(Node n) { ret[0] = 1; } 100 public void visit(Segment s) { ret[0] = 2; } 101 public void visit(Way w) { ret[0] = 3; } 102 }; 103 visit(v); 104 return id == 0 ? super.hashCode() : (int)(id<<3)+ret[0]; 96 105 } 97 106 -
src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java
r86 r159 41 41 * Ways have all nodes from their segments. 42 42 */ 43 public void visit(Way t) {44 for (Segment ls : t.segments)43 public void visit(Way w) { 44 for (Segment ls : w.segments) 45 45 visit(ls); 46 46 } -
src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r146 r159 28 28 } 29 29 30 public void visit(Way t) {31 for (Segment ls : t.segments)30 public void visit(Way w) { 31 for (Segment ls : w.segments) 32 32 visit(ls); 33 33 } -
src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java
r100 r159 57 57 } 58 58 public void visit(Segment ls) { 59 for (Way t: ds.ways) {60 if ( t.deleted)59 for (Way w : ds.ways) { 60 if (w.deleted) 61 61 continue; 62 if ( t.segments.contains(ls))63 data.add( t);62 if (w.segments.contains(ls)) 63 data.add(w); 64 64 } 65 65 } 66 public void visit(Way t) {}66 public void visit(Way w) {} 67 67 } -
src/org/openstreetmap/josm/data/osm/visitor/DeleteVisitor.java
r86 r159 29 29 ds.segments.remove(ls); 30 30 } 31 public void visit(Way t) {32 ds.ways.remove( t);31 public void visit(Way w) { 32 ds.ways.remove(w); 33 33 } 34 34 } -
src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r119 r159 147 147 148 148 Way my = null; 149 for (Way t: ds.ways) {150 if (match(other, t)) {151 my = t;149 for (Way w : ds.ways) { 150 if (match(other, w)) { 151 my = w; 152 152 break; 153 153 } … … 211 211 } 212 212 213 private void fixWay(Way t) {213 private void fixWay(Way w) { 214 214 boolean replacedSomething = false; 215 215 LinkedList<Segment> newSegments = new LinkedList<Segment>(); 216 for (Segment ls : t.segments) {216 for (Segment ls : w.segments) { 217 217 Segment otherLs = mergedSegments.get(ls); 218 218 newSegments.add(otherLs == null ? ls : otherLs); … … 221 221 } 222 222 if (replacedSomething) { 223 t.segments.clear();224 t.segments.addAll(newSegments);223 w.segments.clear(); 224 w.segments.addAll(newSegments); 225 225 } 226 for (Segment ls : t.segments)226 for (Segment ls : w.segments) 227 227 fixSegment(ls); 228 228 } … … 258 258 * @return Whether the ways matches (in sense of "be mergable"). 259 259 */ 260 private boolean match(Way t1, Way t2) {261 if ( t1.id == 0 || t2.id == 0) {262 if ( t1.segments.size() != t2.segments.size())260 private boolean match(Way w1, Way w2) { 261 if (w1.id == 0 || w2.id == 0) { 262 if (w1.segments.size() != w2.segments.size()) 263 263 return false; 264 Iterator<Segment> it = t1.segments.iterator();265 for (Segment ls : t2.segments)264 Iterator<Segment> it = w1.segments.iterator(); 265 for (Segment ls : w2.segments) 266 266 if (!match(ls, it.next())) 267 267 return false; 268 268 return true; 269 269 } 270 return t1.id == t2.id;270 return w1.id == w2.id; 271 271 } 272 272 -
src/org/openstreetmap/josm/gui/MainApplet.java
r104 r159 26 26 private MainCaller() { 27 27 setContentPane(contentPane); 28 setJMenuBar(m ainMenu);28 setJMenuBar(menu); 29 29 setBounds(bounds); 30 30 } -
src/org/openstreetmap/josm/gui/MainApplication.java
r155 r159 14 14 import java.util.LinkedList; 15 15 import java.util.List; 16 import java.util.Locale;17 16 import java.util.Map; 18 17 … … 23 22 import org.openstreetmap.josm.gui.layer.Layer; 24 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 import org.openstreetmap.josm.plugins.PluginException; 25 import org.openstreetmap.josm.plugins.PluginInformation; 25 26 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 27 import org.openstreetmap.josm.tools.ImageProvider; 26 28 /** 27 29 * Main window class application. … … 36 38 public MainApplication(JFrame mainFrame) { 37 39 mainFrame.setContentPane(contentPane); 38 mainFrame.setJMenuBar(m ainMenu);40 mainFrame.setJMenuBar(menu); 39 41 mainFrame.setBounds(bounds); 40 42 mainFrame.addWindowListener(new WindowAdapter(){ … … 73 75 ///////////////////////////////////////////////////////////////////////// 74 76 // Do not translate the early strings below until the locale is set up. 77 // (By the eager loaded plugins) 78 // 75 79 // These strings cannot be translated. That's live. Really. Sorry. 76 //77 // The next one sending me a patch translating these strings owe me a beer!78 80 // 79 81 // Imi. … … 118 120 } 119 121 120 // setup the locale121 if (args.containsKey("language") && !args.get("language").isEmpty() && args.get("language").iterator().next().length() >= 2) {122 String s = args.get("language").iterator().next();123 Locale l = null;124 if (s.length() <= 2 || s.charAt(2) != '_')125 l = new Locale(s);126 else if (s.length() <= 5 || s.charAt(5) != '.')127 l = new Locale(s.substring(0,2), s.substring(3));128 else129 l = new Locale(s.substring(0,2), s.substring(3,5), s.substring(6));130 Locale.setDefault(l);131 } else if (!Main.pref.get("language").equals("")) {132 String lang = Main.pref.get("language");133 for (Locale l : Locale.getAvailableLocales()) {134 if (l.toString().equals(lang)) {135 Locale.setDefault(l);136 break;122 // load the early plugins 123 if (Main.pref.hasKey("plugins")) { 124 for (String pluginName : Main.pref.get("plugins").split(",")) { 125 try { 126 File pluginFile = new File(pref.getPreferencesDir()+"plugins/"+pluginName+".jar"); 127 if (pluginFile.exists()) { 128 PluginInformation info = new PluginInformation(pluginFile); 129 if (!info.early) 130 continue; 131 Class<?> klass = info.loadClass(); 132 ImageProvider.sources.add(0, klass); 133 Main.plugins.add(info.load(klass)); 134 } else 135 System.out.println("Plugin not found: "+pluginName); 136 } catch (PluginException e) { 137 System.out.println("Could not load plugin "+pluginName); 138 e.printStackTrace(); 137 139 } 138 140 } 139 141 } 140 141 // Locale is set. From now on, tr(), trn() and trc() may be called.142 142 143 143 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) { -
src/org/openstreetmap/josm/gui/NavigatableComponent.java
r155 r159 267 267 } 268 268 if (osm instanceof Node || osm instanceof Segment) { 269 for (Way t: Main.ds.ways) {270 if ( t.deleted)269 for (Way w : Main.ds.ways) { 270 if (w.deleted) 271 271 continue; 272 for (Segment ls : t.segments) {272 for (Segment ls : w.segments) { 273 273 if (!ls.deleted && !ls.incomplete && c.contains(ls)) { 274 c.add( t);274 c.add(w); 275 275 break; 276 276 } -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r153 r159 14 14 import java.util.Collection; 15 15 import java.util.HashMap; 16 import java.util.HashSet; 17 import java.util.Locale; 16 import java.util.LinkedList; 18 17 import java.util.Map; 19 18 import java.util.StringTokenizer; … … 85 84 public void actionPerformed(ActionEvent e) { 86 85 Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName()); 87 Main.pref.put("language", languages.getSelectedItem().toString());88 86 Main.pref.put("projection", projectionCombo.getSelectedItem().getClass().getName()); 89 87 Main.pref.put("osm-server.url", osmDataServer.getText()); … … 156 154 */ 157 155 private JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels()); 158 private JComboBox languages = new JComboBox(new Locale[]{159 new Locale("en", "US"),160 new Locale("en", "GB"),161 Locale.GERMAN,162 Locale.FRENCH,163 new Locale("ro", "RO")});164 156 /** 165 157 * The main tab panel. … … 232 224 }); 233 225 lafCombo.addActionListener(requireRestartAction); 234 235 // language236 String lang = Main.pref.get("language");237 for (int i = 0; i < languages.getItemCount(); ++i) {238 if (languages.getItemAt(i).toString().equals(lang)) {239 languages.setSelectedIndex(i);240 break;241 }242 }243 languages.setRenderer(new DefaultListCellRenderer(){244 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {245 return super.getListCellRendererComponent(list, ((Locale)value).getDisplayName(), index, isSelected, cellHasFocus);246 }247 });248 languages.addActionListener(requireRestartAction);249 226 250 227 // projection combo box … … 285 262 286 263 Box pluginPanel = Box.createVerticalBox(); 287 Collection<PluginInformation> availablePlugins = new HashSet<PluginInformation>();264 Collection<PluginInformation> availablePlugins = new LinkedList<PluginInformation>(); 288 265 File[] pluginFiles = new File(Main.pref.getPreferencesDir()+"plugins").listFiles(); 289 if (pluginFiles != null) 266 if (pluginFiles != null) { 267 Arrays.sort(pluginFiles); 290 268 for (File f : pluginFiles) 291 269 if (f.isFile() && f.getName().endsWith(".jar")) 292 270 availablePlugins.add(new PluginInformation(f)); 271 } 293 272 294 273 Collection<String> enabledPlugins = Arrays.asList(Main.pref.get("plugins").split(",")); … … 320 299 for (Entry<String,String> e : allColors.entrySet()) { 321 300 Vector<Object> row = new Vector<Object>(2); 322 row.add( tr(e.getKey().substring("color.".length())));301 row.add(e.getKey().substring("color.".length())); 323 302 row.add(ColorHelper.html2color(e.getValue())); 324 303 rows.add(row); … … 342 321 return l; 343 322 } 344 return oldColorsRenderer.getTableCellRendererComponent(t, o,selected,focus,row,column);323 return oldColorsRenderer.getTableCellRendererComponent(t,tr(o.toString()),selected,focus,row,column); 345 324 } 346 325 }); … … 429 408 display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 430 409 display.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL)); 431 display.add(new JLabel(tr("Language")), GBC.std());432 display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));433 display.add(languages, GBC.eol().fill(GBC.HORIZONTAL));434 410 display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0)); 435 411 display.add(forceRawGpsLines, GBC.eop().insets(40,0,0,0)); … … 487 463 plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH)); 488 464 plugin.add(GBC.glue(0,10), GBC.eol()); 489 plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", "Get more plugins"), GBC.std().fill(GBC.HORIZONTAL));465 plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", tr("Get more plugins")), GBC.std().fill(GBC.HORIZONTAL)); 490 466 491 467 tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); … … 505 481 setModal(true); 506 482 pack(); 483 if (getHeight() > 400) 484 setSize(getWidth(), 400); 485 if (getWidth() > 600) 486 setSize(600, getHeight()); 507 487 setLocationRelativeTo(Main.parent); 508 488 } -
src/org/openstreetmap/josm/plugins/Plugin.java
r154 r159 1 1 package org.openstreetmap.josm.plugins; 2 2 3 import java.io.File; 3 4 import java.io.FileNotFoundException; 4 5 import java.io.FileOutputStream; … … 71 72 */ 72 73 public void copy(String from, String to) throws FileNotFoundException, IOException { 74 File pluginDir = new File(getPluginDir()); 75 if (!pluginDir.exists()) 76 pluginDir.mkdirs(); 73 77 FileOutputStream out = new FileOutputStream(getPluginDir()+to); 74 78 InputStream in = getClass().getResourceAsStream(from); -
src/org/openstreetmap/josm/plugins/PluginInformation.java
r157 r159 6 6 import java.net.URL; 7 7 import java.net.URLClassLoader; 8 import java.util.Map; 9 import java.util.TreeMap; 10 import java.util.jar.Attributes; 8 11 import java.util.jar.JarInputStream; 9 12 import java.util.jar.Manifest; … … 20 23 public final String className; 21 24 public final String description; 25 public final boolean early; 26 public final String author; 27 28 public final Map<String, String> attr = new TreeMap<String, String>(); 22 29 23 30 public PluginInformation(File file) { … … 25 32 name = file.getName().substring(0, file.getName().length()-4); 26 33 try { 27 JarInputStream jar = new JarInputStream(new FileInputStream(file)); 28 Manifest manifest = jar.getManifest(); 29 className = manifest.getMainAttributes().getValue("Plugin-Class"); 30 description = manifest.getMainAttributes().getValue("Plugin-Description"); 31 jar.close(); 32 } catch (IOException e) { 33 throw new PluginException(null, name, e); 34 } 35 } 34 JarInputStream jar = new JarInputStream(new FileInputStream(file)); 35 Manifest manifest = jar.getManifest(); 36 Attributes attr = manifest.getMainAttributes(); 37 className = attr.getValue("Plugin-Class"); 38 description = attr.getValue("Plugin-Description"); 39 early = Boolean.parseBoolean(attr.getValue("Plugin-Early")); 40 author = attr.getValue("Author"); 41 for (Object o : attr.keySet()) 42 this.attr.put(o.toString(), attr.getValue(o.toString())); 43 jar.close(); 44 } catch (IOException e) { 45 throw new PluginException(null, name, e); 46 } 47 } 36 48 37 49 /** 38 50 * Load and instantiate the plugin 39 51 */ 40 public PluginProxy load() { 52 public PluginProxy load(Class<?> klass) { 53 try { 54 return new PluginProxy(klass.newInstance(), this); 55 } catch (Exception e) { 56 throw new PluginException(null, name, e); 57 } 58 } 59 60 /** 61 * Load the class of the plugin 62 */ 63 public Class<?> loadClass() { 41 64 try { 42 65 ClassLoader loader = URLClassLoader.newInstance( 43 66 new URL[]{new URL(getURLString())}, 44 67 getClass().getClassLoader()); 45 Object plugin = Class.forName(className, true, loader).newInstance();46 return new PluginProxy(plugin, this);68 Class<?> realClass = Class.forName(className, true, loader); 69 return realClass; 47 70 } catch (Exception e) { 48 71 throw new PluginException(null, name, e); … … 54 77 return "file:/"+file.getAbsolutePath(); 55 78 return "file://"+file.getAbsolutePath(); 56 79 } 57 80 } -
src/org/openstreetmap/josm/tools/I18n.java
r158 r159 1 1 package org.openstreetmap.josm.tools; 2 2 3 import java.io.File;4 import java.net.URL;5 import java.net.URLClassLoader;6 3 import java.text.MessageFormat; 7 import java.util.Locale;8 import java.util.MissingResourceException;9 10 import org.openstreetmap.josm.Main;11 import org.xnap.commons.i18n.I18nFactory;12 4 13 5 /** … … 17 9 */ 18 10 public class I18n { 19 private static org.xnap.commons.i18n.I18n i18n; 20 21 static { 22 String localeFile = Main.pref.getPreferencesDir()+"lang/"+Locale.getDefault()+".jar"; 23 Class<?> klass = Main.class; 24 if (new File(localeFile).exists()) { 25 try { 26 String url = localeFile.replace('\\','/'); 27 if (System.getProperty("os.name").startsWith("Windows")) 28 url = "file:/"+url; 29 else 30 url = "file://"+url; 31 URLClassLoader loader = new URLClassLoader(new URL[]{new URL(url)}); 32 klass = Class.forName("org.openstreetmap.josm.Translation_"+Locale.getDefault(), true, loader); 33 } catch (Exception e) { 34 System.out.println("Couldn't load locale file "+localeFile); 35 e.printStackTrace(); 36 } 37 } 38 try { 39 i18n = I18nFactory.getI18n(klass); 40 } catch (MissingResourceException e) { 41 System.out.println("Locale '"+Locale.getDefault()+"' not found. Using default."); 42 } 43 } 11 /** 12 * Set by MainApplication. Changes here later will probably mess up everything, because 13 * many strings are already loaded. 14 */ 15 public static org.xnap.commons.i18n.I18n i18n; 44 16 45 17 public static String tr(String text, Object... objects) { -
src/org/openstreetmap/josm/tools/ImageProvider.java
r101 r159 12 12 import java.net.URL; 13 13 import java.util.HashMap; 14 import java.util.LinkedList; 15 import java.util.List; 14 16 import java.util.Map; 15 17 … … 37 39 38 40 /** 41 * Add here all ClassLoader whose ressource should be searched. 42 * Plugin's class loaders are added by main. 43 */ 44 public static final List<Class<?>> sources = new LinkedList<Class<?>>(); 45 46 /** 39 47 * Return an image from the specified location. 40 48 * … … 47 55 subdir += "/"; 48 56 String ext = name.indexOf('.') != -1 ? "" : ".png"; 49 URL path = Main.class.getResource("/images/"+subdir+name+ext); 57 URL path = null; 58 for (Class<?> source : sources) { 59 path = source.getResource("/images/"+subdir+name+ext); 60 if (path != null) 61 break; 62 } 50 63 if (path == null) 51 64 throw new NullPointerException("/images/"+subdir+name+ext+" not found"); … … 108 121 return new ImageIcon(img); 109 122 } 123 124 static { 125 sources.add(Main.class); 126 } 110 127 } -
src/org/openstreetmap/josm/tools/UrlLabel.java
r149 r159 21 21 setContentType("text/html"); 22 22 setText("<html><a href=\""+url+"\">"+description+"</a></html>"); 23 setToolTipText(url); 23 24 setEditable(false); 24 25 setOpaque(false);
Note:
See TracChangeset
for help on using the changeset viewer.