Example usage for org.jfree.chart ChartPanel setChart

List of usage examples for org.jfree.chart ChartPanel setChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel setChart.

Prototype

public void setChart(JFreeChart chart) 

Source Link

Document

Sets the chart that is displayed in the panel.

Usage

From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChart.java

private JPanel createPanel() {
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
    LocalDate start = end.minusYears(1);
    startDateField.setDate(start);/*from w  ww.j av a2 s .  c  o m*/

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));

    subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
    subAccountCheckBox.setSelected(true);

    hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
    hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));

    Account a = combo.getSelectedAccount();
    JFreeChart chart = createVerticalXYBarChart(a);
    final ChartPanel chartPanel = new ChartPanel(chart);

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

    FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
    DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);

    dBuilder.append(rb.getString("Label.StartDate"), startDateField);
    dBuilder.append(rb.getString("Label.EndDate"), endDateField);
    dBuilder.append(refreshButton);

    FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
    DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);

    cbBuilder.append(subAccountCheckBox);
    cbBuilder.append(hideLockedAccountCheckBox);
    cbBuilder.append(hidePlaceholderAccountCheckBox);

    builder.append(rb.getString("Label.Account"), combo);
    builder.nextLine();
    builder.append(" ");
    builder.append(cbBuilder.getPanel());
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(dBuilder.getPanel(), 3);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();

    builder.appendRow(RowSpec.decode("fill:p:g"));
    builder.append(chartPanel, 3);

    final JPanel panel = builder.getPanel();

    ActionListener listener = e -> {
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    };

    combo.addActionListener(listener);

    hideLockedAccountCheckBox.addActionListener(e -> {
        combo.setHideLocked(hideLockedAccountCheckBox.isSelected());
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    });

    hidePlaceholderAccountCheckBox.addActionListener(e -> {
        combo.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        try {
            Account account = combo.getSelectedAccount();
            if (account == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChart.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    });
    refreshButton.addActionListener(listener);

    updateSubAccountBox();

    return panel;
}

From source file:edu.smc.mediacommons.panels.PasswordPanel.java

public PasswordPanel() {
    setLayout(null);/*from  w ww .j  a va2s.  com*/

    add(Utils.createLabel("Enter a Password to Test", 60, 30, 200, 20, null));

    final JButton test = Utils.createButton("Test", 260, 50, 100, 20, null);
    add(test);

    final JPasswordField fieldPassword = new JPasswordField(32);
    fieldPassword.setBounds(60, 50, 200, 20);
    add(fieldPassword);

    final PieDataset dataset = createSampleDataset(33, 33, 33);
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(300, 300));
    chartPanel.setBounds(45, 80, 340, 250);

    add(chartPanel);

    test.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String password = new String(fieldPassword.getPassword());

            if (password.isEmpty() || password == null) {
                JOptionPane.showMessageDialog(getParent(), "Warning! The input was blank!", "Invalid Input",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                int letterCount = 0, numberCount = 0, specialCount = 0, total = password.length();

                for (char c : password.toCharArray()) {
                    if (Character.isLetter(c)) {
                        letterCount++;
                    } else if (Character.isDigit(c)) {
                        numberCount++;
                    } else {
                        specialCount++;
                    }
                }

                long totalCombinations = 0;
                double percentLetters = 0;
                double percentNumbers = 0;
                double percentCharacters = 0;

                if (letterCount > 0) {
                    totalCombinations += (factorial(26) / factorial(26 - letterCount));
                    percentLetters = (letterCount + 0.0 / total);
                }

                if (numberCount > 0) {
                    totalCombinations += (factorial(10) / factorial(10 - numberCount));
                    percentNumbers = (numberCount + 0.0 / total);
                }

                if (specialCount > 0) {
                    totalCombinations += (factorial(40) / factorial(40 - specialCount));
                    percentCharacters = (specialCount + 0.0 / total);
                }

                PieDataset dataset = createSampleDataset(percentLetters, percentNumbers, percentCharacters);
                JFreeChart chart = createChart(dataset);
                chartPanel.setChart(chart);

                JOptionPane.showMessageDialog(getParent(),
                        "Total Combinations: " + totalCombinations + "\nAssuming Rate Limited, Single: "
                                + (totalCombinations / 1000) + " seconds" + "\n\nBreakdown:\nLetters: "
                                + percentLetters + "%\nNumbers: " + percentNumbers + "%\nCharacters: "
                                + percentCharacters + "%");
            }
        }
    });

    setVisible(true);
}

From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChartCompare.java

private JPanel createPanel() {
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
    LocalDate start = end.minusYears(1);

    startDateField.setDate(start);/*from w w w . j  a va  2 s. c  o m*/

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));

    subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
    subAccountCheckBox.setSelected(true);

    hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
    hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));

    jcb_compare = new JCheckBox(rb.getString("Button.Compare"));
    jcb_compare.setSelected(true);

    Account a = combo1.getSelectedAccount();
    Account a2 = combo2.getSelectedAccount();

    JFreeChart chart = createVerticalXYBarChart(a, a2);
    final ChartPanel chartPanel = new ChartPanel(chart);

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

    FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
    DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);

    dBuilder.append(rb.getString("Label.StartDate"), startDateField);
    dBuilder.append(rb.getString("Label.EndDate"), endDateField);
    dBuilder.append(refreshButton);

    FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
    DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);

    cbBuilder.append(subAccountCheckBox);
    cbBuilder.append(hideLockedAccountCheckBox);
    cbBuilder.append(hidePlaceholderAccountCheckBox);

    builder.append(rb.getString("Label.Account"), combo1);
    builder.nextLine();
    builder.append(rb.getString("Label.Compare"), combo2);
    builder.nextLine();
    builder.append(jcb_compare);
    builder.append(cbBuilder.getPanel());
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(dBuilder.getPanel(), 3);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();

    builder.appendRow(RowSpec.decode("fill:p:g"));
    builder.append(chartPanel, 3);

    final JPanel panel = builder.getPanel();

    ActionListener listener = e -> {
        try {
            if (e.getSource() == jcb_compare) {
                combo2.setEnabled(jcb_compare.isSelected());
            }

            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }

            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    };

    combo1.addActionListener(listener);
    combo2.addActionListener(listener);
    jcb_compare.addActionListener(listener);
    subAccountCheckBox.addActionListener(listener);

    hideLockedAccountCheckBox.addActionListener(e -> {
        combo1.setHideLocked(hideLockedAccountCheckBox.isSelected());
        combo2.setHideLocked(hideLockedAccountCheckBox.isSelected());
        try {
            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }

            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    });

    hidePlaceholderAccountCheckBox.addActionListener(e -> {
        combo1.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        combo2.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        try {
            Account account = combo1.getSelectedAccount();
            if (account == null) {
                return;
            }
            Account account2 = combo2.getSelectedAccount();
            if (jcb_compare.isSelected() && account2 == null) {
                return;
            }

            updateSubAccountBox();

            chartPanel.setChart(createVerticalXYBarChart(account, account2));
            panel.validate();
        } catch (final Exception ex) {
            Logger.getLogger(MonthlyAccountBalanceChartCompare.class.getName()).log(Level.SEVERE,
                    ex.getLocalizedMessage(), ex);
        }
    });
    refreshButton.addActionListener(listener);

    updateSubAccountBox();

    return panel;
}