Changeset 2344 in josm for trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java
- Timestamp:
- 2009-10-29T05:18:55+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.