source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesPanel.java@ 2817

Last change on this file since 2817 was 2817, checked in by Gubaer, 14 years ago

fixed #3063: Downloading a plugin yields 3 dialogs at the same time: Downloading plugin / You should restart JOSM / Plugin downloaded
fixed #3628: JOSM blocking itself updating broken plugin
fixed #4187: JOSM deleted random files from disk after start (data loss)
fixed #4199: new version - plugins update vs josm start [should be fixed. Be careful if you have two JOSM instances running. Auto-update of plugins in the second instance will fail because plugin files are locked by the first instance]
fixed #4034: JOSM should auto-download plugin list when it hasn't been downloaded before [JOSM now displays a hint]

fixed: splash screen showing again even if plugins are auto-updated
new: progress indication integrated in splash screen
new: cancelable, asynchronous download of plugins from preferences
new: cancelable, asynchronous download of plugin list from plugin download sites
new: asynchronous loading of plugin information, launch of preferences dialog accelerated
refactored: clean up, documentation of plugin management code (PluginHandler)

File size: 5.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.plugin;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Font;
7import java.awt.GridBagConstraints;
8import java.awt.GridBagLayout;
9import java.awt.Insets;
10import java.awt.event.ActionEvent;
11import java.awt.event.ActionListener;
12import java.util.List;
13import java.util.logging.Logger;
14
15import javax.swing.JCheckBox;
16import javax.swing.JLabel;
17import javax.swing.event.HyperlinkEvent;
18import javax.swing.event.HyperlinkListener;
19import javax.swing.event.HyperlinkEvent.EventType;
20
21import org.openstreetmap.josm.gui.JMultilineLabel;
22import org.openstreetmap.josm.gui.widgets.HtmlPanel;
23import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
24import org.openstreetmap.josm.plugins.PluginInformation;
25import org.openstreetmap.josm.tools.OpenBrowser;
26
27public class PluginPreferencesPanel extends VerticallyScrollablePanel{
28 private static final Logger logger = Logger.getLogger(PluginPreferencesPanel.class.getName());
29
30 private PluginPreferencesModel model;
31
32 public PluginPreferencesPanel() {
33 model = new PluginPreferencesModel();
34 setLayout(new GridBagLayout());
35 }
36
37 public PluginPreferencesPanel(PluginPreferencesModel model) {
38 this.model = model;
39 setLayout(new GridBagLayout());
40 }
41
42 protected String formatPluginRemoteVersion(PluginInformation pi) {
43 StringBuilder sb = new StringBuilder();
44 if (pi.version == null || pi.version.trim().equals("")) {
45 sb.append(tr("unknown"));
46 } else {
47 sb.append(pi.version);
48 if (pi.oldmode) {
49 sb.append("*");
50 }
51 }
52 return sb.toString();
53 }
54
55 protected String formatPluginLocalVersion(PluginInformation pi) {
56 if (pi == null) return tr("unknown");
57 if (pi.localversion == null || pi.localversion.trim().equals(""))
58 return tr("unknown");
59 return pi.localversion;
60 }
61
62 protected String formatCheckboxTooltipText(PluginInformation pi) {
63 if (pi == null) return "";
64 if (pi.downloadlink == null)
65 return tr("Plugin bundled with JOSM");
66 else
67 return pi.downloadlink;
68 }
69
70 public void displayEmptyPluginListInformation() {
71 GridBagConstraints gbc = new GridBagConstraints();
72 gbc.gridx = 0;
73 gbc.anchor = GridBagConstraints.CENTER;
74 gbc.fill = GridBagConstraints.BOTH;
75 gbc.insets = new Insets(40,0,40,0);
76 gbc.weightx = 1.0;
77 gbc.weighty = 1.0;
78
79 JMultilineLabel hint = new JMultilineLabel("");
80 hint.setFont(hint.getFont().deriveFont(Font.PLAIN));
81 hint.setHorizontalAlignment(JLabel.CENTER);
82 hint.setText(
83 "<html>"
84 + tr("Please click on <strong>Download list</strong> to download and display a list of available plugins.")
85 + "</html>"
86 );
87 add(hint, gbc);
88 }
89
90 public void refreshView() {
91 List<PluginInformation> displayedPlugins = model.getDisplayedPlugins();
92 removeAll();
93
94 GridBagConstraints gbc = new GridBagConstraints();
95 gbc.gridx = 0;
96 gbc.anchor = GridBagConstraints.NORTHWEST;
97 gbc.fill = GridBagConstraints.HORIZONTAL;
98 gbc.weightx = 1.0;
99
100 if (displayedPlugins.isEmpty()) {
101 displayEmptyPluginListInformation();
102 return;
103 }
104
105 int row = -1;
106 for (final PluginInformation pi : displayedPlugins) {
107 boolean selected = model.isSelectedPlugin(pi.getName());
108 String remoteversion = formatPluginRemoteVersion(pi);
109 String localversion = formatPluginLocalVersion(model.getPluginInformation(pi.getName()));
110
111 final JCheckBox cbPlugin = new JCheckBox(
112 tr("{0}: Version {1} (local: {2})", pi.getName(), remoteversion, localversion)
113 );
114 cbPlugin.setSelected(selected);
115 cbPlugin.setToolTipText(formatCheckboxTooltipText(pi));
116 cbPlugin.addActionListener(new ActionListener(){
117 public void actionPerformed(ActionEvent e) {
118 model.setPluginSelected(pi.getName(), cbPlugin.isSelected());
119 }
120 });
121 gbc.gridy = ++row;
122 gbc.insets = new Insets(5,5,0,5);
123 gbc.weighty = 0.0;
124 add(cbPlugin, gbc);
125
126 HtmlPanel description = new HtmlPanel();
127 description.setText(pi.getDescriptionAsHtml());
128 description.getEditorPane().addHyperlinkListener(new HyperlinkListener() {
129 public void hyperlinkUpdate(HyperlinkEvent e) {
130 if(e.getEventType() == EventType.ACTIVATED) {
131 OpenBrowser.displayUrl(e.getURL().toString());
132 }
133 }
134 });
135
136 gbc.gridy = ++row;
137 gbc.insets = new Insets(3,25,5,5);
138 gbc.weighty = 1.0;
139 add(description, gbc);
140 }
141 revalidate();
142 repaint();
143 }
144}
Note: See TracBrowser for help on using the repository browser.