source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java@ 339

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