source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java@ 1648

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

prevent overwriting of GPX files

  • Property svn:eol-style set to native
File size: 5.5 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.Dimension;
7import java.awt.GridBagLayout;
8import java.awt.Rectangle;
9import java.awt.event.ActionEvent;
10import java.awt.event.ActionListener;
11import java.util.Collection;
12import java.util.LinkedList;
13
14import javax.swing.AbstractAction;
15import javax.swing.DefaultListModel;
16import javax.swing.JButton;
17import javax.swing.JLabel;
18import javax.swing.JList;
19import javax.swing.JOptionPane;
20import javax.swing.JPanel;
21import javax.swing.JScrollPane;
22import javax.swing.Scrollable;
23
24import org.openstreetmap.josm.plugins.PluginDownloader;
25import org.openstreetmap.josm.plugins.PluginSelection;
26import org.openstreetmap.josm.tools.GBC;
27
28public class PluginPreference implements PreferenceSetting {
29
30 private JPanel plugin;
31 private JPanel pluginPanel = new NoHorizontalScrollPanel(new GridBagLayout());
32 private PreferenceDialog gui;
33 private JScrollPane pluginPane;
34 private PluginSelection selection = new PluginSelection();
35
36 public void addGui(final PreferenceDialog gui) {
37 this.gui = gui;
38 plugin = gui.createPreferenceTab("plugin", tr("Plugins"), tr("Configure available plugins."), false);
39 pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
40 pluginPane.setBorder(null);
41 plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH));
42 plugin.add(GBC.glue(0,10), GBC.eol());
43 JButton morePlugins = new JButton(tr("Download List"));
44 morePlugins.addActionListener(new ActionListener(){
45 public void actionPerformed(ActionEvent e) {
46 selection.updateDescription(pluginPanel);
47 }
48 });
49 plugin.add(morePlugins, GBC.std().insets(0,0,10,0));
50
51 JButton update = new JButton(tr("Update"));
52 update.addActionListener(new ActionListener(){
53 public void actionPerformed(ActionEvent e) {
54 selection.update(pluginPanel);
55 }
56 });
57 plugin.add(update, GBC.std().insets(0,0,10,0));
58
59 JButton configureSites = new JButton(tr("Configure Sites..."));
60 configureSites.addActionListener(new ActionListener(){
61 public void actionPerformed(ActionEvent e) {
62 configureSites();
63 }
64 });
65 plugin.add(configureSites, GBC.std());
66
67 selection.drawPanel(pluginPanel);
68 }
69
70 private void configureSites() {
71 JPanel p = new JPanel(new GridBagLayout());
72 p.add(new JLabel(tr("Add JOSM Plugin description URL.")), GBC.eol());
73 final DefaultListModel model = new DefaultListModel();
74 for (String s : PluginDownloader.getSites())
75 model.addElement(s);
76 final JList list = new JList(model);
77 p.add(new JScrollPane(list), GBC.std().fill());
78 JPanel buttons = new JPanel(new GridBagLayout());
79 buttons.add(new JButton(new AbstractAction(tr("Add")){
80 public void actionPerformed(ActionEvent e) {
81 String s = JOptionPane.showInputDialog(gui, tr("Add JOSM Plugin description URL."));
82 if (s != null)
83 model.addElement(s);
84 }
85 }), GBC.eol().fill(GBC.HORIZONTAL));
86 buttons.add(new JButton(new AbstractAction(tr("Edit")){
87 public void actionPerformed(ActionEvent e) {
88 if (list.getSelectedValue() == null) {
89 JOptionPane.showMessageDialog(gui, tr("Please select an entry."));
90 return;
91 }
92 String s = JOptionPane.showInputDialog(gui, tr("Edit JOSM Plugin description URL."), list.getSelectedValue());
93 model.setElementAt(s, list.getSelectedIndex());
94 }
95 }), GBC.eol().fill(GBC.HORIZONTAL));
96 buttons.add(new JButton(new AbstractAction(tr("Delete")){
97 public void actionPerformed(ActionEvent event) {
98 if (list.getSelectedValue() == null) {
99 JOptionPane.showMessageDialog(gui, tr("Please select an entry."));
100 return;
101 }
102 model.removeElement(list.getSelectedValue());
103 }
104 }), GBC.eol().fill(GBC.HORIZONTAL));
105 p.add(buttons, GBC.eol());
106 int answer = JOptionPane.showConfirmDialog(gui, p, tr("Configure Plugin Sites"), JOptionPane.OK_CANCEL_OPTION);
107 if (answer != JOptionPane.OK_OPTION)
108 return;
109 Collection<String> sites = new LinkedList<String>();
110 for (int i = 0; i < model.getSize(); ++i)
111 sites.add((String)model.getElementAt(i));
112 PluginDownloader.setSites(sites);
113 }
114
115 public boolean ok() {
116 return selection.finish();
117 }
118
119 class NoHorizontalScrollPanel extends JPanel implements Scrollable {
120 public NoHorizontalScrollPanel(GridBagLayout gridBagLayout) {
121 super(gridBagLayout);
122 }
123
124 public Dimension getPreferredScrollableViewportSize() {
125 return super.getPreferredSize();
126 }
127
128 public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
129 return 30;
130 }
131
132 public boolean getScrollableTracksViewportHeight() {
133 return false;
134 }
135
136 public boolean getScrollableTracksViewportWidth() {
137 return true;
138 }
139
140 public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
141 return 10;
142 }
143 }
144}
Note: See TracBrowser for help on using the repository browser.