- Timestamp:
- 2009-12-12T11:58:05+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java
r2512 r2616 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 18 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 19 import org.openstreetmap.josm.gui.help.HelpUtil; 20 import org.openstreetmap.josm.tools.ImageProvider; 17 21 import org.openstreetmap.josm.tools.OpenBrowser; 18 22 import org.openstreetmap.josm.tools.Shortcut; … … 78 82 } 79 83 80 p rotected boolean confirmLaunchMultiple(int numPrimitives) {84 public static boolean confirmLaunchMultiple(int numBrowsers) { 81 85 String msg = tr( 82 86 "You''re about to launch {0} browser windows.<br>" 83 87 + "This may both clutter your screen with browser windows<br>" 84 + "and take some time to finish.", num Primitives);88 + "and take some time to finish.", numBrowsers); 85 89 msg = "<html>" + msg + "</html>"; 86 String [] options = new String [] { 87 tr("Continue"), 88 tr("Cancel") 90 ButtonSpec[] spec = new ButtonSpec[] { 91 new ButtonSpec( 92 tr("Continue"), 93 ImageProvider.get("ok"), 94 tr("Click to continue and to open {0} browsers", numBrowsers), 95 null // no specific help topic 96 ), 97 new ButtonSpec( 98 tr("Cancel"), 99 ImageProvider.get("cancel"), 100 tr("Click to abort launching external browsers"), 101 null // no specific help topic 102 ) 89 103 }; 90 int ret = JOptionPane.showOptionDialog(104 int ret = HelpAwareOptionPane.showOptionDialog( 91 105 Main.parent, 92 106 msg, 93 107 tr("Warning"), 94 JOptionPane.YES_NO_OPTION,95 108 JOptionPane.WARNING_MESSAGE, 96 109 null, 97 options, 98 options[0] 110 spec, 111 spec[0], 112 HelpUtil.ht("/WarningMessages#ToManyBrowsersToOpen") 99 113 ); 100 return ret == JOptionPane.YES_OPTION;114 return ret == 0; 101 115 } 102 116 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
r2613 r2616 12 12 import java.awt.event.MouseEvent; 13 13 import java.util.HashSet; 14 import java.util.List; 14 15 import java.util.Set; 15 16 import java.util.logging.Logger; … … 20 21 import javax.swing.JList; 21 22 import javax.swing.JPanel; 23 import javax.swing.JPopupMenu; 22 24 import javax.swing.JScrollPane; 23 25 import javax.swing.JToolBar; … … 28 30 29 31 import org.openstreetmap.josm.Main; 32 import org.openstreetmap.josm.actions.AbstractInfoAction; 33 import org.openstreetmap.josm.data.osm.Changeset; 30 34 import org.openstreetmap.josm.data.osm.ChangesetCache; 31 35 import org.openstreetmap.josm.data.osm.DataSet; … … 38 42 import org.openstreetmap.josm.gui.dialogs.changeset.DownloadChangesetsTask; 39 43 import org.openstreetmap.josm.gui.help.HelpUtil; 44 import org.openstreetmap.josm.gui.io.CloseChangesetTask; 40 45 import org.openstreetmap.josm.gui.layer.Layer; 41 46 import org.openstreetmap.josm.tools.ImageProvider; 42 47 import org.openstreetmap.josm.tools.OpenBrowser; 48 49 /** 50 * ChangesetDialog is a toggle dialog which displays the current list of changesets. 51 * It either displays 52 * <ul> 53 * <li>the list of changesets the currently selected objects are assigned to</li> 54 * <li>the list of changesets objects in the current data layer are assigend to</li> 55 * </ul> 56 * 57 * The dialog offers actions to download and to close changesets. It can also launch an external 58 * browser with information about a changeset. Furthermore, it can select all objects in 59 * the current data layer being assigned to a specific changeset. 60 * 61 */ 43 62 public class ChangesetDialog extends ToggleDialog{ 44 63 static private final Logger logger = Logger.getLogger(ChangesetDialog.class.getName()); … … 51 70 private JPanel pnlList; 52 71 72 // the actions 73 private SelectObjectsAction selectObjectsAction; 74 private ReadChangesetsAction readChangesetAction; 75 private ShowChangesetInfoAction showChangsetInfoAction; 76 private CloseOpenChangesetsAction closeChangesetAction; 77 78 53 79 protected void buildChangesetsLists() { 54 80 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); … … 77 103 lstInSelection.addMouseListener(dblClickHandler); 78 104 lstInActiveDataLayer.addMouseListener(dblClickHandler); 105 106 PopupMenuLauncher popupMenuLauncher = new PopupMenuLauncher(); 107 lstInSelection.addMouseListener(popupMenuLauncher); 108 lstInActiveDataLayer.addMouseListener(popupMenuLauncher); 79 109 } 80 110 … … 114 144 tp.setFloatable(false); 115 145 116 SelectObjectsAction selectObjectsAction = new SelectObjectsAction(); 146 // -- select objects action 147 selectObjectsAction = new SelectObjectsAction(); 117 148 tp.add(selectObjectsAction); 118 149 cbInSelectionOnly.addItemListener(selectObjectsAction); … … 120 151 lstInSelection.getSelectionModel().addListSelectionListener(selectObjectsAction); 121 152 122 ReadChangesetsAction readChangesetAction = new ReadChangesetsAction(); 153 // -- read changesets action 154 readChangesetAction = new ReadChangesetsAction(); 123 155 tp.add(readChangesetAction); 124 156 cbInSelectionOnly.addItemListener(readChangesetAction); 125 157 lstInActiveDataLayer.getSelectionModel().addListSelectionListener(readChangesetAction); 126 158 lstInSelection.getSelectionModel().addListSelectionListener(readChangesetAction); 159 160 // -- close changesets action 161 closeChangesetAction = new CloseOpenChangesetsAction(); 162 tp.add(closeChangesetAction); 163 cbInSelectionOnly.addItemListener(closeChangesetAction); 164 lstInActiveDataLayer.getSelectionModel().addListSelectionListener(closeChangesetAction); 165 lstInSelection.getSelectionModel().addListSelectionListener(closeChangesetAction); 166 167 // -- show info action 168 showChangsetInfoAction = new ShowChangesetInfoAction(); 169 tp.add(showChangsetInfoAction); 170 cbInSelectionOnly.addItemListener(showChangsetInfoAction); 171 lstInActiveDataLayer.getSelectionModel().addListSelectionListener(showChangsetInfoAction); 172 lstInSelection.getSelectionModel().addListSelectionListener(showChangsetInfoAction); 127 173 128 174 pnl.add(tp); … … 203 249 } 204 250 251 /** 252 * Selects objects for the currently selected changesets. 253 */ 205 254 class SelectObjectsAction extends AbstractAction implements ListSelectionListener, ItemListener{ 206 255 … … 260 309 } 261 310 311 /** 312 * Downloads selected changesets 313 * 314 */ 262 315 class ReadChangesetsAction extends AbstractAction implements ListSelectionListener, ItemListener{ 263 316 public ReadChangesetsAction() { … … 291 344 } 292 345 346 /** 347 * Closes the currently selected changesets 348 * 349 */ 350 class CloseOpenChangesetsAction extends AbstractAction implements ListSelectionListener, ItemListener { 351 public CloseOpenChangesetsAction() { 352 putValue(NAME, tr("Close open changesets")); 353 putValue(SHORT_DESCRIPTION, tr("Closes the selected open changesets")); 354 putValue(SMALL_ICON, ImageProvider.get("closechangeset")); 355 updateEnabledState(); 356 } 357 358 public void actionPerformed(ActionEvent arg0) { 359 List<Changeset> sel = getCurrentChangesetListModel().getSelectedOpenChangesets(); 360 if (sel.isEmpty()) 361 return; 362 Main.worker.submit(new CloseChangesetTask(sel)); 363 } 364 365 protected void updateEnabledState() { 366 setEnabled(getCurrentChangesetListModel().hasSelectedOpenChangesets()); 367 } 368 369 public void itemStateChanged(ItemEvent arg0) { 370 updateEnabledState(); 371 } 372 373 public void valueChanged(ListSelectionEvent e) { 374 updateEnabledState(); 375 } 376 } 377 378 /** 379 * Show information about the currently selected changesets 380 * 381 */ 382 class ShowChangesetInfoAction extends AbstractAction implements ListSelectionListener, ItemListener { 383 public ShowChangesetInfoAction() { 384 putValue(NAME, tr("Show info")); 385 putValue(SHORT_DESCRIPTION, tr("Open a web page for each selected changeset")); 386 putValue(SMALL_ICON, ImageProvider.get("about")); 387 updateEnabledState(); 388 } 389 390 public void actionPerformed(ActionEvent arg0) { 391 Set<Changeset> sel = getCurrentChangesetListModel().getSelectedChangesets(); 392 if (sel.isEmpty()) 393 return; 394 if (sel.size() > 10 && ! AbstractInfoAction.confirmLaunchMultiple(sel.size())) 395 return; 396 String baseUrl = AbstractInfoAction.getBaseBrowseUrl(); 397 for (Changeset cs: sel) { 398 String url = baseUrl + "/changeset/" + cs.getId(); 399 OpenBrowser.displayUrl( 400 url 401 ); 402 } 403 } 404 405 protected void updateEnabledState() { 406 setEnabled(getCurrentChangesetList().getSelectedIndices().length > 0); 407 } 408 409 public void itemStateChanged(ItemEvent arg0) { 410 updateEnabledState(); 411 } 412 413 public void valueChanged(ListSelectionEvent e) { 414 updateEnabledState(); 415 } 416 } 417 418 class PopupMenuLauncher extends MouseAdapter { 419 protected void showPopup(MouseEvent evt) { 420 if (!evt.isPopupTrigger()) 421 return; 422 JList lst = getCurrentChangesetList(); 423 if (lst.getSelectedIndices().length == 0) { 424 int idx = lst.locationToIndex(evt.getPoint()); 425 if (idx >=0) { 426 lst.getSelectionModel().addSelectionInterval(idx, idx); 427 } 428 } 429 ChangesetDialogPopup popup = new ChangesetDialogPopup(); 430 popup.show(lst, evt.getX(), evt.getY()); 431 432 } 433 @Override 434 public void mouseClicked(MouseEvent evt) { 435 showPopup(evt); 436 } 437 @Override 438 public void mousePressed(MouseEvent evt) { 439 showPopup(evt); 440 } 441 @Override 442 public void mouseReleased(MouseEvent evt) { 443 showPopup(evt); 444 } 445 } 446 447 class ChangesetDialogPopup extends JPopupMenu { 448 public ChangesetDialogPopup() { 449 add(selectObjectsAction); 450 addSeparator(); 451 add(readChangesetAction); 452 add(closeChangesetAction); 453 addSeparator(); 454 add(showChangsetInfoAction); 455 } 456 } 293 457 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetListModel.java
r2613 r2616 162 162 } 163 163 164 /** 165 * Replies true if there is at least one selected open changeset 166 * 167 * @return true if there is at least one selected open changeset 168 */ 169 public boolean hasSelectedOpenChangesets() { 170 return !getSelectedOpenChangesets().isEmpty(); 171 } 172 173 /** 174 * Replies the selected open changesets 175 * 176 * @return the selected open changesets 177 */ 178 public List<Changeset> getSelectedOpenChangesets() { 179 List<Changeset> ret = new ArrayList<Changeset>(); 180 for (int i=0; i< getSize(); i++) { 181 if (selectionModel.isSelectedIndex(i)) { 182 Changeset cs = data.get(i); 183 if (cs.isOpen()) { 184 ret.add(cs); 185 } 186 } 187 } 188 return ret; 189 } 190 164 191 /* ---------------------------------------------------------------------------- */ 165 192 /* Interface ChangesetCacheListener */
Note:
See TracChangeset
for help on using the changeset viewer.