Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle 7.7.0 #25

Open
wants to merge 2 commits into
base: 7.7.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,582 changes: 838 additions & 744 deletions src/java/com/cabecinha84/zelcashui/ZelCashZelNodeDialog.java

Large diffs are not rendered by default.

1,377 changes: 709 additions & 668 deletions src/java/com/cabecinha84/zelcashui/ZelNodesPanel.java

Large diffs are not rendered by default.

363 changes: 175 additions & 188 deletions src/java/com/cabecinha84/zelcashui/ZelcashRescanDialog.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/************************************************************************************************
/************************************************************************************************
* Copyright (c) 2019 The ZelCash Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -21,19 +21,6 @@
**********************************************************************************/
package com.cabecinha84.zelcashui;


import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JOptionPane;

import com.cabecinha84.zelcashui.ZelCashJButton;
import com.cabecinha84.zelcashui.ZelCashJDialog;
import com.cabecinha84.zelcashui.ZelCashJFrame;
Expand All @@ -47,183 +34,183 @@
import com.vaklinov.zcashui.Log;
import com.vaklinov.zcashui.Util;
import com.vaklinov.zcashui.ZCashClientCaller;
import com.vaklinov.zcashui.ZCashUI;
import com.vaklinov.zcashui.ZCashClientCaller.WalletCallException;

import com.vaklinov.zcashui.ZCashUI;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JOptionPane;

/**
* Dialog to enter a single private key to import
*/
public class ZelcashRescanDialog
extends ZelCashJDialog
{
protected boolean isOKPressed = false;

private static final int POLL_PERIOD = 5000;
private static final int STARTUP_ERROR_CODE = -28;

protected ZelCashJLabel upperLabel;
protected ZelCashJLabel lowerLabel;

protected ZelCashJProgressBar progress = null;

protected ZCashClientCaller caller;

private LanguageUtil langUtil;

ZelCashJButton okButon;
ZelCashJButton cancelButon;
private ZCashUI parent;

public ZelcashRescanDialog(ZCashUI parent, ZCashClientCaller caller)
{
super(parent);
this.parent = parent;
this.caller = caller;
langUtil = LanguageUtil.instance();
this.setTitle(langUtil.getString("wallet.operations.dialog.rescan.title"));
this.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 50);
this.setModal(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

ZelCashJPanel controlsPanel = new ZelCashJPanel();
controlsPanel.setLayout(new BoxLayout(controlsPanel, BoxLayout.Y_AXIS));
controlsPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

ZelCashJPanel tempPanel = new ZelCashJPanel(new BorderLayout(0, 0));
tempPanel.add(this.upperLabel = new ZelCashJLabel(
langUtil.getString("wallet.operations.dialog.rescan.message")),
BorderLayout.CENTER);
controlsPanel.add(tempPanel);

ZelCashJLabel dividerLabel = new ZelCashJLabel(" ");
dividerLabel.setFont(new Font("Helvetica", Font.PLAIN, 8));
controlsPanel.add(dividerLabel);

tempPanel = new ZelCashJPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
tempPanel.add(progress = new ZelCashJProgressBar());
controlsPanel.add(tempPanel);

this.getContentPane().setLayout(new BorderLayout(0, 0));
this.getContentPane().add(controlsPanel, BorderLayout.NORTH);

// Form buttons
ZelCashJPanel buttonPanel = new ZelCashJPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
okButon = new ZelCashJButton(langUtil.getString("wallet.operations.dialog.rescan.title"));
buttonPanel.add(okButon);
buttonPanel.add(new ZelCashJLabel(" "));
cancelButon = new ZelCashJButton(langUtil.getString("single.key.import.dialog.tmp.panel.cancel.button.text"));
buttonPanel.add(cancelButon);
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);

okButon.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
ZelcashRescanDialog.this.processOK();
}
});

cancelButon.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
ZelcashRescanDialog.this.setVisible(false);
ZelcashRescanDialog.this.dispose();

ZelcashRescanDialog.this.isOKPressed = false;
}
});

this.setSize(740, 210);
this.validate();
this.repaint();

this.pack();
}


protected void processOK()
{
ZelcashRescanDialog.this.isOKPressed = true;

// Start import
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.progress.setIndeterminate(true);
this.progress.setValue(1);

this.okButon.setEnabled(false);
this.cancelButon.setEnabled(false);

new Thread(new Runnable()
{
@Override
public void run()
{
parent.restartDaemon(false, true);
try {
restartAfterRescan();
} catch (IOException | InterruptedException | InvocationTargetException | WalletCallException e1) {
Log.error("Error restarting the UI, the wallet will be closed. Error:"+e1.getMessage());
JOptionPane.showMessageDialog(null,
LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.2.text",
e1.getMessage()),
LanguageUtil.instance()
.getString("main.frame.option.pane.wallet.critical.error.2.title"),
JOptionPane.ERROR_MESSAGE);
System.exit(1);
} finally
{
ZelcashRescanDialog.this.setVisible(false);
ZelcashRescanDialog.this.dispose();
}
}
}).start();
}


public boolean isOKPressed()
{
return this.isOKPressed;
}


public void restartAfterRescan() throws IOException, InterruptedException, WalletCallException, InvocationTargetException {
Log.info("Waiting for rescan complete.");
while(true) {
Thread.sleep(POLL_PERIOD);

JsonObject info = null;

try
{
info = caller.getDaemonRawRuntimeInfo();
} catch (IOException e)
{
throw e;
}

JsonValue code = info.get("code");
Log.debug("clientCaller:"+info.toString());
if (code == null || (code.asInt() != STARTUP_ERROR_CODE))
break;
}
Log.info("Rescan complete.");

JOptionPane.showMessageDialog(this.parent,
langUtil.getString("wallet.operations.dialog.rescan.complete.message"),
langUtil.getString("wallet.operations.dialog.rescan.complete.title"),
JOptionPane.INFORMATION_MESSAGE);

this.parent.setVisible(false);
this.parent.dispose();

ZCashUI z = new ZCashUI(null);
this.parent = z;
this.parent.repaint();
this.parent.setVisible(true);
}
public class ZelcashRescanDialog extends ZelCashJDialog {
protected boolean isOKPressed = false;

private static final int POLL_PERIOD = 5000;
private static final int STARTUP_ERROR_CODE = -28;

protected ZelCashJLabel upperLabel;
protected ZelCashJLabel lowerLabel;

protected ZelCashJProgressBar progress = null;

protected ZCashClientCaller caller;

private LanguageUtil langUtil;

ZelCashJButton okButon;
ZelCashJButton cancelButon;
private ZCashUI parent;

public ZelcashRescanDialog(ZCashUI parent, ZCashClientCaller caller) {
super(parent);
this.parent = parent;
this.caller = caller;
langUtil = LanguageUtil.instance();
this.setTitle(langUtil.getString("wallet.operations.dialog.rescan.title"));
this.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 50);
this.setModal(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

ZelCashJPanel controlsPanel = new ZelCashJPanel();
controlsPanel.setLayout(new BoxLayout(controlsPanel, BoxLayout.Y_AXIS));
controlsPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));

ZelCashJPanel tempPanel = new ZelCashJPanel(new BorderLayout(0, 0));
tempPanel.add(this.upperLabel = new ZelCashJLabel(langUtil.getString(
"wallet.operations.dialog.rescan.message")),
BorderLayout.CENTER);
controlsPanel.add(tempPanel);

ZelCashJLabel dividerLabel = new ZelCashJLabel(" ");
dividerLabel.setFont(new Font("Helvetica", Font.PLAIN, 8));
controlsPanel.add(dividerLabel);

tempPanel = new ZelCashJPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
tempPanel.add(progress = new ZelCashJProgressBar());
controlsPanel.add(tempPanel);

this.getContentPane().setLayout(new BorderLayout(0, 0));
this.getContentPane().add(controlsPanel, BorderLayout.NORTH);

// Form buttons
ZelCashJPanel buttonPanel = new ZelCashJPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
okButon = new ZelCashJButton(
langUtil.getString("wallet.operations.dialog.rescan.title"));
buttonPanel.add(okButon);
buttonPanel.add(new ZelCashJLabel(" "));
cancelButon = new ZelCashJButton(langUtil.getString(
"single.key.import.dialog.tmp.panel.cancel.button.text"));
buttonPanel.add(cancelButon);
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);

okButon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ZelcashRescanDialog.this.processOK();
}
});

cancelButon.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ZelcashRescanDialog.this.setVisible(false);
ZelcashRescanDialog.this.dispose();

ZelcashRescanDialog.this.isOKPressed = false;
}
});

this.setSize(740, 210);
this.validate();
this.repaint();

this.pack();
}

protected void processOK() {
ZelcashRescanDialog.this.isOKPressed = true;

// Start import
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.progress.setIndeterminate(true);
this.progress.setValue(1);

this.okButon.setEnabled(false);
this.cancelButon.setEnabled(false);

new Thread(new Runnable() {
@Override
public void run() {
parent.restartDaemon(false, true);
try {
restartAfterRescan();
} catch (IOException | InterruptedException |
InvocationTargetException | WalletCallException e1) {
Log.error(
"Error restarting the UI, the wallet will be closed. Error:" +
e1.getMessage());
JOptionPane.showMessageDialog(
null,
LanguageUtil.instance().getString(
"main.frame.option.pane.wallet.critical.error.2.text",
e1.getMessage()),
LanguageUtil.instance().getString(
"main.frame.option.pane.wallet.critical.error.2.title"),
JOptionPane.ERROR_MESSAGE);
System.exit(1);
} finally {
ZelcashRescanDialog.this.setVisible(false);
ZelcashRescanDialog.this.dispose();
}
}
}).start();
}

public boolean isOKPressed() { return this.isOKPressed; }

public void restartAfterRescan() throws IOException, InterruptedException,
WalletCallException,
InvocationTargetException {
Log.info("Waiting for rescan complete.");
while (true) {
Thread.sleep(POLL_PERIOD);

JsonObject info = null;

try {
info = caller.getDaemonRawRuntimeInfo();
} catch (IOException e) {
throw e;
}

JsonValue code = info.get("code");
Log.debug("clientCaller:" + info.toString());
if (code == null || (code.asInt() != STARTUP_ERROR_CODE))
break;
}
Log.info("Rescan complete.");

JOptionPane.showMessageDialog(
this.parent,
langUtil.getString("wallet.operations.dialog.rescan.complete.message"),
langUtil.getString("wallet.operations.dialog.rescan.complete.title"),
JOptionPane.INFORMATION_MESSAGE);

this.parent.setVisible(false);
this.parent.dispose();

ZCashUI z = new ZCashUI(null);
this.parent = z;
this.parent.repaint();
this.parent.setVisible(true);
}
}
Loading