Skip to content
Snippets Groups Projects
Unverified Commit 5e0aeffc authored by David Bohn's avatar David Bohn
Browse files

Some Usability improvements

parent 8b79cd4c
No related branches found
No related tags found
1 merge request!3Preliminary result of the software
......@@ -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<>();
......
......@@ -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();
}
......@@ -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);
......
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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment