use of com.vaklinov.zcashui.ZCashClientCaller.NetworkAndBlockchainInfo in project zencash-swing-wallet-ui by ZencashOfficial.
the class DashboardPanel method updateNetworkAndBlockchainLabel.
private void updateNetworkAndBlockchainLabel() throws IOException, InterruptedException {
NetworkAndBlockchainInfo info = this.netInfoGatheringThread.getLastData();
// It is possible there has been no gathering initially
if (info == null) {
return;
}
// TODO: Get the start date right after ZCash release - from first block!!!
final Date startDate = new Date("06 Nov 2016 02:00:00 GMT");
final Date nowDate = new Date(System.currentTimeMillis());
long fullTime = nowDate.getTime() - startDate.getTime();
long remainingTime = nowDate.getTime() - info.lastBlockDate.getTime();
String percentage = "100";
if (// After 30 min we report 100% anyway
remainingTime > 30 * 60 * 1000) {
double dPercentage = 100d - (((double) remainingTime / (double) fullTime) * 100d);
if (dPercentage < 0) {
dPercentage = 0;
} else if (dPercentage > 100d) {
dPercentage = 100d;
}
DecimalFormat df = new DecimalFormat("##0.##");
percentage = df.format(dPercentage);
// Also set a member that may be queried
this.blockchainPercentage = new Integer((int) dPercentage);
} else {
this.blockchainPercentage = 100;
}
// Just in case early on the call returns some junk date
if (info.lastBlockDate.before(startDate)) {
// TODO: write log that we fix minimum date! - this condition should not occur
info.lastBlockDate = startDate;
}
String text = langUtil.getString("panel.dashboard.network.blockchain.label", percentage, info.lastBlockDate.toLocaleString(), info.numConnections);
this.networkAndBlockchainLabel.setText(text);
// Connections check (typically not an open node with more than 8)
int numConnections = info.numConnections;
if (numConnections > 8) {
numConnections = 8;
}
// Set the correct number of connections (icon)
switch(numConnections) {
case 8:
case 7:
this.networkConnectionsIconLabel.setIcon(connect_4_Icon);
break;
case 6:
case 5:
this.networkConnectionsIconLabel.setIcon(connect_3_Icon);
break;
case 4:
case 3:
this.networkConnectionsIconLabel.setIcon(connect_2_Icon);
break;
case 2:
case 1:
this.networkConnectionsIconLabel.setIcon(connect_1_Icon);
break;
case 0:
default:
this.networkConnectionsIconLabel.setIcon(connect_0_Icon);
}
// Set the blockchain synchronization icon
if (this.blockchainPercentage < 100) {
this.blockchain100PercentLabel.setIcon(null);
} else {
this.blockchain100PercentLabel.setIcon(this.confirmedTXIcon);
}
// Possibly show a blockchain synchronization warning
if (this.blockchainPercentage < 100) {
String warningText = langUtil.getString("panel.dashboard.synchronisation.warning", info.lastBlockDate.toLocaleString());
if (this.blockcahinWarningPanel == null) {
// Create a new warning panel
JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
PresentationPanel warningPanel = new PresentationPanel();
this.blockcahinWarningLabel = new JLabel(warningText);
warningPanel.add(this.blockcahinWarningLabel);
tempPanel.add(warningPanel);
this.blockcahinWarningPanel = tempPanel;
this.upperLogoAndWarningPanel.add(this.blockcahinWarningPanel, BorderLayout.EAST);
} else if (this.blockcahinWarningLabel != null) {
this.blockcahinWarningLabel.setText(warningText);
}
} else {
if (this.blockcahinWarningPanel != null) {
this.upperLogoAndWarningPanel.remove(this.blockcahinWarningPanel);
this.upperLogoAndWarningPanel.revalidate();
this.upperLogoAndWarningPanel.repaint();
// The entire dashboard panel
this.revalidate();
this.blockcahinWarningPanel = null;
this.blockcahinWarningLabel = null;
}
}
}
use of com.vaklinov.zcashui.ZCashClientCaller.NetworkAndBlockchainInfo in project zencash-swing-wallet-ui by ZencashOfficial.
the class MessagingPanel method collectAndStoreNewReceivedMessagesAndHandleErrors.
private void collectAndStoreNewReceivedMessagesAndHandleErrors() throws Exception {
try {
synchronized (this.messageCollectionMutex) {
// When a large number of messages has been accumulated, this operation partly
// slows down blockchain synchronization. So messages are collected only when
// sync is full.
NetworkAndBlockchainInfo info = this.clientCaller.getNetworkAndBlockchainInfo();
// If more than 60 minutes behind in the blockchain - skip collection
if ((System.currentTimeMillis() - info.lastBlockDate.getTime()) > (60 * 60 * 1000)) {
Log.warning("Current blockchain synchronization date is {0}. Message collection skipped for now!", new Date(info.lastBlockDate.getTime()));
return;
}
// Call it for the own identity
collectAndStoreNewReceivedMessages(null);
// Call it for all existing groups
for (MessagingIdentity id : this.messagingStorage.getContactIdentities(false)) {
if (id.isGroup()) {
collectAndStoreNewReceivedMessages(id);
}
}
}
} catch (Exception e) {
if (Thread.currentThread() instanceof DataGatheringThread) {
if (((DataGatheringThread) Thread.currentThread()).isSuspended()) {
// Just rethrow the exception
throw e;
}
}
Log.error("Unexpected error in gathering received messages (wrapper): ", e);
this.errorReporter.reportError(e);
}
}
use of com.vaklinov.zcashui.ZCashClientCaller.NetworkAndBlockchainInfo in project zencash-swing-wallet-ui by ZencashOfficial.
the class ZCashUI method main.
public static void main(String[] argv) throws IOException {
try {
OS_TYPE os = OSUtil.getOSType();
if ((os == OS_TYPE.WINDOWS) || (os == OS_TYPE.MAC_OS)) {
possiblyCreateZENConfigFile();
}
LanguageUtil langUtil = LanguageUtil.instance();
Log.info("Starting ZENCash Swing Wallet ...");
Log.info("OS: " + System.getProperty("os.name") + " = " + os);
Log.info("Current directory: " + new File(".").getCanonicalPath());
Log.info("Class path: " + System.getProperty("java.class.path"));
Log.info("Environment PATH: " + System.getenv("PATH"));
// Look and feel settings - a custom OS-look and feel is set for Windows
if (os == OS_TYPE.WINDOWS) {
// Custom Windows L&F and font settings
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
// This font looks good but on Windows 7 it misses some chars like the stars...
// FontUIResource font = new FontUIResource("Lucida Sans Unicode", Font.PLAIN, 11);
// UIManager.put("Table.font", font);
} else if (os == OS_TYPE.MAC_OS) {
// The MacOS L&F is active by default - the property sets the menu bar Mac style
System.setProperty("apple.laf.useScreenMenuBar", "true");
} else {
for (LookAndFeelInfo ui : UIManager.getInstalledLookAndFeels()) {
Log.info("Available look and feel: " + ui.getName() + " " + ui.getClassName());
if (ui.getName().equals("Nimbus")) {
Log.info("Setting look and feel: {0}", ui.getClassName());
UIManager.setLookAndFeel(ui.getClassName());
break;
}
;
}
}
// If zend is currently not running, do a startup of the daemon as a child process
// It may be started but not ready - then also show dialog
ZCashInstallationObserver initialInstallationObserver = new ZCashInstallationObserver(OSUtil.getProgramDirectory());
DaemonInfo zcashdInfo = initialInstallationObserver.getDaemonInfo();
initialInstallationObserver = null;
ZCashClientCaller initialClientCaller = new ZCashClientCaller(OSUtil.getProgramDirectory());
boolean daemonStartInProgress = false;
try {
if (zcashdInfo.status == DAEMON_STATUS.RUNNING) {
NetworkAndBlockchainInfo info = initialClientCaller.getNetworkAndBlockchainInfo();
// If more than 20 minutes behind in the blockchain - startup in progress
if ((System.currentTimeMillis() - info.lastBlockDate.getTime()) > (20 * 60 * 1000)) {
Log.info("Current blockchain synchronization date is " + new Date(info.lastBlockDate.getTime()));
daemonStartInProgress = true;
}
}
} catch (WalletCallException wce) {
if (// Started but not ready
(wce.getMessage().indexOf("{\"code\":-28") != -1) || (wce.getMessage().indexOf("error code: -28") != -1)) {
Log.info("zend is currently starting...");
daemonStartInProgress = true;
}
}
StartupProgressDialog startupBar = null;
if ((zcashdInfo.status != DAEMON_STATUS.RUNNING) || (daemonStartInProgress)) {
Log.info("zend is not runing at the moment or has not started/synchronized 100% - showing splash...");
startupBar = new StartupProgressDialog(initialClientCaller);
startupBar.setVisible(true);
startupBar.waitForStartup();
}
initialClientCaller = null;
// Main GUI is created here
ZCashUI ui = new ZCashUI(startupBar);
ui.setVisible(true);
} catch (InstallationDetectionException ide) {
Log.error("Unexpected error: ", ide);
JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.installation.error.text", OSUtil.getProgramDirectory(), ide.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.installation.error.title"), JOptionPane.ERROR_MESSAGE);
System.exit(1);
} catch (WalletCallException wce) {
Log.error("Unexpected error: ", wce);
if ((wce.getMessage().indexOf("{\"code\":-28,\"message\"") != -1) || (wce.getMessage().indexOf("error code: -28") != -1)) {
JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.text"), LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.title"), JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.2.text", wce.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.communication.error.2.title"), JOptionPane.ERROR_MESSAGE);
}
System.exit(2);
} catch (Exception e) {
Log.error("Unexpected error: ", e);
JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.text", e.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.title"), JOptionPane.ERROR_MESSAGE);
System.exit(3);
} catch (Error err) {
// Last resort catch for unexpected problems - just to inform the user
err.printStackTrace();
JOptionPane.showMessageDialog(null, LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.2.text", err.getMessage()), LanguageUtil.instance().getString("main.frame.option.pane.wallet.critical.error.2.title"), JOptionPane.ERROR_MESSAGE);
System.exit(4);
}
}
Aggregations