- Timestamp:
- 2008-04-18T00:47:08+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r595 r611 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 1 // License: GPL. See LICENSE file for details. 2 2 3 package org.openstreetmap.josm.gui.dialogs; 3 4 … … 29 30 import javax.swing.Box; 30 31 import javax.swing.DefaultComboBoxModel; 32 import javax.swing.DefaultListCellRenderer; 31 33 import javax.swing.JButton; 32 34 import javax.swing.JComboBox; 33 35 import javax.swing.JDialog; 34 36 import javax.swing.JLabel; 37 import javax.swing.JList; 35 38 import javax.swing.JOptionPane; 36 39 import javax.swing.JPanel; … … 112 115 } 113 116 117 private final Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>(); 114 118 /** 115 119 * Edit the value in the properties table row … … 118 122 void propertyEdit(int row) { 119 123 String key = propertyData.getValueAt(row, 0).toString(); 124 objKey=key; 120 125 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 121 126 if (sel.isEmpty()) { … … 143 148 144 149 final AutoCompleteComboBox values = new AutoCompleteComboBox(); 150 values.setRenderer(new DefaultListCellRenderer() { 151 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 152 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 153 if (c instanceof JLabel) { 154 String str = null; 155 str=(String) value; 156 if (valueCount.containsKey(objKey)){ 157 Map<String, Integer> m=valueCount.get(objKey); 158 if (m.containsKey(str)) { 159 str+="("+m.get(str)+")"; 160 c.setFont(c.getFont().deriveFont(Font.ITALIC+Font.BOLD)); 161 } 162 } 163 ((JLabel)c).setText(str); 164 } 165 return c; 166 } 167 }); 145 168 values.setEditable(true); 146 Collection<String> newItems; 147 if (allData.containsKey(key)) { 148 newItems = allData.get(key); 149 } else { 150 newItems = Collections.emptyList(); 151 } 152 values.setPossibleItems(newItems); 153 values.setSelectedItem(null); 154 final String selection= ((JComboBox)propertyData.getValueAt(row, 1)).getEditor().getItem().toString(); 169 updateListData(key, allData, values); 170 Map<String, Integer> m=(Map<String, Integer>)propertyData.getValueAt(row, 1); 171 final String selection= m.size()!=1?"<different>":m.entrySet().iterator().next().getKey(); 155 172 values.setSelectedItem(selection); 156 173 values.getEditor().setItem(selection); … … 158 175 p.add(Box.createHorizontalStrut(10), GBC.std()); 159 176 p.add(values, GBC.eol().fill(GBC.HORIZONTAL)); 160 addFocusAdapter( allData, keys, values);177 addFocusAdapter(row, allData, keys, values); 161 178 162 179 final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) { … … 203 220 } 204 221 205 222 selectionChanged(sel); // update whole table 206 223 Main.parent.repaint(); // repaint all - drawing could have been changed 207 224 } 225 226 /** 227 * @param row 228 * @param key 229 * @param allData 230 * @param values 231 */ 232 private void updateListData(String key, final TreeMap<String, TreeSet<String>> allData, final AutoCompleteComboBox values) { 233 Collection<String> newItems; 234 if (allData.containsKey(key)) { 235 newItems = allData.get(key); 236 } else { 237 newItems = Collections.emptyList(); 238 } 239 values.setPossibleItems(newItems); 240 } 208 241 209 242 /** … … 246 279 p2.add(values, BorderLayout.CENTER); 247 280 281 addFocusAdapter(-1, allData, keys, values); 248 282 JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 249 283 @Override public void selectInitialValue() { … … 269 303 * @param values 270 304 */ 271 private void addFocusAdapter( 272 final TreeMap<String, TreeSet<String>> allData, 273 final AutoCompleteComboBox keys, final AutoCompleteComboBox values) { 305 private void addFocusAdapter(final int row, final TreeMap<String, TreeSet<String>> allData,final AutoCompleteComboBox keys, final AutoCompleteComboBox values) { 274 306 // get the combo box' editor component 275 307 JTextComponent editor = (JTextComponent)values.getEditor() … … 279 311 @Override public void focusGained(FocusEvent e) { 280 312 String key = keys.getEditor().getItem().toString(); 281 Collection<String> newItems; 282 if (allData.containsKey(key)) { 283 newItems = allData.get(key); 284 } else { 285 newItems = Collections.emptyList(); 286 } 287 values.setPossibleItems(newItems); 313 updateListData(key, allData, values); 314 objKey=key; 288 315 } 289 316 }); 290 317 } 291 318 private String objKey; 292 319 /** 293 320 * @return … … 334 361 } 335 362 @Override public Class<?> getColumnClass(int columnIndex) { 336 return columnIndex == 1 ? Relation.class :String.class;363 return String.class; 337 364 } 338 365 }; … … 402 429 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 403 430 if (c instanceof JLabel) { 404 String str = ((JComboBox) value).getEditor().getItem().toString(); 431 String str = null; 432 switch (column) { 433 case 0: 434 str = (String) value; 435 break; 436 case 1: 437 Map<String, Integer> v = (Map<String,Integer>) value; 438 if (v.size()!=1) { 439 str="<different>"; 440 c.setFont(c.getFont().deriveFont(Font.ITALIC)); 441 } else { 442 str=v.entrySet().iterator().next().getKey(); 443 } 444 break; 445 } 405 446 ((JLabel)c).setText(str); 406 if (str.equals(tr("<different>")))407 c.setFont(c.getFont().deriveFont(Font.ITALIC));408 447 } 409 448 return c; … … 498 537 propertyData.setRowCount(0); 499 538 500 Map<String, Integer> valueCount = new HashMap<String, Integer>();501 TreeMap<String, Collection<String>> props = new TreeMap<String, Collection<String>>();539 Map<String, Integer> keyCount = new HashMap<String, Integer>(); 540 valueCount.clear(); 502 541 for (OsmPrimitive osm : newSelection) { 503 542 for (Entry<String, String> e : osm.entrySet()) { 504 Collection<String> value = props.get(e.getKey()); 505 if (value == null) { 506 value = new TreeSet<String>(); 507 props.put(e.getKey(), value); 508 } 509 value.add(e.getValue()); 510 valueCount.put(e.getKey(), valueCount.containsKey(e.getKey()) ? valueCount.get(e.getKey())+1 : 1); 511 } 512 } 513 for (Entry<String, Collection<String>> e : props.entrySet()) { 514 JComboBox value = new JComboBox(e.getValue().toArray()); 515 value.setEditable(true); 516 value.getEditor().setItem(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next()); 517 propertyData.addRow(new Object[]{e.getKey(), value}); 543 keyCount.put(e.getKey(), keyCount.containsKey(e.getKey()) ? keyCount.get(e.getKey())+1 : 1); 544 if (valueCount.containsKey(e.getKey())) { 545 Map<String, Integer> v = valueCount.get(e.getKey()); 546 v.put(e.getValue(), v.containsKey(e.getValue())? v.get(e.getValue())+1 : 1 ); 547 } else { 548 TreeMap<String,Integer> v = new TreeMap<String, Integer>(); 549 v.put(e.getValue(), 1); 550 valueCount.put(e.getKey(), v); 551 } 552 } 553 } 554 for (Entry<String, Map<String, Integer>> e : valueCount.entrySet()) { 555 int count=0; 556 for (Entry<String, Integer> e1: e.getValue().entrySet()) { 557 // System.out.println(e.getKey()+" Entry "+e1.getKey()+" value "+e1.getValue()); 558 count+=e1.getValue(); 559 } 560 if (count < newSelection.size()) { 561 e.getValue().put("", newSelection.size()-count); 562 } 563 propertyData.addRow(new Object[]{e.getKey(), e.getValue()}); 518 564 } 519 565 … … 536 582 } 537 583 value.add(m.role); 538 valueCountM.put(r, valueCount.containsKey(r) ? valueCount.get(r)+1 : 1);584 valueCountM.put(r, keyCount.containsKey(r) ? keyCount.get(r)+1 : 1); 539 585 } 540 586 }
Note:
See TracChangeset
for help on using the changeset viewer.