Index: /trunk/src/org/openstreetmap/josm/actions/AboutAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/AboutAction.java (revision 14821)
+++ /trunk/src/org/openstreetmap/josm/actions/AboutAction.java (revision 14822)
@@ -13,6 +13,4 @@
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
@@ -69,6 +67,5 @@
}
- @Override
- public void actionPerformed(ActionEvent e) {
+ protected JPanel buildAboutPanel() {
final JTabbedPane about = new JTabbedPane();
@@ -133,5 +130,4 @@
}
-
about.addTab(tr("Info"), info);
about.addTab(tr("Readme"), createScrollPane(readme));
@@ -154,4 +150,10 @@
JLabel.CENTER), GBC.std().insets(0, 5, 0, 0));
panel.add(about, GBC.std().fill());
+ return panel;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JPanel panel = buildAboutPanel();
GuiHelper.prepareResizeableOptionPane(panel, panel.getPreferredSize());
@@ -172,5 +174,4 @@
OpenDirAction(String dir) {
- super();
putValue(Action.NAME, "...");
this.dir = dir;
@@ -215,13 +216,5 @@
private static JLabel createImageLink(String tooltip, String icon, final String link) {
- JLabel label = new JLabel(ImageProvider.get("dialogs/about", icon, ImageSizes.LARGEICON));
- label.setToolTipText(tooltip);
- label.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- OpenBrowser.displayUrl(link);
- }
- });
- return label;
+ return new UrlLabel(link, tooltip, ImageProvider.get("dialogs/about", icon, ImageSizes.LARGEICON));
}
Index: /trunk/src/org/openstreetmap/josm/gui/widgets/UrlLabel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/widgets/UrlLabel.java (revision 14821)
+++ /trunk/src/org/openstreetmap/josm/gui/widgets/UrlLabel.java (revision 14822)
@@ -8,4 +8,5 @@
import java.awt.event.MouseListener;
+import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
@@ -28,6 +29,5 @@
*/
public UrlLabel() {
- addMouseListener(this);
- setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+ init("", "", 0);
}
@@ -62,8 +62,24 @@
* @param url The URL to use
* @param description The description to display
+ * @param image The image to be displayed by the label instead of text
+ * @since 14822
+ */
+ public UrlLabel(String url, String description, Icon image) {
+ super(image);
+ init(url, description, 0);
+ }
+
+ /**
+ * Constructs a new {@code UrlLabel} for the given URL, description and font increase.
+ * @param url The URL to use
+ * @param description The description to display
* @param fontPlus The font increase in 1/72 of an inch units.
*/
public UrlLabel(String url, String description, int fontPlus) {
- this();
+ init(url, description, fontPlus);
+ }
+
+ private void init(String url, String description, int fontPlus) {
+ addMouseListener(this);
setUrl(url);
setDescription(description);
@@ -76,12 +92,19 @@
protected final void refresh() {
if (url != null && !url.isEmpty()) {
- setText(""+description+"");
- setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
- setToolTipText(String.format("%s
%s", url, tr("Right click = copy to clipboard")));
+ refresh(""+description+"",
+ Cursor.getPredefinedCursor(Cursor.HAND_CURSOR),
+ String.format("%s
%s", url, tr("Right click = copy to clipboard")));
} else {
- setText("" + description + "");
- setCursor(null);
- setToolTipText(null);
+ refresh("" + description + "", null, null);
}
+ }
+
+ private void refresh(String text, Cursor cursor, String tooltip) {
+ boolean hasImage = getIcon() != null;
+ if (!hasImage) {
+ setText(text);
+ }
+ setCursor(cursor);
+ setToolTipText(tooltip);
}
Index: /trunk/test/unit/org/openstreetmap/josm/actions/AboutActionTest.java
===================================================================
--- /trunk/test/unit/org/openstreetmap/josm/actions/AboutActionTest.java (revision 14822)
+++ /trunk/test/unit/org/openstreetmap/josm/actions/AboutActionTest.java (revision 14822)
@@ -0,0 +1,31 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.actions;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.openstreetmap.josm.testutils.JOSMTestRules;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+/**
+ * Unit tests for class {@link AboutAction}.
+ */
+public final class AboutActionTest {
+
+ /**
+ * Setup test.
+ */
+ @Rule
+ @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
+ public JOSMTestRules test = new JOSMTestRules().main();
+
+ /**
+ * Unit test of {@link AboutAction#buildAboutPanel}.
+ */
+ @Test
+ public void testBuildAboutPanel() {
+ assertNotNull(new AboutAction().buildAboutPanel());
+ }
+}