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

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

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

  • Property svn:eol-style set to native
File size: 2.1 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.<br>{0}</html>", e.getMessage()),
47 tr("Error"),
48 JOptionPane.ERROR_MESSAGE
49 );
50 }
51 }
52
53 /**
54 * Save all bookmarks to the preferences file
55 */
56 public void save() {
57 try {
58 Collection<Preferences.Bookmark> bookmarks = new LinkedList<Preferences.Bookmark>();
59 for (Object o : ((DefaultListModel)getModel()).toArray()) {
60 bookmarks.add((Preferences.Bookmark)o);
61 }
62 Main.pref.saveBookmarks(bookmarks);
63 } catch (IOException e) {
64 JOptionPane.showMessageDialog(
65 Main.parent,
66 tr("<html>Could not write bookmark.<br>{0}</html>", e.getMessage()),
67 tr("Error"),
68 JOptionPane.ERROR_MESSAGE
69 );
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.