Changeset 23261 in osm for applications/editors/josm/plugins/smed
- Timestamp:
- 2010-09-19T11:55:14+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/smed/src/smed
- Files:
-
- 6 edited
-
Smed.java (modified) (2 diffs)
-
SmedFile.java (modified) (1 diff)
-
menu/SmedMenuBar.java (modified) (1 diff)
-
plug/ifc/SmedPluggable.java (modified) (1 diff)
-
plug/util/SmedPluginLoader.java (modified) (1 diff)
-
tabs/SmedTabbedPane.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed/src/smed/Smed.java
r23244 r23261 42 42 String pluginDirName = pluginDir.getAbsolutePath(); 43 43 SmedFile splugDir = new SmedFile(pluginDirName + "/splug"); 44 44 45 45 if(!splugDir.exists()) splugDir.mkdir(); 46 46 47 47 File[] jars = splugDir.listFiles(new JARFileFilter()); 48 48 49 49 // build smed_ifc.jar from smed.jar 50 50 JarEntry e = null; … … 59 59 JarOutputStream jos = new JarOutputStream(fos); 60 60 BufferedOutputStream oos = new BufferedOutputStream( jos); 61 61 62 62 // extract *.jar to splug 63 63 Enumeration<JarEntry> ent = file.entries(); 64 64 while(ent.hasMoreElements()) { 65 e = ent.nextElement();66 eName = e.getName();67 if(eName.endsWith(".jar")) {68 if(splugDir.needUpdate(jars,eName)) {69 FileOutputStream pfos = new FileOutputStream(pluginDirName + "/splug/" + eName);70 BufferedOutputStream pos = new BufferedOutputStream(pfos);71 inp = new BufferedInputStream(file.getInputStream( e ));72 73 while ((len = inp.read(buffer)) > 0) {74 pos.write(buffer, 0, len);75 }76 77 pos.flush();78 pos.close();79 inp.close();80 pfos.close();81 }82 }65 e = ent.nextElement(); 66 eName = e.getName(); 67 if(eName.endsWith(".jar")) { 68 if(splugDir.needUpdate(jars,eName)) { 69 FileOutputStream pfos = new FileOutputStream(pluginDirName + "/splug/" + eName); 70 BufferedOutputStream pos = new BufferedOutputStream(pfos); 71 inp = new BufferedInputStream(file.getInputStream( e )); 72 73 while ((len = inp.read(buffer)) > 0) { 74 pos.write(buffer, 0, len); 75 } 76 77 pos.flush(); 78 pos.close(); 79 inp.close(); 80 pfos.close(); 81 } 82 } 83 83 } 84 85 84 86 85 86 87 87 // write smed_ifc.jar to splug 88 88 e = file.getJarEntry("smed/plug/ifc/SmedPluggable.class"); -
applications/editors/josm/plugins/smed/src/smed/SmedFile.java
r23244 r23261 7 7 public class SmedFile extends File{ 8 8 9 /**10 *11 */12 private static final long serialVersionUID = 1L;9 /** 10 * 11 */ 12 private static final long serialVersionUID = 1L; 13 13 14 public SmedFile(String pathname) {15 super(pathname);16 }14 public SmedFile(String pathname) { 15 super(pathname); 16 } 17 17 18 public boolean needUpdate(File[] jars, String name) {19 20 for(File j : jars) {21 String jName = j.getName();22 23 if(jName.length() > 15) { // < 16 isn'nt a SmedFile18 public boolean needUpdate(File[] jars, String name) { 19 20 for(File j : jars) { 21 String jName = j.getName(); 22 23 if(jName.length() > 15) { // < 16 isn'nt a SmedFile 24 24 25 if (jName.substring(16).equals(name.substring(16))) {26 if(jName.substring(0, 15).compareTo(name.substring(0, 15)) < 0) { // obsolet27 j.delete();28 return true;29 } else return false;// no update needed30 }31 }32 }25 if (jName.substring(16).equals(name.substring(16))) { 26 if(jName.substring(0, 15).compareTo(name.substring(0, 15)) < 0) { // obsolet 27 j.delete(); 28 return true; 29 } else return false; // no update needed 30 } 31 } 32 } 33 33 34 // nothing found -> extract35 return true;36 }34 // nothing found -> extract 35 return true; 36 } 37 37 } -
applications/editors/josm/plugins/smed/src/smed/menu/SmedMenuBar.java
r23259 r23261 9 9 public class SmedMenuBar extends JMenuBar { 10 10 11 /**12 * 13 */14 private static final long serialVersionUID = 1L;15 16 JMenuBar menuBar;17 JMenu menu, submenu;18 JMenuItem menuItem;19 20 public SmedMenuBar() {21 menuBar = new JMenuBar();22 11 /** 12 * 13 */ 14 private static final long serialVersionUID = 1L; 15 16 JMenuBar menuBar; 17 JMenu menu, submenu; 18 JMenuItem menuItem; 19 20 public SmedMenuBar() { 21 menuBar = new JMenuBar(); 22 23 23 menu = new JMenu("File"); 24 24 menu.setMnemonic(KeyEvent.VK_F); 25 25 menu.getAccessibleContext().setAccessibleDescription( 26 26 "The only menu in this program that has menu items"); 27 27 28 28 menuItem = new JMenuItem("Hide", 29 29 KeyEvent.VK_H); 30 30 31 31 menuItem.addActionListener(new java.awt.event.ActionListener() { 32 public void actionPerformed(java.awt.event.ActionEvent e) {33 System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()34 }35 });32 public void actionPerformed(java.awt.event.ActionEvent e) { 33 System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() 34 } 35 }); 36 36 37 37 38 38 menu.add(menuItem); 39 39 40 40 menuBar.add(menu); 41 42 add(menuBar);43 }41 42 add(menuBar); 43 } 44 44 45 45 } -
applications/editors/josm/plugins/smed/src/smed/plug/ifc/SmedPluggable.java
r23244 r23261 6 6 public interface SmedPluggable { 7 7 8 boolean start();9 boolean stop();10 String getName();11 String getInfo();12 JComponent getComponent();13 14 void setPluginManager(SmedPluginManager manager);8 boolean start(); 9 boolean stop(); 10 String getName(); 11 String getInfo(); 12 JComponent getComponent(); 13 14 void setPluginManager(SmedPluginManager manager); 15 15 16 16 } -
applications/editors/josm/plugins/smed/src/smed/plug/util/SmedPluginLoader.java
r23236 r23261 21 21 22 22 23 public static List<SmedPluggable> loadPlugins(File plugDir) throws IOException {24 File[] plugJars = plugDir.listFiles(new JARFileFilter());25 Arrays.sort(plugJars);26 27 URL[] urls = fileArrayToURLArray(plugJars);28 if(urls == null) return null;29 30 ClassLoader cl = new URLClassLoader(urls);31 List<Class<SmedPluggable>> plugClasses = extractClassesFromJARs(plugJars, cl);32 33 if(plugClasses == null) return null;34 else return createPluggableObjects(plugClasses);35 }23 public static List<SmedPluggable> loadPlugins(File plugDir) throws IOException { 24 File[] plugJars = plugDir.listFiles(new JARFileFilter()); 25 Arrays.sort(plugJars); 26 27 URL[] urls = fileArrayToURLArray(plugJars); 28 if(urls == null) return null; 29 30 ClassLoader cl = new URLClassLoader(urls); 31 List<Class<SmedPluggable>> plugClasses = extractClassesFromJARs(plugJars, cl); 32 33 if(plugClasses == null) return null; 34 else return createPluggableObjects(plugClasses); 35 } 36 36 37 37 private static List<SmedPluggable> createPluggableObjects(List<Class<SmedPluggable>> pluggables) { -
applications/editors/josm/plugins/smed/src/smed/tabs/SmedTabbedPane.java
r23236 r23261 24 24 private static final long serialVersionUID = 1L; 25 25 26 public SmedTabbedPane() { 27 super(new GridLayout(1, 1)); 28 29 List<SmedPluggable> plugins = null; 30 String pluginDirName = Main.pref.getPluginsDirectory().getAbsolutePath(); 31 try { 32 plugins = SmedPluginLoader.loadPlugins(new File(pluginDirName + "/splug")); 33 } catch (IOException e) { 34 e.printStackTrace(); 35 } 36 37 if(plugins != null) { 38 Icon icon = null; 39 JTabbedPane tabbedPane = new JTabbedPane(); 26 public SmedTabbedPane() { 27 super(new GridLayout(1, 1)); 40 28 41 JComponent panel; 42 int i = 0; 43 for(SmedPluggable p : plugins) { 44 panel = p.getComponent(); 45 tabbedPane.addTab(p.getName(),icon, panel, p.getInfo()); 46 tabbedPane.setMnemonicAt(i, KeyEvent.VK_1 + i); 47 48 i++; 49 } 29 List<SmedPluggable> plugins = null; 30 String pluginDirName = Main.pref.getPluginsDirectory().getAbsolutePath(); 31 try { 32 plugins = SmedPluginLoader.loadPlugins(new File(pluginDirName + "/splug")); 33 } catch (IOException e) { 34 e.printStackTrace(); 35 } 50 36 51 //Add the tabbed pane to this panel. 52 add(tabbedPane); 37 if(plugins != null) { 38 Icon icon = null; 39 JTabbedPane tabbedPane = new JTabbedPane(); 53 40 54 //The following line enables to use scrolling tabs. 55 tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 56 } 41 JComponent panel; 42 int i = 0; 43 for(SmedPluggable p : plugins) { 44 panel = p.getComponent(); 45 tabbedPane.addTab(p.getName(),icon, panel, p.getInfo()); 46 tabbedPane.setMnemonicAt(i, KeyEvent.VK_1 + i); 47 48 i++; 49 } 50 51 //Add the tabbed pane to this panel. 52 add(tabbedPane); 53 54 //The following line enables to use scrolling tabs. 55 tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 56 } 57 57 } 58 58 }
Note:
See TracChangeset
for help on using the changeset viewer.
