use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class IncomeExpensePieChart method setChartCursor.
private void setChartCursor(final ChartPanel chartPanel, final ChartEntity e, final Point point) {
lastPoint = point;
EventQueue.invokeLater(new Runnable() {
ChartEntity entity = e;
@Override
public void run() {
if (entity == null && point != null) {
entity = chartPanel.getEntityForPoint(lastPoint.x, lastPoint.y);
}
Account parent = currentAccount;
if (entity instanceof PieSectionEntity) {
// change cursor if section is interesting
Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
if (a.getChildCount() > 0 && a != parent) {
chartPanel.setCursor(ZOOM_IN);
} else {
chartPanel.setCursor(Cursor.getDefaultCursor());
}
return;
} else if (entity == null && parent != null) {
parent = parent.getParent();
if (parent != null && !(parent instanceof RootAccount)) {
chartPanel.setCursor(ZOOM_OUT);
return;
}
}
chartPanel.setCursor(Cursor.getDefaultCursor());
}
});
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AbstractSumByTypeReport method createReportModel.
ReportModel createReportModel(final LocalDate startDate, final LocalDate endDate) {
logger.info(rb.getString("Message.CollectingReportData"));
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
// generate the date information
if (runningTotal) {
dates = DateUtils.getLastDayOfTheMonths(startDate, endDate);
} else {
dates = DateUtils.getFirstDayOfTheMonths(startDate, endDate);
dates.set(0, startDate);
if (DateUtils.after(endDate, dates.get(dates.size() - 1))) {
dates.add(endDate);
}
}
final CurrencyNode baseCurrency = engine.getDefaultCurrency();
List<Account> accounts = new ArrayList<>();
for (AccountGroup group : getAccountGroups()) {
accounts.addAll(getAccountList(AccountType.getAccountTypes(group)));
}
// remove any account that will report a zero balance for all periods
if (hideZeroBalanceAccounts.isSelected()) {
Iterator<Account> i = accounts.iterator();
while (i.hasNext()) {
Account account = i.next();
boolean remove = true;
if (runningTotal) {
for (LocalDate date : dates) {
if (account.getBalance(date).compareTo(BigDecimal.ZERO) != 0) {
remove = false;
break;
}
}
} else {
for (int j = 0; j < dates.size() - 1; j++) {
final LocalDate sDate = dates.get(j);
final LocalDate eDate = dates.get(j + 1).minusDays(1);
if (account.getBalance(sDate, eDate).compareTo(BigDecimal.ZERO) != 0) {
remove = false;
break;
}
}
}
if (remove) {
i.remove();
}
}
}
ReportModel model = new ReportModel(baseCurrency);
model.addAccounts(accounts);
return model;
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class IncomeExpensePieChart method createPanel.
private JPanel createPanel() {
EnumSet<AccountType> set = EnumSet.of(AccountType.INCOME, AccountType.EXPENSE);
JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
startField = new DatePanel();
endField = new DatePanel();
showEmptyCheck = new JCheckBox(rb.getString("Label.ShowEmptyAccounts"));
showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
combo = AccountListComboBox.getParentTypeInstance(engine.getRootAccount(), set);
final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now()).minusYears(1);
long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));
startField.setDate(DateUtils.asLocalDate(start));
currentAccount = combo.getSelectedAccount();
JFreeChart chart = createPieChart(currentAccount);
chartPanel = new ChartPanel(chart, true, true, true, false, true);
// (chart, properties, save, print, zoom, tooltips)
FormLayout layout = new FormLayout("p, 4dlu, 70dlu, 8dlu, p, 4dlu, 70dlu, 8dlu, p, 4dlu:g, left:p", "f:d, 3dlu, f:d, 6dlu, f:p:g");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
layout.setRowGroups(new int[][] { { 1, 3 } });
builder.append(combo, 9);
builder.append(showEmptyCheck);
builder.nextLine();
builder.nextLine();
builder.append(rb.getString("Label.StartDate"), startField);
builder.append(rb.getString("Label.EndDate"), endField);
builder.append(refreshButton);
builder.append(showPercentCheck);
builder.nextLine();
builder.nextLine();
builder.append(chartPanel, 11);
JPanel panel = builder.getPanel();
combo.addActionListener(e -> {
setCurrentAccount(combo.getSelectedAccount());
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
refreshButton.addActionListener(e -> {
setCurrentAccount(currentAccount);
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
showEmptyCheck.addActionListener(e -> setCurrentAccount(currentAccount));
showPercentCheck.addActionListener(e -> ((PiePlot) chartPanel.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels));
ChartMouseListener mouseListener = new ChartMouseListener() {
@Override
public void chartMouseClicked(final ChartMouseEvent event) {
MouseEvent me = event.getTrigger();
if (me.getID() == MouseEvent.MOUSE_CLICKED && me.getClickCount() == 1) {
try {
ChartEntity entity = event.getEntity();
// expand sections if interesting, back out if in nothing
if (entity instanceof PieSectionEntity) {
Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
if (a.getChildCount() > 0) {
setCurrentAccount(a);
}
} else if (entity == null) {
Account parent = currentAccount;
if (parent == null) {
return;
}
parent = parent.getParent();
if (parent == null || parent instanceof RootAccount) {
return;
}
setCurrentAccount(parent);
}
} catch (final Exception e) {
Logger.getLogger(IncomeExpensePieChart.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
}
@Override
public void chartMouseMoved(ChartMouseEvent event) {
setChartCursor(chartPanel, event.getEntity(), event.getTrigger().getPoint());
}
};
chartPanel.addChartMouseListener(mouseListener);
return panel;
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class RegisterTableModel method getInternalValueAt.
@Override
protected Object getInternalValueAt(int row, int col) {
Transaction t = getTransactionAt(row);
BigDecimal amount = t.getAmount(account);
int signum = amount.signum();
switch(col) {
case 0:
return t.getLocalDate();
case 1:
return t.getNumber();
case 2:
return t.getPayee();
case 3:
return t.getMemo();
case 4:
if (t instanceof InvestmentTransaction) {
return ((InvestmentTransaction) t).getInvestmentAccount().getName();
}
int count = t.size();
if (count > 1) {
return "[ " + count + " " + split + " ]";
}
Account creditAccount = t.getTransactionEntries().get(0).getCreditAccount();
if (creditAccount != account) {
return creditAccount.getName();
}
return t.getTransactionEntries().get(0).getDebitAccount().getName();
case 5:
return t.getReconciled(account).toString();
case 6:
if (signum >= 0) {
return amount;
}
return null;
case 7:
if (signum < 0) {
return amount.abs();
}
return null;
case 8:
return getBalanceAt(row);
default:
return ERROR;
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountExport method getAccountColumnValue.
private static String getAccountColumnValue(final Transaction transaction, final Account account) {
if (transaction instanceof InvestmentTransaction) {
return ((InvestmentTransaction) transaction).getInvestmentAccount().getName();
}
int count = transaction.size();
if (count > 1) {
return "[ " + count + " " + ResourceUtils.getString("Button.Splits") + " ]";
}
final Account creditAccount = transaction.getTransactionEntries().get(0).getCreditAccount();
if (creditAccount != account) {
return creditAccount.getName();
}
return transaction.getTransactionEntries().get(0).getDebitAccount().getName();
}
Aggregations