Changeset 329 in josm for branch/0.5/src/org/openstreetmap/josm/gui/dialogs
- Timestamp:
- 2007-09-24T01:36:24+02:00 (17 years ago)
- Location:
- branch/0.5/src/org/openstreetmap/josm/gui/dialogs
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branch/0.5/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r301 r329 33 33 import org.openstreetmap.josm.data.SelectionChangedListener; 34 34 import org.openstreetmap.josm.data.osm.DataSet; 35 import org.openstreetmap.josm.data.osm.Relation; 36 import org.openstreetmap.josm.data.osm.RelationMember; 35 37 import org.openstreetmap.josm.data.osm.Node; 36 38 import org.openstreetmap.josm.data.osm.OsmPrimitive; 37 import org.openstreetmap.josm.data.osm.Segment;38 39 import org.openstreetmap.josm.data.osm.Way; 39 40 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; … … 88 89 add(buttonPanel, BorderLayout.SOUTH); 89 90 90 DataSet. listeners.add(new SelectionChangedListener(){91 DataSet.selListeners.add(new SelectionChangedListener(){ 91 92 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 92 93 displaylist.clearSelection(); … … 130 131 model.addElement(osm); 131 132 for (OsmPrimitive osm : this.conflicts.keySet()) 132 if (osm instanceof Segment)133 model.addElement(osm);134 for (OsmPrimitive osm : this.conflicts.keySet())135 133 if (osm instanceof Way) 136 134 model.addElement(osm); … … 155 153 g.drawRect(p.x-1, p.y-1, 2, 2); 156 154 } 157 public void visit(Segment ls) { 158 if (ls.incomplete) 159 return; 160 Point p1 = nc.getPoint(ls.from.eastNorth); 161 Point p2 = nc.getPoint(ls.to.eastNorth); 155 public void visit(Node n1, Node n2) { 156 Point p1 = nc.getPoint(n1.eastNorth); 157 Point p2 = nc.getPoint(n2.eastNorth); 162 158 g.drawLine(p1.x, p1.y, p2.x, p2.y); 163 159 } 164 160 public void visit(Way w) { 165 for (Segment ls : w.segments) 166 visit(ls); 161 Node lastN = null; 162 for (Node n : w.nodes) { 163 if (lastN == null) { 164 lastN = n; 165 continue; 166 } 167 visit(lastN, n); 168 lastN = n; 169 } 170 } 171 public void visit(Relation e) { 172 for (RelationMember em : e.members) 173 em.member.visit(this); 167 174 } 168 175 }; -
branch/0.5/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r298 r329 144 144 revertButton.putClientProperty("help", "Dialog/History/Revert"); 145 145 146 DataSet. listeners.add(this);146 DataSet.selListeners.add(this); 147 147 } 148 148 -
branch/0.5/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r301 r329 48 48 import org.openstreetmap.josm.data.osm.DataSet; 49 49 import org.openstreetmap.josm.data.osm.OsmPrimitive; 50 import org.openstreetmap.josm.data.osm.Relation; 51 import org.openstreetmap.josm.data.osm.RelationMember; 52 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 50 53 import org.openstreetmap.josm.gui.MapFrame; 51 54 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 55 import org.openstreetmap.josm.gui.tagging.ForwardActionListener; 52 56 import org.openstreetmap.josm.gui.tagging.TaggingCellRenderer; 53 import org.openstreetmap.josm.gui.tagging.ForwardActionListener;54 57 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 55 58 import org.openstreetmap.josm.tools.AutoCompleteComboBox; … … 77 80 78 81 /** 82 * Used to display relation names in the membership table 83 */ 84 private NameVisitor nameVisitor = new NameVisitor(); 85 86 /** 79 87 * Watches for double clicks and from editing or new property, depending on the 80 88 * location, the click was. … … 85 93 if (e.getClickCount() < 2) 86 94 return; 87 if (e.getSource() instanceof JScrollPane)88 add();89 else{95 96 if (e.getSource() == propertyTable) 97 { 90 98 int row = propertyTable.rowAtPoint(e.getPoint()); 91 edit(row); 92 } 93 } 94 } 95 96 /** 97 * Edit the value in the table row 98 * @param row The row of the table, from which the value is edited. 99 */ 100 void edit(int row) { 101 String key = data.getValueAt(row, 0).toString(); 99 if (row > -1) { 100 propertyEdit(row); 101 return; 102 } 103 } else if (e.getSource() == membershipTable) { 104 int row = membershipTable.rowAtPoint(e.getPoint()); 105 if (row > -1) { 106 membershipEdit(row); 107 return; 108 } 109 } 110 add(); 111 } 112 } 113 114 /** 115 * Edit the value in the properties table row 116 * @param row The row of the table from which the value is edited. 117 */ 118 void propertyEdit(int row) { 119 String key = propertyData.getValueAt(row, 0).toString(); 102 120 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 103 121 if (sel.isEmpty()) { … … 118 136 p.add(keyField, GBC.eol().fill(GBC.HORIZONTAL)); 119 137 120 final J ComboBox combo = (JComboBox)data.getValueAt(row, 1);138 final JTextField valueField = new JTextField((String)propertyData.getValueAt(row, 1)); 121 139 p.add(new JLabel(tr("Value")), GBC.std()); 122 140 p.add(Box.createHorizontalStrut(10), GBC.std()); 123 p.add( combo, GBC.eol().fill(GBC.HORIZONTAL));141 p.add(valueField, GBC.eol().fill(GBC.HORIZONTAL)); 124 142 125 143 final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 126 144 @Override public void selectInitialValue() { 127 combo.requestFocusInWindow();128 combo.getEditor().selectAll();145 valueField.requestFocusInWindow(); 146 valueField.selectAll(); 129 147 } 130 148 }; 131 149 final JDialog dlg = optionPane.createDialog(Main.parent, tr("Change values?")); 132 combo.getEditor().addActionListener(new ActionListener(){150 valueField.addActionListener(new ActionListener(){ 133 151 public void actionPerformed(ActionEvent e) { 134 152 optionPane.setValue(JOptionPane.OK_OPTION); … … 136 154 } 137 155 }); 138 String oldComboEntry = combo.getEditor().getItem().toString();139 156 dlg.setVisible(true); 140 157 … … 142 159 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE || 143 160 (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION)) { 144 combo.getEditor().setItem(oldComboEntry); 145 return; 146 } 147 148 String value = combo.getEditor().getItem().toString(); 161 return; 162 } 163 164 String value = valueField.getText(); 149 165 if (value.equals(tr("<different>"))) 150 166 return; … … 164 180 } 165 181 166 if (!key.equals(newkey) || value == null)167 182 selectionChanged(sel); // update whole table 168 169 183 Main.parent.repaint(); // repaint all - drawing could have been changed 184 } 185 186 /** 187 * This simply fires up an relation editor for the relation shown; everything else 188 * is the editor's business. 189 * 190 * @param row 191 */ 192 void membershipEdit(int row) { 193 final RelationEditor editor = new RelationEditor((Relation)membershipData.getValueAt(row, 0)); 194 editor.setVisible(true); 170 195 } 171 196 … … 197 222 } 198 223 } 199 for (int i = 0; i < data.getRowCount(); ++i)200 allData.remove( data.getValueAt(i, 0));224 for (int i = 0; i < propertyData.getRowCount(); ++i) 225 allData.remove(propertyData.getValueAt(i, 0)); 201 226 final AutoCompleteComboBox keys = new AutoCompleteComboBox(); 202 227 keys.setPossibleItems(allData.keySet()); … … 249 274 */ 250 275 private void delete(int row) { 251 String key = data.getValueAt(row, 0).toString();276 String key = propertyData.getValueAt(row, 0).toString(); 252 277 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 253 278 Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null)); … … 258 283 * The property data. 259 284 */ 260 private final DefaultTableModel data = new DefaultTableModel(){285 private final DefaultTableModel propertyData = new DefaultTableModel() { 261 286 @Override public boolean isCellEditable(int row, int column) { 262 287 return false; 263 288 } 264 289 @Override public Class<?> getColumnClass(int columnIndex) { 265 return columnIndex == 1 ? JComboBox.class :String.class;290 return String.class; 266 291 } 267 292 }; 293 294 /** 295 * The membership data. 296 */ 297 private final DefaultTableModel membershipData = new DefaultTableModel() { 298 @Override public boolean isCellEditable(int row, int column) { 299 return false; 300 } 301 @Override public Class<?> getColumnClass(int columnIndex) { 302 return columnIndex == 1 ? Relation.class : String.class; 303 } 304 }; 305 268 306 /** 269 307 * The properties list. 270 308 */ 271 private final JTable propertyTable = new JTable(data); 309 private final JTable propertyTable = new JTable(propertyData); 310 private final JTable membershipTable = new JTable(membershipData); 311 272 312 public JComboBox taggingPresets = new JComboBox(); 273 313 … … 277 317 */ 278 318 public PropertiesDialog(MapFrame mapFrame) { 279 super(tr("Properties "), "propertiesdialog", tr("Properties for selected objects."), KeyEvent.VK_P, 150);319 super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), KeyEvent.VK_P, 150); 280 320 281 321 if (TaggingPresetPreference.taggingPresets.size() > 0) { … … 300 340 taggingPresets.setRenderer(new TaggingCellRenderer()); 301 341 302 data.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")}); 342 // setting up the properties table 343 344 propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")}); 303 345 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 304 propertyTable.setDefaultRenderer(JComboBox.class, new DefaultTableCellRenderer(){ 346 347 propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){ 305 348 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 306 349 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 307 350 if (c instanceof JLabel) { 308 String str = ( (JComboBox)value).getEditor().getItem().toString();351 String str = (String) value; 309 352 ((JLabel)c).setText(str); 310 353 if (str.equals(tr("<different>"))) … … 314 357 } 315 358 }); 316 propertyTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer(){ 359 360 // setting up the membership table 361 362 membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role")}); 363 membershipTable.setRowSelectionAllowed(false); 364 365 membershipTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { 317 366 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 318 return super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 367 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 368 if (c instanceof JLabel) { 369 nameVisitor.visit((Relation)value); 370 ((JLabel)c).setText(nameVisitor.name); 371 } 372 return c; 319 373 } 320 374 }); 375 376 // combine both tables and wrap them in a scrollPane 377 JPanel bothTables = new JPanel(); 378 bothTables.setLayout(new GridBagLayout()); 379 bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 380 bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH)); 381 bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 382 bothTables.add(membershipTable, GBC.eol().fill(GBC.BOTH)); 383 321 384 DblClickWatch dblClickWatch = new DblClickWatch(); 322 385 propertyTable.addMouseListener(dblClickWatch); 323 JScrollPane scrollPane = new JScrollPane(propertyTable); 386 membershipTable.addMouseListener(dblClickWatch); 387 JScrollPane scrollPane = new JScrollPane(bothTables); 324 388 scrollPane.addMouseListener(dblClickWatch); 325 389 add(scrollPane, BorderLayout.CENTER); … … 335 399 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit.")); 336 400 else 337 edit(sel);401 propertyEdit(sel); 338 402 } else if (e.getActionCommand().equals("Delete")) { 339 403 if (sel == -1) … … 344 408 } 345 409 }; 410 346 411 buttonPanel.add(createButton(marktr("Add"),tr("Add a new key/value pair to all objects"), KeyEvent.VK_A, buttonAction)); 347 412 buttonPanel.add(createButton(marktr("Edit"),tr( "Edit the value of the selected key for all objects"), KeyEvent.VK_E, buttonAction)); … … 349 414 add(buttonPanel, BorderLayout.SOUTH); 350 415 351 DataSet. listeners.add(this);416 DataSet.selListeners.add(this); 352 417 } 353 418 … … 375 440 if (propertyTable.getCellEditor() != null) 376 441 propertyTable.getCellEditor().cancelCellEditing(); 377 data.setRowCount(0); 442 443 // re-load property data 444 445 propertyData.setRowCount(0); 378 446 379 447 Map<String, Integer> valueCount = new HashMap<String, Integer>(); … … 391 459 } 392 460 for (Entry<String, Collection<String>> e : props.entrySet()) { 393 JComboBox value = new JComboBox(e.getValue().toArray()); 394 value.setEditable(true); 395 value.getEditor().setItem(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next()); 396 data.addRow(new Object[]{e.getKey(), value}); 461 String value=(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next()); 462 propertyData.addRow(new Object[]{e.getKey(), value}); 463 } 464 465 // re-load membership data 466 // this is rather expensive since we have to walk through all members of all existing relationships. 467 // could use back references here for speed if necessary. 468 469 membershipData.setRowCount(0); 470 471 Map<Relation, Integer> valueCountM = new HashMap<Relation, Integer>(); 472 TreeMap<Relation, Collection<String>> roles = new TreeMap<Relation, Collection<String>>(); 473 for (Relation r : Main.ds.relations) { 474 for (RelationMember m : r.members) { 475 if (newSelection.contains(m.member)) { 476 Collection<String> value = roles.get(r); 477 if (value == null) { 478 value = new TreeSet<String>(); 479 roles.put(r, value); 480 } 481 value.add(m.role); 482 valueCountM.put(r, valueCount.containsKey(r) ? valueCount.get(r)+1 : 1); 483 } 484 } 485 } 486 487 for (Entry<Relation, Collection<String>> e : roles.entrySet()) { 488 //JComboBox value = new JComboBox(e.getValue().toArray()); 489 //value.setEditable(true); 490 //value.getEditor().setItem(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next()); 491 String value = e.getValue().size() > 1 || valueCountM.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next(); 492 membershipData.addRow(new Object[]{e.getKey(), value}); 397 493 } 398 494 } -
branch/0.5/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r298 r329 80 80 selectionChanged(Main.ds.getSelected()); 81 81 82 DataSet. listeners.add(this);82 DataSet.selListeners.add(this); 83 83 } 84 84 -
branch/0.5/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
r298 r329 54 54 selectionChanged(Main.ds.getSelected()); 55 55 56 DataSet. listeners.add(this);56 DataSet.selListeners.add(this); 57 57 } 58 58
Note:
See TracChangeset
for help on using the changeset viewer.