source: osm/applications/editors/josm/plugins/smed/src/smed/Smed.java@ 23236

Last change on this file since 23236 was 23236, checked in by postfix, 14 years ago

wieder da

  • Property svn:executable set to *
File size: 4.5 KB
Line 
1package smed;
2
3import java.io.BufferedInputStream;
4import java.io.BufferedOutputStream;
5import java.io.File;
6import java.io.FileOutputStream;
7import java.lang.reflect.Method;
8import java.net.URL;
9import java.net.URLClassLoader;
10import java.util.Enumeration;
11import java.util.List;
12import java.util.jar.JarEntry;
13import java.util.jar.JarFile;
14import java.util.jar.JarOutputStream;
15
16import javax.swing.JMenuItem;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.gui.MapFrame;
20import org.openstreetmap.josm.plugins.Plugin;
21import org.openstreetmap.josm.plugins.PluginInformation;
22
23import smed.plug.SmedPluginApp;
24import smed.plug.ifc.SmedPluggable;
25import smed.plug.util.SmedPluginLoader;
26import smed.tabs.SmedTabAction;
27
28public class Smed extends Plugin{
29
30 private JMenuItem item;
31 private SmedTabAction SmedTab;
32
33 public Smed(PluginInformation info) {
34 super(info);
35
36 String os = "";
37 String userHome = "";
38
39 File pluginDir = Main.pref.getPluginsDirectory();
40 String pluginDirName = pluginDir.getAbsolutePath();
41 File splug = new File(pluginDirName + "/splug");
42 if(!splug.exists()) splug.mkdir();
43
44 // build smed_ifc.jar from smed.jar
45 JarEntry e = null;
46 BufferedInputStream inp = null;
47 String eName = null;
48 byte[] buffer = new byte[16384];
49 int len;
50
51 System.out.println(new java.util.Date());
52
53 try {
54 JarFile file = new JarFile(pluginDirName + "/smed.jar");
55 FileOutputStream fos = new FileOutputStream(pluginDirName + "/splug/smed_ifc.jar");
56 JarOutputStream jos = new JarOutputStream(fos);
57 BufferedOutputStream oos = new BufferedOutputStream( jos);
58
59 /* nicht ohne Versionierung freigeben
60 // extract *.jar to splug
61 Enumeration<JarEntry> ent = file.entries();
62 while(ent.hasMoreElements()) {
63 e = ent.nextElement();
64 eName = e.getName();
65 if(eName.endsWith(".jar")) {
66 FileOutputStream pfos = new FileOutputStream(pluginDirName + "/splug/" + eName);
67 BufferedOutputStream pos = new BufferedOutputStream(pfos);
68 inp = new BufferedInputStream(file.getInputStream( e ));
69
70 while ((len = inp.read(buffer)) > 0) {
71 pos.write(buffer, 0, len);
72 }
73
74 pos.flush();
75 pos.close();
76 inp.close();
77 pfos.close();
78 }
79 }
80 */
81
82 // write smed_ifc.jar to splug
83 e = file.getJarEntry("smed/plug/ifc/SmedPluggable.class");
84 inp = new BufferedInputStream(file.getInputStream( e ));
85 eName = e.getName();
86
87 jos.putNextEntry(new JarEntry(eName));
88
89 while ((len = inp.read(buffer)) > 0) {
90 oos.write(buffer, 0, len);
91 }
92
93 oos.flush();
94 inp.close();
95
96 e = file.getJarEntry("smed/plug/ifc/SmedPluginManager.class");
97 inp = new BufferedInputStream(file.getInputStream( e ));
98 eName = e.getName();
99 jos.putNextEntry(new JarEntry(eName));
100
101 while ((len = inp.read(buffer)) > 0) {
102 oos.write(buffer, 0, len);
103 }
104
105 oos.flush();
106 oos.close();
107 fos.flush();
108 fos.close();
109 inp.close();
110
111 } catch (Exception ex) {
112 ex.printStackTrace();
113 }
114
115 // add smed_ifc.jar to classpath (josm need this archive, or perhaps only the interface)
116 File f = new java.io.File(pluginDirName + "/splug/smed_ifc.jar");
117 ClassLoader myClassLoader = Thread.currentThread().getContextClassLoader();
118
119 try {
120 Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
121 addUrlMethod.setAccessible(true);
122 addUrlMethod.invoke(myClassLoader, f.toURI().toURL());
123 } catch (Exception ex) {
124 ex.printStackTrace();
125 }
126
127 SmedTab = new SmedTabAction();
128 item = Main.main.menu.toolsMenu.add(SmedTab);
129
130 item.setEnabled(false);
131
132 }
133
134 @Override
135 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
136 if (oldFrame == null && newFrame != null) {
137 item.setEnabled(true);
138 } else {
139 item.setEnabled(false);
140 // SmpDialog.CloseDialog();
141 }
142 }
143
144}
Note: See TracBrowser for help on using the repository browser.