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

Last change on this file since 2331 was 2327, checked in by Gubaer, 15 years ago

Cleanup in download logic (less global, more encapsulation)

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