Changeset 2317 in josm
- Timestamp:
- 2009-10-25T15:13:08+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r2254 r2317 19 19 super(tr("Update data"), 20 20 "updatedata", 21 tr("Updates the objects in the currentdata layer from the server."),21 tr("Updates the objects in the active data layer from the server."), 22 22 Shortcut.registerShortcut("file:updatedata", 23 23 tr("Update data"), -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r2303 r2317 117 117 118 118 public UploadAction() { 119 super(tr("Upload data"), "upload", tr("Upload all changes in the currentdata layer to the OSM server"),119 super(tr("Upload data"), "upload", tr("Upload all changes in the active data layer to the OSM server"), 120 120 Shortcut.registerShortcut("file:upload", tr("File: {0}", tr("Upload data")), KeyEvent.VK_U, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY), true); 121 121 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r2309 r2317 5 5 import java.util.Arrays; 6 6 import java.util.Collection; 7 import java.util.Collections;8 7 import java.util.Comparator; 9 8 import java.util.HashMap; 10 import java.util.LinkedHashSet;11 9 import java.util.HashSet; 12 10 import java.util.Iterator; 11 import java.util.LinkedHashSet; 13 12 import java.util.LinkedList; 14 13 import java.util.List; … … 16 15 17 16 import org.openstreetmap.josm.data.SelectionChangedListener; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive;19 17 20 18 /** … … 135 133 relations.add(relation); 136 134 return relation; 137 } else {135 } else 138 136 throw new AssertionError(); 139 }140 137 } 141 138 … … 170 167 for (OsmPrimitive osm : selectedPrimitives) { 171 168 if (osm instanceof Way || 172 osm instanceof Node)169 osm instanceof Node) { 173 170 sel.add(osm); 171 } 174 172 } 175 173 return sel; … … 245 243 246 244 public boolean toggleSelected(OsmPrimitive osm) { 247 if (!selectedPrimitives.remove(osm)) 245 if (!selectedPrimitives.remove(osm)) { 248 246 selectedPrimitives.add(osm); 247 } 249 248 return true; 250 249 } … … 480 479 OsmPrimitive result = null; 481 480 switch (type) { 482 case NODE: result = new Node(id, true); break;483 case WAY: result = new Way(id, true); break;484 case RELATION: result = new Relation(id, true); break;481 case NODE: result = new Node(id, true); break; 482 case WAY: result = new Way(id, true); break; 483 case RELATION: result = new Relation(id, true); break; 485 484 } 486 485 addPrimitive(result); 487 486 return result; 488 } else {487 } else 489 488 return null; 490 }491 489 } 492 490 -
trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java
r2269 r2317 271 271 if (numPanels == 1 && panels.get(N-1).getComponents().length == 0) 272 272 { 273 parent.setDividerSize(0); 273 274 this.setVisible(false); 274 275 } else { … … 277 278 } 278 279 this.setVisible(true); 280 parent.setDividerSize(5); 279 281 parent.resetToPreferredSizes(); 280 282 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r2301 r2317 1 1 package org.openstreetmap.josm.gui.dialogs; 2 2 3 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 5 6 import java.awt.BorderLayout; 6 7 import java.awt.GridLayout; 8 import java.awt.Point; 7 9 import java.awt.event.ActionEvent; 8 10 import java.awt.event.KeyEvent; … … 10 12 import java.awt.event.MouseEvent; 11 13 import java.util.ArrayList; 14 import java.util.Arrays; 12 15 import java.util.Collection; 13 16 import java.util.Collections; 14 17 import java.util.Comparator; 15 18 import java.util.HashSet; 19 import java.util.List; 16 20 import java.util.logging.Logger; 17 21 18 22 import javax.swing.AbstractAction; 19 23 import javax.swing.AbstractListModel; 24 import javax.swing.DefaultListSelectionModel; 20 25 import javax.swing.JList; 21 26 import javax.swing.JPanel; 27 import javax.swing.JPopupMenu; 22 28 import javax.swing.JScrollPane; 23 29 import javax.swing.KeyStroke; … … 36 42 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 37 43 import org.openstreetmap.josm.gui.SideButton; 44 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 38 45 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 39 46 import org.openstreetmap.josm.gui.layer.DataChangeListener; … … 64 71 /** the delete action */ 65 72 private DeleteAction deleteAction; 73 /** the popup menu */ 74 private RelationDialogPopupMenu popupMenu; 66 75 67 76 … … 75 84 // create the list of relations 76 85 // 77 model = new RelationListModel(); 86 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 87 model = new RelationListModel(selectionModel); 78 88 displaylist = new JList(model); 89 displaylist.setSelectionModel(selectionModel); 79 90 displaylist.setCellRenderer(new OsmPrimitivRenderer()); 80 91 displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 81 displaylist.addMouseListener(new DoubleClickAdapter());92 displaylist.addMouseListener(new MouseEventHandler()); 82 93 add(new JScrollPane(displaylist), BorderLayout.CENTER); 83 94 … … 119 130 displaylist.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), "deleteRelation"); 120 131 displaylist.getActionMap().put("deleteRelation", deleteAction); 132 133 popupMenu = new RelationDialogPopupMenu(); 121 134 122 135 // register as layer listener … … 170 183 return; 171 184 } 172 Relation selected = getSelected();185 Relation[] selected = getAllSelected(); 173 186 174 187 model.setRelations(getDisplayedRelationsInSortOrder(Main.main.getCurrentDataSet())); … … 178 191 setTitle(tr("Relations")); 179 192 } 180 selectRelation (selected);193 selectRelations(selected); 181 194 } 182 195 … … 240 253 241 254 /** 255 * @return All selected relations in the list, possibly empty List 256 */ 257 private Relation[] getAllSelected() { 258 return Arrays.asList(displaylist.getSelectedValues()).toArray(new Relation[0]); 259 } 260 261 /** 242 262 * Selects the relation <code>relation</code> in the list of relations. 243 263 * … … 245 265 */ 246 266 public void selectRelation(Relation relation) { 247 if (relation == null){ 267 selectRelations(new Relation[] {relation}); 268 } 269 270 /** 271 * Selects the relations <code>relations</code> in the list of relations. 272 * 273 * @param relations the relations (may be empty) 274 */ 275 public void selectRelations(Relation[] relations) { 276 List<Integer> sel = new ArrayList<Integer>(); 277 for (Relation r : relations) { 278 if (r == null) { 279 continue; 280 } 281 int idx = model.getIndexOfRelation(r); 282 if (idx != -1) { 283 sel.add(idx); 284 } 285 } 286 if (sel.isEmpty()) { 248 287 displaylist.clearSelection(); 249 288 return; 250 }251 int idx = model.getIndexOfRelation(relation);252 if (idx == -1) {253 displaylist.clearSelection();254 289 } else { 255 displaylist.setSelectedIndex(idx); 256 displaylist.scrollRectToVisible(displaylist.getCellBounds(idx,idx)); 257 } 258 } 259 260 class DoubleClickAdapter extends MouseAdapter { 290 int fst = Collections.min(sel); 291 displaylist.scrollRectToVisible(displaylist.getCellBounds(fst, fst)); 292 } 293 294 int[] aSel = new int[sel.size()]; //FIXME: how to cast Integer[] -> int[] ? 295 for (int i=0; i<sel.size(); ++i) { 296 aSel[i] = sel.get(i); 297 } 298 299 displaylist.setSelectedIndices(aSel); 300 } 301 302 class MouseEventHandler extends MouseAdapter { 261 303 protected void setCurrentRelationAsSelection() { 262 304 Main.main.getCurrentDataSet().setSelected((Relation)displaylist.getSelectedValue()); … … 274 316 setCurrentRelationAsSelection(); 275 317 } 318 } 319 } 320 private void openPopup(MouseEvent e) { 321 Point p = e.getPoint(); 322 int index = displaylist.locationToIndex(p); 323 if (index < 0) return; 324 if (!displaylist.getCellBounds(index, index).contains(e.getPoint())) 325 return; 326 if (! displaylist.isSelectedIndex(index)) { 327 displaylist.setSelectedIndex(index); 328 } 329 popupMenu.show(RelationListDialog.this, p.x, p.y-3); 330 } 331 @Override public void mousePressed(MouseEvent e) { 332 if (e.isPopupTrigger()) { 333 openPopup(e); 334 } 335 } 336 @Override public void mouseReleased(MouseEvent e) { 337 if (e.isPopupTrigger()) { 338 openPopup(e); 276 339 } 277 340 } … … 441 504 public SelectAction() { 442 505 putValue(SHORT_DESCRIPTION,tr("Set the current selection to the list of selected relations")); 443 //putValue(NAME, tr("Select"));444 506 putValue(SMALL_ICON, ImageProvider.get("dialogs", "select")); 445 507 setEnabled(false); … … 463 525 } 464 526 527 /** 528 * Sets the current selection to the list of relations selected in this dialog 529 * 530 */ 531 class SelectMembersAction extends AbstractAction implements ListSelectionListener{ 532 public SelectMembersAction() { 533 putValue(SHORT_DESCRIPTION,tr("Select the members of all selected relations")); 534 putValue(SMALL_ICON, ImageProvider.get("selectall")); 535 putValue(NAME, tr("Select members")); 536 updateEnabledState(); 537 } 538 539 public void actionPerformed(ActionEvent e) { 540 if (!isEnabled()) return; 541 List<Relation> relations = model.getSelectedRelations(); 542 HashSet<OsmPrimitive> members = new HashSet<OsmPrimitive>(); 543 for(Relation r: relations) { 544 members.addAll(r.getMemberPrimitives()); 545 } 546 Main.map.mapView.getEditLayer().data.setSelected(members); 547 DataSet.fireSelectionChanged(members); 548 } 549 550 protected void updateEnabledState() { 551 setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0); 552 } 553 554 public void valueChanged(ListSelectionEvent e) { 555 updateEnabledState(); 556 } 557 } 558 559 560 class DownloadMembersAction extends AbstractAction implements ListSelectionListener{ 561 562 public DownloadMembersAction() { 563 putValue(SHORT_DESCRIPTION,tr("Download all members of the selected relations")); 564 putValue(NAME, tr("Download members")); 565 putValue(SMALL_ICON, ImageProvider.get("dialogs", "downloadincomplete")); 566 putValue("help", ht("/Dialog/RelationList#DownloadMembers")); 567 updateEnabledState(); 568 } 569 570 protected void updateEnabledState() { 571 setEnabled(! model.getSelectedNonNewRelations().isEmpty()); 572 } 573 574 public void valueChanged(ListSelectionEvent e) { 575 updateEnabledState(); 576 } 577 578 public void actionPerformed(ActionEvent e) { 579 List<Relation> relations = model.getSelectedNonNewRelations(); 580 if (relations.isEmpty()) 581 return; 582 Main.worker.submit(new GenericRelationEditor.DownloadTask( 583 model.getSelectedNonNewRelations(), 584 Main.map.mapView.getEditLayer(), null)); 585 } 586 } 587 465 588 private static class RelationListModel extends AbstractListModel { 466 589 private ArrayList<Relation> relations; 590 private DefaultListSelectionModel selectionModel; 591 592 public RelationListModel(DefaultListSelectionModel selectionModel) { 593 this.selectionModel = selectionModel; 594 } 467 595 468 596 public ArrayList<Relation> getRelations() { … … 493 621 return relations.indexOf(relation); 494 622 } 623 624 /** 625 * Replies the list of selected, non-new relations. Empty list, 626 * if there are no selected, non-new relations. 627 * 628 * @return the list of selected, non-new relations. 629 */ 630 public List<Relation> getSelectedNonNewRelations() { 631 ArrayList<Relation> ret = new ArrayList<Relation>(); 632 for (int i=0; i<getSize();i++) { 633 if (!selectionModel.isSelectedIndex(i)) { 634 continue; 635 } 636 if (relations.get(i).isNew()) { 637 continue; 638 } 639 ret.add(relations.get(i)); 640 } 641 return ret; 642 } 643 644 /** 645 * Replies the list of selected relations. Empty list, 646 * if there are no selected relations. 647 * 648 * @return the list of selected, non-new relations. 649 */ 650 public List<Relation> getSelectedRelations() { 651 ArrayList<Relation> ret = new ArrayList<Relation>(); 652 for (int i=0; i<getSize();i++) { 653 if (!selectionModel.isSelectedIndex(i)) { 654 continue; 655 } 656 ret.add(relations.get(i)); 657 } 658 return ret; 659 } 660 } 661 662 class RelationDialogPopupMenu extends JPopupMenu { 663 664 protected void build() { 665 // -- download members action 666 // 667 DownloadMembersAction downloadMembersAction = new DownloadMembersAction(); 668 displaylist.addListSelectionListener(downloadMembersAction); 669 add(downloadMembersAction); 670 671 // -- select members action 672 // 673 SelectMembersAction selectMembersAction = new SelectMembersAction(); 674 displaylist.addListSelectionListener(selectMembersAction); 675 add(selectMembersAction); 676 } 677 678 public RelationDialogPopupMenu() { 679 build(); 680 } 495 681 } 496 682 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r2301 r2317 1203 1203 if (!isEnabled()) 1204 1204 return; 1205 Main.worker.submit(new DownloadTask(GenericRelationEditor.this)); 1205 Main.worker.submit(new DownloadTask( 1206 Collections.singletonList(getRelation()), 1207 getLayer(), 1208 memberTableModel, 1209 GenericRelationEditor.this) 1210 ); 1206 1211 } 1207 1212 … … 1369 1374 * 1370 1375 */ 1371 class DownloadTask extends PleaseWaitRunnable {1376 public static class DownloadTask extends PleaseWaitRunnable { 1372 1377 private boolean cancelled; 1373 1378 private int conflictsCount; 1374 1379 private Exception lastException; 1375 1376 public DownloadTask(Dialog parent) { 1380 private List<Relation> relations; 1381 private OsmDataLayer curLayer; 1382 private MemberTableModel memberTableModel; 1383 1384 public DownloadTask(List<Relation> relations, OsmDataLayer curLayer, MemberTableModel memberTableModel, Dialog parent) { 1377 1385 super(tr("Download relation members"), new PleaseWaitProgressMonitor(parent), false /* 1378 1386 * don't … … 1380 1388 * exception 1381 1389 */); 1390 this.relations = relations; 1391 this.curLayer = curLayer; 1392 this.memberTableModel = memberTableModel; 1393 } 1394 1395 public DownloadTask(List<Relation> relations, OsmDataLayer curLayer, MemberTableModel memberTableModel) { 1396 super(tr("Download relation members"), new PleaseWaitProgressMonitor(), false /* 1397 * don't 1398 * ignore 1399 * exception 1400 */); 1401 this.relations = relations; 1402 this.curLayer = curLayer; 1403 this.memberTableModel = memberTableModel; 1382 1404 } 1383 1405 … … 1390 1412 @Override 1391 1413 protected void finish() { 1414 Main.map.repaint(); 1392 1415 if (cancelled) 1393 1416 return; 1394 memberTableModel.updateMemberReferences(getLayer().data); 1417 if (memberTableModel != null) { 1418 memberTableModel.fireTableDataChanged(); 1419 } 1395 1420 if (lastException != null) { 1396 1421 ExceptionDialogUtil.explainException(lastException); … … 1410 1435 protected void realRun() throws SAXException, IOException, OsmTransferException { 1411 1436 try { 1412 progressMonitor.indeterminateSubTask(""); 1413 OsmServerObjectReader reader = new OsmServerObjectReader(getRelation().getId(), OsmPrimitiveType.RELATION, 1414 true); 1415 DataSet dataSet = reader.parseOsm(progressMonitor 1416 .createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 1417 if (dataSet != null) { 1418 final MergeVisitor visitor = new MergeVisitor(getLayer().data, dataSet); 1419 visitor.merge(); 1420 1421 // copy the merged layer's data source info 1422 for (DataSource src : dataSet.dataSources) { 1423 getLayer().data.dataSources.add(src); 1437 boolean changed = false; 1438 for (Relation relation : relations) { 1439 progressMonitor.indeterminateSubTask(""); 1440 OsmServerObjectReader reader = new OsmServerObjectReader(relation.getId(), OsmPrimitiveType.RELATION, 1441 true); 1442 DataSet dataSet = reader.parseOsm(progressMonitor 1443 .createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 1444 if (dataSet != null) { 1445 changed = true; 1446 final MergeVisitor visitor = new MergeVisitor(curLayer.data, dataSet); 1447 visitor.merge(); 1448 1449 // copy the merged layer's data source info 1450 for (DataSource src : dataSet.dataSources) { 1451 curLayer.data.dataSources.add(src); 1452 } 1453 if (!visitor.getConflicts().isEmpty()) { 1454 curLayer.getConflicts().add(visitor.getConflicts()); 1455 conflictsCount = visitor.getConflicts().size(); 1456 } 1424 1457 } 1425 // FIXME: this is necessary because there are dialogs listening 1426 // for DataChangeEvents which manipulate Swing components on this 1427 // thread. 1428 // 1458 } 1459 // FIXME: this is necessary because there are dialogs listening 1460 // for DataChangeEvents which manipulate Swing components on this 1461 // thread. 1462 // 1463 if (changed) { 1429 1464 SwingUtilities.invokeLater(new Runnable() { 1430 1465 public void run() { 1431 getLayer().fireDataChange();1466 curLayer.fireDataChange(); 1432 1467 } 1433 1468 }); 1434 if (!visitor.getConflicts().isEmpty()) {1435 getLayer().getConflicts().add(visitor.getConflicts());1436 conflictsCount = visitor.getConflicts().size();1437 }1438 1469 } 1439 1470 } catch (Exception e) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java
r2156 r2317 41 41 String role = (String)value; 42 42 editor.setText(role); 43 System.out.println(role + " - initializing autocompletion list ...");44 43 AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).populateWithMemberRoles(autoCompletionList); 45 44 autoCompletionList.dump(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r2311 r2317 18 18 19 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.data.osm.DataSet;21 20 import org.openstreetmap.josm.data.osm.Node; 22 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;24 22 import org.openstreetmap.josm.data.osm.Relation; 25 23 import org.openstreetmap.josm.data.osm.RelationMember; … … 87 85 public Object getValueAt(int rowIndex, int columnIndex) { 88 86 switch (columnIndex) { 89 case 0:90 return members.get(rowIndex).getRole();91 case 1:92 return members.get(rowIndex).getMember();93 case 2:94 return wayConnection(rowIndex);87 case 0: 88 return members.get(rowIndex).getRole(); 89 case 1: 90 return members.get(rowIndex).getMember(); 91 case 2: 92 return wayConnection(rowIndex); 95 93 } 96 94 // should not happen … … 197 195 } 198 196 return listSelectionModel; 199 }200 201 public void updateMemberReferences(DataSet ds) {202 for (int i=0; i< members.size();i++) {203 RelationMember member = members.get(i);204 if (member.getMember().isNew()) {205 continue;206 }207 OsmPrimitive primitive = ds.getPrimitiveById(member.getMember().getId(), OsmPrimitiveType.from(member.getMember()));208 if (primitive != null) {209 RelationMember newMember = new RelationMember(member.getRole(), primitive);210 members.remove(i);211 members.add(i, newMember);212 }213 }214 fireTableDataChanged();215 197 } 216 198 … … 724 706 private WayConnectionType wayConnection(int i) { 725 707 RelationMember m = members.get(i); 726 if (! m.isWay()) {708 if (! m.isWay()) 727 709 return new WayConnectionType(); 728 }729 710 Way w = m.getWay(); 730 if (w == null || w.incomplete) {711 if (w == null || w.incomplete) 731 712 return new WayConnectionType(); 732 } 733 713 734 714 int ip = (i - 1 + members.size()) % members.size(); 735 715 Integer link_p = linked(ip); -
trunk/src/org/openstreetmap/josm/gui/help/HelpBrowserCommandProcessor.java
r2308 r2317 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.help; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.io.BufferedReader; 5 7 import java.io.IOException; 6 8 import java.io.InputStreamReader; 7 import java.util.logging.Level;8 9 import java.util.logging.Logger; 9 10 10 11 import javax.swing.SwingUtilities; 11 12 import static org.openstreetmap.josm.tools.I18n.tr;13 12 14 13 /** … … 71 70 try { 72 71 cmd = reader.readLine(); 73 logger.info("got command: " + cmd);74 72 } catch(IOException e) { 75 logger.log(Level.SEVERE,e.toString());76 73 System.out.println(tr("Failed to read command. Exiting help browser. Exception was:" + e.toString())); 77 74 System.exit(1);
Note:
See TracChangeset
for help on using the changeset viewer.