source: josm/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java@ 239

Last change on this file since 239 was 239, checked in by framm, 17 years ago

Remove debug println

File size: 3.2 KB
Line 
1package org.openstreetmap.josm.gui.download;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.GridBagLayout;
6import java.awt.GridLayout;
7import java.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
9import java.awt.event.MouseAdapter;
10import java.awt.event.MouseEvent;
11
12import javax.swing.DefaultListModel;
13import javax.swing.JButton;
14import javax.swing.JDialog;
15import javax.swing.JLabel;
16import javax.swing.JOptionPane;
17import javax.swing.JPanel;
18import javax.swing.JScrollPane;
19import javax.swing.event.ListSelectionEvent;
20import javax.swing.event.ListSelectionListener;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.data.Preferences;
24import org.openstreetmap.josm.data.coor.LatLon;
25import org.openstreetmap.josm.gui.BookmarkList;
26import org.openstreetmap.josm.tools.GBC;
27
28/**
29 * Bookmark selector.
30 *
31 * Provides selection, creation and deletion of bookmarks.
32 * Extracted from old DownloadAction.
33 *
34 * @author Frederik Ramm <frederik@remote.org>
35 *
36 */
37public class BookmarkSelection implements DownloadSelection {
38
39 private Preferences.Bookmark tempBookmark= null;
40 private BookmarkList bookmarks;
41
42 public void addGui(final DownloadDialog gui) {
43
44 JPanel dlg = new JPanel(new GridBagLayout());
45 gui.tabpane.addTab("Bookmarks", dlg);
46
47 bookmarks = new BookmarkList();
48 bookmarks.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
49 public void valueChanged(ListSelectionEvent e) {
50 Preferences.Bookmark b = (Preferences.Bookmark)bookmarks.getSelectedValue();
51 if (b != null) {
52 gui.minlat = b.latlon[0];
53 gui.minlon = b.latlon[1];
54 gui.maxlat = b.latlon[2];
55 gui.maxlon = b.latlon[3];
56 gui.boundingBoxChanged(BookmarkSelection.this);
57 }
58 }
59 });
60 //wc.addListMarker(bookmarks);
61 dlg.add(new JScrollPane(bookmarks), GBC.eol().fill());
62
63 JPanel buttons = new JPanel(new GridLayout(1,2));
64 JButton add = new JButton(tr("Add"));
65 add.addActionListener(new ActionListener(){
66 public void actionPerformed(ActionEvent e) {
67
68 if (tempBookmark == null) {
69 JOptionPane.showMessageDialog(Main.parent, tr("Please enter the desired coordinates first."));
70 return;
71 }
72 tempBookmark.name = JOptionPane.showInputDialog(Main.parent,tr("Please enter a name for the location."));
73 if (tempBookmark.name != null && !tempBookmark.name.equals("")) {
74 ((DefaultListModel)bookmarks.getModel()).addElement(tempBookmark);
75 bookmarks.save();
76 }
77 }
78 });
79 buttons.add(add);
80 JButton remove = new JButton(tr("Remove"));
81 remove.addActionListener(new ActionListener(){
82 public void actionPerformed(ActionEvent e) {
83 Object sel = bookmarks.getSelectedValue();
84 if (sel == null) {
85 JOptionPane.showMessageDialog(Main.parent,tr("Select a bookmark first."));
86 return;
87 }
88 ((DefaultListModel)bookmarks.getModel()).removeElement(sel);
89 bookmarks.save();
90 }
91 });
92 buttons.add(remove);
93 dlg.add(buttons, GBC.eop().fill(GBC.HORIZONTAL));
94 }
95
96 public void boundingBoxChanged(DownloadDialog gui) {
97 tempBookmark = new Preferences.Bookmark();
98 tempBookmark.latlon[0] = gui.minlat;
99 tempBookmark.latlon[1] = gui.minlon;
100 tempBookmark.latlon[2] = gui.maxlat;
101 tempBookmark.latlon[3] = gui.maxlon;
102 bookmarks.clearSelection();
103 }
104
105
106}
Note: See TracBrowser for help on using the repository browser.