source: josm/src/org/openstreetmap/josm/gui/BookmarkList.java@ 260

Last change on this file since 260 was 172, checked in by imi, 18 years ago
  • added support for Applet mode again (the basics)
  • added customizable toolbar
  • fixed shortcut for "New Empty Layer"
File size: 1.6 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.io.IOException;
6import java.util.Collection;
7import java.util.LinkedList;
8
9import javax.swing.DefaultListModel;
10import javax.swing.JList;
11import javax.swing.JOptionPane;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.Preferences;
15
16/**
17 * List class that read and save its content from the bookmark file.
18 * @author imi
19 */
20public class BookmarkList extends JList {
21
22 /**
23 * Create a bookmark list as well as the Buttons add and remove.
24 */
25 public BookmarkList() {
26 setModel(new DefaultListModel());
27 load();
28 setVisibleRowCount(7);
29 }
30
31 /**
32 * Loads the bookmarks from file.
33 */
34 public void load() {
35 DefaultListModel model = (DefaultListModel)getModel();
36 model.removeAllElements();
37 try {
38 for (Preferences.Bookmark b : Main.pref.loadBookmarks())
39 model.addElement(b);
40 } catch (IOException e) {
41 e.printStackTrace();
42 JOptionPane.showMessageDialog(Main.parent, tr("Could not read bookmarks.")+"\n"+e.getMessage());
43 }
44 }
45
46 /**
47 * Save all bookmarks to the preferences file
48 */
49 public void save() {
50 try {
51 Collection<Preferences.Bookmark> bookmarks = new LinkedList<Preferences.Bookmark>();
52 for (Object o : ((DefaultListModel)getModel()).toArray())
53 bookmarks.add((Preferences.Bookmark)o);
54 Main.pref.saveBookmarks(bookmarks);
55 } catch (IOException e) {
56 JOptionPane.showMessageDialog(Main.parent,tr("Could not write bookmark.")+"\n"+e.getMessage());
57 }
58 }
59}
Note: See TracBrowser for help on using the repository browser.