Clean up formatting of some classes

This commit is contained in:
nicksavers 2014-05-26 23:49:33 +02:00
parent 4c65678296
commit c94ff5bfa2
3 changed files with 45 additions and 95 deletions

View File

@ -11,7 +11,6 @@ import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeListener;
/**
* www.ethereumJ.com
@ -26,7 +25,6 @@ public class BlockChainTable extends JFrame {
private int lastFindIndex = 0;
public BlockChainTable() {
final BlockChainTable blockChainTable = this;
@ -68,7 +66,7 @@ public class BlockChainTable extends JFrame {
table.getColumnModel().getColumn(0).setCellRenderer(new TableCellLongTextRenderer());
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK), "Copy");
table.getActionMap().put("Copy", new AbstractAction(){
table.getActionMap().put("Copy", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
@ -89,12 +87,12 @@ public class BlockChainTable extends JFrame {
String toFind = JOptionPane.showInputDialog(blockChainTable, "Find:",
"Find in BlockChain", JOptionPane.QUESTION_MESSAGE);
if (toFind.equals("")){
if (toFind.equals("")) {
lastFindIndex = 0;
return;
}
for (int i = lastFindIndex + 1; i < MainData.instance.getAllBlocks().size(); ++i){
for (int i = lastFindIndex + 1; i < MainData.instance.getAllBlocks().size(); ++i) {
if (MainData.instance.getAllBlocks().size() - 1 < i) return;
Block block = MainData.instance.getAllBlocks().get(i);
@ -110,15 +108,12 @@ public class BlockChainTable extends JFrame {
}
}
});
// Add the table to a scrolling pane
scrollPane = new JScrollPane(table);
topPanel.add(scrollPane, BorderLayout.CENTER);
}
public static void main(String args[]){
BlockChainTable mainFrame = new BlockChainTable();
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

View File

@ -22,7 +22,6 @@ import java.math.BigInteger;
import java.net.URL;
import java.util.Collection;
/**
* www.ethereumJ.com
* User: Roman Mandeleil
@ -30,15 +29,11 @@ import java.util.Collection;
*/
class ContractCallDialog extends JDialog implements MessageAwareDialog{
ContractCallDialog dialog;
JComboBox<AddressStateWraper> creatorAddressCombo;
final JTextField gasInput;
final JTextField contractAddrInput;
JTextArea msgDataTA;
JLabel statusMsg = null;
public ContractCallDialog(Frame parent) {
@ -87,14 +82,12 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
rejectLabel.setBounds(260, 325, 45, 45);
this.getContentPane().add(rejectLabel);
rejectLabel.setVisible(true);
rejectLabel.addMouseListener(
new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
dialog.dispose();
}}
);
rejectLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
dialog.dispose();
}
});
URL approveIconURL = ClassLoader.getSystemResource("buttons/approve.png");
ImageIcon approveIcon = new ImageIcon(approveIconURL);
@ -117,15 +110,13 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
gasInput.setText("1000");
JComboBox<AddressStateWraper> creatorAddressCombo = new JComboBox<AddressStateWraper>(){
@Override
public ComboBoxUI getUI() {
BasicComboBoxUI ui = (BasicComboBoxUI)super.getUI();
return super.getUI();
}
};
JComboBox<AddressStateWraper> creatorAddressCombo = new JComboBox<AddressStateWraper>() {
@Override
public ComboBoxUI getUI() {
BasicComboBoxUI ui = (BasicComboBoxUI) super.getUI();
return super.getUI();
}
};
creatorAddressCombo.setOpaque(true);
creatorAddressCombo.setEnabled(true);
@ -142,22 +133,19 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
MainData.instance.getWallet().getAddressStateCollection();
for (AddressState addressState : addressStates){
creatorAddressCombo.addItem(new AddressStateWraper(addressState));
}
creatorAddressCombo.setRenderer(new DefaultListCellRenderer() {
@Override
public void paint(Graphics g) {
setBackground(Color.WHITE);
setForeground(new Color(143, 170, 220));
setFont(new Font("Monospaced", 0, 13));
setBorder(BorderFactory.createEmptyBorder());
super.paint(g);
}
});
creatorAddressCombo.setRenderer(new DefaultListCellRenderer() {
@Override
public void paint(Graphics g) {
setBackground(Color.WHITE);
setForeground(new Color(143, 170, 220));
setFont(new Font("Monospaced", 0, 13));
setBorder(BorderFactory.createEmptyBorder());
super.paint(g);
}
});
creatorAddressCombo.setPopupVisible(false);
@ -168,13 +156,10 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
list.setSelectionBackground(Color.cyan);
list.setBorder(null);
for (int i = 0; i < creatorAddressCombo.getComponentCount(); i++)
{
for (int i = 0; i < creatorAddressCombo.getComponentCount(); i++) {
if (creatorAddressCombo.getComponent(i) instanceof CellRendererPane) {
CellRendererPane crp = ((CellRendererPane) (creatorAddressCombo.getComponent(i)));
}
if (creatorAddressCombo.getComponent(i) instanceof AbstractButton) {
((AbstractButton) creatorAddressCombo.getComponent(i)).setBorder(line);
}
@ -182,7 +167,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
creatorAddressCombo.setBounds(73, 267, 230, 36);
this.getContentPane().add(creatorAddressCombo);
this.getContentPane().revalidate();
this.getContentPane().repaint();
this.setResizable(false);
@ -212,7 +196,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
this.setSize(500, 430);
this.setVisible(true);
return rootPane;
}
@ -226,7 +209,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
this.statusMsg.setText(text);
}
public void submitContract(){
ClientPeer peer = MainData.instance.getActivePeer();
@ -240,7 +222,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
byte[] contractAddress = Hex.decode( contractAddrInput.getText());
AddressState addressState = ((AddressStateWraper)creatorAddressCombo.getSelectedItem()).getAddressState();
byte[] senderPrivKey = addressState.getEcKey().getPrivKeyBytes();
@ -251,9 +232,8 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
byte[] gasValue = BigIntegers.asUnsignedByteArray(gasBI);
byte[] endowment = BigIntegers.asUnsignedByteArray(new BigInteger("1000"));
Transaction tx = new Transaction(nonce, gasPrice, gasValue,
contractAddress, endowment, data);
Transaction tx = new Transaction(nonce, gasPrice, gasValue,
contractAddress, endowment, data);
try {
tx.sign(senderPrivKey);
@ -263,17 +243,12 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
return;
}
// SwingWorker
DialogWorker worker = new DialogWorker(tx, this);
worker.execute();
}
public class AddressStateWraper{
public class AddressStateWraper {
private AddressState addressState;
@ -285,17 +260,14 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{
return addressState;
}
@Override
public String toString() {
String addressShort = Utils.getAddressShortString(addressState.getEcKey().getAddress());
String valueShort = Utils.getValueShortString(addressState.getBalance());
String result =
String.format(" By: [%s] %s",
addressShort, valueShort);
return result;
}
@Override
public String toString() {
String addressShort = Utils.getAddressShortString(addressState.getEcKey().getAddress());
String valueShort = Utils.getValueShortString(addressState.getBalance());
String result = String.format(" By: [%s] %s", addressShort,
valueShort);
return result;
}
}
}

View File

@ -1,15 +1,12 @@
package org.ethereum.manager;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import com.maxmind.geoip.Location;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Block;
import org.ethereum.core.Genesis;
import org.ethereum.core.Transaction;
import org.ethereum.core.Wallet;
import org.ethereum.crypto.ECKey;
@ -58,8 +55,7 @@ public class MainData {
e.printStackTrace();
}
PeerData peer = new PeerData(
ip.getAddress(), (short) 30303, new byte[]{00});
PeerData peer = new PeerData(ip.getAddress(), (short) 30303, new byte[] { 00 });
peers.add(peer);
byte[] cowAddr = HashUtil.sha3("cow".getBytes());
@ -73,7 +69,6 @@ public class MainData {
peerDiscovery = new PeerDiscovery(peers);
}
public void addBlocks(List<Block> blocks) {
// TODO: redesign this part when the state part and the genesis block is ready
@ -107,7 +102,6 @@ public class MainData {
// Remove all pending transactions as they already approved by the net
for (Block block : blocks){
for (Transaction tx : block.getTransactionsList()){
if (logger.isDebugEnabled())
logger.debug("pending cleanup: tx.hash: [{}]", Hex.toHexString( tx.getHash()));
pendingTransactions.remove(tx.getHash());
@ -139,7 +133,6 @@ public class MainData {
return activePeer;
}
/*
* 1) the dialog put a pending transaction on the list
* 2) the dialog send the transaction to a net
@ -153,14 +146,12 @@ public class MainData {
BigInteger hash = new BigInteger(transaction.getHash());
PendingTransaction pendingTransaction = pendingTransactions.get(hash);
if (pendingTransaction != null)
pendingTransaction.incApproved();
else{
pendingTransaction = new PendingTransaction(transaction);
pendingTransactions.put(hash, pendingTransaction);
}
if (pendingTransaction != null)
pendingTransaction.incApproved();
else {
pendingTransaction = new PendingTransaction(transaction);
pendingTransactions.put(hash, pendingTransaction);
}
return pendingTransaction;
}
@ -169,11 +160,8 @@ public class MainData {
}
public void updatePeerIsDead(String ip, short port){
for (PeerData peer : peers) {
if (peer.getInetAddress().getHostAddress().equals(ip) && (peer.getPort() == port)){
System.out.println("update peer is dead: " + ip + ":" + port);
peer.setOnline(false);
break;
@ -182,24 +170,19 @@ public class MainData {
}
public void addPeers(List<PeerData> newPeers){
for (PeerData peer : newPeers){
if (this.peers.indexOf(peer) == -1){
Location location = IpGeoDB.getLocationForIp(peer.getInetAddress());
if (location != null){
this.peers.add(peer);
if (peerDiscovery.isStarted())
peerDiscovery.addNewPeerData(peer);
}
}
}
}
public void startPeerDiscovery(){
peerDiscovery.start();
};
}