Changeset 3085 in josm


Ignore:
Timestamp:
2010-03-05T12:04:34+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #4670: Not Locilised #7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r3017 r3085  
    1414import java.awt.event.ComponentAdapter;
    1515import java.awt.event.ComponentEvent;
     16import java.util.ArrayList;
    1617import java.util.Collection;
    1718import java.util.Collections;
     
    4041import org.openstreetmap.josm.Main;
    4142import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     43import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    4244import org.openstreetmap.josm.gui.help.HelpUtil;
    4345import org.openstreetmap.josm.gui.preferences.plugin.PluginListPanel;
     
    185187
    186188    private void configureSites() {
    187         JPanel p = new JPanel(new GridBagLayout());
    188         p.add(new JLabel(tr("Add JOSM Plugin description URL.")), GBC.eol());
    189         final DefaultListModel model = new DefaultListModel();
    190         for (String s : Main.pref.getPluginSites()) {
    191             model.addElement(s);
    192         }
    193         final JList list = new JList(model);
    194         p.add(new JScrollPane(list), GBC.std().fill());
    195         JPanel buttons = new JPanel(new GridBagLayout());
    196         buttons.add(new JButton(new AbstractAction(tr("Add")){
    197             public void actionPerformed(ActionEvent e) {
    198                 String s = JOptionPane.showInputDialog(
    199                         JOptionPane.getFrameForComponent(pnlPluginPreferences),
    200                         tr("Add JOSM Plugin description URL."),
    201                         tr("Enter URL"),
    202                         JOptionPane.QUESTION_MESSAGE
    203                 );
    204                 if (s != null) {
    205                     model.addElement(s);
    206                 }
    207             }
    208         }), GBC.eol().fill(GBC.HORIZONTAL));
    209         buttons.add(new JButton(new AbstractAction(tr("Edit")){
    210             public void actionPerformed(ActionEvent e) {
    211                 if (list.getSelectedValue() == null) {
    212                     JOptionPane.showMessageDialog(
    213                             JOptionPane.getFrameForComponent(pnlPluginPreferences),
    214                             tr("Please select an entry."),
    215                             tr("Warning"),
    216                             JOptionPane.WARNING_MESSAGE
    217                     );
    218                     return;
    219                 }
    220                 String s = (String)JOptionPane.showInputDialog(
    221                         Main.parent,
    222                         tr("Edit JOSM Plugin description URL."),
    223                         tr("JOSM Plugin description URL"),
    224                         JOptionPane.QUESTION_MESSAGE,
    225                         null,
    226                         null,
    227                         list.getSelectedValue()
    228                 );
    229                 model.setElementAt(s, list.getSelectedIndex());
    230             }
    231         }), GBC.eol().fill(GBC.HORIZONTAL));
    232         buttons.add(new JButton(new AbstractAction(tr("Delete")){
    233             public void actionPerformed(ActionEvent event) {
    234                 if (list.getSelectedValue() == null) {
    235                     JOptionPane.showMessageDialog(
    236                             JOptionPane.getFrameForComponent(pnlPluginPreferences),
    237                             tr("Please select an entry."),
    238                             tr("Warning"),
    239                             JOptionPane.WARNING_MESSAGE
    240                     );
    241                     return;
    242                 }
    243                 model.removeElement(list.getSelectedValue());
    244             }
    245         }), GBC.eol().fill(GBC.HORIZONTAL));
    246         p.add(buttons, GBC.eol());
    247         int answer = JOptionPane.showConfirmDialog(
    248                 JOptionPane.getFrameForComponent(pnlPluginPreferences),
    249                 p,
    250                 tr("Configure Plugin Sites"), JOptionPane.OK_CANCEL_OPTION,
    251                 JOptionPane.PLAIN_MESSAGE);
    252         if (answer != JOptionPane.OK_OPTION)
     189        ButtonSpec[] options = new ButtonSpec[] {
     190                new ButtonSpec(
     191                        tr("OK"),
     192                        ImageProvider.get("ok"),
     193                        tr("Accept the new plugin sites and close the dialog"),
     194                        null /* no special help topic */
     195                ),
     196                new ButtonSpec(
     197                        tr("Cancel"),
     198                        ImageProvider.get("cancel"),
     199                        tr("Close the dialog"),
     200                        null /* no special help topic */
     201                )
     202        };
     203        PluginConfigurationSitesPanel pnl = new PluginConfigurationSitesPanel();
     204
     205        int answer = HelpAwareOptionPane.showOptionDialog(
     206                pnlPluginPreferences,
     207                pnl,
     208                tr("Configure Plugin Sites"),
     209                JOptionPane.QUESTION_MESSAGE,
     210                null,
     211                options,
     212                options[0],
     213                null /* no help topic */
     214        );
     215        if (answer != 0 /* OK */)
    253216            return;
    254         Collection<String> sites = new LinkedList<String>();
    255         for (int i = 0; i < model.getSize(); ++i) {
    256             sites.add((String)model.getElementAt(i));
    257         }
     217        List<String> sites = pnl.getUpdateSites();
    258218        Main.pref.setPluginSites(sites);
    259219    }
     
    450410        }
    451411    }
     412
     413    static private class PluginConfigurationSitesPanel extends JPanel {
     414
     415        private DefaultListModel model;
     416
     417        protected void build() {
     418            setLayout(new GridBagLayout());
     419            add(new JLabel(tr("Add JOSM Plugin description URL.")), GBC.eol());
     420            model = new DefaultListModel();
     421            for (String s : Main.pref.getPluginSites()) {
     422                model.addElement(s);
     423            }
     424            final JList list = new JList(model);
     425            add(new JScrollPane(list), GBC.std().fill());
     426            JPanel buttons = new JPanel(new GridBagLayout());
     427            buttons.add(new JButton(new AbstractAction(tr("Add")){
     428                public void actionPerformed(ActionEvent e) {
     429                    String s = JOptionPane.showInputDialog(
     430                            JOptionPane.getFrameForComponent(PluginConfigurationSitesPanel.this),
     431                            tr("Add JOSM Plugin description URL."),
     432                            tr("Enter URL"),
     433                            JOptionPane.QUESTION_MESSAGE
     434                    );
     435                    if (s != null) {
     436                        model.addElement(s);
     437                    }
     438                }
     439            }), GBC.eol().fill(GBC.HORIZONTAL));
     440            buttons.add(new JButton(new AbstractAction(tr("Edit")){
     441                public void actionPerformed(ActionEvent e) {
     442                    if (list.getSelectedValue() == null) {
     443                        JOptionPane.showMessageDialog(
     444                                JOptionPane.getFrameForComponent(PluginConfigurationSitesPanel.this),
     445                                tr("Please select an entry."),
     446                                tr("Warning"),
     447                                JOptionPane.WARNING_MESSAGE
     448                        );
     449                        return;
     450                    }
     451                    String s = (String)JOptionPane.showInputDialog(
     452                            Main.parent,
     453                            tr("Edit JOSM Plugin description URL."),
     454                            tr("JOSM Plugin description URL"),
     455                            JOptionPane.QUESTION_MESSAGE,
     456                            null,
     457                            null,
     458                            list.getSelectedValue()
     459                    );
     460                    model.setElementAt(s, list.getSelectedIndex());
     461                }
     462            }), GBC.eol().fill(GBC.HORIZONTAL));
     463            buttons.add(new JButton(new AbstractAction(tr("Delete")){
     464                public void actionPerformed(ActionEvent event) {
     465                    if (list.getSelectedValue() == null) {
     466                        JOptionPane.showMessageDialog(
     467                                JOptionPane.getFrameForComponent(PluginConfigurationSitesPanel.this),
     468                                tr("Please select an entry."),
     469                                tr("Warning"),
     470                                JOptionPane.WARNING_MESSAGE
     471                        );
     472                        return;
     473                    }
     474                    model.removeElement(list.getSelectedValue());
     475                }
     476            }), GBC.eol().fill(GBC.HORIZONTAL));
     477            add(buttons, GBC.eol());
     478        }
     479
     480        public PluginConfigurationSitesPanel() {
     481            build();
     482        }
     483
     484        public List<String> getUpdateSites() {
     485            if (model.getSize() == 0) return Collections.emptyList();
     486            List<String> ret = new ArrayList<String>(model.getSize());
     487            for (int i=0; i< model.getSize();i++){
     488                ret.add((String)model.get(i));
     489            }
     490            return ret;
     491        }
     492    }
    452493}
Note: See TracChangeset for help on using the changeset viewer.