private void initComponents() {

    final Resource rb = Resource.get();

    setTitle(rb.getString("Title.DefTranNum"));

    okButton = new JButton(rb.getString("Button.Ok"));
    cancelButton = new JButton(rb.getString("Button.Cancel"));
    insertButton = new JButton(rb.getString("Button.Insert"));
    removeButton = new JButton(rb.getString("Button.Remove"));

    upButton = new JButton(Resource.getIcon("/jgnash/resource/stock_up-16.png"));
    downButton = new JButton(Resource.getIcon("/jgnash/resource/stock_down-16.png"));

    insertButton.addActionListener(this);
    cancelButton.addActionListener(this);
    okButton.addActionListener(this);
    removeButton.addActionListener(this);
    upButton.addActionListener(this);
    downButton.addActionListener(this);

    model = new DefaultListModel<>();
    final List<String> items =
        EngineFactory.getEngine(EngineFactory.DEFAULT).getTransactionNumberList();

    for (String s : items) {
      model.addElement(s);
    }

    list = new JList<>(model);

    entryField = new JTextFieldEx(10);
  }
Exemplo n.º 2
0
  private void createReport() {
    Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Account root = engine.getRootAccount();

    baseCommodity = engine.getDefaultCurrency();

    numberFormat = CommodityFormat.getFullNumberFormat(baseCommodity);
    SimpleDateFormat df = new SimpleDateFormat("dd-MMMMM-yyyy");

    dates = getDates();

    // title and dates
    pl.add(rb.getString("Title.ProfitLoss"));
    pl.add("");
    pl.add("From " + df.format(dates[0]) + " To " + df.format(dates[1]));
    pl.add("");
    pl.add("");

    // Income
    pl.add("Income");
    pl.add("------------------------------------------------------");
    getBalances(root, dates, AccountType.INCOME);

    // Add up the  Gross Income.
    BigDecimal total1 = BigDecimal.ZERO;
    for (Object aBalance1 : balance) {
      total1 = total1.add((BigDecimal) aBalance1);
    }
    pl.add("------------------------------------------------------");
    pl.add(formatAcctNameOut(rb.getString("Word.GrossIncome")) + " " + formatDecimalOut(total1));
    pl.add("------------------------------------------------------");
    pl.add("");
    pl.add("");

    // Expense
    pl.add("Expenses");
    pl.add("------------------------------------------------------");
    balance = new ArrayList<>();
    getBalances(root, dates, AccountType.EXPENSE);

    // Add up the Gross Expenses
    BigDecimal total2 = BigDecimal.ZERO;
    for (Object aBalance : balance) {
      total2 = total2.add((BigDecimal) aBalance);
    }
    pl.add("------------------------------------------------------");
    pl.add(formatAcctNameOut(rb.getString("Word.GrossExpense")) + " " + formatDecimalOut(total2));
    pl.add("------------------------------------------------------");
    pl.add("");
    pl.add("");

    // Net Total
    pl.add("------------------------------------------------------");
    pl.add(
        formatAcctNameOut(rb.getString("Word.NetIncome"))
            + " "
            + formatDecimalOut(total1.add(total2)));
    pl.add("======================================================");
  }
  private void initComponents() {
    datePanel = new DatePanel();
    numberCombo = new TransactionNumberComboBox(account);

    okButton = new JButton(rb.getString("Button.Ok"));
    cancelButton = new JButton(rb.getString("Button.Cancel"));

    okButton.addActionListener(this);
    cancelButton.addActionListener(this);

    getRootPane().setDefaultButton(okButton);
  }
  private void initComponents() {
    Preferences preferences = Preferences.userNodeForPackage(RemoteConnectionDialog.class);

    setPort(preferences.getInt(LAST_PORT, JpaNetworkServer.DEFAULT_PORT));
    setHost(preferences.get(LAST_HOST, "localhost"));

    cancelButton = new JButton(rb.getString("Button.Cancel"));
    okButton = new JButton(rb.getString("Button.Ok"));

    cancelButton.addActionListener(this);
    okButton.addActionListener(this);
  }
Exemplo n.º 5
0
  private void layoutMainPanel() {
    initComponents();

    FormLayout layout = new FormLayout("p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    builder.setDefaultDialogBorder();

    builder.appendTitle(rb.getString("Message.TransToPrint"));
    builder.append(ButtonBarFactory.buildLeftAlignedBar(selectButton, clearButton, invertButton));
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();
    builder.appendRow(RowSpec.decode("f:75dlu:g"));
    builder.append(new JScrollPane(table));
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();
    builder.append(ButtonBarFactory.buildOKCancelBar(okButton, cancelButton));

    getContentPane().add(builder.getPanel(), BorderLayout.CENTER);

    pack();

    setMinimumSize(getSize());
  }
Exemplo n.º 6
0
  private void layoutMainPanel() {
    initComponents();

    FormLayout layout = new FormLayout("p, 8dlu, 85dlu:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout, this);

    builder.appendSeparator(rb.getString("Title.SelDestAccount"));
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.appendRow(RowSpec.decode("p"));
    builder.append(helpPane, 3);

    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(rb.getString("Label.DestAccount"), accountCombo);
    builder.nextLine();
    builder.append(rb.getString("Label.DateFormat"), dateFormatCombo);
  }
  private void buildPanel() {
    initComponents();

    FormLayout layout =
        new FormLayout("max(20dlu;d), 4dlu, 75dlu:grow(1.0)", "f:d, 3dlu, f:d, 10dlu, f:d");
    CellConstraints cc = new CellConstraints();

    layout.setRowGroups(new int[][] {{1, 3, 5}});

    JPanel p = new JPanel(layout);

    p.setBorder(Borders.DIALOG);
    p.add(new JLabel(rb.getString("Label.Date")), cc.xy(1, 1));
    p.add(datePanel, cc.xy(3, 1));
    p.add(new JLabel(rb.getString("Label.Number")), cc.xy(1, 3));
    p.add(numberCombo, cc.xy(3, 3));
    p.add(StaticUIMethods.buildOKCancelBar(okButton, cancelButton), cc.xyw(1, 5, 3));

    getContentPane().add(p, BorderLayout.CENTER);
  }
  public RemoteConnectionDialog(final JFrame parent) {
    super(parent, true);
    setTitle(rb.getString("Title.ConnectServer"));
    layoutMainPanel();

    setMinimumSize(getSize());

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    DialogUtils.addBoundsListener(this);
  }
  private void layoutMainPanel() {
    initComponents();

    FormLayout layout = new FormLayout("p, 4dlu, fill:70dlu:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.border(Borders.DIALOG);

    builder.append(rb.getString("Label.DatabaseServer"), hostField);
    builder.append(rb.getString("Label.Port"), portField);
    builder.append(rb.getString("Label.Password"), passwordField);

    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();
    builder.append(StaticUIMethods.buildOKCancelBar(okButton, cancelButton), 3);

    getContentPane().add(builder.getPanel());

    pack();

    setResizable(false);
  }
Exemplo n.º 10
0
  String getFileName() {
    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(false);
    chooser.addChoosableFileFilter(
        new FileNameExtensionFilter(rb.getString("Message.TXTFile"), "txt"));

    if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
      String fileName = chooser.getSelectedFile().getAbsolutePath();
      if (!fileName.endsWith(".txt")) {
        fileName = fileName + ".txt";
      }
      return fileName;
    }
    return null;
  }
Exemplo n.º 11
0
  Date[] getDates() {

    Date start = new Date();
    start = DateUtils.subtractYear(start);

    JDateField startField = new JDateField();
    JDateField endField = new JDateField();

    startField.setValue(start);

    FormLayout layout = new FormLayout("right:p, 4dlu, p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setRowGroupingEnabled(true);

    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();

    JPanel panel = builder.getPanel();

    int option =
        JOptionPane.showConfirmDialog(
            null,
            new Object[] {panel},
            rb.getString("Message.StartEndDate"),
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);

    if (option == JOptionPane.OK_OPTION) {
      return getLastDays(startField.dateValue(), endField.dateValue());
    }

    return null;
  }
Exemplo n.º 12
0
  private void layoutMainPanel() {
    Resource rb = Resource.get();

    initComponents();

    FormLayout layout = new FormLayout("2dlu, right:d, $lcgap, max(40dlu;d), $lcgap, d", "min");

    DefaultFormBuilder builder = new DefaultFormBuilder(layout, this);
    setLayout(layout);

    setBorder(Borders.EMPTY);

    builder.add(new JLabel(rb.getString("Label.Year")), CC.xy(2, 1));
    builder.add(yearSpinner, CC.xy(4, 1));
    builder.add(sparklinePanel, CC.xy(6, 1));
  }
Exemplo n.º 13
0
  private void layoutMainPanel() {
    FormLayout layout = new FormLayout("fill:p:g", "f:p:g, $ugap, f:p");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.border(Borders.DIALOG);

    closeButton = new JButton(rb.getString("Button.Close"));

    builder.append(component);
    builder.nextLine();
    builder.nextLine();
    builder.append(StaticUIMethods.buildCloseBar(closeButton));

    getContentPane().add(builder.getPanel());
    pack();

    closeButton.addActionListener(this);
  }
Exemplo n.º 14
0
  private void initComponents() {
    setTitle(rb.getString("Title.TransactionList"));

    selectButton = new JButton(rb.getString("Button.SelectAll"));
    clearButton = new JButton(rb.getString("Button.ClearAll"));
    invertButton = new JButton(rb.getString("Button.InvertSelection"));
    okButton = new JButton(rb.getString("Button.Ok"));
    cancelButton = new JButton(rb.getString("Button.Cancel"));

    model = new Model(_getPrintableTransactions());
    table = new FormattedJTable(model);

    table.getSelectionModel().addListSelectionListener(this);

    cancelButton.addActionListener(this);
    okButton.addActionListener(this);

    selectButton.addActionListener(this);
    clearButton.addActionListener(this);
    invertButton.addActionListener(this);
  }
Exemplo n.º 15
0
 /**
  * toString must return a valid description for this page that will appear in the task list of the
  * WizardDialog
  */
 @Override
 public String toString() {
   return "1. " + rb.getString("Title.SelDestAccount");
 }
Exemplo n.º 16
0
/**
 * Displays a dialog that list all printable transactions. Specific transactions can be selected to
 * print.
 *
 * @author Craig Cavanaugh
 */
public class TransactionListDialog extends JDialog
    implements ActionListener, ListSelectionListener {

  private final Resource rb = Resource.get();

  private final String PRINT = rb.getString("Item.Print");

  private Model model = null;

  private boolean returnStatus = false; // return status of dialog

  private JTable table;

  private JButton cancelButton;

  private JButton clearButton;

  private JButton invertButton;

  private JButton okButton;

  private JButton selectButton;

  public TransactionListDialog() {
    super(UIApplication.getFrame(), true);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    layoutMainPanel();
    setLocationRelativeTo(UIApplication.getFrame());
  }

  private void initComponents() {
    setTitle(rb.getString("Title.TransactionList"));

    selectButton = new JButton(rb.getString("Button.SelectAll"));
    clearButton = new JButton(rb.getString("Button.ClearAll"));
    invertButton = new JButton(rb.getString("Button.InvertSelection"));
    okButton = new JButton(rb.getString("Button.Ok"));
    cancelButton = new JButton(rb.getString("Button.Cancel"));

    model = new Model(_getPrintableTransactions());
    table = new FormattedJTable(model);

    table.getSelectionModel().addListSelectionListener(this);

    cancelButton.addActionListener(this);
    okButton.addActionListener(this);

    selectButton.addActionListener(this);
    clearButton.addActionListener(this);
    invertButton.addActionListener(this);
  }

  private void layoutMainPanel() {
    initComponents();

    FormLayout layout = new FormLayout("p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    builder.setDefaultDialogBorder();

    builder.appendTitle(rb.getString("Message.TransToPrint"));
    builder.append(ButtonBarFactory.buildLeftAlignedBar(selectButton, clearButton, invertButton));
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();
    builder.appendRow(RowSpec.decode("f:75dlu:g"));
    builder.append(new JScrollPane(table));
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();
    builder.append(ButtonBarFactory.buildOKCancelBar(okButton, cancelButton));

    getContentPane().add(builder.getPanel(), BorderLayout.CENTER);

    pack();

    setMinimumSize(getSize());
  }

  /** Closes the dialog */
  private void closeDialog() {
    dispatchEvent(new WindowEvent(TransactionListDialog.this, WindowEvent.WINDOW_CLOSING));
    table.getSelectionModel().removeListSelectionListener(this);
    table = null;
  }

  private List<Transaction> _getPrintableTransactions() {
    List<Transaction> l = new ArrayList<>();

    for (Transaction t : EngineFactory.getEngine(EngineFactory.DEFAULT).getTransactions()) {
      if (PRINT.equalsIgnoreCase(t.getNumber())) {
        l.add(t);
      }
    }

    Collections.sort(l); // use natural sort order
    return l;
  }

  public boolean getReturnStatus() {
    return returnStatus;
  }

  public List<Transaction> getPrintableTransactions() {
    return model.getPrintableTransactions();
  }

  /**
   * Invoked when an action occurs.
   *
   * @param e event
   */
  @Override
  public void actionPerformed(final ActionEvent e) {
    if (e.getSource() == okButton) {
      returnStatus = true;
      closeDialog();
    } else if (e.getSource() == cancelButton) {
      returnStatus = false;
      closeDialog();
    } else if (e.getSource() == clearButton) {
      model.clearAll();
    } else if (e.getSource() == selectButton) {
      model.selectAll();
    } else if (e.getSource() == invertButton) {
      model.invertAll();
    }
  }

  /**
   * Called whenever the value of the selection changes.
   *
   * @param e the event that characterizes the change.
   */
  @Override
  public void valueChanged(final ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) {
      return;
    } // ignore extra messages

    if (e.getSource() == table.getSelectionModel()) {
      int i = table.getSelectedRow();
      if (i >= 0) {
        Wrapper w = model.getWrapperAt(i);
        w.print = !w.print;
        model.fireTableRowsUpdated(i, i);
        table.clearSelection();
      }
    }
  }

  private class Model extends AbstractTableModel {

    private static final long serialVersionUID = 6665735758964949493L;

    private final ArrayList<Wrapper> wrapperList = new ArrayList<>(); // list of transactions

    private final String[] columnNames = {
      rb.getString("Column.Print"),
      rb.getString("Column.Date"),
      rb.getString("Column.Payee"),
      rb.getString("Column.Account"),
      rb.getString("Column.Amount")
    };

    private final DateFormat dateFormatter = DateUtils.getShortDateFormat();

    private final CommodityFormat commodityformat = CommodityFormat.getFullFormat();

    protected Model(final List<Transaction> list) {

      for (Transaction t : list) {
        wrapperList.add(new Wrapper(t));
      }
    }

    @Override
    public String getColumnName(final int c) {
      return columnNames[c];
    }

    @Override
    public Class<?> getColumnClass(final int column) {
      if (column == 4) {
        return BigDecimal.class;
      }

      return String.class;
    }

    /**
     * Returns the number of columns in the model. A <code>JTable</code> uses this method to
     * determine how many columns it should create and display by default.
     *
     * @return the number of columns in the model
     * @see #getRowCount
     */
    @Override
    public int getColumnCount() {
      return columnNames.length;
    }

    /**
     * Returns the number of rows in the model. A <code>JTable</code> uses this method to determine
     * how many rows it should display. This method should be quick, as it is called frequently
     * during rendering.
     *
     * @return the number of rows in the model
     * @see #getColumnCount
     */
    @Override
    public int getRowCount() {
      return wrapperList.size();
    }

    /**
     * Returns the value for the cell at <code>columnIndex</code> and <code>rowIndex</code>.
     *
     * @param rowIndex the row whose value is to be queried
     * @param columnIndex the column whose value is to be queried
     * @return the value Object at the specified cell
     */
    @Override
    public Object getValueAt(final int rowIndex, final int columnIndex) {
      Wrapper w = wrapperList.get(rowIndex);

      Account baseAccount;

      if (w.transaction.getTransactionEntries().size() > 1) {
        baseAccount = w.transaction.getCommonAccount();
      } else {
        baseAccount = w.transaction.getTransactionEntries().get(0).getDebitAccount();
      }

      switch (columnIndex) {
        case 0:
          if (w.print) {
            return AccountTableModel.RECONCILED_SYM;
          }
          return null;
        case 1:
          return dateFormatter.format(w.transaction.getDate());
        case 2:
          return w.transaction.getPayee();
        case 3:
          return baseAccount.getName();
        case 4:
          return commodityformat.format(
              w.transaction.getAmount(baseAccount).abs(), baseAccount.getCurrencyNode());
        default:
          return null;
      }
    }

    protected Wrapper getWrapperAt(final int i) {
      return wrapperList.get(i);
    }

    public List<Transaction> getPrintableTransactions() {

      ArrayList<Transaction> list = new ArrayList<>();

      for (Wrapper w : wrapperList) {
        if (w.print) {
          list.add(w.transaction);
        }
      }

      return list;
    }

    protected void clearAll() {
      int size = wrapperList.size();
      for (int i = 0; i < size; i++) {
        getWrapperAt(i).print = false;
      }
      fireTableDataChanged();
    }

    protected void selectAll() {
      int size = wrapperList.size();
      for (int i = 0; i < size; i++) {
        getWrapperAt(i).print = true;
      }
      fireTableDataChanged();
    }

    protected void invertAll() {
      int size = wrapperList.size();
      for (int i = 0; i < size; i++) {
        getWrapperAt(i).print = !getWrapperAt(i).print;
      }
      fireTableDataChanged();
    }
  }

  /** Class to wrap a transaction and maintain the selection state of the transaction */
  private static final class Wrapper {

    Transaction transaction;

    boolean print;

    protected Wrapper(final Transaction t) {
      assert t != null;
      this.transaction = t;
    }
  }
}