- Timestamp:
- 2009-10-29T05:18:55+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/BookmarkList.java
r2334 r2344 10 10 11 11 import javax.swing.DefaultListModel; 12 import javax.swing.ImageIcon; 12 13 import javax.swing.JLabel; 13 14 import javax.swing.JList; … … 20 21 import org.openstreetmap.josm.data.Preferences; 21 22 import org.openstreetmap.josm.data.Preferences.Bookmark; 23 import org.openstreetmap.josm.tools.ImageProvider; 22 24 23 25 /** … … 83 85 class BookmarkCellRenderer extends JLabel implements ListCellRenderer { 84 86 87 private ImageIcon icon; 88 85 89 public BookmarkCellRenderer() { 86 90 setOpaque(true); 91 icon = ImageProvider.get("dialogs", "bookmark"); 92 setIcon(icon); 87 93 } 88 94 -
trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java
r2334 r2344 6 6 import java.awt.GridBagConstraints; 7 7 import java.awt.GridBagLayout; 8 import java.awt.Insets; 8 9 import java.awt.event.ActionEvent; 10 import java.awt.event.MouseAdapter; 11 import java.awt.event.MouseEvent; 9 12 10 13 import javax.swing.AbstractAction; … … 14 17 import javax.swing.JPanel; 15 18 import javax.swing.JScrollPane; 19 import javax.swing.SwingUtilities; 16 20 import javax.swing.event.ListSelectionEvent; 17 21 import javax.swing.event.ListSelectionListener; … … 21 25 import org.openstreetmap.josm.data.Preferences; 22 26 import org.openstreetmap.josm.data.Preferences.Bookmark; 27 import org.openstreetmap.josm.data.coor.CoordinateFormat; 23 28 import org.openstreetmap.josm.gui.BookmarkList; 29 import org.openstreetmap.josm.gui.JMultilineLabel; 24 30 import org.openstreetmap.josm.tools.ImageProvider; 25 31 26 32 /** 27 * Bookmark selector. 28 * 29 * Provides selection, creation and deletion of bookmarks. 30 * Extracted from old DownloadAction. 31 * 32 * @author Frederik Ramm <frederik@remote.org> 33 * DownloadAreaSelector which manages a list of "bookmarks", i.e. a list of 34 * name download areas. 33 35 * 34 36 */ 35 37 public class BookmarkSelection implements DownloadSelection { 36 38 39 /** the currently selected download area. One can add bookmarks for this 40 * area, if not null 41 */ 37 42 private Bounds currentArea; 43 /** the list of bookmarks */ 38 44 private BookmarkList bookmarks; 39 45 46 /** the parent download GUI */ 47 private DownloadDialog parent; 48 49 /** displays information about the current download area */ 50 private JMultilineLabel lblCurrentDownloadArea; 51 /** the add action */ 52 private AddAction actAdd; 53 54 /** 55 * Creates the panel with the action buttons on the left 56 * 57 * @return the panel with the action buttons on the left 58 */ 40 59 protected JPanel buildButtonPanel() { 41 60 JPanel pnl = new JPanel(); 42 61 pnl.setLayout(new GridBagLayout()); 43 62 GridBagConstraints gc = new GridBagConstraints(); 44 gc.fill = GridBagConstraints.HORIZONTAL;45 gc.weightx = 1.0;46 gc.weighty = 0.0;47 pnl.add(new JButton(new AddAction()), gc);48 49 gc.gridy = 1;63 // gc.fill = GridBagConstraints.HORIZONTAL; 64 // gc.weightx = 1.0; 65 // gc.weighty = 0.0; 66 // pnl.add(new JButton(actAdd = new AddAction()), gc); 67 68 gc.gridy = 0; 50 69 RemoveAction removeAction = new RemoveAction(); 51 70 bookmarks.addListSelectionListener(removeAction); 52 71 pnl.add(new JButton(removeAction), gc); 53 72 54 gc.gridy = 2;73 gc.gridy = 1; 55 74 RenameAction renameAction = new RenameAction(); 56 75 bookmarks.addListSelectionListener(renameAction); … … 62 81 gc.gridy = 3; 63 82 pnl.add(new JPanel(), gc); // just a filler 83 return pnl; 84 } 85 86 protected JPanel buildDownloadAreaAddPanel() { 87 JPanel pnl = new JPanel(); 88 pnl.setLayout(new GridBagLayout()); 89 90 GridBagConstraints gc = new GridBagConstraints(); 91 gc.anchor = GridBagConstraints.NORTHWEST; 92 gc.fill = GridBagConstraints.BOTH; 93 gc.weightx = 1.0; 94 gc.weighty = 1.0; 95 gc.insets = new Insets(5,5,5,5); 96 97 pnl.add(lblCurrentDownloadArea = new JMultilineLabel(""), gc); 98 99 gc.anchor = GridBagConstraints.NORTHEAST; 100 gc.fill = GridBagConstraints.HORIZONTAL; 101 gc.weightx = 0.0; 102 gc.weighty = 0.0; 103 gc.insets = new Insets(5,5,5,5); 104 pnl.add(new JButton(actAdd = new AddAction()), gc); 64 105 return pnl; 65 106 } … … 80 121 } 81 122 }); 123 bookmarks.addMouseListener(new DoubleClickAdapter()); 124 125 gc.fill = GridBagConstraints.HORIZONTAL; 126 gc.weightx = 1.0; 127 gc.weighty = 0.0; 128 gc.gridwidth = 2; 129 dlg.add(buildDownloadAreaAddPanel(),gc); 82 130 131 gc.gridwidth = 1; 132 gc.gridx = 0; 133 gc.gridy = 1; 83 134 gc.fill = GridBagConstraints.VERTICAL; 84 135 gc.weightx = 0.0; 85 136 gc.weighty = 1.0; 86 137 dlg.add(buildButtonPanel(),gc); 87 138 139 gc.gridwidth = 1; 140 gc.gridx = 1; 141 gc.gridy = 1; 88 142 gc.fill = GridBagConstraints.BOTH; 89 143 gc.weightx = 1.0; 90 144 gc.weighty = 1.0; 91 145 gc.gridx = 1; 92 dlg.add(new JScrollPane(bookmarks), gc); 93 } 94 146 dlg.add(new JScrollPane(bookmarks), gc); 147 148 this.parent = gui; 149 } 150 151 protected void updateDownloadAreaLabel() { 152 if (currentArea == null) { 153 lblCurrentDownloadArea.setText(tr("<html>There is currently no download area selected.</html>")); 154 } else { 155 lblCurrentDownloadArea.setText(tr("<html><strong>Current download area</strong> (minlat,minlon, maxlat, maxlon): {0}, {1}, {2}, {3}</html>", 156 currentArea.getMin().latToString(CoordinateFormat.DECIMAL_DEGREES), 157 currentArea.getMin().lonToString(CoordinateFormat.DECIMAL_DEGREES), 158 currentArea.getMax().latToString(CoordinateFormat.DECIMAL_DEGREES), 159 currentArea.getMax().lonToString(CoordinateFormat.DECIMAL_DEGREES) 160 ) 161 ); 162 } 163 } 164 165 /** 166 * Sets the current download area 167 * 168 * @param area the download area. 169 */ 95 170 public void setDownloadArea(Bounds area) { 96 171 if (area == null) return; 97 172 this.currentArea = area; 98 173 bookmarks.clearSelection(); 99 } 100 174 updateDownloadAreaLabel(); 175 actAdd.setEnabled(area != null); 176 } 177 178 /** 179 * The action to add a new bookmark for the current download area. 180 * 181 */ 101 182 class AddAction extends AbstractAction { 102 183 public AddAction() { 103 //putValue(NAME, tr("Add"));104 putValue(SMALL_ICON, ImageProvider.get("dialogs", " add"));184 putValue(NAME, tr("Create bookmark")); 185 putValue(SMALL_ICON, ImageProvider.get("dialogs", "bookmark-new")); 105 186 putValue(SHORT_DESCRIPTION, tr("Add a bookmark for the currently selected download area")); 106 187 } … … 193 274 } 194 275 } 195 276 277 class DoubleClickAdapter extends MouseAdapter { 278 @Override 279 public void mouseClicked(MouseEvent e) { 280 if (!(SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2)) 281 return; 282 int idx = bookmarks.locationToIndex(e.getPoint()); 283 if (idx < 0 || idx >= bookmarks.getModel().getSize()) 284 return; 285 Bookmark b = (Bookmark)bookmarks.getModel().getElementAt(idx); 286 parent.startDownload(b.getArea()); 287 } 288 } 196 289 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r2340 r2344 55 55 static private DownloadDialog instance; 56 56 57 57 58 /** 58 59 * Replies the unique instance of the download dialog … … 75 76 private JCheckBox cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), true); 76 77 private JCheckBox cbDownloadGpxData = new JCheckBox(tr("Raw GPS data")); 78 /** the download action and button */ 79 private DownloadAction actDownload; 80 private SideButton btnDownload; 77 81 78 82 … … 124 128 JPanel pnl = new JPanel(); 125 129 pnl.setLayout(new FlowLayout()); 126 127 pnl.add(new SideButton(new DownloadAction())); 130 131 pnl.add(btnDownload = new SideButton(actDownload = new DownloadAction())); 132 btnDownload.setFocusable(true); 128 133 pnl.add(new SideButton(new CancelAction())); 129 134 pnl.add(new SideButton(new ContextSensitiveHelpAction(ht("/Dialog/DownloadDialog")))); … … 199 204 } 200 205 updateSizeCheck(); 206 } 207 208 /** 209 * Invoked by 210 * @param b 211 */ 212 public void startDownload(Bounds b) { 213 this.currentBounds = b; 214 actDownload.run(); 201 215 } 202 216 … … 343 357 } 344 358 345 public void actionPerformed(ActionEvent e) {359 public void run() { 346 360 if (currentBounds == null) { 347 361 JOptionPane.showMessageDialog( … … 367 381 } 368 382 setCanceled(false); 369 setVisible(false); 383 setVisible(false); 384 } 385 386 public void actionPerformed(ActionEvent e) { 387 run(); 370 388 } 371 389 } … … 375 393 public void windowClosing(WindowEvent e) { 376 394 new CancelAction().run(); 395 } 396 397 @Override 398 public void windowActivated(WindowEvent e) { 399 btnDownload.requestFocusInWindow(); 377 400 } 378 401 }
Note:
See TracChangeset
for help on using the changeset viewer.