Changeset 23227 in osm for applications/editors/josm
- Timestamp:
- 2010-09-16T21:39:21+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/toms/src/toms/Toms.java
r23193 r23227 4 4 package toms; 5 5 6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;7 import static org.openstreetmap.josm.tools.I18n.marktr;8 9 import java.awt.event.KeyEvent;10 import java.io.BufferedInputStream;11 import java.io.BufferedOutputStream;12 import java.io.File;13 import java.io.FileInputStream;14 import java.io.FileNotFoundException;15 import java.io.FileOutputStream;16 import java.io.IOException;17 import java.io.InputStream;18 import java.io.ObjectOutputStream;19 import java.lang.reflect.Method;20 import java.net.URL;21 import java.net.URLClassLoader;22 import java.util.ArrayList;23 import java.util.List;24 import java.util.Properties;25 import java.util.Set;26 import java.util.jar.JarEntry;27 import java.util.jar.JarFile;28 import java.util.jar.JarInputStream;29 import java.util.jar.JarOutputStream;30 import java.util.zip.ZipEntry;31 6 32 7 import javax.swing.JMenuItem; 33 import javax.swing.SwingUtilities; 8 34 9 35 10 import org.openstreetmap.josm.Main; 36 import org.openstreetmap.josm.gui.MainMenu;37 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;38 import org.openstreetmap.josm.gui.layer.Layer;39 11 import org.openstreetmap.josm.plugins.Plugin; 40 12 import org.openstreetmap.josm.plugins.PluginInformation; … … 42 14 43 15 import toms.dialogs.SmpDialogAction; 44 import toms.plug.PluginApp;45 import toms.plug.ifc.Pluggable;46 import toms.plug.util.PluginLoader;47 import toms.seamarks.SeaMark;48 16 49 17 // Kommentar zum Ausprobieren von svn … … 53 21 public class Toms extends Plugin { 54 22 55 56 23 private JMenuItem Smp; 24 private SmpDialogAction SmpDialog; 57 25 58 59 26 public Toms(PluginInformation info) { 27 super(info); 60 28 61 62 29 String os = ""; //$NON-NLS-1$ 30 String userHome = ""; //$NON-NLS-1$ 63 31 64 65 66 32 SmpDialog = new SmpDialogAction(); 33 Smp = Main.main.menu.toolsMenu.add(SmpDialog); 34 // Smp = MainMenu.add(Main.main.menu.toolsMenu, SmpDialog); 67 35 68 SmpDialog.setSmpItem(Smp); 69 SmpDialog.setOs(os); 70 SmpDialog.setUserHome(userHome); 71 Smp.setEnabled(false); 72 73 File pluginDir = Main.pref.getPluginsDirectory(); 74 String pluginDirName = pluginDir.getAbsolutePath(); 75 File tplug = new File(pluginDirName + "/tplug"); 76 if(!tplug.exists()) tplug.mkdir(); 77 78 // build ifc.jar from toms.jar 79 JarEntry ent = null; 80 BufferedInputStream inp = null; 81 String entName = null; 82 byte[] buffer = new byte[16384]; 83 int len; 84 85 try { 86 JarFile file = new JarFile(pluginDirName + "/toms.jar"); 87 FileOutputStream fos = new FileOutputStream(pluginDirName + "/tplug/ifc.jar"); 88 JarOutputStream jos = new JarOutputStream(fos); 89 BufferedOutputStream oos = new BufferedOutputStream( jos); 90 91 ent = file.getJarEntry("toms/plug/ifc/Pluggable.class"); 92 inp = new BufferedInputStream(file.getInputStream( ent )); 93 entName = ent.getName(); 94 95 jos.putNextEntry(new JarEntry(entName)); 96 97 while ((len = inp.read(buffer)) > 0) { 98 oos.write(buffer, 0, len); 99 } 100 101 oos.flush(); 102 inp.close(); 103 104 ent = file.getJarEntry("toms/plug/ifc/PluginManager.class"); 105 inp = new BufferedInputStream(file.getInputStream( ent )); 106 entName = ent.getName(); 107 jos.putNextEntry(new JarEntry(entName)); 108 109 while ((len = inp.read(buffer)) > 0) { 110 oos.write(buffer, 0, len); 111 } 112 113 oos.flush(); 114 oos.close(); 115 fos.flush(); 116 fos.close(); 117 inp.close(); 118 119 } catch (Exception e) { 120 e.printStackTrace(); 121 } 122 123 124 // add ifc.jar to classpath (josm need this archive, or perhaps only the interface) 125 File f = new java.io.File(pluginDirName + "/tplug/ifc.jar"); 126 ClassLoader myClassLoader = Thread.currentThread().getContextClassLoader(); 127 128 try { 129 Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class}); 130 addUrlMethod.setAccessible(true); 131 addUrlMethod.invoke(myClassLoader, f.toURI().toURL()); 132 } catch (Exception e) { 133 e.printStackTrace(); 134 } 135 136 137 try { 138 PluginApp.runPlugins(); 139 } catch (Exception e) { 140 e.printStackTrace(); 141 } 142 143 } 36 SmpDialog.setSmpItem(Smp); 37 SmpDialog.setOs(os); 38 SmpDialog.setUserHome(userHome); 39 Smp.setEnabled(false); 40 } 144 41 145 42 146 147 148 149 150 151 152 153 154 43 @Override 44 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 45 if (oldFrame == null && newFrame != null) { 46 Smp.setEnabled(true); 47 } else { 48 Smp.setEnabled(false); 49 SmpDialog.CloseDialog(); 50 } 51 } 155 52 156 53 }
Note:
See TracChangeset
for help on using the changeset viewer.