Changeset 6021 in josm for trunk/src/org
- Timestamp:
- 2013-06-25T11:37:01+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/preferences/advanced
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r5886 r6021 2 2 package org.openstreetmap.josm.gui.preferences.advanced; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 7 import java.awt.Color;8 import java.awt.Component;9 6 import java.awt.Dimension; 10 import java.awt.Font;11 import java.awt.GridBagLayout;12 7 import java.awt.event.ActionEvent; 13 8 import java.awt.event.ActionListener; 14 import java.awt.event.MouseAdapter;15 import java.awt.event.MouseEvent;16 9 import java.io.File; 10 import java.io.IOException; 17 11 import java.util.ArrayList; 18 import java.util.Collection;19 12 import java.util.Collections; 20 13 import java.util.Comparator; … … 22 15 import java.util.Map; 23 16 import java.util.Map.Entry; 17 import javax.swing.AbstractAction; 24 18 25 19 import javax.swing.Box; 26 import javax.swing.ButtonGroup;27 import javax.swing.DefaultCellEditor;28 20 import javax.swing.JButton; 29 21 import javax.swing.JFileChooser; … … 31 23 import javax.swing.JOptionPane; 32 24 import javax.swing.JPanel; 33 import javax.swing.J RadioButton;25 import javax.swing.JPopupMenu; 34 26 import javax.swing.JScrollPane; 35 import javax.swing.JTable;36 27 import javax.swing.event.DocumentEvent; 37 28 import javax.swing.event.DocumentListener; 38 29 import javax.swing.filechooser.FileFilter; 39 import javax.swing.table.DefaultTableCellRenderer;40 import javax.swing.table.DefaultTableModel;41 30 42 31 import org.openstreetmap.josm.Main; … … 44 33 import org.openstreetmap.josm.data.CustomConfigurator; 45 34 import org.openstreetmap.josm.data.Preferences; 46 import org.openstreetmap.josm.data.Preferences.ListListSetting;47 import org.openstreetmap.josm.data.Preferences.ListSetting;48 import org.openstreetmap.josm.data.Preferences.MapListSetting;49 35 import org.openstreetmap.josm.data.Preferences.Setting; 50 import org.openstreetmap.josm.data.Preferences.StringSetting;51 import org.openstreetmap.josm.gui.ExtendedDialog;52 36 import org.openstreetmap.josm.gui.actionsupport.LogShowDialog; 53 37 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; … … 55 39 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 56 40 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 41 import org.openstreetmap.josm.gui.util.GuiHelper; 57 42 import org.openstreetmap.josm.gui.widgets.JosmTextField; 58 import org.openstreetmap.josm.tools.CheckParameterUtil;59 43 import org.openstreetmap.josm.tools.GBC; 60 import org.openstreetmap.josm.tools.Utils;44 import static org.openstreetmap.josm.tools.I18n.tr; 61 45 62 46 public class AdvancedPreference extends DefaultTabPreferenceSetting { 63 47 64 48 public static class Factory implements PreferenceSettingFactory { 49 @Override 65 50 public PreferenceSetting createPreferenceSetting() { 66 51 return new AdvancedPreference(); … … 77 62 } 78 63 79 public static class PrefEntry implements Comparable<PrefEntry> { 80 private String key; 81 private Setting value; 82 private Setting defaultValue; 83 private boolean isDefault; 84 private boolean changed; 85 86 public PrefEntry(String key, Setting value, Setting defaultValue, boolean isDefault) { 87 CheckParameterUtil.ensureParameterNotNull(key); 88 CheckParameterUtil.ensureParameterNotNull(value); 89 CheckParameterUtil.ensureParameterNotNull(defaultValue); 90 this.key = key; 91 this.value = value; 92 this.defaultValue = defaultValue; 93 this.isDefault = isDefault; 94 } 95 96 public String getKey() { 97 return key; 98 } 99 100 public Setting getValue() { 101 return value; 102 } 103 104 public Setting getDefaultValue() { 105 return defaultValue; 106 } 107 108 public void setValue(Setting value) { 109 this.value = value; 110 changed = true; 111 isDefault = false; 112 } 113 114 public boolean isDefault() { 115 return isDefault; 116 } 117 118 public boolean isChanged() { 119 return changed; 120 } 121 122 private void markAsChanged() { 123 changed = true; 124 } 125 126 public void reset() { 127 value = defaultValue; 128 changed = true; 129 isDefault = true; 130 } 131 132 @Override 133 public int compareTo(PrefEntry other) { 134 return key.compareTo(other.key); 135 } 136 137 @Override 138 public String toString() { 139 return value.toString(); 140 } 141 } 142 143 private AllSettingsTableModel model; 144 protected List<PrefEntry> data; 145 protected List<PrefEntry> displayData; 64 protected List<PrefEntry> allData; 65 protected List<PrefEntry> displayData = new ArrayList<PrefEntry>(); 146 66 protected JosmTextField txtFilter; 147 67 protected PreferencesTable table; 68 69 @Override 148 70 public void addGui(final PreferenceTabbedPane gui) { 149 71 JPanel p = gui.createPreferenceTab(this); … … 169 91 }); 170 92 readPreferences(Main.pref); 171 model = new AllSettingsTableModel();93 172 94 applyFilter(); 173 174 final JTable list = new JTable(model); 175 list.putClientProperty("terminateEditOnFocusLost", true); 176 list.getColumnModel().getColumn(1).setCellRenderer(new SettingCellRenderer()); 177 list.getColumnModel().getColumn(1).setCellEditor(new SettingCellEditor()); 178 179 JScrollPane scroll = new JScrollPane(list); 95 table = new PreferencesTable(displayData); 96 JScrollPane scroll = new JScrollPane(table); 180 97 p.add(scroll, GBC.eol().fill(GBC.BOTH)); 181 98 scroll.setPreferredSize(new Dimension(400,200)); … … 185 102 p.add(add, GBC.std().insets(0,5,0,0)); 186 103 add.addActionListener(new ActionListener(){ 187 public void actionPerformed(ActionEvent e) { 188 addPreference(gui); 104 @Override public void actionPerformed(ActionEvent e) { 105 PrefEntry pe = table.addPreference(gui); 106 if (pe!=null) { 107 allData.add(pe); 108 Collections.sort(allData); 109 applyFilter(); 110 } 189 111 } 190 112 }); … … 193 115 p.add(edit, GBC.std().insets(5,5,5,0)); 194 116 edit.addActionListener(new ActionListener(){ 195 public void actionPerformed(ActionEvent e) { 196 editPreference(gui, list); 117 @Override public void actionPerformed(ActionEvent e) { 118 boolean ok = table.editPreference(gui); 119 if (ok) applyFilter(); 197 120 } 198 121 }); … … 201 124 p.add(reset, GBC.std().insets(0,5,0,0)); 202 125 reset.addActionListener(new ActionListener(){ 203 public void actionPerformed(ActionEvent e) {204 resetPreference(gui, list);126 @Override public void actionPerformed(ActionEvent e) { 127 table.resetPreferences(gui); 205 128 } 206 129 }); … … 209 132 p.add(read, GBC.std().insets(5,5,0,0)); 210 133 read.addActionListener(new ActionListener(){ 211 public void actionPerformed(ActionEvent e) { 212 File[] files = askUserForCustomSettingsFiles(false, tr("Open JOSM customization file")); 213 if (files.length==0) return; 214 215 Preferences tmpPrefs = CustomConfigurator.clonePreferences(Main.pref); 216 217 StringBuilder log = new StringBuilder(); 218 log.append("<html>"); 219 for (File f: files) { 220 CustomConfigurator.readXML(f, tmpPrefs); 221 log.append(CustomConfigurator.getLog()); 222 } 223 //try { Main.pref.save(); } catch (IOException ex) { } 224 log.append("</html>"); 225 String msg = log.toString().replace("\n", "<br/>"); 226 227 new LogShowDialog(tr("Import log"), tr("<html>Here is file import summary. <br/>" 228 + "You can reject preferences changes by pressing \"Cancel\" in preferences dialog <br/>" 229 + "To activate some changes JOSM restart may be needed.</html>"), msg).showDialog(); 230 231 //JOptionPane.showMessageDialog(Main.parent, 232 // tr("Installed plugins and some changes in preferences will start to work after JOSM restart"), tr("Warning"), JOptionPane.WARNING_MESSAGE); 233 234 readPreferences(tmpPrefs); 235 // sorting after modification - first modified, then non-default, then default entries 236 Collections.sort(data, new Comparator<PrefEntry>() { 237 @Override 238 public int compare(PrefEntry o1, PrefEntry o2) { 239 if (o1.changed && !o2.changed) return -1; 240 if (o2.changed && !o1.changed) return 1; 241 if (!(o1.isDefault) && o2.isDefault) return -1; 242 if (!(o2.isDefault) && o1.isDefault) return 1; 243 return o1.key.compareTo(o2.key); 244 } 245 }); 246 247 applyFilter(); 248 ((AllSettingsTableModel) list.getModel()).fireTableDataChanged(); 249 } 250 134 @Override public void actionPerformed(ActionEvent e) { 135 readPreferencesFromXML(); 136 } 251 137 }); 252 138 … … 254 140 p.add(export, GBC.std().insets(5,5,0,0)); 255 141 export.addActionListener(new ActionListener(){ 256 public void actionPerformed(ActionEvent e) { 257 ArrayList<String> keys = new ArrayList<String>(); 258 boolean hasLists = false; 259 for (int row : list.getSelectedRows()) { 260 PrefEntry p = (PrefEntry) model.getValueAt(row, -1); 261 if (!p.isDefault()) { 262 // preferences with default values are not saved 263 if (!(p.getValue() instanceof StringSetting)) hasLists=true; // => append and replace differs 264 keys.add(p.getKey()); 265 } 266 } 267 if (keys.size()==0) { 268 JOptionPane.showMessageDialog(Main.parent, 269 tr("Please select some preference keys not marked as default"), tr("Warning"), JOptionPane.WARNING_MESSAGE); 270 return; 271 } 272 273 File[] files = askUserForCustomSettingsFiles(true, tr("Export preferences keys to JOSM customization file")); 274 if (files.length==0) return; 275 276 int answer = 0; 277 if (hasLists) { 278 answer = JOptionPane.showOptionDialog( 279 Main.parent, tr("What to do with preference lists when this file is to be imported?"), tr("Question"), 280 JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, 281 new String[]{tr("Append preferences from file to existing values"), tr("Replace existing values")}, 0); 282 } 283 CustomConfigurator.exportPreferencesKeysToFile(files[0].getAbsolutePath(), answer==0, keys); 284 } 285 }); 286 287 288 list.addMouseListener(new MouseAdapter(){ 289 @Override public void mouseClicked(MouseEvent e) { 290 if (e.getClickCount() == 2) { 291 editPreference(gui, list); 292 } 142 @Override public void actionPerformed(ActionEvent e) { 143 exportSelectedToXML(); 144 } 145 }); 146 147 final JButton more = new JButton(tr("More...")); 148 p.add(more, GBC.std().insets(5,5,0,0)); 149 more.addActionListener(new ActionListener() { 150 JPopupMenu menu = buildPopupMenu(); 151 @Override public void actionPerformed(ActionEvent ev) { 152 menu.show(more, 0, 0); 293 153 } 294 154 }); … … 312 172 loaded = orig; 313 173 } 314 prepareData(loaded, orig, defaults);174 allData = prepareData(loaded, orig, defaults); 315 175 } 316 176 … … 334 194 return new File[0]; 335 195 } 336 337 private void prepareData(Map<String, Setting> loaded, Map<String, Setting> orig, Map<String, Setting> defaults) { 338 data = new ArrayList<PrefEntry>(); 196 197 private void exportSelectedToXML() { 198 ArrayList<String> keys = new ArrayList<String>(); 199 boolean hasLists = false; 200 201 for (PrefEntry p: table.getSelectedItems()) { 202 // preferences with default values are not saved 203 if (!(p.getValue() instanceof Preferences.StringSetting)) { 204 hasLists = true; // => append and replace differs 205 } 206 if (!p.isDefault()) { 207 keys.add(p.getKey()); 208 } 209 } 210 211 if (keys.isEmpty()) { 212 JOptionPane.showMessageDialog(Main.parent, 213 tr("Please select some preference keys not marked as default"), tr("Warning"), JOptionPane.WARNING_MESSAGE); 214 return; 215 } 216 217 File[] files = askUserForCustomSettingsFiles(true, tr("Export preferences keys to JOSM customization file")); 218 if (files.length == 0) { 219 return; 220 } 221 222 int answer = 0; 223 if (hasLists) { 224 answer = JOptionPane.showOptionDialog( 225 Main.parent, tr("What to do with preference lists when this file is to be imported?"), tr("Question"), 226 JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, 227 new String[]{tr("Append preferences from file to existing values"), tr("Replace existing values")}, 0); 228 } 229 CustomConfigurator.exportPreferencesKeysToFile(files[0].getAbsolutePath(), answer == 0, keys); 230 } 231 232 private void readPreferencesFromXML() { 233 File[] files = askUserForCustomSettingsFiles(false, tr("Open JOSM customization file")); 234 if (files.length == 0) return; 235 236 Preferences tmpPrefs = CustomConfigurator.clonePreferences(Main.pref); 237 238 StringBuilder log = new StringBuilder(); 239 log.append("<html>"); 240 for (File f : files) { 241 CustomConfigurator.readXML(f, tmpPrefs); 242 log.append(CustomConfigurator.getLog()); 243 } 244 //try { Main.pref.save(); } catch (IOException ex) { } 245 log.append("</html>"); 246 String msg = log.toString().replace("\n", "<br/>"); 247 248 new LogShowDialog(tr("Import log"), tr("<html>Here is file import summary. <br/>" 249 + "You can reject preferences changes by pressing \"Cancel\" in preferences dialog <br/>" 250 + "To activate some changes JOSM restart may be needed.</html>"), msg).showDialog(); 251 252 //JOptionPane.showMessageDialog(Main.parent, 253 // tr("Installed plugins and some changes in preferences will start to work after JOSM restart"), tr("Warning"), JOptionPane.WARNING_MESSAGE); 254 255 readPreferences(tmpPrefs); 256 // sorting after modification - first modified, then non-default, then default entries 257 Collections.sort(allData, new Comparator<PrefEntry>() { 258 @Override 259 public int compare(PrefEntry o1, PrefEntry o2) { 260 if (o1.isChanged() && !o2.isChanged()) return -1; 261 if (o2.isChanged() && !o1.isChanged()) return 1; 262 if (!(o1.isDefault()) && o2.isDefault()) return -1; 263 if (!(o2.isDefault()) && o1.isDefault()) return 1; 264 return o1.compareTo(o2); 265 } 266 }); 267 applyFilter(); 268 } 269 270 private List<PrefEntry> prepareData(Map<String, Setting> loaded, Map<String, Setting> orig, Map<String, Setting> defaults) { 271 List<PrefEntry> data = new ArrayList<PrefEntry>(); 339 272 for (Entry<String, Setting> e : loaded.entrySet()) { 340 273 Setting value = e.getValue(); … … 363 296 } 364 297 Collections.sort(data); 365 displayData = new ArrayList<PrefEntry>(data); 366 } 367 368 class AllSettingsTableModel extends DefaultTableModel { 369 370 public AllSettingsTableModel() { 371 setColumnIdentifiers(new String[]{tr("Key"), tr("Value")}); 372 } 373 374 @Override 375 public boolean isCellEditable(int row, int column) { 376 return column == 1 && (displayData.get(row).getValue() instanceof StringSetting); 377 } 378 379 @Override 380 public int getRowCount() { 381 return displayData.size(); 382 } 383 384 @Override 385 public Object getValueAt(int row, int column) { 386 if (column == 0) 387 return displayData.get(row).getKey(); 388 else 389 return displayData.get(row); 390 } 391 392 @Override 393 public void setValueAt(Object o, int row, int column) { 394 PrefEntry pe = displayData.get(row); 395 String s = (String) o; 396 if (!s.equals(pe.getValue().getValue())) { 397 pe.setValue(new StringSetting(s)); 398 fireTableCellUpdated(row, column); 399 } 400 } 401 } 402 403 private static class SettingCellRenderer extends DefaultTableCellRenderer { 404 private Color backgroundColor = Main.pref.getUIColor("Table.background"); 405 private Color changedColor = Main.pref.getColor( 406 marktr("Advanced Background: Changed"), 407 new Color(200,255,200)); 408 private Color foregroundColor = Main.pref.getUIColor("Table.foreground"); 409 private Color nonDefaultColor = Main.pref.getColor( 410 marktr("Advanced Background: NonDefalut"), 411 new Color(255,255,200)); 412 413 @Override 414 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 415 if (value == null) 416 return this; 417 PrefEntry pe = (PrefEntry) value; 418 Setting setting = pe.getValue(); 419 Object val = setting.getValue(); 420 String display = val != null ? val.toString() : "<html><i><"+tr("unset")+"></i></html>"; 421 422 JLabel label = (JLabel)super.getTableCellRendererComponent(table, 423 display, isSelected, hasFocus, row, column); 424 425 label.setBackground(backgroundColor); 426 if (isSelected) { 427 label.setForeground(foregroundColor); 428 } 429 if(pe.isChanged()) { 430 label.setBackground(changedColor); 431 } else if(!pe.isDefault()) { 432 label.setBackground(nonDefaultColor); 433 } 434 435 if (!pe.isDefault()) { 436 label.setFont(label.getFont().deriveFont(Font.BOLD)); 437 } 438 val = pe.getDefaultValue().getValue(); 439 if(val != null) 440 { 441 if(pe.isDefault()) { 442 label.setToolTipText(tr("Current value is default.")); 443 } else { 444 label.setToolTipText(tr("Default value is ''{0}''.", val)); 298 displayData.clear(); 299 displayData.addAll(data); 300 return data; 301 } 302 303 private JPopupMenu buildPopupMenu() { 304 JPopupMenu menu = new JPopupMenu(); 305 menu.add(new AbstractAction(tr("Reset preferences")) { 306 @Override public void actionPerformed(ActionEvent ae) { 307 if (!GuiHelper.warnUser(tr("Reset preferences"), 308 "<html>"+ 309 tr("You are about to clear all preferences to their default values<br />"+ 310 "All your settings will be deleted: plugins, imagery, filters, toolbar buttons, keyboard, etc. <br />"+ 311 "Are you sure you want to continue?") 312 +"</html>", null, "")) { 313 Main.pref.resetToDefault(); 314 try { Main.pref.save(); } catch (IOException ex) {} 315 readPreferences(Main.pref); 316 applyFilter(); 445 317 } 446 } else { 447 label.setToolTipText(tr("Default value currently unknown (setting has not been used yet).")); 448 } 449 return label; 450 } 451 } 452 453 private static class SettingCellEditor extends DefaultCellEditor { 454 public SettingCellEditor() { 455 super(new JosmTextField()); 456 } 457 458 @Override 459 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { 460 PrefEntry pe = (PrefEntry) value; 461 StringSetting stg = (StringSetting) pe.getValue(); 462 String s = stg.getValue() == null ? "" : stg.getValue(); 463 return super.getTableCellEditorComponent(table, s, isSelected, row, column); 464 } 318 } 319 }); 320 return menu; 465 321 } 466 322 467 323 private void applyFilter() { 468 324 displayData.clear(); 469 for (PrefEntry e : data) { 470 325 for (PrefEntry e : allData) { 471 326 String prefKey = e.getKey(); 472 327 Setting valueSetting = e.getValue(); … … 490 345 } 491 346 } 492 model.fireTableDataChanged(); 347 System.out.println(displayData.size()) ; 348 if (table!=null) table.fireDataChanged(); 493 349 } 494 350 495 351 @Override 496 352 public boolean ok() { 497 for (PrefEntry e : data) {353 for (PrefEntry e : allData) { 498 354 if (e.isChanged()) { 499 355 Main.pref.putSetting(e.getKey(), e.getValue()); … … 502 358 return false; 503 359 } 504 505 private void resetPreference(final PreferenceTabbedPane gui, final JTable list) {506 if (list.getSelectedRowCount() == 0) {507 JOptionPane.showMessageDialog(508 gui,509 tr("Please select the row to delete."),510 tr("Warning"),511 JOptionPane.WARNING_MESSAGE512 );513 return;514 }515 for (int row : list.getSelectedRows()) {516 PrefEntry e = displayData.get(row);517 e.reset();518 }519 model.fireTableDataChanged();520 }521 522 private void addPreference(final PreferenceTabbedPane gui) {523 JPanel p = new JPanel(new GridBagLayout());524 p.add(new JLabel(tr("Key")), GBC.std().insets(0,0,5,0));525 JosmTextField tkey = new JosmTextField("", 50);526 p.add(tkey, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));527 528 p.add(new JLabel(tr("Select Setting Type:")), GBC.eol().insets(5,15,5,0));529 530 JRadioButton rbString = new JRadioButton(tr("Simple"));531 JRadioButton rbList = new JRadioButton(tr("List"));532 JRadioButton rbListList = new JRadioButton(tr("List of lists"));533 JRadioButton rbMapList = new JRadioButton(tr("List of maps"));534 535 ButtonGroup group = new ButtonGroup();536 group.add(rbString);537 group.add(rbList);538 group.add(rbListList);539 group.add(rbMapList);540 541 p.add(rbString, GBC.eol());542 p.add(rbList, GBC.eol());543 p.add(rbListList, GBC.eol());544 p.add(rbMapList, GBC.eol());545 546 rbString.setSelected(true);547 548 ExtendedDialog dlg = new ExtendedDialog(gui, tr("Add setting"), new String[] {tr("OK"), tr("Cancel")});549 dlg.setButtonIcons(new String[] {"ok.png", "cancel.png"});550 dlg.setContent(p);551 dlg.showDialog();552 553 PrefEntry pe = null;554 boolean ok = false;555 if (dlg.getValue() == 1) {556 if (rbString.isSelected()) {557 StringSetting sSetting = new StringSetting(null);558 pe = new PrefEntry(tkey.getText(), sSetting, sSetting, false);559 StringEditor sEditor = new StringEditor(gui, pe, sSetting);560 sEditor.showDialog();561 if (sEditor.getValue() == 1) {562 String data = sEditor.getData();563 if (!Utils.equal(sSetting.getValue(), data)) {564 pe.setValue(new StringSetting(data));565 ok = true;566 }567 }568 } else if (rbList.isSelected()) {569 ListSetting lSetting = new ListSetting(null);570 pe = new PrefEntry(tkey.getText(), lSetting, lSetting, false);571 ListEditor lEditor = new ListEditor(gui, pe, lSetting);572 lEditor.showDialog();573 if (lEditor.getValue() == 1) {574 List<String> data = lEditor.getData();575 if (!Preferences.equalCollection(lSetting.getValue(), data)) {576 pe.setValue(new ListSetting(data));577 ok = true;578 }579 }580 } else if (rbListList.isSelected()) {581 ListListSetting llSetting = new ListListSetting(null);582 pe = new PrefEntry(tkey.getText(), llSetting, llSetting, false);583 ListListEditor llEditor = new ListListEditor(gui, pe, llSetting);584 llEditor.showDialog();585 if (llEditor.getValue() == 1) {586 List<List<String>> data = llEditor.getData();587 @SuppressWarnings("unchecked")588 Collection<Collection<String>> llSettingValue = (Collection) llSetting.getValue();589 if (!Preferences.equalArray(llSettingValue, data)) {590 pe.setValue(new ListListSetting(data));591 ok = true;592 }593 }594 } else if (rbMapList.isSelected()) {595 MapListSetting mlSetting = new MapListSetting(null);596 pe = new PrefEntry(tkey.getText(), mlSetting, mlSetting, false);597 MapListEditor mlEditor = new MapListEditor(gui, pe, mlSetting);598 mlEditor.showDialog();599 if (mlEditor.getValue() == 1) {600 List<Map<String, String>> data = mlEditor.getData();601 if (!Preferences.equalListOfStructs(mlSetting.getValue(), data)) {602 pe.setValue(new MapListSetting(data));603 ok = true;604 }605 }606 }607 if (ok) {608 data.add(pe);609 Collections.sort(data);610 applyFilter();611 }612 }613 }614 615 private void editPreference(final PreferenceTabbedPane gui, final JTable list) {616 if (list.getSelectedRowCount() != 1) {617 JOptionPane.showMessageDialog(618 gui,619 tr("Please select the row to edit."),620 tr("Warning"),621 JOptionPane.WARNING_MESSAGE622 );623 return;624 }625 final PrefEntry e = (PrefEntry) model.getValueAt(list.getSelectedRow(), 1);626 Setting stg = e.getValue();627 if (stg instanceof StringSetting) {628 list.editCellAt(list.getSelectedRow(), 1);629 Component editor = list.getEditorComponent();630 if (editor != null) {631 editor.requestFocus();632 }633 } else if (stg instanceof ListSetting) {634 ListSetting lSetting = (ListSetting) stg;635 ListEditor lEditor = new ListEditor(gui, e, lSetting);636 lEditor.showDialog();637 if (lEditor.getValue() == 1) {638 List<String> data = lEditor.getData();639 if (!Preferences.equalCollection(lSetting.getValue(), data)) {640 e.setValue(new ListSetting(data));641 applyFilter();642 }643 }644 } else if (stg instanceof ListListSetting) {645 ListListEditor llEditor = new ListListEditor(gui, e, (ListListSetting) stg);646 llEditor.showDialog();647 if (llEditor.getValue() == 1) {648 List<List<String>> data = llEditor.getData();649 @SuppressWarnings("unchecked")650 Collection<Collection<String>> stgValue = (Collection) stg.getValue();651 if (!Preferences.equalArray(stgValue, data)) {652 e.setValue(new ListListSetting(data));653 applyFilter();654 }655 }656 } else if (stg instanceof MapListSetting) {657 MapListSetting mlSetting = (MapListSetting) stg;658 MapListEditor mlEditor = new MapListEditor(gui, e, mlSetting);659 mlEditor.showDialog();660 if (mlEditor.getValue() == 1) {661 List<Map<String, String>> data = mlEditor.getData();662 if (!Preferences.equalListOfStructs(mlSetting.getValue(), data)) {663 e.setValue(new MapListSetting(data));664 applyFilter();665 }666 }667 }668 }669 360 } -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ListEditor.java
r5886 r6021 10 10 11 11 import javax.swing.DefaultCellEditor; 12 import javax.swing.JComponent; 12 13 import javax.swing.JLabel; 13 14 import javax.swing.JPanel; … … 18 19 import org.openstreetmap.josm.data.Preferences.ListSetting; 19 20 import org.openstreetmap.josm.gui.ExtendedDialog; 20 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;21 import org.openstreetmap.josm.gui.preferences.advanced.AdvancedPreference.PrefEntry;22 21 import org.openstreetmap.josm.gui.widgets.JosmTextField; 23 22 import org.openstreetmap.josm.tools.GBC; … … 29 28 PrefEntry entry; 30 29 31 public ListEditor(final PreferenceTabbedPanegui, PrefEntry entry, ListSetting setting) {30 public ListEditor(final JComponent gui, PrefEntry entry, ListSetting setting) { 32 31 super(gui, tr("Change list setting"), new String[] {tr("OK"), tr("Cancel")}); 33 32 this.entry = entry; -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ListListEditor.java
r5886 r6021 14 14 import javax.swing.AbstractListModel; 15 15 import javax.swing.DefaultCellEditor; 16 import javax.swing.JComponent; 16 17 import javax.swing.JLabel; 17 18 import javax.swing.JList; … … 27 28 import org.openstreetmap.josm.data.Preferences.ListListSetting; 28 29 import org.openstreetmap.josm.gui.ExtendedDialog; 29 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;30 import org.openstreetmap.josm.gui.preferences.advanced.AdvancedPreference.PrefEntry;31 30 import org.openstreetmap.josm.gui.widgets.JosmTextField; 32 31 import org.openstreetmap.josm.tools.GBC; … … 46 45 ListTableModel tableModel; 47 46 48 public ListListEditor(final PreferenceTabbedPanegui, PrefEntry entry, ListListSetting setting) {47 public ListListEditor(final JComponent gui, PrefEntry entry, ListListSetting setting) { 49 48 super(gui, tr("Change list of lists setting"), new String[] {tr("OK"), tr("Cancel")}); 50 49 this.entry = entry; -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/MapListEditor.java
r5886 r6021 18 18 import javax.swing.AbstractListModel; 19 19 import javax.swing.DefaultCellEditor; 20 import javax.swing.JComponent; 20 21 import javax.swing.JLabel; 21 22 import javax.swing.JList; … … 31 32 import org.openstreetmap.josm.data.Preferences.MapListSetting; 32 33 import org.openstreetmap.josm.gui.ExtendedDialog; 33 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;34 import org.openstreetmap.josm.gui.preferences.advanced.AdvancedPreference.PrefEntry;35 34 import org.openstreetmap.josm.gui.widgets.JosmTextField; 36 35 import org.openstreetmap.josm.tools.GBC; … … 51 50 Integer entryIdx; 52 51 53 public MapListEditor( PreferenceTabbedPanegui, PrefEntry entry, MapListSetting setting) {52 public MapListEditor(JComponent gui, PrefEntry entry, MapListSetting setting) { 54 53 super(gui, tr("Change list of maps setting"), new String[] {tr("OK"), tr("Cancel")}); 55 54 this.entry = entry; -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/StringEditor.java
r5886 r6021 5 5 6 6 import java.awt.GridBagLayout; 7 import javax.swing.JComponent; 7 8 8 9 import javax.swing.JLabel; … … 11 12 import org.openstreetmap.josm.data.Preferences.StringSetting; 12 13 import org.openstreetmap.josm.gui.ExtendedDialog; 13 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;14 import org.openstreetmap.josm.gui.preferences.advanced.AdvancedPreference.PrefEntry;15 14 import org.openstreetmap.josm.gui.widgets.JosmTextField; 16 15 import org.openstreetmap.josm.tools.GBC; … … 21 20 JosmTextField tvalue; 22 21 23 public StringEditor(final PreferenceTabbedPanegui, PrefEntry entry, StringSetting setting) {22 public StringEditor(final JComponent gui, PrefEntry entry, StringSetting setting) { 24 23 super(gui, tr("Change string setting"), new String[] {tr("OK"), tr("Cancel")}); 25 24 this.entry = entry;
Note:
See TracChangeset
for help on using the changeset viewer.