Skip to content
Snippets Groups Projects
Unverified Commit a37596f9 authored by Luca Keidel's avatar Luca Keidel
Browse files

Added a status bar showing wallet information when a node is clicked

parent f7e401d9
No related branches found
No related tags found
1 merge request!6Overlay topology
package fucoin.configurations; package fucoin.configurations;
import akka.actor.ActorRef;
import akka.pattern.Patterns;
import akka.util.Timeout;
import fucoin.actions.transaction.ActionGetAmount;
import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.configurations.internal.ConfigurationName; import fucoin.configurations.internal.ConfigurationName;
import fucoin.configurations.internal.GephiLoader; import fucoin.configurations.internal.GephiLoader;
import fucoin.gui.gephi.GraphWindow; import fucoin.gui.gephi.GraphWindow;
import org.gephi.graph.api.Graph; import org.gephi.graph.api.Graph;
import scala.concurrent.Await;
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ConfigurationName("Gephi Test Configuration") @ConfigurationName("Gephi Test Configuration")
public class GephiConfiguration extends AbstractConfiguration { public class GephiConfiguration extends AbstractConfiguration {
private Timeout timeout = new Timeout(Duration.create(10, "seconds"));
@Override @Override
public void run() { public void run() {
initSupervisor(); initSupervisor();
...@@ -27,7 +38,18 @@ public class GephiConfiguration extends AbstractConfiguration { ...@@ -27,7 +38,18 @@ public class GephiConfiguration extends AbstractConfiguration {
createOverlayNetwork(g); createOverlayNetwork(g);
GraphWindow graphWindow = new GraphWindow(); GraphWindow graphWindow = new GraphWindow();
graphWindow.addNodeClickHandler((node, event) -> System.out.println(node.getLabel() + " wurde angeklickt!")); graphWindow.addNodeClickHandler((node, event) -> {
ActorRef wallet = walletByName(node.getLabel());
Future<Object> future = Patterns.ask(wallet, new ActionGetAmount(), timeout);
ActionGetAmountAnswer answer = null;
try {
answer = (ActionGetAmountAnswer) Await.result(future, timeout.duration());
} catch (Exception e) {
System.err.println("An error occured while fetching the wallet info: "+e.getMessage());
}
graphWindow.setInfobarText(node.getLabel()+" has "+answer.amount+" FUCs");
});
graphWindow.setVisible(true); graphWindow.setVisible(true);
} }
......
...@@ -19,6 +19,8 @@ public class GraphWindow extends JFrame implements NodeMouseListener { ...@@ -19,6 +19,8 @@ public class GraphWindow extends JFrame implements NodeMouseListener {
private final PreviewController previewController; private final PreviewController previewController;
private final PreviewSketch previewSketch; private final PreviewSketch previewSketch;
private JLabel infobarText;
public GraphWindow() { public GraphWindow() {
super(); super();
...@@ -41,8 +43,36 @@ public class GraphWindow extends JFrame implements NodeMouseListener { ...@@ -41,8 +43,36 @@ public class GraphWindow extends JFrame implements NodeMouseListener {
G2DTarget target = (G2DTarget) previewController.getRenderTarget(RenderTarget.G2D_TARGET); G2DTarget target = (G2DTarget) previewController.getRenderTarget(RenderTarget.G2D_TARGET);
previewSketch = new PreviewSketch(target, isRetina()); previewSketch = new PreviewSketch(target, isRetina());
infobarText = new JLabel("Click on a node to see further information.", SwingConstants.LEFT);
this.add(previewSketch, BorderLayout.CENTER); this.add(previewSketch, BorderLayout.CENTER);
JPanel infobar = new JPanel(new BorderLayout());
infobar.add(infobarText, BorderLayout.WEST);
JPanel zoomOptions = new JPanel(new FlowLayout(FlowLayout.CENTER, 5,2));
zoomOptions.add(new JLabel("Zoom: "));
Dimension zoomBtnSize = new Dimension(20,20);
JButton minusButton = new JButton("-");
minusButton.setPreferredSize(zoomBtnSize);
minusButton.addActionListener(e -> previewSketch.zoomMinus());
zoomOptions.add(minusButton);
JButton resetButton = new JButton("0");
resetButton.setPreferredSize(zoomBtnSize);
resetButton.addActionListener(e -> previewSketch.resetZoom());
zoomOptions.add(resetButton);
JButton plusButton = new JButton("+");
plusButton.setPreferredSize(zoomBtnSize);
plusButton.addActionListener(e -> previewSketch.zoomPlus());
zoomOptions.add(plusButton);
infobar.add(zoomOptions, BorderLayout.EAST);
this.add(infobar, BorderLayout.SOUTH);
previewController.refreshPreview(); previewController.refreshPreview();
previewSketch.resetZoom(); previewSketch.resetZoom();
...@@ -86,4 +116,8 @@ public class GraphWindow extends JFrame implements NodeMouseListener { ...@@ -86,4 +116,8 @@ public class GraphWindow extends JFrame implements NodeMouseListener {
previewController.refreshPreview(); previewController.refreshPreview();
previewSketch.repaint(); previewSketch.repaint();
} }
public void setInfobarText(String text){
SwingUtilities.invokeLater(() -> infobarText.setText(text));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment