Changeset 23382 in osm for applications/editors/josm
- Timestamp:
- 2010-09-28T00:43:08+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 198 added
- 10 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed/src/smed/Smed.java
r23282 r23382 22 22 import org.openstreetmap.josm.plugins.PluginInformation; 23 23 24 import smed.io.SmedFile; 24 25 import smed.plug.SmedPluginApp; 25 26 import smed.plug.ifc.SmedPluggable; … … 47 48 48 49 File[] jars = splugDir.listFiles(new JARFileFilter()); 50 SmedFile.init(); 49 51 50 52 // build smed_ifc.jar from smed.jar … … 80 82 inp.close(); 81 83 pfos.close(); 84 85 SmedFile.createMF(eName); 82 86 } 83 87 } … … 130 134 ex.printStackTrace(); 131 135 } 132 136 133 137 SmedTab = new SmedTabAction(); 134 138 item = Main.main.menu.toolsMenu.add(SmedTab); -
applications/editors/josm/plugins/smed/src/smed/io/SmedFile.java
r23328 r23382 1 package smed ;1 package smed.io; 2 2 3 3 import java.io.File; 4 import java.io.FileOutputStream; 5 import java.io.IOException; 6 import java.io.ObjectOutputStream; 7 import java.util.jar.Attributes; 8 import java.util.jar.JarFile; 9 import java.util.jar.JarOutputStream; 10 import java.util.jar.Manifest; 11 import java.util.zip.ZipEntry; 12 13 import smed.plug.ifc.SmedPluggable; 14 import smed.plug.util.JARFileFilter; 4 15 5 16 public class SmedFile extends File{ … … 9 20 */ 10 21 private static final long serialVersionUID = 1L; 22 private static File plugDir = null; 23 private static String pathname = null; 24 private static File[] plugJars = null; 11 25 12 26 public SmedFile(String pathname) { 13 27 super(pathname); 28 this.pathname = pathname; 29 plugDir = new File(pathname); 30 plugJars = plugDir.listFiles(new JARFileFilter()); 14 31 } 15 32 33 /** 34 * show if plugin need update 35 * 36 * @param jars 37 * @param name 38 * @return boolean true/false 39 */ 16 40 public boolean needUpdate(File[] jars, String name) { 17 18 41 for(File j : jars) { 19 42 String jName = j.getName(); … … 33 56 return true; 34 57 } 58 59 60 61 /** 62 * show if plugin is visible 63 * 64 * @param name 65 * @return boolean true/false 66 */ 67 public boolean isVisible(String name) { return getAttributeState("visible", name); } 68 69 /** 70 * show if plugin is deleted 71 * 72 * @param name 73 * @return boolean true/false 74 */ 75 public boolean isDeleted(String name) { return getAttributeState("deleted", name); } 76 77 public boolean getAttributeState(String attribute, String name) { 78 File f = getFile(plugJars, name, true); 79 80 if(f == null) return false; 81 else { 82 String str; 83 JarFile test; 84 try { 85 test = new JarFile(pathname + "/.ini/MF" + f.getName().substring(16)); 86 Manifest mf = test.getManifest(); 87 str = mf.getMainAttributes().getValue(attribute); 88 89 if(str == null || !str.equals("yes")) return false; 90 91 } catch (IOException e) { 92 e.printStackTrace(); 93 } 94 95 return true; 96 } 97 98 } 99 100 /** 101 * search file in files 102 * 103 * @param 104 * @return if found -> File, if not found -> null 105 */ 106 private static File getFile(File[] files, String name, Boolean isSmed) { 107 for(int i = 0; i < files.length; i++) { 108 String fileName = files[i].getName(); 109 110 if(isSmed) { 111 if(fileName.length() > 15) { // < 16 isn'nt a SmedFile 112 if (fileName.substring(16).equals("_" + name)) return files[i]; 113 } 114 } else if(fileName.equals(name)) return files[i]; 115 } 116 return null; 117 } 118 119 /** 120 * set the state "visible" of the plugin (name) 121 * 122 * @param name 123 * @param isVisible 124 */ 125 public void setVisible(String name, boolean isVisible) { setAttr("visible", name, isVisible); } 126 127 /** 128 * set the state "deleted" of the plugin (name) 129 * 130 * @param name 131 * @param isDeleted 132 */ 133 public void setDeleted(String name, boolean isDeleted) { setAttr("deleted", name, isDeleted); } 134 135 136 private void setAttr(String attribute, String name, boolean b) { 137 File f = getFile(plugJars,name,true); 138 if(f == null) return; 139 else { 140 try { 141 JarFile file = new JarFile(pathname + "/.ini/MF" + f.getName().substring(16)); 142 143 Manifest mf = file.getManifest(); 144 Attributes attr = mf.getMainAttributes(); 145 if(b) attr.putValue(attribute,"yes"); 146 else attr.putValue(attribute,"no"); 147 148 FileOutputStream fos = new FileOutputStream(pathname + "/.ini/MF" + f.getName().substring(16)); 149 JarOutputStream jos = new JarOutputStream(fos,mf); 150 jos.close(); 151 fos.flush(); 152 fos.close(); 153 154 } catch (IOException e) { 155 e.printStackTrace(); 156 } 157 } 158 } 159 160 /** 161 * copies the manifests from the plugin.jar to 162 * .ini/mf_plugin.jar. Necessary, because you 163 * can't modified the original jars under windows, 164 * (because under windows, they are used) 165 */ 166 private static void copyMFs(File[] plugInis) { 167 for(int i = 0; i < plugJars.length; i++) { 168 String source = plugJars[i].getName(); 169 String dest; 170 171 if(source.length() > 15) { // < 16 isn'nt a SmedFile 172 dest = "MF" + source.substring(16); 173 174 if(getFile(plugInis, dest, false) == null) { 175 try { 176 JarFile file = new JarFile(pathname + "/" + source); 177 Manifest mf = file.getManifest(); 178 Attributes attr = mf.getMainAttributes(); 179 attr.putValue("visible","yes"); 180 attr.putValue("deleted","no"); 181 182 FileOutputStream fos = new FileOutputStream(pathname + "/.ini/" + dest); 183 JarOutputStream jos = new JarOutputStream(fos,mf); 184 185 jos.close(); 186 fos.flush(); 187 fos.close(); 188 } catch (IOException e) { 189 e.printStackTrace(); 190 } 191 } 192 193 } 194 } 195 196 } 197 198 public static void init() { 199 File splugDirIni = new File(pathname + "/.ini"); 200 201 if(!splugDirIni.exists()) splugDirIni.mkdir(); 202 File[] plugInis = splugDirIni.listFiles(new JARFileFilter()); 203 204 copyMFs(plugInis); 205 206 SmedFile smedDir = new SmedFile(pathname); 207 208 for(int i = 0; i < plugJars.length; i++) { 209 File file = plugJars[i]; 210 211 if(file.getName().length() > 16) { // < 16 isn'nt a SmedFile 212 String name = file.getName().substring(17); 213 214 if(smedDir.isDeleted(name)) { 215 File fileMF = new File(pathname + "/.ini/MF_" + name); 216 217 fileMF.delete(); 218 file.delete(); 219 } 220 } 221 } 222 } 223 224 public static void createMF(String name) { 225 String dest; 226 if(name.length() > 17) { // < 17 isn'nt a SmedFile 227 dest = "MF_" + name.substring(17); 228 try { 229 JarFile file = new JarFile(pathname + "/" + name); 230 Manifest mf = file.getManifest(); 231 Attributes attr = mf.getMainAttributes(); 232 attr.putValue("visible","yes"); 233 attr.putValue("deleted","no"); 234 235 FileOutputStream fos = new FileOutputStream(pathname + "/.ini/" + dest); 236 JarOutputStream jos = new JarOutputStream(fos,mf); 237 238 jos.close(); 239 fos.flush(); 240 fos.close(); 241 } catch (IOException e) { 242 e.printStackTrace(); 243 } 244 } 245 } 246 35 247 } -
applications/editors/josm/plugins/smed/src/smed/menu/SmedMenuBar.java
r23324 r23382 38 38 39 39 menuItem.addActionListener(new java.awt.event.ActionListener() { 40 41 public void actionPerformed(java.awt.event.ActionEvent e) { 42 DefaultListModel myModel = new DefaultListModel(); 43 plugins = SmedTabbedPane.getPlugins(); 44 45 for(SmedPluggable p : plugins) myModel.addElement (p.getName()); 46 47 new TabManager(myModel); 48 } 49 }); 40 public void actionPerformed(java.awt.event.ActionEvent e) { new TabManager(); } 41 }); 50 42 51 43 -
applications/editors/josm/plugins/smed/src/smed/menu/file/TabManager.java
r23324 r23382 3 3 4 4 import javax.swing.DefaultListModel; 5 import javax.swing.Icon; 6 import javax.swing.JComponent; 5 7 import javax.swing.JDialog; 6 8 import javax.swing.JScrollPane; 9 import javax.swing.JTabbedPane; 7 10 8 11 import javax.swing.JPanel; … … 13 16 import java.awt.event.ActionEvent; 14 17 import java.awt.event.ActionListener; 18 import java.awt.event.KeyEvent; 19 import java.io.IOException; 15 20 import java.util.List; 16 21 … … 18 23 import javax.swing.JTextField; 19 24 25 import org.openstreetmap.josm.Main; 26 27 import smed.io.SmedFile; 20 28 import smed.jide.swing.CheckBoxList; 21 29 import smed.jide.swing.CheckBoxListSelectionModel; … … 33 41 private CheckBoxListSelectionModel selModel; 34 42 private List<SmedPluggable> plugins = null; 43 private SmedFile splugDir = null; 35 44 private int modelSize = 0; 36 45 … … 52 61 private JTextField tabTextFieldRename = null; 53 62 54 public TabManager( DefaultListModel model) {55 this.model =model;63 public TabManager() { 64 model = new DefaultListModel(); //model; 56 65 plugins = SmedTabbedPane.getPlugins(); 66 String pluginDirName = Main.pref.getPluginsDirectory().getAbsolutePath(); 67 splugDir = new SmedFile(pluginDirName + "/splug"); 68 69 for(SmedPluggable p : plugins){ 70 if(splugDir.isVisible(p.getFileName()) && !splugDir.isDeleted(p.getFileName())) model.addElement (p.getName()); 71 else if(splugDir.isDeleted(p.getFileName())) model.addElement("delete - " + p.getName()); 72 else model.addElement("invisible - " + p.getName()); 73 } 74 57 75 modelSize = model.getSize(); 58 76 getTabManagerDialog().setVisible(true); 59 77 } 60 78 79 61 80 /** 62 81 * This method initializes tabManagerDialog … … 200 219 tabButtonLoad = new JButton(); 201 220 tabButtonLoad.setBounds(new Rectangle(186, 328, 104, 30)); 202 tabButtonLoad.setFont(new Font("Dialog", Font. BOLD, 12));221 tabButtonLoad.setFont(new Font("Dialog", Font.PLAIN, 12)); 203 222 tabButtonLoad.setText("Load"); 204 223 tabButtonLoad.addActionListener(this); … … 217 236 tabButtonSave = new JButton(); 218 237 tabButtonSave.setBounds(new Rectangle(293, 328, 104, 30)); 219 tabButtonSave.setFont(new Font("Dialog", Font. BOLD, 12));238 tabButtonSave.setFont(new Font("Dialog", Font.PLAIN, 12)); 220 239 tabButtonSave.setText("Save"); 221 240 tabButtonSave.addActionListener(this); … … 234 253 tabButtonDelete = new JButton(); 235 254 tabButtonDelete.setBounds(new Rectangle(186, 362, 104, 30)); 255 tabButtonDelete.setFont(new Font("Dialog", Font.PLAIN, 12)); 236 256 tabButtonDelete.setText("Delete"); 237 257 tabButtonDelete.addActionListener(this); … … 250 270 tabButtonVisible = new JButton(); 251 271 tabButtonVisible.setBounds(new Rectangle(293, 362, 104, 30)); 272 tabButtonVisible.setFont(new Font("Dialog", Font.PLAIN, 12)); 252 273 tabButtonVisible.setText("invisible"); 253 274 tabButtonVisible.addActionListener(this); … … 309 330 310 331 if(cmd.equals("ok")) { 332 int i = 0; 333 JTabbedPane tabbedPane = SmedTabbedPane.getTabbedPane(); 334 Icon icon = null; 335 336 for(SmedPluggable p : plugins) { 337 String str = model.get(i).toString(); 338 339 if(str.length() > 9 && str.substring(0,9).equals("invisible")) { 340 splugDir.setVisible(p.getFileName(),false); 341 } else splugDir.setVisible(p.getFileName(),true); 342 343 if(str.length() > 6 && str.substring(0,6).equals("delete")) { 344 splugDir.setDeleted(p.getFileName(),true); 345 } else splugDir.setDeleted(p.getFileName(),false); 346 347 i++; 348 } 349 350 tabbedPane.removeAll(); 351 352 JComponent panel = null; 353 354 for(SmedPluggable p : plugins) { 355 if(splugDir.isVisible(p.getFileName()) && !splugDir.isDeleted(p.getFileName())) { 356 panel = p.getComponent(); 357 358 tabbedPane.addTab(p.getName(),icon, panel, p.getInfo()); 359 } 360 } 361 311 362 System.out.println("Aufraeumarbeiten beginnen"); 312 363 tabManagerDialog.setVisible(false); … … 331 382 } 332 383 333 if(cmd.equals("invisible")) { 334 for(int i = 0; i < modelSize ; i++) { 335 if(selModel.isSelectedIndex(i)) model.set(i,"invisible"); 336 } 337 } 338 339 if(cmd.equals("delete")) { 340 for(int i = 0; i < modelSize ; i++) { 341 if(selModel.isSelectedIndex(i)) model.set(i,""); 342 } 343 } 344 345 if(cmd.equals("undo")) { 346 int i = 0; 347 348 for(SmedPluggable p : plugins) model.set(i++,p.getName()); 349 selModel.removeSelectionInterval(0, modelSize - 1); 350 } 351 384 if(cmd.equals("invisible")) cmd("invisible - "); 385 if(cmd.equals("delete")) cmd ("delete - "); 386 if(cmd.equals("undo")) cmd(""); 387 } 388 389 private void cmd(String s) { 390 int i = 0; 391 392 for(SmedPluggable p : plugins) { 393 if(selModel.isSelectedIndex(i)) model.set(i,s + p.getName()); 394 i++; 395 } 352 396 } 353 397 -
applications/editors/josm/plugins/smed/src/smed/plug/ifc/SmedPluggable.java
r23261 r23382 9 9 boolean stop(); 10 10 String getName(); 11 String getFileName(); 11 12 String getInfo(); 12 13 JComponent getComponent(); -
applications/editors/josm/plugins/smed/src/smed/tabs/SmedTabAction.java
r23288 r23382 50 50 JFrame frame = new JFrame("TabbedPaneDemo"); 51 51 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 52 frame.setResizable(false); 53 frame.setAlwaysOnTop(true); 52 54 53 smedMenu.plugins = smedTabs.plugins;54 55 55 //Add content to the window. 56 56 frame.setJMenuBar(smedMenu); -
applications/editors/josm/plugins/smed/src/smed/tabs/SmedTabbedPane.java
r23324 r23382 1 1 package smed.tabs; 2 2 3 import java.awt.Dimension; 3 4 import java.awt.GridLayout; 4 5 import java.awt.event.KeyEvent; … … 14 15 import org.openstreetmap.josm.Main; 15 16 17 import smed.io.SmedFile; 16 18 import smed.plug.ifc.SmedPluggable; 17 19 import smed.plug.util.SmedPluginLoader; … … 25 27 26 28 static private List<SmedPluggable> plugins = null; 29 static private JTabbedPane tabbedPane = null; 27 30 28 31 public SmedTabbedPane() { … … 30 33 31 34 String pluginDirName = Main.pref.getPluginsDirectory().getAbsolutePath(); 35 32 36 try { 33 37 plugins = SmedPluginLoader.loadPlugins(new File(pluginDirName + "/splug")); 34 38 39 if(plugins != null) { 40 Icon icon = null; 41 tabbedPane = new JTabbedPane(); 42 43 JComponent panel; 44 int i = 0; 45 SmedFile splugDir = new SmedFile(pluginDirName + "/splug"); 46 47 for(SmedPluggable p : plugins) { 48 if(splugDir.isVisible(p.getFileName())) { 49 panel = p.getComponent(); 50 51 tabbedPane.addTab(p.getName(),icon, panel, p.getInfo()); 52 tabbedPane.setMnemonicAt(i, KeyEvent.VK_1 + i); 53 54 i++; 55 } else splugDir.setVisible(p.getFileName(),false); 56 } 57 58 //Add the tabbed pane to this panel. 59 add(tabbedPane); 60 61 tabbedPane.setPreferredSize(new Dimension(400, 400)); 62 63 //The following line enables to use scrolling tabs. 64 tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 65 } 35 66 } catch (IOException e) { 36 67 e.printStackTrace(); 37 } 68 } 38 69 39 if(plugins != null) { 40 Icon icon = null; 41 JTabbedPane tabbedPane = new JTabbedPane(); 42 43 JComponent panel; 44 int i = 0; 45 for(SmedPluggable p : plugins) { 46 panel = p.getComponent(); 47 tabbedPane.addTab(p.getName(),icon, panel, p.getInfo()); 48 tabbedPane.setMnemonicAt(i, KeyEvent.VK_1 + i); 49 50 i++; 51 } 52 53 //Add the tabbed pane to this panel. 54 add(tabbedPane); 55 56 //The following line enables to use scrolling tabs. 57 tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 58 } 59 } 70 } 60 71 61 public static List<SmedPluggable> getPlugins() { 62 return plugins; 63 } 72 public static List<SmedPluggable> getPlugins() { return plugins; } 73 public static JTabbedPane getTabbedPane() { return tabbedPane; } 64 74 } -
applications/editors/josm/plugins/smed_about/build.xml
r23244 r23382 134 134 --> 135 135 <manifest> 136 <attribute name="Author" value="Werner , Malcolm"/>136 <attribute name="Author" value="Werner"/> 137 137 <attribute name="Plugin-Class" value="smed.Smed"/> 138 138 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> … … 188 188 --> 189 189 <manifest> 190 <attribute name="Author" value="Werner , Malcolm"/>190 <attribute name="Author" value="Werner"/> 191 191 <attribute name="Plugin-Class" value="smed_ex.impl.SmedExImpl"/> 192 192 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> -
applications/editors/josm/plugins/smed_about/src/smed_about/SmedAbout.java
r23261 r23382 12 12 public class SmedAbout implements SmedPluggable{ 13 13 14 private boolean visible = true; 15 14 16 private JPanel jPanel = null; // @jve:decl-index=0:visual-constraint="43,24" 15 17 private JLabel jLabel = null; … … 78 80 } 79 81 82 @Override 83 public String getFileName() { return "smed_about.jar"; } 80 84 } -
applications/editors/josm/plugins/smed_ex/build.xml
r23244 r23382 135 135 --> 136 136 <manifest> 137 <attribute name="Author" value="Werner , Malcolm"/>137 <attribute name="Author" value="Werner"/> 138 138 <attribute name="Plugin-Class" value="smed.Smed"/> 139 139 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> … … 188 188 --> 189 189 <manifest> 190 <attribute name="Author" value="Werner , Malcolm"/>190 <attribute name="Author" value="Werner"/> 191 191 <attribute name="Plugin-Class" value="smed_ex.impl.SmedExImpl"/> 192 192 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> -
applications/editors/josm/plugins/smed_ex/src/smed_ex/SmedEx.java
r23261 r23382 16 16 public class SmedEx implements SmedPluggable { 17 17 18 private boolean visible = true; 19 18 20 private JPanel jPanel = null; // @jve:decl-index=0:visual-constraint="78,30" 19 21 private JButton jButton = null; … … 93 95 } 94 96 97 @Override 98 public String getFileName() { return "smed_ex.jar"; } 95 99 }
Note:
See TracChangeset
for help on using the changeset viewer.