Source Code Cross Referenced for LineChartPage.java in  » ERP-CRM-Financial » jmoney » net » sf » jmoney » charts » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » jmoney » net.sf.jmoney.charts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.jmoney.charts;
002:
003:        import java.awt.Dimension;
004:        import java.text.DateFormat;
005:        import java.text.SimpleDateFormat;
006:        import java.util.Date;
007:        import java.util.Iterator;
008:        import java.util.Vector;
009:
010:        import net.sf.jmoney.IBookkeepingPage;
011:        import net.sf.jmoney.IBookkeepingPageFactory;
012:        import net.sf.jmoney.JMoneyPlugin;
013:        import net.sf.jmoney.model2.Account;
014:        import net.sf.jmoney.model2.CapitalAccount;
015:        import net.sf.jmoney.model2.Session;
016:        import net.sf.jmoney.views.NodeEditor;
017:        import net.sf.jmoney.views.SectionlessPage;
018:
019:        import org.eclipse.swt.SWT;
020:        import org.eclipse.swt.events.SelectionAdapter;
021:        import org.eclipse.swt.events.SelectionEvent;
022:        import org.eclipse.swt.layout.FillLayout;
023:        import org.eclipse.swt.widgets.Button;
024:        import org.eclipse.swt.widgets.Composite;
025:        import org.eclipse.swt.widgets.Group;
026:        import org.eclipse.swt.widgets.Label;
027:        import org.eclipse.swt.widgets.Text;
028:        import org.eclipse.swt.widgets.Tree;
029:        import org.eclipse.swt.widgets.TreeItem;
030:        import org.eclipse.ui.IMemento;
031:        import org.eclipse.ui.PartInitException;
032:        import org.eclipse.ui.forms.widgets.FormToolkit;
033:        import org.eclipse.ui.internal.layout.CellLayout;
034:        import org.jfree.chart.ChartPanel;
035:
036:        /**
037:         * @author Faucheux
038:         */
039:        public class LineChartPage implements  IBookkeepingPageFactory {
040:
041:            private static final String PAGE_ID = "net.sf.jmoney.charts.lineChart";
042:            private Session session;
043:            private Tree tree;
044:            private Text fromDate, toDate;
045:            private final DateFormat df;
046:            private Button chkDaily, chkAverage30, chkAverage120,
047:                    chkAverage365;
048:            private Button chkWithSubaccounts;
049:            private Button radSaldoAbsolut, radSaldoRelativ, radMouvement,
050:                    radBalance;
051:
052:            /**
053:             * Constructor
054:             *
055:             */
056:            public LineChartPage() {
057:                super ();
058:                df = new SimpleDateFormat();
059:            }
060:
061:            /* (non-Javadoc)
062:             * @see net.sf.jmoney.IBookkeepingPageListener#createPages(java.lang.Object, org.eclipse.swt.widgets.Composite)
063:             */
064:            public Composite createContent(final Session session,
065:                    Composite parent, Vector selectedAccounts,
066:                    Vector selectedTreeItems) {
067:
068:                this .session = session;
069:                Composite swingComposite = new Composite(parent, SWT.EMBEDDED);
070:                swingComposite.setLayout(new FillLayout());
071:
072:                // Add Account Tree
073:                Group accountGroup = new Group(swingComposite, SWT.NULL);
074:                accountGroup.setText("Accounts");
075:                accountGroup.setLayout(new FillLayout());
076:
077:                tree = new Tree(accountGroup, SWT.CHECK | SWT.MULTI
078:                        | SWT.VERTICAL);
079:                TreeItem treeItem = new TreeItem(tree, SWT.NULL);
080:                treeItem.setText("Accounts"); // TODO - Faucheux Internationlization
081:                addAccountsInTree(treeItem,
082:                        session.getCapitalAccountIterator(), selectedAccounts,
083:                        selectedTreeItems);
084:
085:                // Add other components (Parameters)
086:
087:                Composite parameterContainer = new Composite(swingComposite,
088:                        SWT.EMBEDDED);
089:                parameterContainer.setLayout(new FillLayout(SWT.VERTICAL));
090:
091:                Group typeGroup = new Group(parameterContainer, SWT.NULL);
092:                typeGroup.setText("Type");
093:                typeGroup.setLayout(new CellLayout(2));
094:
095:                Group actionGroup = new Group(parameterContainer, SWT.NULL);
096:                actionGroup.setText("Actions");
097:                actionGroup.setLayout(new CellLayout(2));
098:
099:                (new Label(actionGroup, SWT.NULL)).setText("From date:");
100:                fromDate = new Text(actionGroup, SWT.NULL);
101:                fromDate.setText(df.format(new Date(0)));
102:
103:                (new Label(actionGroup, SWT.NULL)).setText("To date:");
104:                toDate = new Text(actionGroup, SWT.NULL);
105:                toDate.setText(df.format(new Date()));
106:
107:                chkDaily = new Button(actionGroup, SWT.CHECK);
108:                chkDaily.setText("Daily");
109:
110:                chkAverage30 = new Button(actionGroup, SWT.CHECK);
111:                chkAverage30.setText("Average 30 days");
112:
113:                chkAverage120 = new Button(actionGroup, SWT.CHECK);
114:                chkAverage120.setText("Average 120 days");
115:
116:                chkAverage365 = new Button(actionGroup, SWT.CHECK);
117:                chkAverage365.setText("Average 365 days");
118:
119:                radSaldoAbsolut = new Button(typeGroup, SWT.RADIO);
120:                radSaldoAbsolut.setText("Saldo (absolut)");
121:
122:                radSaldoRelativ = new Button(typeGroup, SWT.RADIO);
123:                radSaldoRelativ.setText("Saldo (relativ)");
124:
125:                radMouvement = new Button(typeGroup, SWT.RADIO);
126:                radMouvement.setText("Mouvement");
127:
128:                radBalance = new Button(typeGroup, SWT.RADIO);
129:                radBalance.setText("Balance");
130:
131:                chkWithSubaccounts = new Button(actionGroup, SWT.CHECK);
132:                chkWithSubaccounts.setText("Include the sub-accounts");
133:
134:                // Add the "Draw" Button
135:
136:                Button redraw = new Button(actionGroup, SWT.NULL);
137:                redraw.setText("Draw!");
138:
139:                redraw.addSelectionListener(new SelectionAdapter() {
140:                    public void widgetSelected(SelectionEvent e) {
141:                        createChart();
142:                    }
143:                });
144:
145:                return swingComposite;
146:            }
147:
148:            /**
149:             * Add each element (account) of the Iterator in the tree and 
150:             * add all its subaccounts too as subtree
151:             * <P>
152:             * This method also checks if the account is in the list of
153:             * selected accounts and, if so, adds the TreeItem to the list of
154:             * selected tree items.  This must be done so that the set of
155:             * selected accounts are persisted when the workbench is closed and
156:             * re-opened.
157:             *   
158:             * @param tn TreeItem the accounts are to add to.
159:             * @param it accounts to add
160:             */
161:            private void addAccountsInTree(TreeItem tn, Iterator it,
162:                    Vector selectedAccounts, Vector selectedTreeItems) {
163:                while (it.hasNext()) {
164:                    CapitalAccount a2 = (CapitalAccount) it.next();
165:                    TreeItem treeItem = new TreeItem(tn, SWT.NULL);
166:                    treeItem.setText(a2.getName());
167:                    treeItem.setData(a2);
168:                    if (Util.getEntriesFromAccount(session, a2).size() == 0) {
169:                        treeItem.setText(a2.getName() + " (no entries)");
170:                        treeItem.setGrayed(true);
171:                    }
172:
173:                    // If the account is in the list of selected accounts
174:                    // then add the tree item to the list of selected tree items.
175:                    if (selectedAccounts.indexOf(a2) != -1) {
176:                        selectedTreeItems.add(treeItem);
177:                    }
178:
179:                    addAccountsInTree(treeItem, a2.getSubAccountCollection()
180:                            .iterator(), selectedAccounts, selectedTreeItems);
181:                }
182:            }
183:
184:            /* (non-Javadoc)
185:             * @see net.sf.jmoney.IBookkeepingPageListener#createPages(java.lang.Object, org.eclipse.swt.widgets.Composite)
186:             */
187:            public IBookkeepingPage createFormPage(NodeEditor editor,
188:                    IMemento memento) {
189:                SectionlessPage formPage = new SectionlessPage(editor, PAGE_ID,
190:                        "Chart", "Line Chart") {
191:
192:                    public Composite createControl(Object nodeObject,
193:                            Composite parent, FormToolkit toolkit,
194:                            IMemento memento) {
195:                        Session session = JMoneyPlugin.getDefault()
196:                                .getSession();
197:
198:                        Vector selectedAccounts = new Vector();
199:                        Vector selectedTreeItems = new Vector();
200:                        if (memento != null) {
201:                            IMemento[] accountMementos = memento
202:                                    .getChildren("selectedAccount");
203:                            for (int i = 0; i < accountMementos.length; i++) {
204:                                String fullAccountName = accountMementos[i]
205:                                        .getString("name");
206:                                if (fullAccountName != null) {
207:                                    Account account = session
208:                                            .getAccountByFullName(fullAccountName);
209:                                    if (account != null) {
210:                                        selectedAccounts.add(account);
211:                                    }
212:                                }
213:                            }
214:                        }
215:
216:                        Composite control = createContent(session, parent,
217:                                selectedAccounts, selectedTreeItems);
218:
219:                        // Check the selected accounts
220:                        TreeItem[] array = (TreeItem[]) selectedTreeItems
221:                                .toArray(new TreeItem[selectedTreeItems.size()]);
222:                        for (int j = 0; j < array.length; j++) {
223:                            if (ChartsPlugin.DEBUG)
224:                                System.out.println(array[j].toString());
225:                            array[j].setChecked(true);
226:                        }
227:                        // Also select them.  This causes the tree to be expanded so that
228:                        // the user can see the selection.
229:                        tree.setSelection(array);
230:
231:                        return control;
232:                    }
233:
234:                    public void saveState(IMemento memento) {
235:                        // Save the selected accounts
236:                        Vector accounts = new Vector();
237:                        addChosenAccountsToVector(tree.getItems()[0], accounts);
238:                        for (Iterator iter = accounts.iterator(); iter
239:                                .hasNext();) {
240:                            String selectedAccountName = (String) iter.next();
241:                            memento.createChild("selectedAccount").putString(
242:                                    "name", selectedAccountName);
243:                        }
244:                    }
245:                };
246:
247:                try {
248:                    editor.addPage(formPage);
249:                } catch (PartInitException e) {
250:                    JMoneyPlugin.log(e);
251:                    // TODO: cleanly leave out this page.
252:                }
253:
254:                return formPage;
255:            }
256:
257:            /**
258:             * 
259:             */
260:            private void createChart() {
261:                final LineChart chart;
262:                // Prepare the parameters
263:                LineChartParameters params = new LineChartParameters();
264:
265:                Vector accounts = new Vector();
266:                addChosenAccountsToVector(tree.getItems()[0], accounts);
267:                params.setAccountList(accounts);
268:
269:                params.setDates(fromDate.getText(), toDate.getText());
270:                params.setDaily(chkDaily.getSelection());
271:                params.setAverage30(chkAverage30.getSelection());
272:                params.setAverage120(chkAverage120.getSelection());
273:                params.setAverage365(chkAverage365.getSelection());
274:                params.setWithSubaccounts(chkWithSubaccounts.getSelection());
275:
276:                if (radMouvement.getSelection())
277:                    params.setType(LineChartParameters.MOUVEMENT);
278:                if (radSaldoAbsolut.getSelection())
279:                    params.setType(LineChartParameters.SALDO_ABSOLUT);
280:                if (radSaldoRelativ.getSelection())
281:                    params.setType(LineChartParameters.SALDO_RELATIV);
282:                if (radBalance.getSelection())
283:                    params.setType(LineChartParameters.BALANCE);
284:
285:                chart = new ActivLineChart("myChart", session, params);
286:                final ChartPanel chartPanel = chart.getChartPanel();
287:                chartPanel.setPreferredSize(new Dimension(500, 270));
288:                chart.createOrUpdateValues(params);
289:                chart.displayAsWindow();
290:            }
291:
292:            /**
293:             * 
294:             */
295:            private void addChosenAccountsToVector(TreeItem treeitem,
296:                    Vector vector) {
297:                for (int i = 0; i < treeitem.getItemCount(); i++) {
298:                    if (treeitem.getItems()[i].getChecked()) {
299:                        vector.add(((Account) treeitem.getItems()[i].getData())
300:                                .getFullAccountName());
301:                    }
302:                    addChosenAccountsToVector(treeitem.getItems()[i], vector);
303:                }
304:            }
305:
306:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.