use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class ClippingDecorator method findStopIndex.
private void findStopIndex(final LocalDate date) {
endDate = date;
for (int i = model.getRowCount() - 1; i >= 0; i--) {
Transaction t = model.getTransactionAt(i);
if (DateUtils.before(t.getLocalDate(), date)) {
endIndex = i;
return;
}
}
endIndex = model.getRowCount() - 1;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class ClippingDecorator method findStartIndex.
private void findStartIndex(final LocalDate date) {
startDate = date;
for (int i = 0; i < model.getRowCount(); i++) {
Transaction t = model.getTransactionAt(i);
if (DateUtils.after(t.getLocalDate(), date)) {
startIndex = i;
return;
}
}
startIndex = model.getRowCount() - 1;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class RegisterTable method prepareRenderer.
/**
* Override prepareRenderer instead of using a custom renderer so the look and feel is preserved
*
* @see javax.swing.JTable#prepareRenderer(javax.swing.table.TableCellRenderer, int, int)
*/
@Override
public Component prepareRenderer(final TableCellRenderer renderer, final int row, final int column) {
Component c = super.prepareRenderer(renderer, row, column);
// column may have been reordered
final Object value = getModel().getValueAt(row, convertColumnIndexToModel(column));
if (getModel() instanceof AbstractRegisterTableModel) {
Transaction t = ((AbstractRegisterTableModel) getModel()).getTransactionAt(row);
if (t.getLocalDate().isAfter(LocalDate.now())) {
c.setFont(c.getFont().deriveFont(Font.ITALIC));
}
if (QuantityStyle.class.isAssignableFrom(getColumnClass(column)) && t instanceof InvestmentTransaction && c instanceof JLabel) {
((JLabel) c).setHorizontalAlignment(SwingConstants.RIGHT);
if (value != null && value instanceof Number) {
final NumberFormat numberFormat = CommodityFormat.getShortNumberFormat(((InvestmentTransaction) t).getSecurityNode());
((JLabel) c).setText(numberFormat.format(value));
} else {
((JLabel) c).setText("");
}
}
}
if (LocalDate.class.isAssignableFrom(getColumnClass(column)) && c instanceof JLabel) {
if (value != null && value instanceof LocalDate) {
((JLabel) c).setText(dateFormatter.format((TemporalAccessor) value));
}
} else if (FullCommodityStyle.class.isAssignableFrom(getColumnClass(column)) && c instanceof JLabel) {
((JLabel) c).setHorizontalAlignment(SwingConstants.RIGHT);
if (value != null && value instanceof Number) {
if (!isRowSelected(row) && ((BigDecimal) value).signum() < 0) {
c.setForeground(Color.RED);
}
((JLabel) c).setText(fullFormat.format(value));
} else {
((JLabel) c).setText("");
}
} else if (ShortCommodityStyle.class.isAssignableFrom(getColumnClass(column)) && c instanceof JLabel) {
((JLabel) c).setHorizontalAlignment(SwingConstants.RIGHT);
if (value != null && value instanceof Number) {
((JLabel) c).setText(shortFormat.format(value));
} else {
((JLabel) c).setText("");
}
}
return c;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class ApiTest method testTransactionAPI.
@Test
public void testTransactionAPI() {
final String ACCOUNT_NAME = "testAccount";
final CurrencyNode node = e.getDefaultCurrency();
final Account a = new Account(AccountType.BANK, node);
a.setName(ACCOUNT_NAME);
e.addAccount(e.getRootAccount(), a);
// Test single entry transaction
final Transaction transaction = TransactionFactory.generateSingleEntryTransaction(a, BigDecimal.TEN, LocalDate.now(), "memo", "payee", "1");
e.addTransaction(transaction);
assertEquals(TransactionType.SINGLENTRY, transaction.getTransactionType());
for (final TransactionEntry transactionEntry : transaction.getTransactionEntries()) {
assertFalse(transactionEntry.isMultiCurrency());
}
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class AbstractSlipController method modifyTransactionForAutoComplete.
/**
* Modify a transaction before it is used to complete the panel for auto fill. The supplied transaction must be a
* new or cloned transaction. It can't be a transaction that lives in the map. The returned transaction can be the
* supplied reference or may be a new instance
*
* @param t The transaction to modify
* @return the modified transaction
*/
private Transaction modifyTransactionForAutoComplete(final Transaction t) {
// tweak the transaction
t.setNumber(null);
// clear both sides
t.setReconciled(ReconciledState.NOT_RECONCILED);
// set the last date as required
if (!Options.rememberLastDateProperty().get()) {
t.setDate(LocalDate.now());
} else {
t.setDate(datePicker.getValue());
}
// preserve any transaction entries that may have been entered first
if (amountField.getLength() > 0) {
Transaction newTrans = buildTransaction();
t.clearTransactionEntries();
t.addTransactionEntries(newTrans.getTransactionEntries());
}
// preserve any preexisting memo field info
if (memoTextField.getLength() > 0) {
t.setMemo(memoTextField.getText());
}
// Do not copy over attachments
t.setAttachment(null);
return t;
}
Aggregations