minor changes:

1. fixed un-toggle button on toolbar when by X window closed
2. introduced property for connection
This commit is contained in:
romanman 2014-05-29 17:51:59 +03:00
parent 0e62e5b58f
commit bb9e0d1bee
10 changed files with 163 additions and 56 deletions

View File

@ -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");

View File

@ -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);
}

View File

@ -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,10 +81,6 @@ 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() {
public void run() {
@ -91,17 +100,19 @@ 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();
}
});
}
@Override
public void console(final String output) {
@ -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);
}
});
}

View File

@ -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);
}

View File

@ -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();
else{
if (fileChooser.getSelectedFile() == null){
if (fileChooser == null || fileChooser.getSelectedFile() == null) {
file = callFileChooser();
}else{
file = fileChooser.getSelectedFile();
if (fileChooser.getSelectedFile() == null)
return;
}
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);
}
});
}

View File

@ -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);
}
});

View File

@ -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");
}
});

View File

@ -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();

View File

@ -9,3 +9,5 @@ log4j.appender.stdout.layout.ConversionPattern= %d{HH:mm:ss} [%c{1}] %m%n
# filter noisy classes
log4j.logger.org.ethereum.net.peerdiscovery = WARN
log4j.logger.java.nio = WARN
log4j.logger.io.netty = WARN

View File

@ -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