Ticket #2907: wmsplugin_prefs_usability.patch

File wmsplugin_prefs_usability.patch, 3.7 KB (added by xeen, 17 years ago)
  • src/wmsplugin/WMSPreferenceEditor.java

     
    2727import org.openstreetmap.josm.tools.GBC;
    2828
    2929public class WMSPreferenceEditor implements PreferenceSetting {
    30     private Map<String,String> orig;
    3130    private DefaultTableModel model;
    3231    private JComboBox browser;
    3332    private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>();
     
    5352            public boolean isCellEditable(int row,int column){return false;}
    5453        };
    5554        JScrollPane scrolldef = new JScrollPane(listdef);
    56         p.add(scrolldef, GBC.eol().insets(0,5,0,0).fill(GBC.BOTH));
     55        // scrolldef is added after the buttons so it's clearer the buttons
     56        // control the top list and not the default one
    5757        scrolldef.setPreferredSize(new Dimension(200,200));
    5858
    5959        for (Map.Entry<String,String> i : WMSPlugin.wmsListDefault.entrySet()) {
     
    9999            }
    100100        });
    101101
    102         JButton copy = new JButton(tr("Copy Default"));
     102        JButton copy = new JButton(tr("Copy Selected Default(s)"));
    103103        buttonPanel.add(copy, GBC.std().insets(0,5,0,0));
    104104        copy.addActionListener(new ActionListener(){
    105105            public void actionPerformed(ActionEvent e) {
    106                 Integer line = listdef.getSelectedRow();
    107                 if (line == -1)
     106                int[] lines = listdef.getSelectedRows();
     107                if (lines.length == 0) {
    108108                    JOptionPane.showMessageDialog(
    109109                                gui,
    110                                 tr("Please select the row to copy."),
     110                                tr("Please select at least one row to copy."),
    111111                                tr("Information"),
    112112                                JOptionPane.INFORMATION_MESSAGE
    113113                                );
    114                 else
    115                 {
    116                     model.addRow(new String[]{modeldef.getValueAt(line, 0).toString(),
    117                     modeldef.getValueAt(line, 1).toString()});
     114                    return;
     115                }
     116               
     117                outer: for(int i = 0; i < lines.length; i++) {
     118                        String c1 = modeldef.getValueAt(lines[i], 0).toString();
     119                        String c2 = modeldef.getValueAt(lines[i], 1).toString();
     120                       
     121                        // Check if an entry with exactly the same values already
     122                        // exists
     123                        for(int j = 0; j < model.getRowCount(); j++) {
     124                                if(c1.equals(model.getValueAt(j, 0).toString())
     125                                                && c2.equals(model.getValueAt(j, 1).toString())) {
     126                                        // Select the already existing row so the user has
     127                                        // some feedback in case an entry exists
     128                                        list.getSelectionModel().setSelectionInterval(j, j);
     129                                        list.scrollRectToVisible(list.getCellRect(j, 0, true));
     130                                        continue outer;
     131                                }
     132                        }
     133                       
     134                        model.addRow(new String[] {c1, c2});
     135                        int lastLine = model.getRowCount() - 1;
     136                        list.getSelectionModel().setSelectionInterval(lastLine, lastLine);
     137                        list.scrollRectToVisible(list.getCellRect(lastLine, 0, true));
    118138                }
    119139            }
    120140        });
    121141
    122142        p.add(buttonPanel);
    123143        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
     144        // Add default item list
     145        p.add(scrolldef, GBC.eol().insets(0,5,0,0).fill(GBC.BOTH));       
     146       
    124147        browser = new JComboBox(new String[]{
    125148        "webkit-image {0}",
    126149        "gnome-web-photo --mode=photo --format=png {0} /dev/stdout",