Skip to content

Commit

Permalink
Add icon, add address panel, reorg panels
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Jul 12, 2019
1 parent 38a5412 commit 280b84c
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 289 deletions.
3 changes: 2 additions & 1 deletion BUILD
Expand Up @@ -78,7 +78,7 @@ java_binary(
java_binary(
name = "IceLeaf",
main_class = "snowblossom.iceleaf.IceLeaf",
resources = glob(["iceleaf/resources/*.txt"]),
resources = [ "//iceleaf:resources" ],
runtime_deps = [
"//iceleaf:iceleaf",
]
Expand All @@ -87,6 +87,7 @@ java_binary(
java_binary(
name = "IceLeafTestnet",
main_class = "snowblossom.iceleaf.IceLeafTestnet",
resources = [ "//iceleaf:resources" ],
runtime_deps = [
"//iceleaf:iceleaf",
]
Expand Down
6 changes: 6 additions & 0 deletions iceleaf/BUILD
Expand Up @@ -11,3 +11,9 @@ java_library(
"@duckutil//:duckutil_lib",
],
)

filegroup(
name = "resources",
srcs = glob(["resources/*"]),
)

Binary file added iceleaf/resources/flower-with-ink-256.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
139 changes: 139 additions & 0 deletions iceleaf/src/AddressPanel.java
@@ -0,0 +1,139 @@
package snowblossom.iceleaf;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.util.prefs.Preferences;
import javax.swing.JComboBox;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import snowblossom.client.SnowBlossomClient;
import snowblossom.lib.Globals;
import snowblossom.lib.AddressSpecHash;
import snowblossom.lib.AddressUtil;

import duckutil.PeriodicThread;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Collection;

import snowblossom.proto.SubmitReply;
import snowblossom.proto.Transaction;
import snowblossom.proto.TransactionInner;
import snowblossom.proto.TransactionOutput;
import snowblossom.util.proto.*;
import snowblossom.client.TransactionFactory;
import snowblossom.lib.TransactionUtil;
import snowblossom.lib.ChainHash;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;
import snowblossom.proto.AddressSpec;
import snowblossom.proto.WalletDatabase;
import snowblossom.proto.BalanceInfo;
import javax.swing.JScrollPane;
import javax.swing.JComponent;

public class AddressPanel extends BasePanel
{
protected WalletComboBox wallet_select_box;
protected UpdateThread update_thread;

public AddressPanel(IceLeaf ice_leaf)
{
super(ice_leaf);
}

@Override
public void setupPanel()
{

GridBagConstraints c = new GridBagConstraints();
c.weightx = 0.0;
c.weighty= 0.0;
c.gridheight = 1;
c.anchor = GridBagConstraints.NORTHWEST;

c.gridwidth = 1;
panel.add(new JLabel("Wallet to view addresses of:"), c);
c.gridwidth = GridBagConstraints.REMAINDER;

wallet_select_box = new WalletComboBox(ice_leaf);
panel.add(wallet_select_box, c);

update_thread = new UpdateThread();
update_thread.start();

wallet_select_box.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
update_thread.wake();
}
});

}

public class UpdateThread extends PeriodicThread
{
public UpdateThread()
{
super(15000);

}
public void runPass()
{
try
{
String wallet_name = (String)wallet_select_box.getSelectedItem();
if (wallet_name == null)
{
setMessageBox("no wallet selected");
return;
}

SnowBlossomClient client = ice_leaf.getWalletPanel().getWallet( wallet_name );
if (client == null)
{
setMessageBox("no wallet selected");
return;
}
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(bout);
pout.println(String.format("Wallet: %s", wallet_name));

WalletDatabase db = client.getPurse().getDB();

for(AddressSpec claim : db.getAddressesList())
{
String address = AddressUtil.getAddressString(claim, ice_leaf.getParams());
AddressSpecHash hash = AddressUtil.getHashForSpec(claim);
boolean used = db.getUsedAddressesMap().containsKey(address);
BalanceInfo bi = client.getBalance(hash);
String bi_print = SnowBlossomClient.getBalanceInfoPrint(bi);

pout.println(String.format(" %s - used:%s - %s", address, ""+used, bi_print));

}

setStatusBox(new String(bout.toByteArray()).trim());
setMessageBox("");

}
catch(Throwable t)
{
setMessageBox(ErrorUtil.getThrowInfo(t));
}
}

}

}
124 changes: 124 additions & 0 deletions iceleaf/src/BasePanel.java
@@ -0,0 +1,124 @@
package snowblossom.iceleaf;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.util.prefs.Preferences;
import javax.swing.JComboBox;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import snowblossom.client.SnowBlossomClient;
import snowblossom.lib.Globals;
import snowblossom.lib.AddressSpecHash;
import snowblossom.lib.AddressUtil;

import duckutil.PeriodicThread;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Collection;

import snowblossom.proto.SubmitReply;
import snowblossom.proto.Transaction;
import snowblossom.proto.TransactionInner;
import snowblossom.proto.TransactionOutput;
import snowblossom.util.proto.*;
import snowblossom.client.TransactionFactory;
import snowblossom.lib.TransactionUtil;
import snowblossom.lib.ChainHash;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;
import snowblossom.proto.AddressSpec;
import snowblossom.proto.WalletDatabase;
import snowblossom.proto.BalanceInfo;
import javax.swing.JScrollPane;
import javax.swing.JComponent;

public abstract class BasePanel
{
protected JScrollPane outer_panel;
protected JPanel panel;
protected Preferences ice_leaf_prefs;
protected IceLeaf ice_leaf;

protected JTextArea status_box;
protected JTextArea message_box;


public BasePanel(IceLeaf ice_leaf)
{
this.ice_leaf = ice_leaf;
ice_leaf_prefs = ice_leaf.getPrefs();
GridBagLayout grid_bag = new GridBagLayout();
panel = new JPanel(grid_bag);
outer_panel = new JScrollPane(panel);

panel.setBackground(ice_leaf.getBGColor());
status_box = new JTextArea();
message_box = new JTextArea();

}

public abstract void setupPanel();

public void setup()
{
setupPanel();

GridBagConstraints c = new GridBagConstraints();
c.gridheight = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.NORTHWEST;

c.weightx=0.0;
c.weighty=0.0;

panel.add(new JLabel("Status:"),c);

status_box.setEditable(false);
panel.add(status_box,c);

panel.add(new JLabel("Message:"),c);

message_box.setEditable(false);
panel.add(message_box,c);

c.anchor = GridBagConstraints.SOUTHEAST;
c.weightx=1.0;
c.weighty=1.0;
panel.add(new JLabel("Snowblossom"),c);
}

public JComponent getPanel(){return outer_panel;}

public void setMessageBox(String text)
{
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
message_box.setText(text);
}
});
}

public void setStatusBox(String text)
{
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
status_box.setText(text);
}
});
}


}

0 comments on commit 280b84c

Please sign in to comment.