Search in sources :

Example 6 with RootAccount

use of jgnash.engine.RootAccount 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());
        }
    });
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) RootAccount(jgnash.engine.RootAccount) ChartEntity(org.jfree.chart.entity.ChartEntity) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 7 with RootAccount

use of jgnash.engine.RootAccount 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;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JPanel(javax.swing.JPanel) RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) ChartPanel(org.jfree.chart.ChartPanel) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) MouseEvent(java.awt.event.MouseEvent) JButton(javax.swing.JButton) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) AccountType(jgnash.engine.AccountType) LocalDate(java.time.LocalDate) JFreeChart(org.jfree.chart.JFreeChart) ChartMouseListener(org.jfree.chart.ChartMouseListener) JCheckBox(javax.swing.JCheckBox) RootAccount(jgnash.engine.RootAccount) DatePanel(jgnash.ui.components.DatePanel) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) ChartEntity(org.jfree.chart.entity.ChartEntity) Engine(jgnash.engine.Engine) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 8 with RootAccount

use of jgnash.engine.RootAccount in project jgnash by ccavanaugh.

the class AccountsViewController method loadAccountTree.

private void loadAccountTree() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    if (engine != null) {
        final RootAccount r = engine.getRootAccount();
        final TreeItem<Account> root = new TreeItem<>(r);
        root.setExpanded(true);
        treeTableView.setRoot(root);
        loadChildren(root);
    } else {
        treeTableView.setRoot(null);
    }
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) RootAccount(jgnash.engine.RootAccount) TreeItem(javafx.scene.control.TreeItem) Engine(jgnash.engine.Engine)

Example 9 with RootAccount

use of jgnash.engine.RootAccount in project jgnash by ccavanaugh.

the class XStreamAccountDAO method getRootAccount.

@Override
public RootAccount getRootAccount() {
    RootAccount root = null;
    List<RootAccount> list = container.query(RootAccount.class);
    if (list.size() == 1) {
        root = list.get(0);
    }
    if (list.size() > 1) {
        logger.severe("More than one RootAccount found");
        root = list.get(0);
    }
    return root;
}
Also used : RootAccount(jgnash.engine.RootAccount)

Example 10 with RootAccount

use of jgnash.engine.RootAccount in project jgnash by ccavanaugh.

the class BudgetResultsModel method areParentsIncluded.

private boolean areParentsIncluded(final Account account) {
    boolean result = true;
    Account parent = account.getParent();
    if (parent != null && !(parent instanceof RootAccount)) {
        if (!includeAccount(parent)) {
            result = false;
        } else {
            result = areParentsIncluded(parent);
        }
    }
    return result;
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) RootAccount(jgnash.engine.RootAccount)

Aggregations

RootAccount (jgnash.engine.RootAccount)12 Account (jgnash.engine.Account)5 Engine (jgnash.engine.Engine)5 IOException (java.io.IOException)2 ResourceBundle (java.util.ResourceBundle)2 ExecutionException (java.util.concurrent.ExecutionException)2 SwingWorker (javax.swing.SwingWorker)2 CurrencyNode (jgnash.engine.CurrencyNode)2 ChartEntity (org.jfree.chart.entity.ChartEntity)2 PieSectionEntity (org.jfree.chart.entity.PieSectionEntity)2 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Set (java.util.Set)1 Preferences (java.util.prefs.Preferences)1 TreeItem (javafx.scene.control.TreeItem)1 JButton (javax.swing.JButton)1