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

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

added isUsable() to primitives to replace (!incomplete && !deleted) checks with a more descriptive variant

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7import java.util.Collection;
8import java.util.LinkedList;
9
10import javax.swing.DefaultListModel;
11import javax.swing.JList;
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.data.Preferences;
16
17/**
18 * List class that read and save its content from the bookmark file.
19 * @author imi
20 */
21public class BookmarkList extends JList {
22
23 /**
24 * Create a bookmark list as well as the Buttons add and remove.
25 */
26 public BookmarkList() {
27 setModel(new DefaultListModel());
28 load();
29 setVisibleRowCount(7);
30 }
31
32 /**
33 * Loads the bookmarks from file.
34 */
35 public void load() {
36 DefaultListModel model = (DefaultListModel)getModel();
37 model.removeAllElements();
38 try {
39 for (Preferences.Bookmark b : Main.pref.loadBookmarks()) {
40 model.addElement(b);
41 }
42 } catch (IOException e) {
43 e.printStackTrace();
44 JOptionPane.showMessageDialog(
45 Main.parent,
46 tr("<html>Could not read bookmarks from<br>''{0}''<br>Error was: {1}</html>",
47 Main.pref.getBookmarksFile(),
48 e.getMessage()
49 ),
50 tr("Error"),
51 JOptionPane.ERROR_MESSAGE
52 );
53 }
54 }
55
56 /**
57 * Save all bookmarks to the preferences file
58 */
59 public void save() {
60 try {
61 Collection<Preferences.Bookmark> bookmarks = new LinkedList<Preferences.Bookmark>();
62 for (Object o : ((DefaultListModel)getModel()).toArray()) {
63 bookmarks.add((Preferences.Bookmark)o);
64 }
65 Main.pref.saveBookmarks(bookmarks);
66 } catch (IOException e) {
67 JOptionPane.showMessageDialog(
68 Main.parent,
69 tr("<html>Could not write bookmark.<br>{0}</html>", e.getMessage()),
70 tr("Error"),
71 JOptionPane.ERROR_MESSAGE
72 );
73 }
74 }
75}
Note: See TracBrowser for help on using the repository browser.