Ticket #2907: wmsplugin_prefs_usability.patch
| File wmsplugin_prefs_usability.patch, 3.7 KB (added by , 17 years ago) |
|---|
-
src/wmsplugin/WMSPreferenceEditor.java
27 27 import org.openstreetmap.josm.tools.GBC; 28 28 29 29 public class WMSPreferenceEditor implements PreferenceSetting { 30 private Map<String,String> orig;31 30 private DefaultTableModel model; 32 31 private JComboBox browser; 33 32 private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>(); … … 53 52 public boolean isCellEditable(int row,int column){return false;} 54 53 }; 55 54 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 57 57 scrolldef.setPreferredSize(new Dimension(200,200)); 58 58 59 59 for (Map.Entry<String,String> i : WMSPlugin.wmsListDefault.entrySet()) { … … 99 99 } 100 100 }); 101 101 102 JButton copy = new JButton(tr("Copy Default"));102 JButton copy = new JButton(tr("Copy Selected Default(s)")); 103 103 buttonPanel.add(copy, GBC.std().insets(0,5,0,0)); 104 104 copy.addActionListener(new ActionListener(){ 105 105 public void actionPerformed(ActionEvent e) { 106 Integer line = listdef.getSelectedRow();107 if (line == -1)106 int[] lines = listdef.getSelectedRows(); 107 if (lines.length == 0) { 108 108 JOptionPane.showMessageDialog( 109 109 gui, 110 tr("Please select the row to copy."),110 tr("Please select at least one row to copy."), 111 111 tr("Information"), 112 112 JOptionPane.INFORMATION_MESSAGE 113 113 ); 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)); 118 138 } 119 139 } 120 140 }); 121 141 122 142 p.add(buttonPanel); 123 143 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 124 147 browser = new JComboBox(new String[]{ 125 148 "webkit-image {0}", 126 149 "gnome-web-photo --mode=photo --format=png {0} /dev/stdout",
