/** Creates new form CDRSettingsJDialog */
  public CDRSettingsJDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    this.stockComboBox = new AutoCompleteJComboBox();
    this.stockComboBox.setEditable(true);
    this.stockComboBox.setPreferredSize(new java.awt.Dimension(150, 24));
    this.stockComboBox.attachStockInfoObserver(getStockInfoObserver());
    this.stockComboBox.attachResultObserver(getResultObserver());
    this.stockComboBox.setStockInfoDatabase(MainFrame.getInstance().getStockInfoDatabase());
    this.jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER));
    this.jPanel1.add(Utils.getBusyJXLayer(this.stockComboBox));
    this.pack();

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(
        (screenSize.width - this.getSize().width) / 2,
        (screenSize.height - this.getSize().height) / 2,
        this.getSize().width,
        this.getSize().height);

    this.settings = CDRSettings.globalSettings.clone();
    this.jList1.setListData(this.settings.getList());
  }
Exemple #2
0
  public static Statements newInstanceFromBuyPortfolioTreeTableModel(
      BuyPortfolioTreeTableModelEx buyPortfolioTreeTableModel, boolean languageIndependent) {
    final JStockOptions jStockOptions = MainFrame.getInstance().getJStockOptions();
    final boolean isPenceToPoundConversionEnabled = jStockOptions.isPenceToPoundConversionEnabled();

    final GUIBundleWrapper guiBundleWrapper =
        GUIBundleWrapper.newInstance(
            languageIndependent
                ? GUIBundleWrapper.Language.INDEPENDENT
                : GUIBundleWrapper.Language.DEFAULT);

    final String[] tmp = {
      guiBundleWrapper.getString("MainFrame_Code"),
      guiBundleWrapper.getString("MainFrame_Symbol"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_Date"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_Units"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_PurchasePrice"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_CurrentPrice"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_PurchaseValue"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_CurrentValue"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_GainLossPrice"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_GainLossValue"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_GainLossPercentage"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_Broker"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_ClearingFee"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_StampDuty"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_NetPurchaseValue"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_NetGainLossValue"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_NetGainLossPercentage"),
      guiBundleWrapper.getString("PortfolioManagementJPanel_Comment")
    };

    Statement.What what = Statement.what(Arrays.asList(tmp));
    final Statements statements = new Statements(what.type, what.guiBundleWrapper);

    final Portfolio portfolio = (Portfolio) buyPortfolioTreeTableModel.getRoot();
    final int summaryCount = portfolio.getChildCount();

    for (int i = 0; i < summaryCount; i++) {
      Object o = portfolio.getChildAt(i);
      final TransactionSummary transactionSummary = (TransactionSummary) o;

      // Metadatas will be used to store TransactionSummary's comment.
      final String comment = transactionSummary.getComment().trim();
      if (comment.isEmpty() == false) {
        final Stock stock = ((Transaction) transactionSummary.getChildAt(0)).getStock();
        statements.metadatas.put(stock.getCode().toString(), comment);
      }

      final int transactionCount = transactionSummary.getChildCount();
      for (int j = 0; j < transactionCount; j++) {
        final Transaction transaction = (Transaction) transactionSummary.getChildAt(j);
        final Stock stock = transaction.getStock();
        final List<Atom> atoms = new ArrayList<Atom>();
        atoms.add(new Atom(stock.getCode().toString(), tmp[0]));
        atoms.add(new Atom(stock.getSymbol().toString(), tmp[1]));

        DateFormat dateFormat = org.yccheok.jstock.gui.Utils.getCommonDateFormat();
        final String dateString =
            transaction.getDate() != null ? dateFormat.format(transaction.getDate().getTime()) : "";
        atoms.add(new Atom(dateString, tmp[2]));
        atoms.add(new Atom(transaction.getQuantity(), tmp[3]));
        atoms.add(new Atom(transaction.getPrice(), tmp[4]));
        atoms.add(new Atom(buyPortfolioTreeTableModel.getCurrentPrice(transaction), tmp[5]));
        if (isPenceToPoundConversionEnabled == false) {
          atoms.add(new Atom(transaction.getTotal(), tmp[6]));
        } else {
          atoms.add(new Atom(transaction.getTotal() / 100.0, tmp[6]));
        }
        atoms.add(new Atom(buyPortfolioTreeTableModel.getCurrentValue(transaction), tmp[7]));
        atoms.add(new Atom(buyPortfolioTreeTableModel.getGainLossPrice(transaction), tmp[8]));
        if (isPenceToPoundConversionEnabled == false) {
          atoms.add(new Atom(buyPortfolioTreeTableModel.getGainLossValue(transaction), tmp[9]));
        } else {
          atoms.add(
              new Atom(buyPortfolioTreeTableModel.getGainLossValue(transaction) / 100.0, tmp[9]));
        }
        atoms.add(new Atom(buyPortfolioTreeTableModel.getGainLossPercentage(transaction), tmp[10]));
        atoms.add(new Atom(transaction.getBroker(), tmp[11]));
        atoms.add(new Atom(transaction.getClearingFee(), tmp[12]));
        atoms.add(new Atom(transaction.getStampDuty(), tmp[13]));
        if (isPenceToPoundConversionEnabled == false) {
          atoms.add(new Atom(transaction.getNetTotal(), tmp[14]));
          atoms.add(new Atom(buyPortfolioTreeTableModel.getNetGainLossValue(transaction), tmp[15]));
        } else {
          atoms.add(new Atom(transaction.getNetTotal() / 100.0, tmp[14]));
          atoms.add(
              new Atom(
                  buyPortfolioTreeTableModel.getNetGainLossValue(transaction) / 100.0, tmp[15]));
        }
        atoms.add(
            new Atom(buyPortfolioTreeTableModel.getNetGainLossPercentage(transaction), tmp[16]));
        atoms.add(new Atom(transaction.getComment(), tmp[17]));

        final Statement statement = new Statement(atoms);

        if (statements.getType() != statement.getType()) {
          return UNKNOWN_STATEMENTS;
        }
        statements.statements.add(statement);
      }
    }
    return statements;
  }