- Timestamp:
- 2007-07-06T00:38:51+02:00 (17 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r243 r277 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 import static org.openstreetmap.josm.tools.I18n.trn; 5 6 import java.awt.Dimension; 5 7 import java.awt.event.ActionEvent; 6 8 import java.awt.event.ActionListener; 7 9 import java.io.File; 10 import java.io.FileReader; 8 11 import java.util.Arrays; 9 12 import java.util.Collection; 10 import java.util.Collections;11 13 import java.util.Comparator; 12 14 import java.util.HashMap; 13 15 import java.util.LinkedList; 14 import java.util.List;15 16 import java.util.Map; 17 import java.util.SortedMap; 18 import java.util.TreeMap; 16 19 import java.util.Map.Entry; 17 20 18 21 import javax.swing.BorderFactory; 19 22 import javax.swing.Box; 23 import javax.swing.JButton; 20 24 import javax.swing.JCheckBox; 21 25 import javax.swing.JLabel; 26 import javax.swing.JOptionPane; 22 27 import javax.swing.JPanel; 23 28 import javax.swing.JScrollPane; 24 29 25 30 import org.openstreetmap.josm.Main; 31 import org.openstreetmap.josm.plugins.PluginDownloader; 26 32 import org.openstreetmap.josm.plugins.PluginException; 27 33 import org.openstreetmap.josm.plugins.PluginInformation; 34 import org.openstreetmap.josm.plugins.PluginProxy; 28 35 import org.openstreetmap.josm.tools.GBC; 29 import org.openstreetmap.josm.tools. UrlLabel;36 import org.openstreetmap.josm.tools.XmlObjectParser.Uniform; 30 37 31 38 public class PluginPreference implements PreferenceSetting { 32 39 33 private Map<PluginInformation, Boolean> pluginMap; 40 /** 41 * Only the plugin name, it's jar location and the description. 42 * In other words, this is the minimal requirement the plugin preference page 43 * needs to show the plugin as available 44 * 45 * @author imi 46 */ 47 public static class PluginDescription { 48 public String name; 49 public String description; 50 public String resource; 51 public PluginDescription(String name, String description, String resource) { 52 this.name = name; 53 this.description = description; 54 this.resource = resource; 55 } 56 public PluginDescription() { 57 } 58 } 59 60 private Map<PluginDescription, Boolean> pluginMap; 61 private Box pluginPanel = Box.createVerticalBox(); 62 private JPanel plugin; 34 63 35 64 public void addGui(final PreferenceDialog gui) { 36 pluginMap = new HashMap<PluginInformation, Boolean>(); 37 Box pluginPanel = Box.createVerticalBox(); 38 List<PluginInformation> availablePlugins = new LinkedList<PluginInformation>(); 39 for (String location : PluginInformation.getPluginLocations()) { 40 File[] pluginFiles = new File(location).listFiles(); 41 if (pluginFiles != null) { 42 Arrays.sort(pluginFiles); 43 for (File f : pluginFiles) { 44 if (f.isFile() && f.getName().endsWith(".jar")) { 45 try { 46 availablePlugins.add(new PluginInformation(f)); 47 } catch (PluginException x) { 48 } 49 } 50 } 51 } 52 } 53 Collections.sort(availablePlugins, new Comparator<PluginInformation>(){ 54 public int compare(PluginInformation o1, PluginInformation o2) { 55 return o1.name.compareTo(o2.name); 56 } 57 }); 58 65 plugin = gui.createPreferenceTab("plugin", tr("Plugins"), tr("Configure available Plugins.")); 66 JScrollPane pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 67 pluginPane.setBorder(null); 68 plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH)); 69 plugin.add(GBC.glue(0,10), GBC.eol()); 70 JButton morePlugins = new JButton(tr("Get more plugins")); 71 morePlugins.addActionListener(new ActionListener(){ 72 public void actionPerformed(ActionEvent e) { 73 int count = PluginDownloader.downloadDescription(); 74 if (count > 0) 75 JOptionPane.showMessageDialog(Main.parent, 76 trn("Downloaded plugin information from {0} site", 77 "Downloaded plugin information from {0} sites", count, count)); 78 else 79 JOptionPane.showMessageDialog(Main.parent, tr("No plugin information found.")); 80 refreshPluginPanel(gui); 81 } 82 }); 83 plugin.add(morePlugins, GBC.std().insets(0,0,10,0)); 84 85 JButton update = new JButton(tr("Update current")); 86 update.addActionListener(new ActionListener(){ 87 public void actionPerformed(ActionEvent e) { 88 JOptionPane.showMessageDialog(Main.parent, tr("Not implemented yet.")); 89 } 90 }); 91 plugin.add(update, GBC.std().insets(0,0,10,0)); 92 93 JButton configureSites = new JButton(tr("Configure Plugin Sites")); 94 configureSites.addActionListener(new ActionListener(){ 95 public void actionPerformed(ActionEvent e) { 96 JOptionPane.showMessageDialog(Main.parent, tr("Not implemented yet.")); 97 } 98 }); 99 plugin.add(configureSites, GBC.std()); 100 101 refreshPluginPanel(gui); 102 } 103 104 private void refreshPluginPanel(final PreferenceDialog gui) { 105 Collection<PluginDescription> availablePlugins = getAvailablePlugins(); 106 pluginMap = new HashMap<PluginDescription, Boolean>(); 107 pluginPanel.removeAll(); 59 108 Collection<String> enabledPlugins = Arrays.asList(Main.pref.get("plugins").split(",")); 60 for (final Plugin Information plugin : availablePlugins) {109 for (final PluginDescription plugin : availablePlugins) { 61 110 boolean enabled = enabledPlugins.contains(plugin.name); 62 111 final JCheckBox pluginCheck = new JCheckBox(plugin.name, enabled); 63 112 pluginPanel.add(pluginCheck); 64 113 65 pluginCheck.setToolTipText(plugin. file != null ? plugin.file.getAbsolutePath(): tr("Plugin bundled with JOSM"));114 pluginCheck.setToolTipText(plugin.resource != null ? plugin.resource : tr("Plugin bundled with JOSM")); 66 115 JLabel label = new JLabel("<html><i>"+(plugin.description==null?"no description available":plugin.description)+"</i></html>"); 67 116 label.setBorder(BorderFactory.createEmptyBorder(0,20,0,0)); 117 label.setMaximumSize(new Dimension(450,1000)); 68 118 pluginPanel.add(label); 69 119 pluginPanel.add(Box.createVerticalStrut(5)); … … 77 127 }); 78 128 } 79 JScrollPane pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 80 pluginPane.setBorder(null); 81 82 JPanel plugin = gui.createPreferenceTab("plugin", tr("Plugins"), tr("Configure available Plugins.")); 83 plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH)); 84 plugin.add(GBC.glue(0,10), GBC.eol()); 85 plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", tr("Get more plugins")), GBC.std().fill(GBC.HORIZONTAL)); 86 } 129 plugin.updateUI(); 130 } 131 132 private Collection<PluginDescription> getAvailablePlugins() { 133 SortedMap<String, PluginDescription> availablePlugins = new TreeMap<String, PluginDescription>(new Comparator<String>(){ 134 public int compare(String o1, String o2) { 135 return o1.compareToIgnoreCase(o2); 136 } 137 }); 138 for (String location : PluginInformation.getPluginLocations()) { 139 File[] pluginFiles = new File(location).listFiles(); 140 if (pluginFiles != null) { 141 for (File f : pluginFiles) { 142 if (!f.isFile()) 143 continue; 144 if (f.getName().endsWith(".jar")) { 145 try { 146 PluginInformation info = new PluginInformation(f); 147 availablePlugins.put(info.name, new PluginDescription(info.name, info.description, PluginInformation.getURLString(f.getPath()))); 148 } catch (PluginException x) { 149 } 150 } else if (f.getName().endsWith(".xml")) { 151 try { 152 Uniform<PluginDescription> parser = new Uniform<PluginDescription>(new FileReader(f), "plugin", PluginDescription.class); 153 for (PluginDescription pd : parser) 154 availablePlugins.put(pd.name, pd); 155 } catch (Exception e) { 156 e.printStackTrace(); 157 JOptionPane.showMessageDialog(Main.parent, tr("Error reading plugin information file: {0}", f.getName())); 158 } 159 } 160 } 161 } 162 } 163 for (PluginProxy proxy : Main.plugins) 164 if (!availablePlugins.containsKey(proxy.info.name)) 165 availablePlugins.put(proxy.info.name, new PluginDescription( 166 proxy.info.name, 167 proxy.info.description, 168 PluginInformation.getURLString(proxy.info.file.getPath()))); 169 return availablePlugins.values(); 170 } 87 171 88 172 public void ok() { 173 Collection<PluginDescription> toDownload = new LinkedList<PluginDescription>(); 174 String msg = ""; 175 for (Entry<PluginDescription, Boolean> entry : pluginMap.entrySet()) { 176 if (entry.getValue() && PluginInformation.findPlugin(entry.getKey().name) == null) { 177 toDownload.add(entry.getKey()); 178 msg += entry.getKey().name+"\n"; 179 } 180 } 181 if (!toDownload.isEmpty()) { 182 int answer = JOptionPane.showConfirmDialog(Main.parent, 183 tr("Download the following plugins?\n\n{0}", msg), 184 tr("Download missing plugins"), 185 JOptionPane.YES_NO_OPTION); 186 if (answer != JOptionPane.OK_OPTION) 187 for (PluginDescription pd : toDownload) 188 pluginMap.put(pd, false); 189 else 190 for (PluginDescription pd : toDownload) 191 PluginDownloader.downloadPlugin(pd); 192 } 193 89 194 String plugins = ""; 90 for (Entry<Plugin Information, Boolean> entry : pluginMap.entrySet())91 if (entry.getValue()) 195 for (Entry<PluginDescription, Boolean> entry : pluginMap.entrySet()) { 196 if (entry.getValue()) { 92 197 plugins += entry.getKey().name + ","; 198 if (PluginInformation.findPlugin(entry.getKey().name) == null) 199 toDownload.add(entry.getKey()); 200 } 201 } 93 202 if (plugins.endsWith(",")) 94 203 plugins = plugins.substring(0, plugins.length()-1); -
src/org/openstreetmap/josm/plugins/PluginInformation.java
r267 r277 32 32 public final String author; 33 33 public final int stage; 34 public final String version; 34 35 public final List<URL> libraries = new ArrayList<URL>(); 35 36 … … 64 65 String stageStr = attr.getValue("Plugin-Stage"); 65 66 stage = stageStr == null ? 50 : Integer.parseInt(stageStr); 67 version = attr.getValue("Plugin-Version"); 66 68 author = attr.getValue("Author"); 67 69 if (file != null) … … 118 120 } 119 121 120 p rivateString getURLString(String fileName) {122 public static String getURLString(String fileName) { 121 123 if (System.getProperty("os.name").startsWith("Windows")) 122 124 return "file:/"+fileName; -
src/org/openstreetmap/josm/tools/XmlObjectParser.java
r215 r277 66 66 if (mapping.containsKey(qname) && !mapping.get(qname).onStart) 67 67 report(); 68 else if (characters != null && !current.isEmpty()) 68 else if (characters != null && !current.isEmpty()) { 69 69 setValue(qname, characters); 70 characters = ""; 71 } 70 72 } 71 73 @Override public void characters(char[] ch, int start, int length) {
Note:
See TracChangeset
for help on using the changeset viewer.