private void send(String address, float amount) { DialogSend dialog = new DialogSend(); dialog.setLocationRelativeTo(frmWow); BigDecimal valueInBTC = new BigDecimal(coreWallet.getBalance()).divide(new BigDecimal(Utils.COIN)); dialog.setMaximum(valueInBTC.floatValue()); dialog.setNetworkParameters(coreWallet.getNetworkParameters()); if (address != null) { dialog.setAddress(address); dialog.setAmount(amount); } while (dialog.showDialog()) { System.out.println( "SEND: " + dialog.getAddress() + " " + dialog.getAmount() + " " + dialog.isFeeUsed()); try { if (coreWallet.isEncrypted()) { DialogPassword d = new DialogPassword(); d.setLocationRelativeTo(frmWow); if (d.showDialog()) { try { if (coreWallet.checkPassword(new String(d.getPassword()))) { coreWallet.sendCoins( dialog.getAddress(), dialog.getAmount(), new String(d.getPassword())); } else { JOptionPane.showMessageDialog( frmWow, "Not correct password provided!", "Information", JOptionPane.INFORMATION_MESSAGE); break; } } catch (KeyCrypterException e) { JOptionPane.showMessageDialog( frmWow, "Wallet dencryption failed!", "Error", JOptionPane.ERROR_MESSAGE); break; } } // coreWallet.sendCoins(dialog.getAddress(), dialog.getAmount()); } else coreWallet.sendCoins(dialog.getAddress(), dialog.getAmount()); break; } catch (InsufficientMoneyException e) { JOptionPane.showMessageDialog( frmWow, "Insufficient coins!", "Warning", JOptionPane.WARNING_MESSAGE); break; } catch (KeyCrypterException e) { JOptionPane.showMessageDialog(frmWow, e.toString(), "Error", JOptionPane.ERROR_MESSAGE); break; } } }
/** Create the application. */ public Wow() { initialize(); // ArrayList<BufferedImage> images = new ArrayList<BufferedImage>(); coreWallet = new CoreWallet(); fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Wow DOGE Wallet Files", "dogewallet"); fileChooser.addChoosableFileFilter(filter); addressesListModel = new AddressesListModel(); listAddresses.setModel(addressesListModel); // new DefaultListModel()); transactionsTableModel = new TransactionsTableModel(); tableTransactions.setModel(transactionsTableModel); tableTransactions.setDefaultRenderer(Object.class, new TransactionsTableCellRenderer()); addressBookTableModel = new AddressBookTableModel(coreWallet.getPreferences()); tableAddressBook.setModel(addressBookTableModel); try { addressBookTableModel.getAddressBook().load(); } catch (IOException e1) { e1.printStackTrace(); JOptionPane.showMessageDialog( frmWow, e1.getMessage(), "Error during Reading Address Book Data", JOptionPane.ERROR_MESSAGE); } catch (ClassNotFoundException e1) { e1.printStackTrace(); JOptionPane.showMessageDialog( frmWow, e1.getMessage(), "Error in Reading Address Book Data", JOptionPane.ERROR_MESSAGE); } catch (BackingStoreException e1) { e1.printStackTrace(); JOptionPane.showMessageDialog( frmWow, e1.getMessage(), "Error within Reading Address Book Data", JOptionPane.ERROR_MESSAGE); } JMenuBar menuBar = new JMenuBar(); frmWow.setJMenuBar(menuBar); mnFile = new JMenu("File"); mnFile.setMnemonic('F'); menuBar.add(mnFile); JMenuItem mntmNew = new JMenuItem("New Wallet"); mntmNew.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { DialogNew d = new DialogNew(); d.setLocationRelativeTo(frmWow); if (d.showDialog()) { try { coreWallet.open(new File(d.getFolder(), d.getWalletFileName())); mnRecent.addFileToFileHistory( new File(d.getFolder(), d.getWalletFileName()).getAbsolutePath()); mnRecent.storeToPreferences(); } catch (IOException e) { JOptionPane.showMessageDialog( frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog( frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); mntmNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.META_MASK)); mntmNew.setMnemonic(KeyEvent.VK_N); mnFile.add(mntmNew); JMenuItem mntmOpen = new JMenuItem("Open Wallet..."); mntmOpen.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { int returnVal = fileChooser.showOpenDialog(frmWow); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = fileChooser.getSelectedFile(); coreWallet.open(file); mnRecent.addFileToFileHistory(file.getAbsolutePath()); mnRecent.storeToPreferences(); } catch (IOException e) { JOptionPane.showMessageDialog( frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog( frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); mntmOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.META_MASK)); mnFile.add(mntmOpen); JMenuItem mntmSaveAs = new JMenuItem("Save As..."); mntmSaveAs.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { int returnVal = fileChooser.showSaveDialog(frmWow); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File file = fileChooser.getSelectedFile(); String file_name = file.toString(); if (!file_name.endsWith(".dogewallet")) file_name += ".dogewallet"; file = new File(file_name); File temp = new File(file.getParentFile().getAbsolutePath(), "TEMP" + file.getName()); coreWallet.saveToFile(temp, file); } catch (IOException e) { JOptionPane.showMessageDialog( frmWow, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); // coreWallet = new CoreWallet(); mnRecent = new RecentFilesMenu("Open Recent Wallet", coreWallet.getPreferences().node("Recent")) { @Override protected Action createOpenAction(String fileFullPath) { return new OpenAction(this, fileFullPath); } }; mnFile.add(mnRecent); mntmSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.META_MASK)); mnFile.add(mntmSaveAs); JMenu mnHelp = new JMenu("Help"); menuBar.add(mnHelp); JMenuItem mntmHelp = new JMenuItem("Wow - Doge Wallet Help"); mnHelp.add(mntmHelp); JMenuItem mntmAbout = new JMenuItem("About Wow - Doge Wallet"); mntmAbout.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { DialogAbout d = new DialogAbout(); d.setLocationRelativeTo(frmWow); d.showDialog(); } }); mnHelp.add(mntmAbout); tableAddressBook.setDefaultRenderer(Object.class, new AddressBookTableCellRenderer()); (new Thread(this)).start(); }
public void run() { while (true) { try { // System.out.println("Hello from a thread!"); if (coreWallet.isDirty()) { // Setup completed updateEncryptionState(); // System.out.println(coreWallet.getKeys()); java.util.List<ECKey> keys = coreWallet.getKeys(); // if (keys.size() != listAddresses.getModel().getSize()) { int selectedIndex = listAddresses.getSelectedIndex(); // DefaultListModel model = (DefaultListModel) listAddresses.getModel(); // model.removeAllElements(); // NetworkParameters params = MainNetParams.get(); List<String> addresses = new ArrayList<String>(); for (ECKey k : keys) { // System.out.println(k.toAddress(coreWallet.getNetworkParameters())); //params)); // model.addElement(k.toAddress(coreWallet.getNetworkParameters()).toString()); addresses.add(k.toAddress(coreWallet.getNetworkParameters()).toString()); } addressesListModel.setAddresses(addresses); if (selectedIndex != -1) { if (selectedIndex < addressesListModel.getSize()) listAddresses.setSelectedIndex(selectedIndex); else listAddresses.setSelectedIndex(0); } else if (addressesListModel.getSize() > 0) listAddresses.setSelectedIndex(0); refreshAddressAndQRCode(); if (coreWallet.getWallet().isEncrypted()) { tglbtnLock.setText("Encrypted"); tglbtnLock.setSelected(true); } else { tglbtnLock.setText("Not Encrypted"); tglbtnLock.setSelected(false); } // } String textBalance = bitcoinValueToFriendlyString(coreWallet.getBalance()); if (!textBalance.matches(textTotalBalance.getText())) { this.textTotalBalance.setText(textBalance); } this.frmWow.setTitle(coreWallet.getWalletFilePath() + " - Wow Doge Wallet"); // java.lang.Iterable<WalletTransaction> transactions = // coreWallet.getWalletTransactions(); List<Transaction> transactions = coreWallet.getTransactionsByTime(); System.out.println(transactions); // transactionsTableModel = new TransactionsTableModel(); // tableTransactions.setModel(transactionsTableModel); this.transactionsTableModel.setTransactions(transactions, coreWallet.getWallet()); tableTransactions.repaint(); coreWallet.setDirty(false); } if (coreWallet.isRunning()) { this.progressBarStatus.setVisible(false); this.lblStatus.setText(" Online "); this.progressBarStatus.setToolTipText("Synchronized"); } else if (coreWallet.isSynchronizing() != 0) { if (this.progressBarStatus.isIndeterminate()) { this.lblStatus.setText(" Synchronizing... "); this.progressBarStatus.setIndeterminate(false); this.progressBarStatus.setMaximum(coreWallet.isSynchronizing()); } int progress = this.progressBarStatus.getMaximum() - coreWallet.isSynchronizing(); int max = this.progressBarStatus.getMaximum(); this.progressBarStatus.setValue(progress); this.progressBarStatus.setToolTipText((((float) progress) / max * 100) + "%"); } else this.progressBarStatus.setIndeterminate(true); if (coreWallet.isStoreFileLocked()) { JOptionPane.showMessageDialog( frmWow, "Another Wow Doge Wallet instance is already running!\nPress OK button to quit.", "Information", JOptionPane.INFORMATION_MESSAGE); System.exit(1); } Thread.sleep(30); } catch (Exception e) { e.printStackTrace(); } } }
private void updateEncryptionState() { tglbtnLock.setText(coreWallet.isEncrypted() ? "Encrypted" : "Not Encrypted"); tglbtnLock.setToolTipText( coreWallet.isEncrypted() ? "Wallet is encrypted" : "Wallet is not encrypted"); tglbtnLock.setSelected(coreWallet.isEncrypted()); }