Changeset 9916 in josm
- Timestamp:
- 2016-03-02T22:54:34+01:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java
r9526 r9916 9 9 import java.awt.Dimension; 10 10 import java.awt.FlowLayout; 11 import java.awt.GraphicsEnvironment; 12 import java.awt.Window; 11 13 import java.awt.event.ActionEvent; 12 14 import java.awt.event.KeyEvent; … … 48 50 import org.openstreetmap.josm.gui.help.HelpUtil; 49 51 import org.openstreetmap.josm.gui.io.CloseChangesetTask; 52 import org.openstreetmap.josm.gui.util.GuiHelper; 50 53 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 51 54 import org.openstreetmap.josm.io.ChangesetQuery; … … 60 63 * downloading, querying, closing changesets, in addition to removing changesets from 61 64 * the local cache. 62 * 65 * @since 2689 63 66 */ 64 67 public class ChangesetCacheManager extends JFrame { … … 86 89 87 90 /** 88 * Hides and destroys the unique instance of the changeset cache 89 * manager. 91 * Hides and destroys the unique instance of the changeset cache manager. 90 92 * 91 93 */ … … 109 111 110 112 /** 111 * Creates the various models required 112 */ 113 protected void buildModel() { 113 * Creates the various models required. 114 * @return the changeset cache model 115 */ 116 static ChangesetCacheManagerModel buildModel() { 114 117 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 115 118 selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 116 model = new ChangesetCacheManagerModel(selectionModel); 117 118 actRemoveFromCacheAction = new RemoveFromCacheAction(); 119 actCloseSelectedChangesetsAction = new CloseSelectedChangesetsAction(); 120 actDownloadSelectedChangesets = new DownloadSelectedChangesetsAction(); 121 actDownloadSelectedContent = new DownloadSelectedChangesetContentAction(); 119 return new ChangesetCacheManagerModel(selectionModel); 122 120 } 123 121 … … 127 125 * @return the toolbar panel 128 126 */ 129 protectedJPanel buildToolbarPanel() {127 static JPanel buildToolbarPanel() { 130 128 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.LEFT)); 131 129 … … 143 141 * @return the button row pane 144 142 */ 145 protectedJPanel buildButtonPanel() {143 static JPanel buildButtonPanel() { 146 144 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 147 145 … … 150 148 151 149 //-- help action 152 pnl.add(new SideButton( 153 new ContextSensitiveHelpAction( 154 HelpUtil.ht("/Dialog/ChangesetManager")) 155 ) 156 ); 150 pnl.add(new SideButton(new ContextSensitiveHelpAction(HelpUtil.ht("/Dialog/ChangesetManager")))); 157 151 158 152 return pnl; … … 266 260 tblChangesets.addMouseListener(new MouseEventHandler()); 267 261 tblChangesets.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "showDetails"); 268 tblChangesets.getActionMap().put("showDetails", new ShowDetailAction( ));269 model.getSelectionModel().addListSelectionListener(new ChangesetDetailViewSynchronizer( ));262 tblChangesets.getActionMap().put("showDetails", new ShowDetailAction(model)); 263 model.getSelectionModel().addListSelectionListener(new ChangesetDetailViewSynchronizer(model)); 270 264 271 265 // activate DEL on the table … … 285 279 cp.setLayout(new BorderLayout()); 286 280 287 buildModel(); 281 model = buildModel(); 282 actRemoveFromCacheAction = new RemoveFromCacheAction(model); 283 actCloseSelectedChangesetsAction = new CloseSelectedChangesetsAction(model); 284 actDownloadSelectedChangesets = new DownloadSelectedChangesetsAction(model); 285 actDownloadSelectedContent = new DownloadSelectedChangesetContentAction(model); 286 288 287 cp.add(buildToolbarPanel(), BorderLayout.NORTH); 289 288 cp.add(buildContentPanel(), BorderLayout.CENTER); … … 340 339 341 340 @Override 342 public void windowActivated(WindowEvent arg0) {341 public void windowActivated(WindowEvent e) { 343 342 if (needsSplitPaneAdjustment) { 344 343 spContent.setDividerLocation(0.5); … … 363 362 364 363 @Override 365 public void actionPerformed(ActionEvent arg0) {364 public void actionPerformed(ActionEvent e) { 366 365 cancelAndClose(); 367 366 } … … 371 370 * The action to query and download changesets 372 371 */ 373 class QueryAction extends AbstractAction { 372 static class QueryAction extends AbstractAction { 373 374 374 QueryAction() { 375 375 putValue(NAME, tr("Query")); … … 381 381 @Override 382 382 public void actionPerformed(ActionEvent evt) { 383 ChangesetQueryDialog dialog = new ChangesetQueryDialog(ChangesetCacheManager.this); 384 dialog.initForUserInput(); 385 dialog.setVisible(true); 386 if (dialog.isCanceled()) 387 return; 388 389 try { 390 ChangesetQuery query = dialog.getChangesetQuery(); 391 if (query == null) return; 392 ChangesetQueryTask task = new ChangesetQueryTask(ChangesetCacheManager.this, query); 393 ChangesetCacheManager.getInstance().runDownloadTask(task); 394 } catch (IllegalStateException e) { 395 JOptionPane.showMessageDialog(ChangesetCacheManager.this, e.getMessage(), tr("Error"), JOptionPane.ERROR_MESSAGE); 383 Window parent = GuiHelper.getWindowAncestorFor(evt); 384 if (!GraphicsEnvironment.isHeadless()) { 385 ChangesetQueryDialog dialog = new ChangesetQueryDialog(parent); 386 dialog.initForUserInput(); 387 dialog.setVisible(true); 388 if (dialog.isCanceled()) 389 return; 390 391 try { 392 ChangesetQuery query = dialog.getChangesetQuery(); 393 if (query != null) { 394 ChangesetCacheManager.getInstance().runDownloadTask(new ChangesetQueryTask(parent, query)); 395 } 396 } catch (IllegalStateException e) { 397 JOptionPane.showMessageDialog(parent, e.getMessage(), tr("Error"), JOptionPane.ERROR_MESSAGE); 398 } 396 399 } 397 400 } … … 402 405 * 403 406 */ 404 class RemoveFromCacheAction extends AbstractAction implements ListSelectionListener { 405 RemoveFromCacheAction() { 407 static class RemoveFromCacheAction extends AbstractAction implements ListSelectionListener { 408 private final ChangesetCacheManagerModel model; 409 410 RemoveFromCacheAction(ChangesetCacheManagerModel model) { 406 411 putValue(NAME, tr("Remove from cache")); 407 412 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 408 413 putValue(SHORT_DESCRIPTION, tr("Remove the selected changesets from the local cache")); 414 this.model = model; 409 415 updateEnabledState(); 410 416 } 411 417 412 418 @Override 413 public void actionPerformed(ActionEvent arg0) { 414 List<Changeset> selected = model.getSelectedChangesets(); 415 ChangesetCache.getInstance().remove(selected); 419 public void actionPerformed(ActionEvent e) { 420 ChangesetCache.getInstance().remove(model.getSelectedChangesets()); 416 421 } 417 422 … … 430 435 * 431 436 */ 432 class CloseSelectedChangesetsAction extends AbstractAction implements ListSelectionListener { 433 CloseSelectedChangesetsAction() { 437 static class CloseSelectedChangesetsAction extends AbstractAction implements ListSelectionListener { 438 private final ChangesetCacheManagerModel model; 439 440 CloseSelectedChangesetsAction(ChangesetCacheManagerModel model) { 434 441 putValue(NAME, tr("Close")); 435 442 putValue(SMALL_ICON, ImageProvider.get("closechangeset")); 436 443 putValue(SHORT_DESCRIPTION, tr("Close the selected changesets")); 444 this.model = model; 437 445 updateEnabledState(); 438 446 } 439 447 440 448 @Override 441 public void actionPerformed(ActionEvent arg0) { 442 List<Changeset> selected = model.getSelectedChangesets(); 443 Main.worker.submit(new CloseChangesetTask(selected)); 449 public void actionPerformed(ActionEvent e) { 450 Main.worker.submit(new CloseChangesetTask(model.getSelectedChangesets())); 444 451 } 445 452 … … 472 479 * 473 480 */ 474 class DownloadSelectedChangesetsAction extends AbstractAction implements ListSelectionListener { 475 DownloadSelectedChangesetsAction() { 481 static class DownloadSelectedChangesetsAction extends AbstractAction implements ListSelectionListener { 482 private final ChangesetCacheManagerModel model; 483 484 DownloadSelectedChangesetsAction(ChangesetCacheManagerModel model) { 476 485 putValue(NAME, tr("Update changeset")); 477 486 putValue(SMALL_ICON, ImageProvider.get("dialogs/changeset", "updatechangeset")); 478 487 putValue(SHORT_DESCRIPTION, tr("Updates the selected changesets with current data from the OSM server")); 488 this.model = model; 479 489 updateEnabledState(); 480 490 } 481 491 482 492 @Override 483 public void actionPerformed(ActionEvent arg0) { 484 List<Changeset> selected = model.getSelectedChangesets(); 485 ChangesetHeaderDownloadTask task = ChangesetHeaderDownloadTask.buildTaskForChangesets(ChangesetCacheManager.this, selected); 486 ChangesetCacheManager.getInstance().runDownloadTask(task); 493 public void actionPerformed(ActionEvent e) { 494 if (!GraphicsEnvironment.isHeadless()) { 495 ChangesetCacheManager.getInstance().runDownloadTask( 496 ChangesetHeaderDownloadTask.buildTaskForChangesets(GuiHelper.getWindowAncestorFor(e), model.getSelectedChangesets())); 497 } 487 498 } 488 499 … … 501 512 * 502 513 */ 503 class DownloadSelectedChangesetContentAction extends AbstractAction implements ListSelectionListener { 504 DownloadSelectedChangesetContentAction() { 514 static class DownloadSelectedChangesetContentAction extends AbstractAction implements ListSelectionListener { 515 private final ChangesetCacheManagerModel model; 516 517 DownloadSelectedChangesetContentAction(ChangesetCacheManagerModel model) { 505 518 putValue(NAME, tr("Download changeset content")); 506 519 putValue(SMALL_ICON, DOWNLOAD_CONTENT_ICON); 507 520 putValue(SHORT_DESCRIPTION, tr("Download the content of the selected changesets from the server")); 521 this.model = model; 508 522 updateEnabledState(); 509 523 } 510 524 511 525 @Override 512 public void actionPerformed(ActionEvent arg0) { 513 ChangesetContentDownloadTask task = new ChangesetContentDownloadTask(ChangesetCacheManager.this, model.getSelectedChangesetIds()); 514 ChangesetCacheManager.getInstance().runDownloadTask(task); 526 public void actionPerformed(ActionEvent e) { 527 if (!GraphicsEnvironment.isHeadless()) { 528 ChangesetCacheManager.getInstance().runDownloadTask( 529 new ChangesetContentDownloadTask(GuiHelper.getWindowAncestorFor(e), model.getSelectedChangesetIds())); 530 } 515 531 } 516 532 … … 525 541 } 526 542 527 class ShowDetailAction extends AbstractAction { 528 529 public void showDetails() { 543 static class ShowDetailAction extends AbstractAction { 544 private final ChangesetCacheManagerModel model; 545 546 ShowDetailAction(ChangesetCacheManagerModel model) { 547 this.model = model; 548 } 549 550 protected void showDetails() { 530 551 List<Changeset> selected = model.getSelectedChangesets(); 531 if (selected.size() != 1) return; 532 model.setChangesetInDetailView(selected.get(0)); 533 } 534 535 @Override 536 public void actionPerformed(ActionEvent arg0) { 552 if (selected.size() == 1) { 553 model.setChangesetInDetailView(selected.get(0)); 554 } 555 } 556 557 @Override 558 public void actionPerformed(ActionEvent e) { 537 559 showDetails(); 538 560 } 539 561 } 540 562 541 class DownloadMyChangesets extends AbstractAction {563 static class DownloadMyChangesets extends AbstractAction { 542 564 DownloadMyChangesets() { 543 565 putValue(NAME, tr("My changesets")); … … 547 569 } 548 570 549 protected void alertAnonymousUser( ) {571 protected void alertAnonymousUser(Component parent) { 550 572 HelpAwareOptionPane.showOptionDialog( 551 ChangesetCacheManager.this,573 parent, 552 574 tr("<html>JOSM is currently running with an anonymous user. It cannot download<br>" 553 575 + "your changesets from the OSM server unless you enter your OSM user name<br>" … … 561 583 562 584 @Override 563 public void actionPerformed(ActionEvent arg0) { 585 public void actionPerformed(ActionEvent e) { 586 Window parent = GuiHelper.getWindowAncestorFor(e); 564 587 JosmUserIdentityManager im = JosmUserIdentityManager.getInstance(); 565 588 if (im.isAnonymous()) { 566 alertAnonymousUser( );589 alertAnonymousUser(parent); 567 590 return; 568 591 } … … 573 596 query = query.forUser(im.getUserName()); 574 597 } 575 ChangesetQueryTask task = new ChangesetQueryTask(ChangesetCacheManager.this, query); 576 ChangesetCacheManager.getInstance().runDownloadTask(task); 598 if (!GraphicsEnvironment.isHeadless()) { 599 ChangesetCacheManager.getInstance().runDownloadTask(new ChangesetQueryTask(parent, query)); 600 } 577 601 } 578 602 } … … 587 611 public void mouseClicked(MouseEvent evt) { 588 612 if (isDoubleClick(evt)) { 589 new ShowDetailAction( ).showDetails();613 new ShowDetailAction(model).showDetails(); 590 614 } 591 615 } … … 601 625 } 602 626 603 class ChangesetDetailViewSynchronizer implements ListSelectionListener { 627 static class ChangesetDetailViewSynchronizer implements ListSelectionListener { 628 private final ChangesetCacheManagerModel model; 629 630 ChangesetDetailViewSynchronizer(ChangesetCacheManagerModel model) { 631 this.model = model; 632 } 633 604 634 @Override 605 635 public void valueChanged(ListSelectionEvent e) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/ChangesetQueryDialog.java
r8836 r9916 6 6 import java.awt.BorderLayout; 7 7 import java.awt.Container; 8 import java.awt.Dialog;9 8 import java.awt.Dimension; 10 9 import java.awt.FlowLayout; 11 import java.awt. Frame;10 import java.awt.Window; 12 11 import java.awt.event.ActionEvent; 13 12 import java.awt.event.KeyEvent; … … 95 94 } 96 95 97 public ChangesetQueryDialog(Dialog parent) { 98 super(parent, ModalityType.DOCUMENT_MODAL); 99 build(); 100 } 101 102 public ChangesetQueryDialog(Frame parent) { 96 public ChangesetQueryDialog(Window parent) { 103 97 super(parent, ModalityType.DOCUMENT_MODAL); 104 98 build(); -
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r9826 r9916 27 27 import java.lang.reflect.InvocationTargetException; 28 28 import java.util.Enumeration; 29 import java.util.EventObject; 29 30 import java.util.concurrent.Callable; 30 31 import java.util.concurrent.ExecutionException; … … 463 464 return GraphicsEnvironment.isHeadless() ? null : Toolkit.getDefaultToolkit().getSystemSelection(); 464 465 } 466 467 /** 468 * Returns the first <code>Window</code> ancestor of event source, or 469 * {@code null} if event source is not a component contained inside a <code>Window</code>. 470 * @param e event object 471 * @return a Window, or {@code null} 472 * @since 9916 473 */ 474 public static Window getWindowAncestorFor(EventObject e) { 475 return e != null && e.getSource() instanceof Component ? SwingUtilities.getWindowAncestor((Component) e.getSource()) : null; 476 } 465 477 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9732 r9916 8 8 import java.awt.Color; 9 9 import java.awt.Font; 10 import java.awt.HeadlessException; 10 11 import java.awt.Toolkit; 11 12 import java.awt.datatransfer.Clipboard; … … 635 636 */ 636 637 public static String getClipboardContent() { 637 Transferable t = getTransferableContent(Toolkit.getDefaultToolkit().getSystemClipboard());638 638 try { 639 Transferable t = getTransferableContent(Toolkit.getDefaultToolkit().getSystemClipboard()); 639 640 if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { 640 641 return (String) t.getTransferData(DataFlavor.stringFlavor); 641 642 } 642 } catch (UnsupportedFlavorException | IOException ex) {643 } catch (UnsupportedFlavorException | IOException | HeadlessException ex) { 643 644 Main.error(ex); 644 645 return null;
Note:
See TracChangeset
for help on using the changeset viewer.