Search in sources :

Example 1 with CashPurseDetails

use of com.moneychanger.core.dataobjects.CashPurseDetails in project otapij by FellowTraveler.

the class MainPage method initMainTab.

private void initMainTab() {
    jPanel_TopPanel.setLayout(new CardLayout());
    jPanel_BottomPanel.setLayout(new CardLayout());
    jTable_AccountTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            System.out.println("valueChanged Action Listener :" + jTable_AccountTable.getSelectedRow() + "e:" + e.getSource());
            if (jTable_AccountTable.getSelectedRow() >= 0) {
                try {
                    jPanel_TopPanel.setVisible(true);
                    jPanel_BottomPanel.setVisible(true);
                    CardLayout topLayout = (CardLayout) (jPanel_TopPanel.getLayout());
                    CardLayout bottomlayout = (CardLayout) (jPanel_BottomPanel.getLayout());
                    String type = null;
                    String accountID = null;
                    type = (String) jTable_AccountTable.getModel().getValueAt(jTable_AccountTable.getSelectedRow(), 2);
                    accountID = (String) jTable_AccountTable.getModel().getValueAt(jTable_AccountTable.getSelectedRow(), 3);
                    System.out.println("Type:" + type);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    for (int i = 0; i < Account.allAccounts.length; i++) {
                        if (Account.allAccounts[i].equalsIgnoreCase(type)) {
                            try {
                                topLayout.show(jPanel_TopPanel, type + "TopPanel");
                                bottomlayout.show(jPanel_BottomPanel, type + "BottomPanel");
                                Class obj = Class.forName("com.moneychanger.core." + type);
                                Account account = (Account) obj.newInstance();
                                Object details = account.getAccountDetails(accountID);
                                if (details == null) {
                                    JOptionPane.showMessageDialog(null, "Error loading details", "Details Error", JOptionPane.ERROR_MESSAGE);
                                    break;
                                }
                                if ("OpenTransactionAccount".equalsIgnoreCase(type)) {
                                    OTDetails otDetails = (OTDetails) details;
                                    Helpers.populateOTDetails(otDetails);
                                    ((AccountTableModel) jTable_AccountTable.getModel()).setValueAt(otDetails.getBalance(), jTable_AccountTable.getSelectedRow(), 1);
                                } else if ("CashPurseAccount".equalsIgnoreCase(type)) {
                                    CashPurseDetails cashDetails = (CashPurseDetails) details;
                                    populateCashPurseDetails(cashDetails, cashDetails.getBalance());
                                }
                                break;
                            } catch (InstantiationException ex) {
                                Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IllegalAccessException ex) {
                                Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (ClassNotFoundException ex) {
                                Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                            }
                            repaint();
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                } finally {
                    setCursor(Cursor.getDefaultCursor());
                }
            }
        }
    });
    nymMap = new NYM().loadNYM();
    jComboBox_Nyms.addItem(new ComboObject("ALL"));
    jComboBoxServerContracts.addItem(new ComboObject("ALL"));
    jComboBox_AssetContracts.addItem(new ComboObject("ALL"));
    Helpers.populateCombo(nymMap, jComboBox_Nyms);
    Contract contract = new Contract();
    serverMap = contract.loadServerContract();
    Helpers.populateCombo(serverMap, jComboBoxServerContracts);
    assetMap = contract.loadAssetContract();
    Helpers.populateCombo(assetMap, jComboBox_AssetContracts);
    Account account = null;
    for (int i = 0; i < Account.allAccounts.length; i++) {
        try {
            if ("OpenTransactionAccount".equals(Account.allAccounts[i]) || "CashPurseAccount".equals(Account.allAccounts[i])) {
                Class obj = Class.forName("com.moneychanger.core." + Account.allAccounts[i]);
                account = (Account) obj.newInstance();
                try {
                    account.loadAccount("ALL", "ALL", "ALL");
                } catch (Exception ex) {
                    Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
                }
                Class obj1 = Class.forName("com.moneychanger.ui.panels." + Account.allAccounts[i] + "TopPanel");
                JPanel topPanel = (JPanel) obj1.newInstance();
                jPanel_TopPanel.add(topPanel, Account.allAccounts[i] + "TopPanel");
                Class obj2 = Class.forName("com.moneychanger.ui.panels." + Account.allAccounts[i] + "BottomPanel");
                JPanel bottomPanel = (JPanel) obj2.newInstance();
                jPanel_BottomPanel.add(bottomPanel, Account.allAccounts[i] + "BottomPanel");
            }
        } catch (InstantiationException ex) {
        //Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
        ///Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
        //Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : CardLayout(java.awt.CardLayout) OpenTransactionAccount(com.moneychanger.core.OpenTransactionAccount) RippleAccount(com.moneychanger.core.RippleAccount) Account(com.moneychanger.core.Account) JPanel(javax.swing.JPanel) NYM(com.moneychanger.core.NYM) CashPurseDetails(com.moneychanger.core.dataobjects.CashPurseDetails) ListSelectionEvent(javax.swing.event.ListSelectionEvent) AWTException(java.awt.AWTException) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) OTDetails(com.moneychanger.core.dataobjects.OTDetails) ComboObject(com.moneychanger.core.util.ComboObject) ComboObject(com.moneychanger.core.util.ComboObject) Contract(com.moneychanger.core.Contract)

Example 2 with CashPurseDetails

use of com.moneychanger.core.dataobjects.CashPurseDetails in project otapij by FellowTraveler.

the class CashPurseDepositDialog method jButton1ActionPerformed.

//GEN-LAST:event_jComboBox1ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_jButton1ActionPerformed
    try {
        CashPurseAccount cashPurseAccount = new CashPurseAccount();
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        boolean isSuccess = cashPurseAccount.depositCashPurse(details.getServerID(), details.getAssetID(), details.getNymID(), details.getPurse(), selectedIndices, jTextField1.getText());
        if (isSuccess) {
            JOptionPane.showMessageDialog(this, "Cash Purse deposited successfully", "Cash Purse Deposit Success", JOptionPane.INFORMATION_MESSAGE);
            CashPurseDetails cashDetails = new CashPurseAccount().getCashPurseDetails(details.getServerID() + ":" + details.getAssetID() + ":" + details.getNymID());
            CashPurseAccountBottomPanel.populateCashPurseDetails(cashDetails);
            CashPurseAccountTopPanel.populateCashPurseDetails(cashDetails, cashDetails.getBalance());
            MainPage.reLoadAccount();
        //CashPurseAccountBottomPanel.refreshGrid(cashPurseAccount.refreshGridData(details.getServerID(), details.getAssetID(), details.getNymID()));
        } else {
            if (Helpers.getObj() != null) {
                new CashPurseExportDetails(null, true, (String) Helpers.getObj(), false).setVisible(true);
            } else
                JOptionPane.showMessageDialog(this, "Error in cash purse deposit", "Server Error", JOptionPane.ERROR_MESSAGE);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }
    this.dispose();
}
Also used : CashPurseDetails(com.moneychanger.core.dataobjects.CashPurseDetails) CashPurseAccount(com.moneychanger.core.CashPurseAccount)

Example 3 with CashPurseDetails

use of com.moneychanger.core.dataobjects.CashPurseDetails in project otapij by FellowTraveler.

the class ExportCashToDialog method jButton1ActionPerformed.

//GEN-LAST:event_jComboBox2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_jButton1ActionPerformed
    CashPurseAccount cashPurseAccount = new CashPurseAccount();
    boolean isPasted = true;
    if (jComboBox2.getSelectedIndex() > 0)
        isPasted = false;
    try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        String purse = cashPurseAccount.exportCashPurse(details.getServerID(), details.getAssetID(), details.getNymID(), details.getPurse(), selectedIndices, jTextField1.getText(), isPasted);
        if (purse != null) {
            CashPurseDetails cashDetails = new CashPurseAccount().getCashPurseDetails(details.getServerID() + ":" + details.getAssetID() + ":" + details.getNymID());
            CashPurseAccountBottomPanel.populateCashPurseDetails(cashDetails);
            CashPurseAccountTopPanel.populateCashPurseDetails(cashDetails, cashDetails.getBalance());
            MainPage.reLoadAccount();
        //((CashPurseTableModel) jTable5.getModel()).setValue(cashPurseAccount.refreshGridData(details.getServerID(), details.getAssetID(), details.getNymID()), jTable5);
        }
        if (Helpers.getObj() != null) {
            new CashPurseExportDetails(null, true, purse, false).setVisible(true);
            dispose();
        } else {
            new CashPurseExportDetails(null, true, purse, true).setVisible(true);
            dispose();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }
    dispose();
}
Also used : CashPurseDetails(com.moneychanger.core.dataobjects.CashPurseDetails) CashPurseAccount(com.moneychanger.core.CashPurseAccount)

Example 4 with CashPurseDetails

use of com.moneychanger.core.dataobjects.CashPurseDetails in project otapij by FellowTraveler.

the class ImportCashPurse method jButton1ActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_jButton1ActionPerformed
    try {
        boolean isPurse = true;
        if (jTextArea1.getText().length() < 1) {
            JOptionPane.showMessageDialog(this, "Error in cash purse import. Empty purse", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (!jTextArea1.getText().trim().startsWith("-----BEGIN SIGNED CASH-----") && !jTextArea1.getText().trim().startsWith("-----BEGIN SIGNED PURSE-----")) {
            JOptionPane.showMessageDialog(this, "Please enter valid purse/token", "Purse Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (jTextArea1.getText().trim().startsWith("-----BEGIN SIGNED CASH-----")) {
            isPurse = false;
        }
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        boolean success = new CashPurseAccount().importCashPurse(serverID, nymID, assetID, jTextArea1.getText(), isPurse);
        if (success) {
            JOptionPane.showMessageDialog(this, "Cash imported successfully", "Success", JOptionPane.INFORMATION_MESSAGE);
            CashPurseDetails details = new CashPurseAccount().getCashPurseDetails(serverID + ":" + assetID + ":" + nymID);
            CashPurseAccountBottomPanel.populateCashPurseDetails(details);
            CashPurseAccountTopPanel.populateCashPurseDetails(details, details.getBalance());
            MainPage.reLoadAccount();
        } else
            JOptionPane.showMessageDialog(this, "Error in cash purse import", "Server Error", JOptionPane.ERROR_MESSAGE);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        setCursor(Cursor.getDefaultCursor());
        this.dispose();
    }
}
Also used : CashPurseDetails(com.moneychanger.core.dataobjects.CashPurseDetails) CashPurseAccount(com.moneychanger.core.CashPurseAccount)

Example 5 with CashPurseDetails

use of com.moneychanger.core.dataobjects.CashPurseDetails in project otapij by FellowTraveler.

the class CashPurseAccountBottomPanel method jButton_ExchangeActionPerformed1.

//GEN-LAST:event_jButton_ExportActionPerformed
private void jButton_ExchangeActionPerformed1(java.awt.event.ActionEvent evt) {
    try {
        if (true) {
            JOptionPane.showMessageDialog(null, "Exchange is currently not supported", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        CashPurseAccount cashPurseAccount = new CashPurseAccount();
        ArrayList selectedIndices = new ArrayList();
        for (int i = 0; i < jTable5.getRowCount(); i++) {
            String id = (String) jTable5.getModel().getValueAt(i, 3);
            if ((Boolean) jTable5.getModel().getValueAt(i, 5)) {
                selectedIndices.add(id);
            }
        }
        System.out.println("selectedIndices:" + selectedIndices);
        if (selectedIndices.isEmpty()) {
            int selected = JOptionPane.showConfirmDialog(this, "This will exchange all of the tokens in the purse", "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (selected == 2)
                return;
        }
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        boolean isSuccess = cashPurseAccount.exchangeCashPurse(details.getServerID(), details.getAssetID(), details.getNymID(), details.getPurse(), selectedIndices);
        if (isSuccess) {
            JOptionPane.showMessageDialog(this, "Cash exchanged successfully", "Exchange Success", JOptionPane.INFORMATION_MESSAGE);
            CashPurseDetails cashDetails = new CashPurseAccount().getCashPurseDetails(details.getServerID() + ":" + details.getAssetID() + ":" + details.getNymID());
            CashPurseAccountBottomPanel.populateCashPurseDetails(cashDetails);
            CashPurseAccountTopPanel.populateCashPurseDetails(cashDetails, cashDetails.getBalance());
            MainPage.reLoadAccount();
        //((CashPurseTableModel) jTable5.getModel()).setValue(cashPurseAccount.refreshGridData(details.getServerID(), details.getAssetID(), details.getNymID()), jTable5);
        } else {
            if (Helpers.getObj() != null) {
                new CashPurseExportDetails(null, true, (String) Helpers.getObj(), false).setVisible(true);
            } else
                JOptionPane.showMessageDialog(this, "Error in cash purse exchange", "Server Error", JOptionPane.ERROR_MESSAGE);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }
}
Also used : CashPurseDetails(com.moneychanger.core.dataobjects.CashPurseDetails) ArrayList(java.util.ArrayList) CashPurseAccount(com.moneychanger.core.CashPurseAccount) CashPurseExportDetails(com.moneychanger.ui.dialogs.CashPurseExportDetails)

Aggregations

CashPurseDetails (com.moneychanger.core.dataobjects.CashPurseDetails)6 CashPurseAccount (com.moneychanger.core.CashPurseAccount)4 Account (com.moneychanger.core.Account)1 Contract (com.moneychanger.core.Contract)1 NYM (com.moneychanger.core.NYM)1 OpenTransactionAccount (com.moneychanger.core.OpenTransactionAccount)1 RippleAccount (com.moneychanger.core.RippleAccount)1 OTDetails (com.moneychanger.core.dataobjects.OTDetails)1 ComboObject (com.moneychanger.core.util.ComboObject)1 CashPurseExportDetails (com.moneychanger.ui.dialogs.CashPurseExportDetails)1 AWTException (java.awt.AWTException)1 CardLayout (java.awt.CardLayout)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JPanel (javax.swing.JPanel)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1