Changeset 150 in josm for src


Ignore:
Timestamp:
2006-10-05T23:33:14+02:00 (18 years ago)
Author:
imi
Message:
  • fixed saving of plugins
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r149 r150  
    1111import java.awt.event.ActionListener;
    1212import java.io.File;
     13import java.util.Arrays;
    1314import java.util.Collection;
    1415import java.util.HashMap;
     
    6263
    6364        private final class RequireRestartAction implements ActionListener {
    64             public void actionPerformed(ActionEvent e) {
    65                 requiresRestart = true;
    66             }
    67     }
     65                public void actionPerformed(ActionEvent e) {
     66                        requiresRestart = true;
     67                }
     68        }
    6869        private RequireRestartAction requireRestartAction = new RequireRestartAction();
    6970
     
    107108                                Main.pref.put("annotation.sources", null);
    108109
     110                        String plugins = "";
     111                        for (Entry<String, Boolean> entry : pluginMap.entrySet())
     112                                if (entry.getValue())
     113                                        plugins += entry.getKey() + ",";
     114                        if (plugins.endsWith(","))
     115                                plugins = plugins.substring(0, plugins.length()-1);
     116                        Main.pref.put("plugins", plugins);
     117
    109118                        for (int i = 0; i < colors.getRowCount(); ++i) {
    110119                                String name = (String)colors.getValueAt(i, 0);
     
    196205        private JComboBox projectionCombo = new JComboBox(Projection.allProjections);
    197206        private JList annotationSources = new JList(new DefaultListModel());
    198         private Map<PluginProxy, Boolean> pluginMap = new HashMap<PluginProxy, Boolean>();
     207        private Map<String, Boolean> pluginMap = new HashMap<String, Boolean>();
    199208
    200209
     
    234243                languages.setRenderer(new DefaultListCellRenderer(){
    235244                        @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    236                     return super.getListCellRendererComponent(list, ((Locale)value).getDisplayName(), index, isSelected, cellHasFocus);
    237             }
     245                                return super.getListCellRendererComponent(list, ((Locale)value).getDisplayName(), index, isSelected, cellHasFocus);
     246                        }
    238247                });
    239248                languages.addActionListener(requireRestartAction);
     
    277286                Box pluginPanel = Box.createVerticalBox();
    278287                Collection<String> availablePlugins = new HashSet<String>();
    279                 for (File f : new File(Main.pref.getPreferencesDir()+"plugins").listFiles()) {
    280                         if (!f.isFile() || !f.getName().endsWith(".jar"))
    281                                 continue;
    282                         availablePlugins.add(f.getName().substring(0, f.getName().length()-4));
    283                 }
    284                 for (PluginProxy plugin : Main.plugins) {
    285                         boolean available = availablePlugins.contains(plugin.name);
    286                         JCheckBox pluginCheck = new JCheckBox(plugin.name, available);
    287                         String desc = plugin.getDescription();
     288                File[] pluginFiles = new File(Main.pref.getPreferencesDir()+"plugins").listFiles();
     289                if (pluginFiles != null) {
     290                        for (File f : pluginFiles) {
     291                                if (!f.isFile() || !f.getName().endsWith(".jar"))
     292                                        continue;
     293                                availablePlugins.add(f.getName().substring(0, f.getName().length()-4));
     294                        }
     295                }
     296                Collection<String> enabledPlugins = Arrays.asList(Main.pref.get("plugins").split(","));
     297                for (final String plugin : availablePlugins) {
     298                        boolean enabled = enabledPlugins.contains(plugin);
     299                        String desc = null;
     300                        for (PluginProxy p : Main.plugins) {
     301                                if (p.name.equals(plugin)) {
     302                                        desc = p.getDescription();
     303                                        break;
     304                                }
     305                        }
     306
     307                        final JCheckBox pluginCheck = new JCheckBox(plugin, enabled);
    288308                        pluginPanel.add(pluginCheck);
    289309                        if (desc != null) {
     
    294314                                pluginPanel.add(Box.createVerticalStrut(5));
    295315                        }
    296                         pluginMap.put(plugin, available);
    297                 }
    298                 JScrollPane pluginPane = new JScrollPane(pluginPanel);
     316                        pluginMap.put(plugin, enabled);
     317                        pluginCheck.addActionListener(new ActionListener(){
     318                                public void actionPerformed(ActionEvent e) {
     319                                        pluginMap.put(plugin, pluginCheck.isSelected());
     320                                        requiresRestart = true;
     321                                }
     322                        });
     323                }
     324                JScrollPane pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    299325                pluginPane.setBorder(null);
    300                
     326
    301327                Map<String,String> allColors = new TreeMap<String, String>(Main.pref.getAllPrefix("color."));
    302328
     
    466492                map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    467493
    468                
     494
    469495                // Plugin tab
    470496                JPanel plugin = createPreferenceTab("plugin", tr("Plugins"), tr("Configure available Plugins."));
    471497                plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH));
    472498                plugin.add(GBC.glue(0,10), GBC.eol());
    473                 plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", "Get more plugins"), GBC.std());
     499                plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", "Get more plugins"), GBC.std().fill(GBC.HORIZONTAL));
    474500
    475501                tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
Note: See TracChangeset for help on using the changeset viewer.