use of jgnash.ui.components.DatePanel in project jgnash by ccavanaugh.
the class WeekTab method layoutMainPanel.
private void layoutMainPanel() {
FormLayout layout = new FormLayout("right:p, $lcgap, f:p, 2dlu, max(48dlu;min), $lcgap, f:p, 2dlu, f:d", "f:p, $lgap, f:p, $lgap, f:p");
layout.setRowGroups(new int[][] { { 1, 3, 5 } });
setLayout(layout);
setBorder(Borders.DIALOG);
CellConstraints cc = new CellConstraints();
noEndButton = new JRadioButton(rb.getString("Button.NoEndDate"));
endButton = new JRadioButton();
endDateField = new DatePanel();
group.add(noEndButton);
group.add(endButton);
numberSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 52, 1));
add(new JLabel(rb.getString("Label.Every")), cc.xy(1, 1));
add(numberSpinner, cc.xywh(3, 1, 3, 1));
add(new JLabel(rb.getString("Tab.Week")), cc.xy(7, 1));
add(new JLabel(rb.getString("Label.EndOn")), cc.xy(1, 3));
add(noEndButton, cc.xywh(3, 3, 5, 1));
add(endButton, cc.xy(3, 5));
add(endDateField, cc.xy(5, 5));
}
use of jgnash.ui.components.DatePanel in project jgnash by ccavanaugh.
the class PayeePieChart method createPanel.
private JPanel createPanel() {
JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
JButton addFilterButton = new JButton(rb.getString("Button.AddFilter"));
final JButton saveButton = new JButton(rb.getString("Button.SaveFilters"));
JButton deleteFilterButton = new JButton(rb.getString("Button.DeleteFilter"));
JButton clearPrefButton = new JButton(rb.getString("Button.MasterDelete"));
filterCombo = new JComboBox<>();
startField = new DatePanel();
endField = new DatePanel();
txtAddFilter = new TextField();
filterList = new ArrayList<>();
filtersChanged = false;
useFilters = new JCheckBox(rb.getString("Label.UseFilters"));
useFilters.setSelected(true);
showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));
combo = AccountListComboBox.getFullInstance();
final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now().minusYears(DEBIT));
long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));
startField.setDate(DateUtils.asLocalDate(start));
currentAccount = combo.getSelectedAccount();
PieDataset[] data = createPieDataSet(currentAccount);
JFreeChart chartCredit = createPieChart(currentAccount, data, CREDIT);
chartPanelCredit = new ChartPanel(chartCredit, true, true, true, false, true);
// (chart, properties, save, print, zoom, tooltips)
JFreeChart chartDebit = createPieChart(currentAccount, data, DEBIT);
chartPanelDebit = new ChartPanel(chartDebit, true, true, true, false, true);
FormLayout layout = new FormLayout("p, $lcgap, 70dlu, 8dlu, p, $lcgap, 70dlu, $ugap, p, $lcgap:g, left:p", "d, $rgap, d, $ugap, f:p:g, $rgap, d");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
layout.setRowGroups(new int[][] { { DEBIT, 3 } });
// row 1
builder.append(combo, 9);
builder.append(useFilters);
builder.nextLine();
builder.nextLine();
// row 3
builder.append(rb.getString("Label.StartDate"), startField);
builder.append(rb.getString("Label.EndDate"), endField);
builder.append(refreshButton);
builder.append(showPercentCheck);
builder.nextLine();
builder.nextLine();
// row 5
FormLayout subLayout = new FormLayout("180dlu:g, 1dlu, 180dlu:g", "f:180dlu:g");
DefaultFormBuilder subBuilder = new DefaultFormBuilder(subLayout);
subBuilder.append(chartPanelCredit);
subBuilder.append(chartPanelDebit);
builder.append(subBuilder.getPanel(), 11);
builder.nextLine();
builder.nextLine();
// row 7
builder.append(txtAddFilter, 3);
builder.append(addFilterButton, 3);
builder.append(saveButton);
builder.nextLine();
// row
builder.append(filterCombo, 3);
builder.append(deleteFilterButton, 3);
builder.append(clearPrefButton);
builder.nextLine();
JPanel panel = builder.getPanel();
combo.addActionListener(e -> {
Account newAccount = combo.getSelectedAccount();
if (filtersChanged) {
int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.SaveFilters"), "Warning", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
saveButton.doClick();
}
}
filtersChanged = false;
String[] list = POUND_DELIMITER_PATTERN.split(pref.get(FILTER_TAG + newAccount.hashCode(), ""));
filterList.clear();
for (String filter : list) {
if (!filter.isEmpty()) {
filterList.add(filter);
}
}
refreshFilters();
setCurrentAccount(newAccount);
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
refreshButton.addActionListener(e -> {
setCurrentAccount(currentAccount);
pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
});
clearPrefButton.addActionListener(e -> {
int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.MasterDelete"), "Warning", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
try {
pref.clear();
} catch (Exception ex) {
System.out.println("Exception clearing preferences" + ex);
}
}
});
saveButton.addActionListener(e -> {
final StringBuilder sb = new StringBuilder();
for (String filter : filterList) {
sb.append(filter);
sb.append('#');
}
pref.put(FILTER_TAG + currentAccount.hashCode(), sb.toString());
filtersChanged = false;
});
addFilterButton.addActionListener(e -> {
String newFilter = txtAddFilter.getText();
filterList.remove(newFilter);
if (!newFilter.isEmpty()) {
filterList.add(newFilter);
filtersChanged = true;
txtAddFilter.setText("");
}
refreshFilters();
});
deleteFilterButton.addActionListener(e -> {
if (!filterList.isEmpty()) {
String filter = (String) filterCombo.getSelectedItem();
filterList.remove(filter);
filtersChanged = true;
}
refreshFilters();
});
useFilters.addActionListener(e -> setCurrentAccount(currentAccount));
showPercentCheck.addActionListener(e -> {
((PiePlot) chartPanelCredit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
((PiePlot) chartPanelDebit.getChart().getPlot()).setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);
});
return panel;
}
Aggregations