Revision: 1562
http://jgnash.svn.sourceforge.net/jgnash/?rev=1562&view=rev
Author: ccavanaugh
Date: 2009-03-04 10:41:47 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
Add switch to improve layout for exporting to CSV
Modified Paths:
--------------
jgnash2/trunk/src/jgnash/ui/report/compiled/AbstractCrosstabReport.java
jgnash2/trunk/src/jgnash/ui/report/compiled/AbstractSumByTypeReport.java
jgnash2/trunk/src/jgnash/ui/report/compiled/AccountRegisterReport.java
jgnash2/trunk/src/jgnash/ui/report/compiled/PortfolioReport.java
jgnash2/trunk/src/jgnash/ui/report/jasper/DynamicJasperReport.java
jgnash2/trunk/src/jgnash/ui/report/jasper/DynamicJasperReportPanel.java
Modified: jgnash2/trunk/src/jgnash/ui/report/compiled/AbstractCrosstabReport.java
===================================================================
--- jgnash2/trunk/src/jgnash/ui/report/compiled/AbstractCrosstabReport.java 2009-03-04 00:24:53 UTC (rev 1561)
+++ jgnash2/trunk/src/jgnash/ui/report/compiled/AbstractCrosstabReport.java 2009-03-04 10:41:47 UTC (rev 1562)
@@ -17,6 +17,11 @@
*/
package jgnash.ui.report.compiled;
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+
+import net.sf.jasperreports.engine.JasperPrint;
+
import java.awt.event.ActionEvent;
import java.math.BigDecimal;
import java.text.MessageFormat;
@@ -49,11 +54,7 @@
import jgnash.ui.report.jasper.DynamicJasperReport;
import jgnash.util.DateUtils;
import jgnash.util.Resource;
-import net.sf.jasperreports.engine.JasperPrint;
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-
/**
* Abstract Report that groups and sums by <code>AccountGroup</code>, has a line for a global sum, and
* cross tabulates all rows.
@@ -116,7 +117,7 @@
showLongNamesCheckBox = new JCheckBox(rb.getString("Button.UseLongNames"));
showLongNamesCheckBox.setSelected(p.getBoolean(USE_LONG_NAMES, false));
- resolutionList = new JComboBox(new String[] { RES_YEAR, RES_QUARTER, RES_MONTH });
+ resolutionList = new JComboBox(new String[]{RES_YEAR, RES_QUARTER, RES_MONTH});
resolutionList.setSelectedIndex(1);
refreshButton = new JButton(rb.getString("Button.Refresh"), Resource.getIcon("/jgnash/resource/view-refresh.png"));
@@ -138,7 +139,7 @@
@Override
public String getSubTitle() {
MessageFormat format = new MessageFormat(rb.getString("Pattern.DateRange"));
- Object[] args = new Object[] { startDates.get(0), endDates.get(endDates.size() - 1) };
+ Object[] args = new Object[]{startDates.get(0), endDates.get(endDates.size() - 1)};
return format.format(args);
}
@@ -260,7 +261,8 @@
List<Account> accounts = engine.getAccountList();
Iterator<Account> i = accounts.iterator();
- search: while (i.hasNext()) {
+ search:
+ while (i.hasNext()) {
Account a = i.next();
if (a.getTransactionCount() == 0) {
@@ -283,10 +285,10 @@
* @return JasperPrint
*/
@Override
- public JasperPrint createJasperPrint() {
+ public JasperPrint createJasperPrint(final boolean formatForCSV) {
ReportModel model = createTableModel();
- return createJasperPrint(model);
+ return createJasperPrint(model, formatForCSV);
}
/**
Modified: jgnash2/trunk/src/jgnash/ui/report/compiled/AbstractSumByTypeReport.java
===================================================================
--- jgnash2/trunk/src/jgnash/ui/report/compiled/AbstractSumByTypeReport.java 2009-03-04 00:24:53 UTC (rev 1561)
+++ jgnash2/trunk/src/jgnash/ui/report/compiled/AbstractSumByTypeReport.java 2009-03-04 10:41:47 UTC (rev 1562)
@@ -17,6 +17,11 @@
*/
package jgnash.ui.report.compiled;
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.FormLayout;
+
+import net.sf.jasperreports.engine.JasperPrint;
+
import java.awt.event.ActionEvent;
import java.math.BigDecimal;
import java.text.DateFormat;
@@ -47,11 +52,7 @@
import jgnash.ui.report.jasper.DynamicJasperReport;
import jgnash.util.DateUtils;
import jgnash.util.Resource;
-import net.sf.jasperreports.engine.JasperPrint;
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-
/**
* Abstract Report that groups and sums by <code>AccountGroup</code> and has a line for a global sum
*
@@ -151,7 +152,8 @@
List<Account> accounts = engine.getAccountList();
Iterator<Account> i = accounts.iterator();
- search: while (i.hasNext()) {
+ search:
+ while (i.hasNext()) {
Account a = i.next();
if (a.getTransactionCount() == 0) {
@@ -174,13 +176,13 @@
* @return JasperPrint
*/
@Override
- public JasperPrint createJasperPrint() {
+ public JasperPrint createJasperPrint(final boolean formatForCSV) {
Date endDate = endDateField.getDate();
Date startDate = startDateField.getDate();
ReportModel model = createTableModel(startDate, endDate);
- return createJasperPrint(model);
+ return createJasperPrint(model, formatForCSV);
}
/**
Modified: jgnash2/trunk/src/jgnash/ui/report/compiled/AccountRegisterReport.java
===================================================================
--- jgnash2/trunk/src/jgnash/ui/report/compiled/AccountRegisterReport.java 2009-03-04 00:24:53 UTC (rev 1561)
+++ jgnash2/trunk/src/jgnash/ui/report/compiled/AccountRegisterReport.java 2009-03-04 10:41:47 UTC (rev 1562)
@@ -139,7 +139,7 @@
* @return JasperPrint object
*/
@Override
- public JasperPrint createJasperPrint() {
+ public JasperPrint createJasperPrint(final boolean formatForCSV) {
ClippingModel model = RegisterFactory.getClippingTableModel(accountCombo.getSelectedAccount(), detailSplitsCheckBox.isSelected());
model.setReconcileSymbol("C"); // report fonts do not support the check mark
@@ -153,7 +153,7 @@
model.setEndDate(endDateField.getDate());
}
- return createJasperPrint(new ReportTableModel(model));
+ return createJasperPrint(new ReportTableModel(model), formatForCSV);
}
/**
Modified: jgnash2/trunk/src/jgnash/ui/report/compiled/PortfolioReport.java
===================================================================
--- jgnash2/trunk/src/jgnash/ui/report/compiled/PortfolioReport.java 2009-03-04 00:24:53 UTC (rev 1561)
+++ jgnash2/trunk/src/jgnash/ui/report/compiled/PortfolioReport.java 2009-03-04 10:41:47 UTC (rev 1562)
@@ -113,14 +113,14 @@
* @return JasperPrint object
*/
@Override
- public JasperPrint createJasperPrint() {
+ public JasperPrint createJasperPrint(final boolean formatForCSV) {
Account account = accountCombo.getSelectedAccount();
Map<SecurityNode, SecurityTransactionHelper> securities = getSecuritiesForAccount(account, subAccountCheckBox.isSelected());
PortfolioReportTableModel model = new PortfolioReportTableModel(securities, account.getCurrencyNode());
model.verbose = verboseCheckBox.isSelected();
- return createJasperPrint(model);
+ return createJasperPrint(model, formatForCSV);
}
/**
Modified: jgnash2/trunk/src/jgnash/ui/report/jasper/DynamicJasperReport.java
===================================================================
--- jgnash2/trunk/src/jgnash/ui/report/jasper/DynamicJasperReport.java 2009-03-04 00:24:53 UTC (rev 1561)
+++ jgnash2/trunk/src/jgnash/ui/report/jasper/DynamicJasperReport.java 2009-03-04 10:41:47 UTC (rev 1562)
@@ -148,9 +148,10 @@
/**
* Creates a JasperPrint object.
*
+ * @param formatForCSV <code>true<code> if the report should be formated for CSV export
* @return JasperPrint object
*/
- public abstract JasperPrint createJasperPrint();
+ public abstract JasperPrint createJasperPrint(final boolean formatForCSV);
/**
* Creates a report control panel. May return null if a panel is not used
@@ -236,14 +237,16 @@
return style;
}
- private Style getStyle(final ColumnStyle style) {
+ private Style getStyle(final ColumnStyle style, final boolean formatForCSV) {
switch (style) {
case SHORT_DATE:
case STRING:
Style stringStyle = new Style();
stringStyle.setFont(ReportFactory.getDefaultMonoFont(getBaseFontSize()));
stringStyle.setHorizontalAlign(HorizontalAlign.LEFT);
- stringStyle.setStretchWithOverflow(false);
+ if (!formatForCSV) {
+ stringStyle.setStretchWithOverflow(false);
+ }
return stringStyle;
case AMOUNT_SUM:
case BALANCE:
@@ -255,13 +258,17 @@
Style amountStyle = new Style();
amountStyle.setFont(ReportFactory.getDefaultMonoFont(getBaseFontSize()));
amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
- amountStyle.setStretchWithOverflow(false);
+ if (!formatForCSV) {
+ amountStyle.setStretchWithOverflow(false);
+ }
return amountStyle;
case CROSSTAB_TOTAL:
Style totalStyle = new Style();
totalStyle.setFont(ReportFactory.getDefaultMonoFont(getBaseFontSize(), true));
totalStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
- totalStyle.setStretchWithOverflow(false);
+ if (!formatForCSV) {
+ totalStyle.setStretchWithOverflow(false);
+ }
return totalStyle;
case GROUP:
case GROUP_NO_HEADER:
@@ -271,7 +278,7 @@
return null;
}
- private Style getStyle(final ColumnHeaderStyle style) {
+ private Style getStyle(final ColumnHeaderStyle style, final boolean formatForCSV) {
Style headerStyle = new Style();
headerStyle.setFont(ReportFactory.getDefaultProportionalFont(getBaseFontSize() + 2, true));
headerStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
@@ -280,7 +287,9 @@
headerStyle.setBackgroundColor(Color.decode("#E0E9F1"));
headerStyle.setTransparency(Transparency.OPAQUE);
headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
- headerStyle.setStretchWithOverflow(false);
+ if (!formatForCSV) {
+ headerStyle.setStretchWithOverflow(false);
+ }
switch (style) {
case LEFT:
@@ -300,24 +309,28 @@
return headerStyle;
}
- public JasperPrint createJasperPrint(AbstractReportTableModel model) {
+ protected final JasperPrint createJasperPrint(final AbstractReportTableModel model, final boolean formatForCSV) {
DynamicReportBuilder drb = new DynamicReportBuilder();
try {
+ if (formatForCSV) {
+ drb.setIgnorePagination(true);
+ }
+
AbstractColumn[] columns = new AbstractColumn[model.getColumnCount()];
assignPageFormat(drb);
- drb.setHeaderHeight(getStyle(model.getColumnHeaderStyle(0)).getFont().getFontSize() * 2);
+ drb.setHeaderHeight(getStyle(model.getColumnHeaderStyle(0), formatForCSV).getFont().getFontSize() * 2);
drb.setDetailHeight(getBaseFontSize() * 2);
// create columns and add to the list
for (int i = 0; i < model.getColumnCount(); i++) {
if (model.getColumnStyle(i) != ColumnStyle.GROUP && model.getColumnStyle(i) != ColumnStyle.GROUP_NO_HEADER) {
- Style columnTypeStyle = getStyle(model.getColumnStyle(i));
- Style columnHeaderStyle = getStyle(model.getColumnHeaderStyle(i));
+ Style columnTypeStyle = getStyle(model.getColumnStyle(i), formatForCSV);
+ Style columnHeaderStyle = getStyle(model.getColumnHeaderStyle(i), formatForCSV);
int width = FontUtilities.getStringWidth(model.getColumnPrototypeValueAt(i), getTypeFooterStyle());
int hWidth = FontUtilities.getStringWidth(model.getColumnName(i), columnHeaderStyle);
@@ -363,7 +376,7 @@
builder.setPattern(pattern);
}
- if (model.isColumnFixedWidth(i)) {
+ if (model.isColumnFixedWidth(i) && !formatForCSV) {
builder.setFixedWidth(true);
}
@@ -453,8 +466,10 @@
drb.setUseFullPageWidth(true); //make columns to fill the page width0
- drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_LEFT, AutoText.PATTERN_DATE_DATE_TIME);
- drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_RIGHT, 80, 50);
+ if (!formatForCSV) {
+ drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_LEFT, AutoText.PATTERN_DATE_DATE_TIME);
+ drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_RIGHT, 80, 50);
+ }
DynamicReport dr = drb.build();
Modified: jgnash2/trunk/src/jgnash/ui/report/jasper/DynamicJasperReportPanel.java
===================================================================
--- jgnash2/trunk/src/jgnash/ui/report/jasper/DynamicJasperReportPanel.java 2009-03-04 00:24:53 UTC (rev 1561)
+++ jgnash2/trunk/src/jgnash/ui/report/jasper/DynamicJasperReportPanel.java 2009-03-04 10:41:47 UTC (rev 1562)
@@ -561,7 +561,15 @@
p.put(LAST_CONTRIBUTOR, contributor.getDescription());
try {
- contributor.save(jPrint, file);
+
+ if (contributor.getDescription().contains("CSV")) {
+ System.out.println("Formating for csv file");
+ JasperPrint print = report.createJasperPrint(true);
+ contributor.save(print, file);
+ } else {
+ contributor.save(jPrint, file);
+ }
+
} catch (JRException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, getBundleString("error.saving"));
@@ -933,7 +941,7 @@
@Override
public JasperPrint doInBackground() {
frame.displayWaitMessage(Resource.get().getString("Message.PleaseWait"));
- return report.createJasperPrint();
+ return report.createJasperPrint(false);
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|