diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java
index 5c11b3c6dc9..474e6956bb8 100644
--- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java
+++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java
@@ -60,6 +60,7 @@ import mage.client.util.ButtonColumn;
import mage.client.util.GUISizeHelper;
import mage.client.util.IgnoreList;
import mage.client.util.MageTableRowSorter;
+import mage.client.util.URLHandler;
import mage.client.util.gui.GuiDisplayUtil;
import mage.client.util.gui.TableUtil;
import mage.constants.*;
@@ -579,7 +580,7 @@ public class TablesPanel extends javax.swing.JPanel {
this.jPanelBottom.setVisible(false);
} else {
this.jPanelBottom.setVisible(true);
- this.jLabelFooterText.setText(serverMessages.get(0));
+ URLHandler.handleMessage(serverMessages.get(0), this.jLabelFooterText);
this.jButtonFooterNext.setVisible(serverMessages.size() > 1);
}
}
@@ -1283,7 +1284,9 @@ public class TablesPanel extends javax.swing.JPanel {
if (currentMessage >= messages.size()) {
currentMessage = 0;
}
- this.jLabelFooterText.setText(messages.get(currentMessage));
+
+ URLHandler.RemoveMouseAdapter(jLabelFooterText);
+ URLHandler.handleMessage(messages.get(currentMessage), this.jLabelFooterText);
}
}
}//GEN-LAST:event_jButtonFooterNextActionPerformed
diff --git a/Mage.Client/src/main/java/mage/client/util/URLHandler.java b/Mage.Client/src/main/java/mage/client/util/URLHandler.java
new file mode 100644
index 00000000000..20d05058f60
--- /dev/null
+++ b/Mage.Client/src/main/java/mage/client/util/URLHandler.java
@@ -0,0 +1,119 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mage.client.util;
+
+import java.awt.Desktop;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.swing.JLabel;
+
+/**
+ *
+ * @author Dahny
+ */
+public class URLHandler {
+
+ private static MouseAdapter currentMouseAdapter;
+
+ /**
+ * This method makes a URL in a message click-able and converts the message
+ * into HTML.
+ *
+ * @param message: The selected message
+ * @param label: The message of the day label
+ */
+ public static void handleMessage(String message, JLabel label) {
+ String url = detectURL(message);
+
+ if (!url.equals("")) {
+ label.addMouseListener(createMouseAdapter(url));
+ }
+
+ label.setText(convertToHTML(message));
+ }
+
+ public static void RemoveMouseAdapter(JLabel label) {
+ label.removeMouseListener(currentMouseAdapter);
+ currentMouseAdapter = null;
+ }
+
+ private static MouseAdapter createMouseAdapter(String url) {
+ currentMouseAdapter = new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() > 0) {
+ if (Desktop.isDesktopSupported()) {
+ Desktop desktop = Desktop.getDesktop();
+ try {
+ URI uri = new URI(url);
+ desktop.browse(uri);
+ } catch (IOException | URISyntaxException ex) {
+ // do nothing
+ }
+ } else {
+ //do nothing
+ }
+ }
+ }
+ };
+
+ return currentMouseAdapter;
+ }
+
+ public static String convertToHTML(String input) {
+ String s = input;
+ String output = "";
+ // separate the input by spaces
+ String[] parts = s.split("\\s+");
+
+ for (String item : parts) {
+ try {
+ URL url = new URL(item);
+ // The item is a valid URL
+ output = output + "" + url + " ";
+
+ } catch (MalformedURLException e) {
+ //The item might still be an URL
+ if (item.startsWith("www.")) {
+ output = output + "" + item + " ";
+ } else {
+ output = output + item + " ";
+ }
+
+ }
+ }
+
+ output = output + "";
+ return output;
+ }
+
+ public static String detectURL(String input) {
+ String s = input;
+ String output = "";
+ // separate the input by spaces
+ String[] parts = s.split("\\s+");
+
+ for (String item : parts) {
+ try {
+ URL url = new URL(item);
+ // The item is a valid URL
+ output = url.toString();
+ } catch (MalformedURLException e) {
+ //The item might still be an URL
+ if (item.startsWith("www.")) {
+ output = "http://" + item;
+ }
+ }
+ }
+
+ return output;
+ }
+
+}