From 4e64d4d757cd07ffd4eb484b1d035df1b8e4b94e Mon Sep 17 00:00:00 2001
From: Luca Keidel <info@lucakeidel.de>
Date: Sat, 9 Jul 2016 13:53:11 +0200
Subject: [PATCH] Node info will now only be display for a certain amount of
 time in the GraphWindow info bar

---
 .../configurations/GephiConfiguration.java    |  4 ++++
 .../java/fucoin/gui/gephi/GraphWindow.java    | 20 ++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/main/java/fucoin/configurations/GephiConfiguration.java b/src/main/java/fucoin/configurations/GephiConfiguration.java
index b35ef6a..6347f78 100644
--- a/src/main/java/fucoin/configurations/GephiConfiguration.java
+++ b/src/main/java/fucoin/configurations/GephiConfiguration.java
@@ -46,13 +46,17 @@ public class GephiConfiguration extends AbstractConfiguration {
         graphWindow.setDisplayedFilename(selectedTopology.getName());
         graphWindow.setVisible(true);
 
+        // add a click listener for displaying further information about a wallet when clicking on a node
         graphWindow.addNodeClickHandler((node, event) -> {
+
+            // get associated wallet and ask for its amount
             ActorRef wallet = walletByName(node.getLabel());
 
             Future<Object> future = Patterns.ask(wallet, new ActionGetAmount(), timeout);
             future.onSuccess(new OnSuccess<Object>() {
                 @Override
                 public void onSuccess(Object result) throws Throwable {
+                    // display the amount when an answer is received
                     ActionGetAmountAnswer answer = (ActionGetAmountAnswer) result;
                     graphWindow.setInfobarText(node.getLabel()+" has "+answer.amount+" FUCs");
                 }
diff --git a/src/main/java/fucoin/gui/gephi/GraphWindow.java b/src/main/java/fucoin/gui/gephi/GraphWindow.java
index f69d9c9..a0cfeed 100644
--- a/src/main/java/fucoin/gui/gephi/GraphWindow.java
+++ b/src/main/java/fucoin/gui/gephi/GraphWindow.java
@@ -11,6 +11,7 @@ import java.awt.*;
 import java.lang.reflect.Field;
 import java.util.*;
 import java.util.List;
+import java.util.Timer;
 
 public class GraphWindow extends JFrame implements NodeMouseListener {
 
@@ -19,12 +20,16 @@ public class GraphWindow extends JFrame implements NodeMouseListener {
     private final PreviewSketch previewSketch;
 
     private JLabel infobarText;
+    private Timer timer;
 
     private final String baseWindowTitle = "Network Overlay Graph";
+    private final String defaultInfoBarText = "Click on a node to see further information.";
 
     public GraphWindow() {
         super();
 
+        timer = new Timer();
+
         setTitle(baseWindowTitle);
 
         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
@@ -44,7 +49,7 @@ public class GraphWindow extends JFrame implements NodeMouseListener {
         G2DTarget target = (G2DTarget) previewController.getRenderTarget(RenderTarget.G2D_TARGET);
         previewSketch = new PreviewSketch(target, isRetina());
 
-        infobarText = new JLabel("Click on a node to see further information.", SwingConstants.LEFT);
+        infobarText = new JLabel(defaultInfoBarText, SwingConstants.LEFT);
 
         this.add(previewSketch, BorderLayout.CENTER);
 
@@ -122,7 +127,20 @@ public class GraphWindow extends JFrame implements NodeMouseListener {
         previewSketch.refreshSketch();
     }
 
+    /**
+     * Sets the displayed text of the infobar to text.
+     * After a certain time the text will be reset to the default text.
+     *
+     * @param text new infobar text
+     */
     public void setInfobarText(String text) {
         SwingUtilities.invokeLater(() -> infobarText.setText(text));
+        // set text back to default text after 2 seconds
+        timer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                SwingUtilities.invokeLater(() -> infobarText.setText(defaultInfoBarText));
+            }
+        }, 2000);
     }
 }
-- 
GitLab