From bb9e0d1bee521474b318253d5cd53fb79d07f756 Mon Sep 17 00:00:00 2001 From: romanman Date: Thu, 29 May 2014 17:51:59 +0300 Subject: [PATCH] minor changes: 1. fixed un-toggle button on toolbar when by X window closed 2. introduced property for connection --- .../org/ethereum/config/SystemProperties.java | 10 ++++ .../org/ethereum/gui/BlockChainTable.java | 27 +++++++--- .../ethereum/gui/ConnectionConsoleWindow.java | 54 +++++++++++++------ .../org/ethereum/gui/PeersTableWindow.java | 29 +++++++--- .../java/org/ethereum/gui/SerpentEditor.java | 37 ++++++++----- .../main/java/org/ethereum/gui/ToolBar.java | 27 ++++++---- .../java/org/ethereum/gui/WalletSumPanel.java | 2 +- .../java/org/ethereum/gui/WalletWindow.java | 21 +++++++- .../src/main/resources/log4j.properties | 4 +- .../src/main/resources/system.properties | 8 +++ 10 files changed, 163 insertions(+), 56 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java index 415847de..e46f3b45 100644 --- a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java +++ b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java @@ -92,6 +92,16 @@ public class SystemProperties { return Integer.parseInt(prop.getProperty("peer.discovery.port")); } + public String activePeerIP(){ + if(prop.isEmpty()) return "54.201.28.117"; + return prop.getProperty("peer.active.ip"); + } + + public int activePeerPort(){ + if(prop.isEmpty()) return 30303; + return Integer.parseInt(prop.getProperty("peer.active.port")); + } + public String samplesDir(){ if(prop.isEmpty()) return "samples"; return prop.getProperty("samples.dir"); diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java b/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java index db318c4b..c79cfb5f 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/BlockChainTable.java @@ -6,13 +6,11 @@ import org.ethereum.manager.MainData; import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; +import javax.tools.Tool; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; +import java.awt.event.*; /** * www.ethereumJ.com @@ -27,7 +25,12 @@ public class BlockChainTable extends JFrame { private int lastFindIndex = 0; - public BlockChainTable() { + ToolBar toolBar; + + public BlockChainTable(ToolBar toolBar) { + + this.toolBar = toolBar; + addCloseAction(); final BlockChainTable blockChainTable = this; @@ -126,8 +129,20 @@ public class BlockChainTable extends JFrame { topPanel.add(scrollPane, BorderLayout.CENTER); } + public void addCloseAction(){ + this.addWindowListener( new WindowAdapter() + { + public void windowClosing(WindowEvent e) + { + toolBar.chainToggle.setSelected(false); + + } + }); + } + + public static void main(String args[]){ - BlockChainTable mainFrame = new BlockChainTable(); + BlockChainTable mainFrame = new BlockChainTable(null); mainFrame.setVisible(true); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ConnectionConsoleWindow.java b/ethereumj-core/src/main/java/org/ethereum/gui/ConnectionConsoleWindow.java index e6c91b70..2c531f7a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ConnectionConsoleWindow.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ConnectionConsoleWindow.java @@ -3,14 +3,20 @@ package org.ethereum.gui; import java.awt.*; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.net.InetAddress; +import java.net.UnknownHostException; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; +import javax.swing.*; +import javax.tools.Tool; +import org.ethereum.config.SystemProperties; import org.ethereum.net.client.ClientPeer; import org.fife.ui.rsyntaxtextarea.*; import org.fife.ui.rtextarea.RTextScrollPane; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A simple example showing how to modify the fonts and colors used in an @@ -25,12 +31,17 @@ import org.fife.ui.rtextarea.RTextScrollPane; */ public class ConnectionConsoleWindow extends JFrame implements PeerListener{ + Logger logger = LoggerFactory.getLogger(getClass()); + + private static final long serialVersionUID = 1L; private boolean autoScroll = false; private RSyntaxTextArea textArea; + ToolBar toolBar = null; + /** * ERROR (exceptions) WARN (when something happens that's not supposed to) * INFO (wire output) @@ -38,13 +49,15 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{ * TRACE (start/end method) */ - public ConnectionConsoleWindow() { + public ConnectionConsoleWindow(ToolBar toolBar) { final ConnectionConsoleWindow thisConsole = this; + this.toolBar = toolBar; java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); Toolkit kit = Toolkit.getDefaultToolkit(); Image img = kit.createImage(url); this.setIconImage(img); + addCloseAction(); JPanel cp = new JPanel(new BorderLayout()); @@ -68,11 +81,7 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{ pack(); setLocation(775, 390); - this.addComponentListener(new ComponentAdapter() { - - @Override - public void componentShown(ComponentEvent e) { - Thread t = new Thread() { + Thread t = new Thread() { public void run() { // Peer Server Zero: peer discovery @@ -91,18 +100,20 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{ // new ClientPeer(thisConsole).connect("54.204.10.41", 30303); // RomanJ - new ClientPeer(thisConsole).connect("54.211.14.10", 40404); - +// new ClientPeer(thisConsole).connect("54.211.14.10", 40404); + new ClientPeer(thisConsole).connect(SystemProperties.CONFIG.activePeerIP(), + SystemProperties.CONFIG.activePeerPort()); } - }; - t.start(); - } - }); + }; + t.start(); } + + + @Override public void console(final String output) { SwingUtilities.invokeLater(new Runnable() { @@ -153,13 +164,24 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{ } + public void addCloseAction(){ + this.addWindowListener( new WindowAdapter() + { + public void windowClosing(WindowEvent e) + { + toolBar.logToggle.setSelected(false); + + } + }); + + } public static void main(String[] args) { // Start all Swing applications on the EDT. SwingUtilities.invokeLater(new Runnable() { public void run() { - new ConnectionConsoleWindow().setVisible(true); + new ConnectionConsoleWindow(null).setVisible(true); } }); } diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableWindow.java b/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableWindow.java index b08d7424..5edc8868 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableWindow.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/PeersTableWindow.java @@ -3,15 +3,12 @@ package org.ethereum.gui; import org.ethereum.manager.MainData; import java.awt.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.util.Timer; import java.util.TimerTask; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.SwingConstants; +import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; @@ -30,9 +27,13 @@ public class PeersTableWindow extends JFrame{ private JScrollPane scrollPane; private Timer updater = new Timer(); + private ToolBar toolBar; // Constructor of main frame - public PeersTableWindow() { + public PeersTableWindow(ToolBar toolBar) { + + this.toolBar = toolBar; + addCloseAction(); // Set the frame characteristics setTitle("Ethereum Peers"); @@ -96,9 +97,21 @@ public class PeersTableWindow extends JFrame{ MainData.instance.startPeerDiscovery(); } + public void addCloseAction(){ + this.addWindowListener( new WindowAdapter() + { + public void windowClosing(WindowEvent e) + { + toolBar.peersToggle.setSelected(false); + + } + }); + } + + public static void main(String args[]) { - PeersTableWindow mainFrame = new PeersTableWindow(); + PeersTableWindow mainFrame = new PeersTableWindow(null); mainFrame.setVisible(true); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java b/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java index d0fa95d4..84ea19c0 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/SerpentEditor.java @@ -6,10 +6,7 @@ import org.fife.ui.rtextarea.RTextScrollPane; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; +import java.awt.event.*; import java.io.*; import java.util.Scanner; import java.util.regex.Matcher; @@ -75,8 +72,12 @@ public class SerpentEditor extends JFrame { final JPanel contentPane; JFileChooser fileChooser = null; - public SerpentEditor() { + ToolBar toolBar = null; + public SerpentEditor(ToolBar toolBar) { + + this.toolBar = toolBar; + addCloseAction(); contentPane = new JPanel(new BorderLayout()); final JFrame mainWindow = this; @@ -329,15 +330,13 @@ public class SerpentEditor extends JFrame { public void actionPerformed(ActionEvent e) { File file = null; - if (fileChooser == null) file = callFileChooser(); + if (fileChooser == null || fileChooser.getSelectedFile() == null) { + file = callFileChooser(); + if (fileChooser.getSelectedFile() == null) + return; + } else{ - - if (fileChooser.getSelectedFile() == null){ - file = callFileChooser(); - }else{ - file = fileChooser.getSelectedFile(); - } } try { @@ -492,11 +491,23 @@ public class SerpentEditor extends JFrame { return file; } + public void addCloseAction(){ + this.addWindowListener( new WindowAdapter() + { + public void windowClosing(WindowEvent e) + { + toolBar.editorToggle.setSelected(false); + + } + }); + } + + public static void main(String[] args) { // Start all Swing applications on the EDT. SwingUtilities.invokeLater(new Runnable() { public void run() { - new SerpentEditor().setVisible(true); + new SerpentEditor(null).setVisible(true); } }); } diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java index 87e74430..8a117404 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java @@ -7,6 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.swing.*; +import javax.tools.Tool; import java.awt.*; import java.awt.event.ItemEvent; @@ -29,6 +30,12 @@ public class ToolBar extends JFrame { WalletWindow walletWindow = null; SerpentEditor serpentEditor = null; + JToggleButton editorToggle; + JToggleButton logToggle; + JToggleButton peersToggle; + JToggleButton chainToggle; + JToggleButton walletToggle; + public ToolBar() throws HeadlessException { @@ -82,7 +89,7 @@ public class ToolBar extends JFrame { ImageIcon image_5 = new ImageIcon(imageURL_5); - JToggleButton editorToggle = new JToggleButton(""); + editorToggle = new JToggleButton(""); editorToggle.setIcon(image_1); editorToggle.setContentAreaFilled(true); editorToggle.setToolTipText("Serpent Editor"); @@ -97,7 +104,7 @@ public class ToolBar extends JFrame { SwingUtilities.invokeLater(new Runnable() { public void run() { if (serpentEditor == null) - serpentEditor = new SerpentEditor(); + serpentEditor = new SerpentEditor(ToolBar.this); serpentEditor.setVisible(true); } }); @@ -107,7 +114,7 @@ public class ToolBar extends JFrame { } }); - JToggleButton logToggle = new JToggleButton(); + logToggle = new JToggleButton(); logToggle.setIcon(image_2); logToggle.setToolTipText("Log Console"); logToggle.setContentAreaFilled(true); @@ -123,7 +130,7 @@ public class ToolBar extends JFrame { SwingUtilities.invokeLater(new Runnable() { public void run() { if (connectionConsoleWindow == null) - connectionConsoleWindow = new ConnectionConsoleWindow(); + connectionConsoleWindow = new ConnectionConsoleWindow(ToolBar.this); connectionConsoleWindow.setVisible(true); } }); @@ -133,7 +140,7 @@ public class ToolBar extends JFrame { } }); - JToggleButton peersToggle = new JToggleButton(); + peersToggle = new JToggleButton(); peersToggle.setIcon(image_3); peersToggle.setToolTipText("Peers"); peersToggle.setContentAreaFilled(true); @@ -148,7 +155,7 @@ public class ToolBar extends JFrame { SwingUtilities.invokeLater(new Runnable() { public void run() { if (mainFrame == null) - mainFrame = new PeersTableWindow(); + mainFrame = new PeersTableWindow(ToolBar.this); mainFrame.setVisible( true ); } }); @@ -158,7 +165,7 @@ public class ToolBar extends JFrame { } }); - JToggleButton chainToggle = new JToggleButton(); + chainToggle = new JToggleButton(); chainToggle.setIcon(image_4); chainToggle.setToolTipText("Block Chain"); chainToggle.setContentAreaFilled(true); @@ -174,7 +181,7 @@ public class ToolBar extends JFrame { public void run() { if (blockChainWindow == null) - blockChainWindow = new BlockChainTable(); + blockChainWindow = new BlockChainTable(ToolBar.this); blockChainWindow.setVisible(true); } }); @@ -184,7 +191,7 @@ public class ToolBar extends JFrame { } }); - JToggleButton walletToggle = new JToggleButton(); + walletToggle = new JToggleButton(); walletToggle.setIcon(image_5); walletToggle.setToolTipText("Wallet"); walletToggle.setContentAreaFilled(true); @@ -200,7 +207,7 @@ public class ToolBar extends JFrame { SwingUtilities.invokeLater(new Runnable() { public void run() { if (walletWindow == null) - walletWindow = new WalletWindow(); + walletWindow = new WalletWindow(ToolBar.this); walletWindow.setVisible(true); } }); diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/WalletSumPanel.java b/ethereumj-core/src/main/java/org/ethereum/gui/WalletSumPanel.java index 1fb255f6..2ba4b877 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/WalletSumPanel.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/WalletSumPanel.java @@ -53,7 +53,7 @@ public class WalletSumPanel extends JPanel{ payOutLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - System.out.println("boom"); + JOptionPane.showMessageDialog(null, "Under construction"); } }); diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/WalletWindow.java b/ethereumj-core/src/main/java/org/ethereum/gui/WalletWindow.java index 5499478e..667d867b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/WalletWindow.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/WalletWindow.java @@ -5,10 +5,13 @@ import org.ethereum.core.Wallet; import org.ethereum.manager.MainData; import javax.swing.*; +import javax.tools.Tool; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.net.URL; /** @@ -19,8 +22,12 @@ import java.net.URL; public class WalletWindow extends JFrame implements Wallet.WalletListener{ WalletWindow walletWindow; + ToolBar toolBar; - public WalletWindow() { + public WalletWindow(ToolBar toolBar) { + + addCloseAction(); + this.toolBar = toolBar; walletWindow = this; java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); @@ -92,6 +99,18 @@ public class WalletWindow extends JFrame implements Wallet.WalletListener{ contentPane.repaint(); } + public void addCloseAction(){ + this.addWindowListener( new WindowAdapter() + { + public void windowClosing(WindowEvent e) + { + toolBar.walletToggle.setSelected(false); + + } + }); + } + + @Override public void valueChanged() { loadWallet(); diff --git a/ethereumj-core/src/main/resources/log4j.properties b/ethereumj-core/src/main/resources/log4j.properties index 1118f65b..a6766f51 100644 --- a/ethereumj-core/src/main/resources/log4j.properties +++ b/ethereumj-core/src/main/resources/log4j.properties @@ -8,4 +8,6 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern= %d{HH:mm:ss} [%c{1}] %m%n # filter noisy classes -log4j.logger.org.ethereum.net.peerdiscovery = WARN \ No newline at end of file +log4j.logger.org.ethereum.net.peerdiscovery = WARN +log4j.logger.java.nio = WARN +log4j.logger.io.netty = WARN \ No newline at end of file diff --git a/ethereumj-core/src/main/resources/system.properties b/ethereumj-core/src/main/resources/system.properties index cf371ca1..f913970c 100644 --- a/ethereumj-core/src/main/resources/system.properties +++ b/ethereumj-core/src/main/resources/system.properties @@ -10,6 +10,14 @@ server.acceptConnections = false peer.discovery.ip = 54.201.28.117 peer.discovery.port = 30303 + +# active peer ip and port +# that is the peer through +# we get the chain: [54.201.28.117] port: [30303] +peer.active.ip = 151.64.223.120 +peer.active.port = 30304 + + # specify if the mechanism # to discover more and more # peers and check the already