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

Resolved merge conflict

parents 3047ad67 4c31e8a6
No related branches found
No related tags found
1 merge request!3Preliminary result of the software
......@@ -3,29 +3,22 @@ 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;
import fucoin.setup.SelectableNetworkInterface;
import fucoin.setup.SetupDialogPanel;
import fucoin.wallet.WalletImpl;
import scala.concurrent.Await;
import scala.concurrent.duration.FiniteDuration;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.net.*;
import java.util.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class MainRemote {
private static JTextField walletNameField = new JTextField(10);
private static JTextField pathField = new JTextField(10);
private static JComboBox<SelectableNetworkInterface> hostnameField = new JComboBox<>();
public static void main(String[] args) throws InterruptedException {
String hostname = "127.0.0.1";
......@@ -49,13 +42,14 @@ public class MainRemote {
//Init System Actor System
ActorSystem system = ActorSystem.create("Remote", ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + hostname).withFallback(config));
JPanel dialogPanel = createDialogPanel(hostname);
//JPanel dialogPanel = createDialogPanel(hostname);
SetupDialogPanel dialogPanel = new SetupDialogPanel(hostname);
Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
ActorRef preknownNeighbour = null;
String walletName = null;
String path = null;
String path;
while (preknownNeighbour == null) {
......@@ -69,7 +63,7 @@ public class MainRemote {
return;
}
SelectableNetworkInterface selectedHostname = (SelectableNetworkInterface) hostnameField.getSelectedItem();
SelectableNetworkInterface selectedHostname = dialogPanel.getNetworkInterface();
if (!selectedHostname.getHostName().equals(hostname)) {
if (system != null) {
......@@ -84,8 +78,8 @@ public class MainRemote {
system = ActorSystem.create("Remote", ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + hostname).withFallback(config));
}
walletName = walletNameField.getText();
path = pathField.getText();
walletName = dialogPanel.getWalletName();
path = dialogPanel.getAddressOfNeighbour();
// check input
if (path.equals("") || walletName.equals("")) {
......@@ -106,47 +100,4 @@ public class MainRemote {
system.actorOf(WalletImpl.props(preknownNeighbour, walletName), walletName);
}
private static JPanel createDialogPanel(String defaultHostname) {
JPanel dialogPanel = new JPanel();
dialogPanel.setLayout(new GridLayout(3, 1));
JLabel walletLabel = new JLabel("Pick your wallet name: ", SwingConstants.LEFT);
dialogPanel.add(walletLabel);
dialogPanel.add(walletNameField);
dialogPanel.add(new JLabel("Enter a neighbour node address: ", SwingConstants.LEFT));
dialogPanel.add(pathField);
dialogPanel.add(new JLabel("Select your reachable IP address: ", SwingConstants.LEFT));
List<SelectableNetworkInterface> interfaces = fetchNetworkInterfaces();
for (SelectableNetworkInterface netint : interfaces) {
hostnameField.addItem(netint);
}
hostnameField.setSelectedItem(new SelectableNetworkInterface(defaultHostname, "default"));
dialogPanel.add(hostnameField);
return dialogPanel;
}
private static List<SelectableNetworkInterface> fetchNetworkInterfaces() {
List<SelectableNetworkInterface> map = new ArrayList<>();
try {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface networkInterface : Collections.list(nets)) {
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
// To ease the setup, currently only IPv4 addresses are supported
Optional<InetAddress> picked = Collections.list(inetAddresses).stream().filter(inetAddress -> !(inetAddress instanceof Inet6Address)).findFirst();
if (picked.isPresent()) {
String hostAddress = picked.get().getHostAddress();
map.add(new SelectableNetworkInterface(hostAddress, networkInterface.getDisplayName()));
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return map;
}
}
......@@ -13,4 +13,10 @@ public interface WalletGuiControl {
void addTransactionLogMessageSuccess(String message);
void addTransactionLogMessageFail(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,8 +134,15 @@ public class WalletGuiControlImpl implements WalletGuiControl {
});
txtLog.setCellRenderer(new LogCellRenderer());
// 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() {
......@@ -155,6 +164,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);
......@@ -186,6 +213,11 @@ public class WalletGuiControlImpl implements WalletGuiControl {
log(new LogMessage(message, LogMessage.Context.TRANSACTION_FAIL));
}
@Override
public void setRemote() {
setTint(new Color(45, 94, 167));
}
private void log(LogMessage logMessage) {
SwingUtilities.invokeLater(() -> {
log.addElement(logMessage);
......
package fucoin.setup;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.*;
public class NetworkInterfaceReader {
/**
* 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
*/
public static List<SelectableNetworkInterface> fetchNetworkInterfaces() {
List<SelectableNetworkInterface> map = new ArrayList<>();
try {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface networkInterface : Collections.list(nets)) {
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
// To ease the setup, currently only IPv4 addresses are supported
Optional<InetAddress> picked = Collections.list(inetAddresses).stream().filter(inetAddress -> !(inetAddress instanceof Inet6Address)).findFirst();
if (picked.isPresent()) {
String hostAddress = picked.get().getHostAddress();
map.add(new SelectableNetworkInterface(hostAddress, networkInterface.getDisplayName()));
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return map;
}
}
package fucoin.setup;
/**
* @author davidbohn
*/
public class SelectableNetworkInterface {
String hostName;
......
package fucoin.setup;
import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import java.awt.*;
import java.util.List;
public class SetupDialogPanel extends JPanel {
private JTextField walletNameField = new JTextField(10);
private JTextField pathField = new JTextField(10);
private JComboBox<SelectableNetworkInterface> hostnameField = new JComboBox<>();
public SetupDialogPanel(String defaultHostname) {
super();
createComponents(defaultHostname);
}
private void createComponents(String defaultHostname) {
this.setLayout(new GridLayout(3, 1));
this.add(new JLabel("Pick your wallet name: ", SwingConstants.LEFT));
this.add(walletNameField);
this.add(new JLabel("Enter a neighbour node address: ", SwingConstants.LEFT));
this.add(pathField);
this.add(new JLabel("Select your reachable IP address: ", SwingConstants.LEFT));
selectWalletNameField();
List<SelectableNetworkInterface> interfaces = NetworkInterfaceReader.fetchNetworkInterfaces();
for (SelectableNetworkInterface netint : interfaces) {
hostnameField.addItem(netint);
}
hostnameField.setSelectedItem(new SelectableNetworkInterface(defaultHostname, "default"));
this.add(hostnameField);
}
/**
* This method makes sure, that the Wallet name field is selected on display of the dialog
*/
private 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) {
}
});
}
public String getWalletName() {
return walletNameField.getText();
}
public String getAddressOfNeighbour() {
return pathField.getText();
}
public SelectableNetworkInterface getNetworkInterface() {
return (SelectableNetworkInterface) hostnameField.getSelectedItem();
}
}
......@@ -72,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.
Please register or to comment