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

Last change on this file since 1169 was 1169, checked in by stoecker, 15 years ago

removed usage of tab stops

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui.download;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.awt.GridLayout;
8import java.awt.event.ActionEvent;
9import java.awt.event.ActionListener;
10import java.awt.event.MouseListener;
11import java.awt.event.MouseAdapter;
12import java.awt.event.MouseEvent;
13
14import javax.swing.DefaultListModel;
15import javax.swing.JButton;
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.gui.BookmarkList;
25import org.openstreetmap.josm.tools.GBC;
26
27/**
28 * Bookmark selector.
29 *
30 * Provides selection, creation and deletion of bookmarks.
31 * Extracted from old DownloadAction.
32 *
33 * @author Frederik Ramm <frederik@remote.org>
34 *
35 */
36public class BookmarkSelection implements DownloadSelection {
37
38 private Preferences.Bookmark tempBookmark = null;
39 private BookmarkList bookmarks;
40
41 public void addGui(final DownloadDialog gui) {
42
43 JPanel dlg = new JPanel(new GridBagLayout());
44 gui.tabpane.addTab(tr("Bookmarks"), dlg);
45
46 bookmarks = new BookmarkList();
47
48 /* add a handler for "double click" mouse events */
49 MouseListener mouseListener = new MouseAdapter() {
50 @Override public void mouseClicked(MouseEvent e) {
51 if (e.getClickCount() == 2) {
52 //int index = bookmarks.locationToIndex(e.getPoint());
53 gui.closeDownloadDialog(true);
54 }
55 }
56 };
57 bookmarks.addMouseListener(mouseListener);
58
59 bookmarks.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
60 public void valueChanged(ListSelectionEvent e) {
61 Preferences.Bookmark b = (Preferences.Bookmark)bookmarks.getSelectedValue();
62 if (b != null) {
63 gui.minlat = b.latlon[0];
64 gui.minlon = b.latlon[1];
65 gui.maxlat = b.latlon[2];
66 gui.maxlon = b.latlon[3];
67 gui.boundingBoxChanged(BookmarkSelection.this);
68 }
69 }
70 });
71 //wc.addListMarker(bookmarks);
72 dlg.add(new JScrollPane(bookmarks), GBC.eol().fill());
73
74 JPanel buttons = new JPanel(new GridLayout(1,2));
75 JButton add = new JButton(tr("Add"));
76 add.addActionListener(new ActionListener(){
77 public void actionPerformed(ActionEvent e) {
78
79 if (tempBookmark == null) {
80 JOptionPane.showMessageDialog(Main.parent, tr("Please enter the desired coordinates first."));
81 return;
82 }
83 tempBookmark.name = JOptionPane.showInputDialog(Main.parent,tr("Please enter a name for the location."));
84 if (tempBookmark.name != null && !tempBookmark.name.equals("")) {
85 ((DefaultListModel)bookmarks.getModel()).addElement(tempBookmark);
86 bookmarks.save();
87 }
88 }
89 });
90 buttons.add(add);
91 JButton remove = new JButton(tr("Remove"));
92 remove.addActionListener(new ActionListener(){
93 public void actionPerformed(ActionEvent e) {
94 Object sel = bookmarks.getSelectedValue();
95 if (sel == null) {
96 JOptionPane.showMessageDialog(Main.parent,tr("Select a bookmark first."));
97 return;
98 }
99 ((DefaultListModel)bookmarks.getModel()).removeElement(sel);
100 bookmarks.save();
101 }
102 });
103 buttons.add(remove);
104 dlg.add(buttons, GBC.eop().fill(GBC.HORIZONTAL));
105 }
106
107 public void boundingBoxChanged(DownloadDialog gui) {
108 tempBookmark = new Preferences.Bookmark();
109 tempBookmark.latlon[0] = gui.minlat;
110 tempBookmark.latlon[1] = gui.minlon;
111 tempBookmark.latlon[2] = gui.maxlat;
112 tempBookmark.latlon[3] = gui.maxlon;
113 bookmarks.clearSelection();
114 }
115
116
117}
Note: See TracBrowser for help on using the repository browser.