Changeset 2689 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
- Timestamp:
- 2009-12-28T00:16:04+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
r2655 r2689 6 6 import java.awt.BorderLayout; 7 7 import java.awt.FlowLayout; 8 import java.awt.Frame; 8 9 import java.awt.event.ActionEvent; 9 10 import java.awt.event.ItemEvent; … … 11 12 import java.awt.event.MouseAdapter; 12 13 import java.awt.event.MouseEvent; 14 import java.util.Collection; 13 15 import java.util.HashSet; 14 16 import java.util.List; 15 17 import java.util.Set; 18 import java.util.concurrent.ExecutionException; 19 import java.util.concurrent.Future; 16 20 17 21 import javax.swing.AbstractAction; … … 37 41 import org.openstreetmap.josm.gui.MapFrame; 38 42 import org.openstreetmap.josm.gui.MapView; 43 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetCacheManager; 44 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetHeaderDownloadTask; 39 45 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetInSelectionListModel; 40 46 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetListCellRenderer; 41 47 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetListModel; 42 48 import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetsInActiveDataLayerListModel; 43 import org.openstreetmap.josm.gui.dialogs.changeset.DownloadChangesetsTask;44 49 import org.openstreetmap.josm.gui.help.HelpUtil; 45 50 import org.openstreetmap.josm.gui.io.CloseChangesetTask; 51 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 52 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 46 53 import org.openstreetmap.josm.tools.ImageProvider; 47 54 import org.openstreetmap.josm.tools.OpenBrowser; … … 75 82 private ShowChangesetInfoAction showChangsetInfoAction; 76 83 private CloseOpenChangesetsAction closeChangesetAction; 84 private LaunchChangesetManagerAction launchChangesetManagerAction; 77 85 78 86 … … 93 101 lstInActiveDataLayer.setCellRenderer(new ChangesetListCellRenderer()); 94 102 95 ChangesetCache.getInstance().addChangesetCacheListener(inSelectionModel);96 MapView.addLayerChangeListener(inSelectionModel);97 DataSet.selListeners.add(inSelectionModel);98 99 ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel);100 101 103 DblClickHandler dblClickHandler = new DblClickHandler(); 102 104 lstInSelection.addMouseListener(dblClickHandler); 103 105 lstInActiveDataLayer.addMouseListener(dblClickHandler); 104 106 105 PopupMenuLauncher popupMenuLauncher = newPopupMenuLauncher();107 ChangesetPopupMenuLauncher popupMenuLauncher = new ChangesetPopupMenuLauncher(); 106 108 lstInSelection.addMouseListener(popupMenuLauncher); 107 109 lstInActiveDataLayer.addMouseListener(popupMenuLauncher); 108 110 } 109 111 112 protected void registerAsListener() { 113 // let the model for changesets in the current selection listen to various 114 // events 115 ChangesetCache.getInstance().addChangesetCacheListener(inSelectionModel); 116 MapView.addEditLayerChangeListener(inSelectionModel); 117 DataSet.selListeners.add(inSelectionModel); 118 119 120 // let the model for changesets in the current layer listen to various 121 // events and bootstrap it's content 122 ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel); 123 MapView.addEditLayerChangeListener(inActiveDataLayerModel); 124 if (Main.main.getEditLayer() != null) { 125 Main.main.getEditLayer().data.addDataSetListener(inActiveDataLayerModel); 126 inActiveDataLayerModel.initFromDataSet(Main.main.getEditLayer().data); 127 inSelectionModel.initFromPrimitives(Main.main.getEditLayer().data.getSelected()); 128 } 129 } 130 131 protected void unregisterAsListener() { 132 // remove the list model for the current edit layer as listener 133 // 134 ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel); 135 MapView.removeEditLayerChangeListener(inActiveDataLayerModel); 136 if (Main.main.getEditLayer() != null) { 137 Main.main.getEditLayer().data.removeDataSetListener(inActiveDataLayerModel); 138 } 139 140 // remove the list model for the changesets in the current selection as 141 // listener 142 // 143 MapView.removeEditLayerChangeListener(inSelectionModel); 144 DataSet.selListeners.remove(inSelectionModel); 145 } 146 110 147 @Override 111 148 public void tearDown() { 112 ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel); 113 MapView.removeLayerChangeListener(inSelectionModel); 114 DataSet.selListeners.remove(inSelectionModel); 149 unregisterAsListener(); 115 150 } 116 151 117 152 @Override 118 153 public void showNotify() { 154 registerAsListener(); 119 155 DatasetEventManager.getInstance().addDatasetListener(inActiveDataLayerModel, true); 120 156 } … … 122 158 @Override 123 159 public void hideNotify() { 160 unregisterAsListener(); 124 161 DatasetEventManager.getInstance().removeDatasetListener(inActiveDataLayerModel); 125 162 } … … 179 216 lstInActiveDataLayer.getSelectionModel().addListSelectionListener(showChangsetInfoAction); 180 217 lstInSelection.getSelectionModel().addListSelectionListener(showChangsetInfoAction); 218 219 // -- launch changeset manager action 220 launchChangesetManagerAction = new LaunchChangesetManagerAction(); 221 tp.add(launchChangesetManagerAction); 222 cbInSelectionOnly.addItemListener(launchChangesetManagerAction); 223 lstInActiveDataLayer.getSelectionModel().addListSelectionListener(launchChangesetManagerAction); 224 lstInSelection.getSelectionModel().addListSelectionListener(launchChangesetManagerAction); 181 225 182 226 pnl.add(tp); … … 334 378 if (sel.isEmpty()) 335 379 return; 336 DownloadChangesetsTask task = new DownloadChangesetsTask(sel);380 ChangesetHeaderDownloadTask task = new ChangesetHeaderDownloadTask(sel); 337 381 Main.worker.submit(task); 338 382 } … … 424 468 } 425 469 426 class PopupMenuLauncher extends MouseAdapter { 427 protected void showPopup(MouseEvent evt) { 428 if (!evt.isPopupTrigger()) 429 return; 470 /** 471 * Show information about the currently selected changesets 472 * 473 */ 474 class LaunchChangesetManagerAction extends AbstractAction implements ListSelectionListener, ItemListener { 475 public LaunchChangesetManagerAction() { 476 putValue(NAME, tr("Details")); 477 putValue(SHORT_DESCRIPTION, tr("Opens the Changeset Manager window for the selected changesets")); 478 putValue(SMALL_ICON, ImageProvider.get("dialogs/changeset", "changesetmanager")); 479 updateEnabledState(); 480 } 481 482 protected void launchChangesetManager(Collection<Integer> toSelect) { 483 ChangesetCacheManager cm = ChangesetCacheManager.getInstance(); 484 if (cm.isVisible()) { 485 cm.setExtendedState(Frame.NORMAL); 486 cm.toFront(); 487 cm.requestFocus(); 488 } else { 489 cm.setVisible(true); 490 cm.toFront(); 491 cm.requestFocus(); 492 } 493 cm.setSelectedChangesetsById(toSelect); 494 } 495 496 public void actionPerformed(ActionEvent arg0) { 497 ChangesetListModel model = getCurrentChangesetListModel(); 498 Set<Integer> sel = model.getSelectedChangesetIds(); 499 if (sel.isEmpty()) 500 return; 501 final Set<Integer> toDownload = new HashSet<Integer>(); 502 ChangesetCache cc = ChangesetCache.getInstance(); 503 for (int id: sel) { 504 if (!cc.contains(id)) { 505 toDownload.add(id); 506 } 507 } 508 509 final ChangesetHeaderDownloadTask task; 510 final Future<?> future; 511 if (toDownload.isEmpty()) { 512 task = null; 513 future = null; 514 } else { 515 task = new ChangesetHeaderDownloadTask(toDownload); 516 future = Main.worker.submit(task); 517 } 518 519 Runnable r = new Runnable() { 520 public void run() { 521 // first, wait for the download task to finish, if a download 522 // task was launched 523 if (future != null) { 524 try { 525 future.get(); 526 } catch(InterruptedException e) { 527 e.printStackTrace(); 528 } catch(ExecutionException e){ 529 e.printStackTrace(); 530 BugReportExceptionHandler.handleException(e.getCause()); 531 return; 532 } 533 } 534 if (task != null) { 535 if (task.isCanceled()) 536 // don't launch the changeset manager if the download task 537 // was canceled 538 return; 539 if (task.isFailed()) { 540 toDownload.clear(); 541 } 542 } 543 // launch the task 544 launchChangesetManager(toDownload); 545 } 546 }; 547 Main.worker.submit(r); 548 } 549 550 protected void updateEnabledState() { 551 setEnabled(getCurrentChangesetList().getSelectedIndices().length > 0); 552 } 553 554 public void itemStateChanged(ItemEvent arg0) { 555 updateEnabledState(); 556 } 557 558 public void valueChanged(ListSelectionEvent e) { 559 updateEnabledState(); 560 } 561 } 562 563 564 class ChangesetPopupMenuLauncher extends PopupMenuLauncher { 565 @Override 566 public void launch(MouseEvent evt) { 430 567 JList lst = getCurrentChangesetList(); 431 568 if (lst.getSelectedIndices().length == 0) { … … 438 575 popup.show(lst, evt.getX(), evt.getY()); 439 576 440 }441 @Override442 public void mouseClicked(MouseEvent evt) {443 showPopup(evt);444 }445 @Override446 public void mousePressed(MouseEvent evt) {447 showPopup(evt);448 }449 @Override450 public void mouseReleased(MouseEvent evt) {451 showPopup(evt);452 577 } 453 578 }
Note:
See TracChangeset
for help on using the changeset viewer.