JAL-3790 Enable copy to clipboard when mouse click on the getdown splashscreen Status...
authorBen Soares <b.soares@dundee.ac.uk>
Tue, 22 Dec 2020 12:54:35 +0000 (12:54 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Tue, 22 Dec 2020 12:54:35 +0000 (12:54 +0000)
getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/StatusPanel.java

index a144c83..6988b82 100644 (file)
@@ -11,9 +11,13 @@ import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Image;
+import java.awt.datatransfer.StringSelection;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseAdapter;
 import java.awt.image.ImageObserver;
+import java.awt.Toolkit;
 import java.text.MessageFormat;
 import java.util.Arrays;
 import java.util.MissingResourceException;
@@ -56,6 +60,17 @@ public final class StatusPanel extends JComponent
                     }
                 }
             });
+
+        // Allow a mouse click to copy the status text
+        addMouseListener(
+          new MouseAdapter() {
+            @Override
+            public void mouseClicked(MouseEvent ev) {
+              StringSelection selection = new StringSelection(labelText());
+              Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
+            }
+          }
+        );
     }
 
     public void init (UpdateInterface ifc, RotatingBackgrounds bg, Image barimg)
@@ -269,29 +284,10 @@ public final class StatusPanel extends JComponent
         if (_ifc == null) {
                return;
         }
-        String status = _status;
-        if (!_displayError) {
-            for (int ii = 0; ii < _statusDots; ii++) {
-                status += " .";
-            }
-        }
  
-       StringBuilder labelText = new StringBuilder();
-       if (_ifc.displayVersion) {
-               labelText.append("launcher version: " + Build.version());
-               labelText.append("\n");
-               labelText.append("install4j version: " + Application.i4jVersion);
-               labelText.append("\n");
-               labelText.append("installer version: " + System.getProperty("installer_template_version"));
-               labelText.append("\n");
-       }
-       if (_ifc.displayAppbase) {
-               labelText.append("appbase: " + _appbase);
-               labelText.append("\n");
-       }
-       labelText.append(status); 
+        String labelText = labelText();
         
-        _newlab = createLabel(labelText.toString(), new Color(_ifc.statusText, true));
+        _newlab = createLabel(labelText, new Color(_ifc.statusText, true));
         // set the width of the label to the width specified
         int width = _ifc.status.width;
         if (width == 0) {
@@ -304,6 +300,32 @@ public final class StatusPanel extends JComponent
         }
         repaint();
     }
+    private String labelText() {
+      String status = _status;
+      if (!_displayError) {
+          for (int ii = 0; ii < _statusDots; ii++) {
+              status += " .";
+          }
+      }
+      return getLabelText()+status;
+    }
+
+    private String getLabelText() {
+       StringBuilder labelText = new StringBuilder();
+       if (_ifc.displayVersion) {
+               labelText.append("launcher version: ").append(Build.version());
+               labelText.append("\n");
+               labelText.append("install4j version: ").append(Application.i4jVersion);
+               labelText.append("\n");
+               labelText.append("installer version: ").append(System.getProperty("installer_template_version"));
+               labelText.append("\n");
+       }
+       if (_ifc.displayAppbase) {
+               labelText.append("appbase: ").append(_appbase);
+               labelText.append("\n");
+       }
+      return labelText.toString();
+    }
 
     /**
      * Get the y coordinate of a label in the status area.