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

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

removed usage of tab stops

  • Property svn:eol-style set to native
File size: 1.7 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 } catch (IOException e) {
42 e.printStackTrace();
43 JOptionPane.showMessageDialog(Main.parent, tr("Could not read bookmarks.")+"\n"+e.getMessage());
44 }
45 }
46
47 /**
48 * Save all bookmarks to the preferences file
49 */
50 public void save() {
51 try {
52 Collection<Preferences.Bookmark> bookmarks = new LinkedList<Preferences.Bookmark>();
53 for (Object o : ((DefaultListModel)getModel()).toArray())
54 bookmarks.add((Preferences.Bookmark)o);
55 Main.pref.saveBookmarks(bookmarks);
56 } catch (IOException e) {
57 JOptionPane.showMessageDialog(Main.parent,tr("Could not write bookmark.")+"\n"+e.getMessage());
58 }
59 }
60}
Note: See TracBrowser for help on using the repository browser.