Source code: com/dghda/kent/reports/DummyReport.java
1 /* Copyright (C) 2001 Duane Griffin <duanegriffin@users.sourceforge.net>
2 This file is part of Kent.
3
4 Kent is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 Kent is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with Kent; see the file COPYING. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 */
19
20 package com.dghda.kent.reports;
21
22 import java.io.*;
23 import java.util.*;
24
25 import com.dghda.kent.*;
26 import com.dghda.module.*;
27
28 public class DummyReport extends BaseKentModule implements Report {
29 public static final String ID = "com.dghda.kent.reports.DummyReport";
30 public static final String INPUT_1 = (ID + ".in1");
31 public static final String INPUT_2 = (ID + ".in2");
32 public static final String INPUT_3 = (ID + ".in3");
33 public static final String SELECT = (ID + ".sel");
34 public static final String [] OPTIONS = {"Option 1", "Option 2", "Option 3", "Option 4", "Option 5"};
35
36 private static final String DATA_SRC_1 = "source1";
37 private static final String DATA_SRC_2 = "source2";
38
39 public DummyReport (ReportEngine engine) {
40 super (ID, "Dummy report", "This report does nothing",
41 new Module.ModuleVersion (1, 0, "Duane Griffin"), engine);
42
43 m_Template = new ReportTemplate ("Dummy report", "This report doesn't do anything");
44 m_Template.addText ("Some text at the top.");
45 m_Template.addText (new ReportTemplateText ("Some more text, but funkier.", java.awt.Color.blue, java.awt.Color.cyan, null, ReportTemplateText.ALIGN_LEFT));
46
47 ReportTemplateDataSet dataSet = new ReportTemplateDataSet (DATA_SRC_1);
48 dataSet.addColumn ("Column 1", "col1");
49 dataSet.addColumn ("Column 2", "col2");
50 dataSet.addColumn ("Column 3", "col3");
51 m_Template.addDataSet (dataSet);
52
53 m_Template.addText ("Some text in the middle, with a subsitution (you chose option {source2, selected, 0}).");
54 }
55
56 public String getConfigurationOptions (java.util.Properties config) {
57 StringBuffer buffer = new StringBuffer();
58 buffer.append (ReportEngine.CONFIG_SPEC_START);
59
60 buffer.append (" <INPUT ID=\"");
61 buffer.append (INPUT_1);
62 buffer.append ("\" Type=\"text\" Label=\"Enter some text\"/>\n");
63
64 buffer.append (" <INPUT ID=\"");
65 buffer.append (INPUT_2);
66 buffer.append ("\" Type=\"text\" Label=\"Enter some text\"/>\n");
67
68 buffer.append (" <INPUT ID=\"");
69 buffer.append (INPUT_3);
70 buffer.append ("\" Length=\"4\" Type=\"text\" Label=\"Enter some text (max 4 characters)\"/>\n");
71
72 ReportEngine.openSelectTag (buffer, SELECT, ReportEngine.SELECT_STYLE_COMBO, "Choose an option", true, 1);
73 for (int index = 0; index != OPTIONS.length; ++index)
74 ReportEngine.addOptionTag (buffer, null, OPTIONS[index], (index == 0), true, 2);
75 buffer.append (" </SELECT>\n");
76
77 buffer.append (ReportEngine.CONFIG_SPEC_END);
78 return buffer.toString();
79 }
80
81 public String getReportData (Properties config) {
82 final String [] DATA_SET_COLUMNS_1 = {"col1", "col2", "col3"};
83 final String [] DATA_SET_COLUMNS_2 = {"selected"};
84 final String [] DATA_1 = {"a", "b", "c"};
85 final String [] DATA_2 = {"x", "y", "z"};
86
87 ReportData data = new ReportData();
88 data.addDataSet (DATA_SRC_1, DATA_SET_COLUMNS_1);
89 data.addDataSet (DATA_SRC_2, DATA_SET_COLUMNS_2);
90
91 data.addRow (DATA_SRC_1, DATA_1);
92 data.addRow (DATA_SRC_1, DATA_2);
93
94 String [] rows = new String[3];
95 rows[0] = config.getProperty (INPUT_1, "1");
96 rows[1] = config.getProperty (INPUT_2, "2");
97 rows[2] = config.getProperty (INPUT_3, "3");
98 data.addRow (DATA_SRC_1, rows);
99 rows = new String[1];
100
101 String selected = config.getProperty (SELECT, "0");
102 try {
103 int index = Integer.parseInt (selected);
104 if (index < 0 || index >= OPTIONS.length)
105 rows[0] = "an invalid selection";
106 else
107 rows[0] = OPTIONS[index];
108 } catch (NumberFormatException exc) {
109 rows[0] = "an invalid (non-numeric) selection";
110 }
111 data.addRow (DATA_SRC_2, rows);
112
113 return data.getData();
114 }
115
116 public String getReportTemplate (Properties config) {
117 return m_Template.getTemplate();
118 }
119
120 private ReportTemplate m_Template;
121 }