From 5e0aeffcee1bbed5ea595b78d55ace5a5b118470 Mon Sep 17 00:00:00 2001 From: David Bohn <david@cancrisoft.net> Date: Wed, 15 Jun 2016 18:24:32 +0200 Subject: [PATCH] Some Usability improvements --- src/main/java/fucoin/MainRemote.java | 47 ++++++++++++++++++- .../java/fucoin/gui/WalletGuiControl.java | 5 ++ .../java/fucoin/gui/WalletGuiControlImpl.java | 37 +++++++++++++-- src/main/java/fucoin/wallet/WalletImpl.java | 8 ++-- 4 files changed, 89 insertions(+), 8 deletions(-) diff --git a/src/main/java/fucoin/MainRemote.java b/src/main/java/fucoin/MainRemote.java index e148dc8..a00a464 100644 --- a/src/main/java/fucoin/MainRemote.java +++ b/src/main/java/fucoin/MainRemote.java @@ -3,7 +3,6 @@ package fucoin; import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.ActorSystem; -import akka.japi.Pair; import akka.util.Timeout; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; @@ -13,6 +12,8 @@ import scala.concurrent.Await; import scala.concurrent.duration.FiniteDuration; import javax.swing.*; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; import java.awt.*; import java.io.File; import java.net.*; @@ -55,7 +56,7 @@ public class MainRemote { ActorRef preknownNeighbour = null; String walletName = null; - String path = null; + String path; while (preknownNeighbour == null) { @@ -107,6 +108,13 @@ public class MainRemote { } + /** + * Create the setup UI for the remote application + * This provides an input for a wallet name, the initially known neighbour and a combo box to select + * the used network interface for the client. + * + * @param defaultHostname This is the default hostname that should be selected. + */ private static JPanel createDialogPanel(String defaultHostname) { JPanel dialogPanel = new JPanel(); dialogPanel.setLayout(new GridLayout(3, 1)); @@ -117,6 +125,8 @@ public class MainRemote { dialogPanel.add(pathField); dialogPanel.add(new JLabel("Select your reachable IP address: ", SwingConstants.LEFT)); + selectWalletNameField(); + List<SelectableNetworkInterface> interfaces = fetchNetworkInterfaces(); for (SelectableNetworkInterface netint : interfaces) { @@ -128,6 +138,39 @@ public class MainRemote { return dialogPanel; } + /** + * This method makes sure, that the Wallet name field is selected on display of the dialog + */ + private static void selectWalletNameField() { + walletNameField.addAncestorListener(new AncestorListener() { + @Override + public void ancestorAdded(AncestorEvent event) { + final AncestorListener al= this; + SwingUtilities.invokeLater(() -> { + JComponent component = event.getComponent(); + component.requestFocusInWindow(); + component.removeAncestorListener( al ); + }); + } + + @Override + public void ancestorRemoved(AncestorEvent event) { + + } + + @Override + public void ancestorMoved(AncestorEvent event) { + + } + }); + } + + /** + * Grab a list of all network interfaces and the associated IP addresses to prevent some strange behaviours of + * the <code>InetAddress.getLocalHost().getHostAddress();</code> call + * + * @return The list contains SelectableNetworkInterfaces, that contain the interface name and the associated IP address + */ private static List<SelectableNetworkInterface> fetchNetworkInterfaces() { List<SelectableNetworkInterface> map = new ArrayList<>(); diff --git a/src/main/java/fucoin/gui/WalletGuiControl.java b/src/main/java/fucoin/gui/WalletGuiControl.java index d19b454..2b7b504 100644 --- a/src/main/java/fucoin/gui/WalletGuiControl.java +++ b/src/main/java/fucoin/gui/WalletGuiControl.java @@ -11,4 +11,9 @@ public interface WalletGuiControl { void addLogMsg(String msg); void addTransactionLogMessage(String message); + + /** + * Tell the GUI, that the wallet is a remote wallet. + */ + void setRemote(); } diff --git a/src/main/java/fucoin/gui/WalletGuiControlImpl.java b/src/main/java/fucoin/gui/WalletGuiControlImpl.java index 5c03f89..3949f36 100644 --- a/src/main/java/fucoin/gui/WalletGuiControlImpl.java +++ b/src/main/java/fucoin/gui/WalletGuiControlImpl.java @@ -40,20 +40,22 @@ public class WalletGuiControlImpl implements WalletGuiControl { // Row 1 JPanel row1 = new JPanel(); row1.setLayout(new BoxLayout(row1, BoxLayout.PAGE_AXIS)); - + txtMyName.setHorizontalAlignment(JTextField.CENTER); txtMyName.setBorder(BorderFactory.createEmptyBorder()); txtMyName.setFont(txtMyName.getFont().deriveFont(18f).deriveFont(Font.BOLD)); txtMyName.setEditable(false); txtMyName.setForeground(Color.WHITE); - txtMyName.setBackground(new Color(123,94,167)); + txtMyName.setText(wallet.getName()); txtMyAddress.setHorizontalAlignment(JTextField.CENTER); txtMyAddress.setBorder(BorderFactory.createEmptyBorder()); txtMyAddress.setEditable(false); txtMyAddress.setForeground(Color.WHITE); - txtMyAddress.setBackground(new Color(137,112,176)); + + //setTint(new Color(123,94,167)); + setTint(new Color(54, 135, 56)); row1.add(txtMyName); row1.add(txtMyAddress); @@ -132,6 +134,12 @@ public class WalletGuiControlImpl implements WalletGuiControl { }); + // Disable currently unused controls that might be useful in the future + addNewButton.setEnabled(false); + btnStore.setEnabled(false); + btnSearch.setEnabled(false); + sendToNewEdt.setEditable(false); + btnExit.addActionListener(e -> window.dispose()); window.addWindowListener(new WindowAdapter() { @@ -153,6 +161,24 @@ public class WalletGuiControlImpl implements WalletGuiControl { }); } + /** + * Set the color of the top section + * + * @param color The color used for the upper row. The color for the bottom row is calculated by lightening up the provided color + */ + private void setTint(Color color) { + txtMyName.setBackground(color); + + // Make the secondary color roughly 15% lighter + float amount = 0.15f; + + int red = (int) ((color.getRed() * (1 - amount) / 255 + amount) * 255); + int green = (int) ((color.getGreen() * (1 - amount) / 255 + amount) * 255); + int blue = (int) ((color.getBlue() * (1 - amount) / 255 + amount) * 255); + + txtMyAddress.setBackground(new Color(red, green, blue)); + } + @Override public void setAddress(String address) { txtMyAddress.setText(address); @@ -179,6 +205,11 @@ public class WalletGuiControlImpl implements WalletGuiControl { log(new LogMessage(message, true)); } + @Override + public void setRemote() { + setTint(new Color(45, 94, 167)); + } + private void log(LogMessage logMessage) { SwingUtilities.invokeLater(() -> { log.addElement(logMessage); diff --git a/src/main/java/fucoin/wallet/WalletImpl.java b/src/main/java/fucoin/wallet/WalletImpl.java index c694583..779e585 100644 --- a/src/main/java/fucoin/wallet/WalletImpl.java +++ b/src/main/java/fucoin/wallet/WalletImpl.java @@ -1,9 +1,7 @@ package fucoin.wallet; import akka.actor.ActorRef; -import akka.actor.ActorSelection; import akka.actor.Props; -import akka.util.Timeout; import fucoin.actions.ClientAction; import fucoin.actions.join.ActionJoin; import fucoin.actions.join.ActionJoinAnswer; @@ -74,7 +72,11 @@ public class WalletImpl extends AbstractWallet { isActive = true; if (gui != null) { - gui.setAddress(getAddress()); + String address = getAddress(); + gui.setAddress(address); + if (address.contains("Remote@")) { + gui.setRemote(); + } } if (preKnownNeighbour != null) { -- GitLab