Changeset 23199 in osm for applications/editors
- Timestamp:
- 2010-09-15T20:11:07+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/smed/src/smed
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed/src/smed/plug/ifc/SmedPluggable.java
r23193 r23199 6 6 public interface SmedPluggable { 7 7 8 boolean start(); 9 boolean start(JComponent panel); 10 boolean stop(); 11 String getName(); 12 13 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 14 16 } 15 17 -
applications/editors/josm/plugins/smed/src/smed/plug/util/SmedPluginLoader.java
r23194 r23199 9 9 import java.net.URLClassLoader; 10 10 import java.util.ArrayList; 11 import java.util.Arrays; 11 12 import java.util.Collection; 12 13 import java.util.List; … … 19 20 public class SmedPluginLoader { 20 21 21 public static List<SmedPluggable> loadPlugins(File plugDir) throws IOException { 22 File[] plugJars = plugDir.listFiles(new JARFileFilter()); 23 24 URL[] urls = fileArrayToURLArray(plugJars); 25 if(urls == null) return null; 26 27 ClassLoader cl = new URLClassLoader(urls); 28 List<Class<SmedPluggable>> plugClasses = extractClassesFromJARs(plugJars, cl); 29 30 if(plugClasses == null) return null; 31 else return createPluggableObjects(plugClasses); 32 } 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 } 33 36 34 37 private static List<SmedPluggable> createPluggableObjects(List<Class<SmedPluggable>> pluggables) { -
applications/editors/josm/plugins/smed/src/smed/tabs/SmedTabbedPane.java
r23194 r23199 1 1 package smed.tabs; 2 2 3 import java.awt.Dimension;4 3 import java.awt.GridLayout; 5 4 import java.awt.event.KeyEvent; … … 10 9 import javax.swing.Icon; 11 10 import javax.swing.JComponent; 12 import javax.swing.JLabel;13 11 import javax.swing.JPanel; 14 12 import javax.swing.JTabbedPane; … … 26 24 private static final long serialVersionUID = 1L; 27 25 28 @SuppressWarnings("null") 29 public SmedTabbedPane() { 30 super(new GridLayout(1, 1)); 31 32 List<SmedPluggable>plugins = null;33 String pluginDirName = Main.pref.getPluginsDirectory().getAbsolutePath(); 34 try { 35 plugins = SmedPluginLoader.loadPlugins(new File(pluginDirName + "/splug")); 36 } catch (IOException e) { 37 e.printStackTrace(); 38 } 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 39 37 40 38 Icon icon = null; 41 39 JTabbedPane tabbedPane = new JTabbedPane(); 42 40 43 JComponent panel1; 44 if(plugins == null) { 45 panel1 = makeTextPanel("Panel #1"); 46 tabbedPane.addTab("Tab 1", icon , panel1, "Does nothing"); 47 } else { 48 panel1 = new JPanel(); 49 plugins.get(0).start(panel1); 50 tabbedPane.addTab(plugins.get(0).getName(), icon , panel1, "say hello"); 51 } 52 53 tabbedPane.setMnemonicAt(0, KeyEvent.VK_1); 54 55 56 JComponent panel2 = makeTextPanel("Panel #2"); 57 tabbedPane.addTab("Tab 2", icon, panel2, "Does twice as much nothing"); 58 tabbedPane.setMnemonicAt(1, KeyEvent.VK_2); 59 60 JComponent panel3 = makeTextPanel("Panel #3"); 61 tabbedPane.addTab("Tab 3", icon, panel3, "Still does nothing"); 62 tabbedPane.setMnemonicAt(2, KeyEvent.VK_3); 63 64 JComponent panel4 = makeTextPanel( "Panel #4 (has a preferred size of 410 x 50)."); 65 panel4.setPreferredSize(new Dimension(410, 50)); 66 tabbedPane.addTab("Tab 4", icon, panel4, "Does nothing at all"); 67 tabbedPane.setMnemonicAt(3, KeyEvent.VK_4); 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 } 68 50 69 51 //Add the tabbed pane to this panel. … … 73 55 tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 74 56 } 75 76 private JComponent makeTextPanel(String text) {77 JPanel panel = new JPanel(false);78 JLabel filler = new JLabel(text);79 filler.setHorizontalAlignment(JLabel.CENTER);80 panel.setLayout(new GridLayout(1, 1));81 panel.add(filler);82 83 return panel;84 }85 57 }
Note:
See TracChangeset
for help on using the changeset viewer.