source: josm/src/org/openstreetmap/josm/gui/preferences/AnnotationPresetPreference.java@ 178

Last change on this file since 178 was 178, checked in by imi, 17 years ago
  • fixed display of tooltip shortcuts
  • added icon=... to annotation presets
  • added support for putting annotation presets in the toolbar
File size: 4.1 KB
Line 
1package org.openstreetmap.josm.gui.preferences;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.GridBagLayout;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8import java.util.Collection;
9import java.util.StringTokenizer;
10
11import javax.swing.Box;
12import javax.swing.DefaultListModel;
13import javax.swing.JButton;
14import javax.swing.JLabel;
15import javax.swing.JList;
16import javax.swing.JOptionPane;
17import javax.swing.JPanel;
18import javax.swing.JScrollPane;
19
20import org.openstreetmap.josm.Main;
21import org.openstreetmap.josm.gui.annotation.AnnotationPreset;
22import org.openstreetmap.josm.tools.GBC;
23
24public class AnnotationPresetPreference implements PreferenceSetting {
25
26 public static Collection<AnnotationPreset> annotationPresets;
27 private JList annotationSources;
28
29 public void addGui(final PreferenceDialog gui) {
30 annotationSources = new JList(new DefaultListModel());
31 String annos = Main.pref.get("annotation.sources");
32 StringTokenizer st = new StringTokenizer(annos, ";");
33 while (st.hasMoreTokens())
34 ((DefaultListModel)annotationSources.getModel()).addElement(st.nextToken());
35
36 JButton addAnno = new JButton(tr("Add"));
37 addAnno.addActionListener(new ActionListener(){
38 public void actionPerformed(ActionEvent e) {
39 String source = JOptionPane.showInputDialog(Main.parent, tr("Annotation preset source"));
40 if (source == null)
41 return;
42 ((DefaultListModel)annotationSources.getModel()).addElement(source);
43 gui.requiresRestart = true;
44 }
45 });
46
47 JButton editAnno = new JButton(tr("Edit"));
48 editAnno.addActionListener(new ActionListener(){
49 public void actionPerformed(ActionEvent e) {
50 if (annotationSources.getSelectedIndex() == -1)
51 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit."));
52 else {
53 String source = JOptionPane.showInputDialog(Main.parent, tr("Annotation preset source"), annotationSources.getSelectedValue());
54 if (source == null)
55 return;
56 ((DefaultListModel)annotationSources.getModel()).setElementAt(source, annotationSources.getSelectedIndex());
57 gui.requiresRestart = true;
58 }
59 }
60 });
61
62 JButton deleteAnno = new JButton(tr("Delete"));
63 deleteAnno.addActionListener(new ActionListener(){
64 public void actionPerformed(ActionEvent e) {
65 if (annotationSources.getSelectedIndex() == -1)
66 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete."));
67 else {
68 ((DefaultListModel)annotationSources.getModel()).remove(annotationSources.getSelectedIndex());
69 gui.requiresRestart = true;
70 }
71 }
72 });
73 annotationSources.setVisibleRowCount(3);
74
75 annotationSources.setToolTipText(tr("The sources (url or filename) of annotation preset definition files. See http://josm.eigenheimstrasse.de/wiki/AnnotationPresets for help."));
76 addAnno.setToolTipText(tr("Add a new annotation preset source to the list."));
77 deleteAnno.setToolTipText(tr("Delete the selected source from the list."));
78
79 gui.map.add(new JLabel(tr("Annotation preset sources")), GBC.eol().insets(0,5,0,0));
80 gui.map.add(new JScrollPane(annotationSources), GBC.eol().fill(GBC.BOTH));
81 JPanel buttonPanel = new JPanel(new GridBagLayout());
82 gui.map.add(buttonPanel, GBC.eol().fill(GBC.HORIZONTAL));
83 buttonPanel.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
84 buttonPanel.add(addAnno, GBC.std().insets(0,5,0,0));
85 buttonPanel.add(editAnno, GBC.std().insets(5,5,5,0));
86 buttonPanel.add(deleteAnno, GBC.std().insets(0,5,0,0));
87 }
88
89 public void ok() {
90 if (annotationSources.getModel().getSize() > 0) {
91 StringBuilder sb = new StringBuilder();
92 for (int i = 0; i < annotationSources.getModel().getSize(); ++i)
93 sb.append(";"+annotationSources.getModel().getElementAt(i));
94 Main.pref.put("annotation.sources", sb.toString().substring(1));
95 } else
96 Main.pref.put("annotation.sources", null);
97 }
98
99 /**
100 * Initialize the annotation presets (load and may display error)
101 */
102 public static void initialize() {
103 annotationPresets = AnnotationPreset.readFromPreferences();
104 }
105}
Note: See TracBrowser for help on using the repository browser.