Source Code Cross Referenced for StackedChartPage.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 StackedChartPage 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, maxLevel;
045:            private final DateFormat df;
046:            private Button radPeriodDay, radPeriodMonth, radPeriodYear;
047:            private Button chkIsStacked;
048:
049:            /**
050:             * Constructor
051:             *
052:             */
053:            public StackedChartPage() {
054:                super ();
055:                df = new SimpleDateFormat();
056:            }
057:
058:            /* (non-Javadoc)
059:             * @see net.sf.jmoney.IBookkeepingPageListener#createPages(java.lang.Object, org.eclipse.swt.widgets.Composite)
060:             */
061:            public Composite createContent(final Session session,
062:                    Composite parent, Vector selectedAccounts,
063:                    Vector selectedTreeItems) {
064:
065:                this .session = session;
066:                Composite swingComposite = new Composite(parent, SWT.EMBEDDED);
067:                swingComposite.setLayout(new FillLayout());
068:
069:                // Add Account Tree
070:                Group accountGroup = new Group(swingComposite, SWT.NULL);
071:                accountGroup.setText("Accounts");
072:                accountGroup.setLayout(new FillLayout());
073:
074:                tree = new Tree(accountGroup, SWT.CHECK | SWT.MULTI
075:                        | SWT.VERTICAL);
076:                TreeItem treeItem = new TreeItem(tree, SWT.NULL);
077:                treeItem.setText("Accounts"); // TODO - Faucheux Internationlization
078:                addAccountsInTree(treeItem,
079:                        session.getCapitalAccountIterator(), selectedAccounts,
080:                        selectedTreeItems);
081:
082:                // Add other components (Parameters)
083:
084:                Composite parameterContainer = new Composite(swingComposite,
085:                        SWT.EMBEDDED);
086:                parameterContainer.setLayout(new FillLayout(SWT.VERTICAL));
087:
088:                Group groupPeriod = new Group(parameterContainer, SWT.NULL);
089:                groupPeriod.setText("Period");
090:                groupPeriod.setLayout(new CellLayout(2));
091:
092:                Group groupOptions = new Group(parameterContainer, SWT.NULL);
093:                groupOptions.setText("Options");
094:                groupOptions.setLayout(new CellLayout(2));
095:
096:                Group actionGroup = new Group(parameterContainer, SWT.NULL);
097:                actionGroup.setText("Actions");
098:                actionGroup.setLayout(new CellLayout(2));
099:
100:                (new Label(actionGroup, SWT.NULL)).setText("From date:");
101:                fromDate = new Text(actionGroup, SWT.NULL);
102:                fromDate.setText(df.format(new Date(0)));
103:
104:                (new Label(actionGroup, SWT.NULL)).setText("To date:");
105:                toDate = new Text(actionGroup, SWT.NULL);
106:                toDate.setText(df.format(new Date()));
107:
108:                (new Label(actionGroup, SWT.NULL)).setText("Maximal level:");
109:                maxLevel = new Text(actionGroup, SWT.NULL);
110:                maxLevel.setText("2");
111:
112:                radPeriodDay = new Button(groupPeriod, SWT.RADIO);
113:                radPeriodDay.setText("Day");
114:
115:                radPeriodMonth = new Button(groupPeriod, SWT.RADIO);
116:                radPeriodMonth.setText("Month");
117:
118:                radPeriodYear = new Button(groupPeriod, SWT.RADIO);
119:                radPeriodYear.setText("Years");
120:
121:                // Add Options
122:                chkIsStacked = new Button(groupOptions, SWT.CHECK);
123:                chkIsStacked.setText("Stack the accounts on eachother");
124:                chkIsStacked.setSelection(true);
125:
126:                // Add the "Draw" Button
127:
128:                Button drawButton = new Button(actionGroup, SWT.NULL);
129:                drawButton.setText("Draw!");
130:
131:                drawButton.addSelectionListener(new SelectionAdapter() {
132:                    public void widgetSelected(SelectionEvent e) {
133:                        createChart();
134:                    }
135:                });
136:
137:                return swingComposite;
138:            }
139:
140:            /**
141:             * Add each element (account) of the Iterator in the tree and 
142:             * add all its subaccounts too as subtree
143:             * <P>
144:             * This method also checks if the account is in the list of
145:             * selected accounts and, if so, adds the TreeItem to the list of
146:             * selected tree items.  This must be done so that the set of
147:             * selected accounts are persisted when the workbench is closed and
148:             * re-opened.
149:             *   
150:             * @param tn TreeItem the accounts are to add to.
151:             * @param it accounts to add
152:             */
153:            private void addAccountsInTree(TreeItem tn, Iterator it,
154:                    Vector selectedAccounts, Vector selectedTreeItems) {
155:                while (it.hasNext()) {
156:                    CapitalAccount a2 = (CapitalAccount) it.next();
157:                    TreeItem treeItem = new TreeItem(tn, SWT.NULL);
158:                    treeItem.setText(a2.getName());
159:                    treeItem.setData(a2);
160:                    if (Util.getEntriesFromAccount(session, a2).size() == 0) {
161:                        treeItem.setText(a2.getName() + " (no entries)");
162:                        treeItem.setGrayed(true);
163:                    }
164:
165:                    // If the account is in the list of selected accounts
166:                    // then add the tree item to the list of selected tree items.
167:                    if (selectedAccounts.indexOf(a2) != -1) {
168:                        selectedTreeItems.add(treeItem);
169:                    }
170:
171:                    addAccountsInTree(treeItem, a2.getSubAccountCollection()
172:                            .iterator(), selectedAccounts, selectedTreeItems);
173:                }
174:            }
175:
176:            /* (non-Javadoc)
177:             * @see net.sf.jmoney.IBookkeepingPageListener#createPages(java.lang.Object, org.eclipse.swt.widgets.Composite)
178:             */
179:            public IBookkeepingPage createFormPage(NodeEditor editor,
180:                    IMemento memento) {
181:                SectionlessPage formPage = new SectionlessPage(editor, PAGE_ID,
182:                        "Chart", "Line Chart") {
183:
184:                    public Composite createControl(Object nodeObject,
185:                            Composite parent, FormToolkit toolkit,
186:                            IMemento memento) {
187:                        Session session = JMoneyPlugin.getDefault()
188:                                .getSession();
189:
190:                        Vector selectedAccounts = new Vector();
191:                        Vector selectedTreeItems = new Vector();
192:                        if (memento != null) {
193:                            IMemento[] accountMementos = memento
194:                                    .getChildren("selectedAccount");
195:                            for (int i = 0; i < accountMementos.length; i++) {
196:                                String fullAccountName = accountMementos[i]
197:                                        .getString("name");
198:                                if (fullAccountName != null) {
199:                                    Account account = session
200:                                            .getAccountByFullName(fullAccountName);
201:                                    if (account != null) {
202:                                        selectedAccounts.add(account);
203:                                    }
204:                                }
205:                            }
206:                        }
207:
208:                        Composite control = createContent(session, parent,
209:                                selectedAccounts, selectedTreeItems);
210:
211:                        // Check the selected accounts
212:                        TreeItem[] array = (TreeItem[]) selectedTreeItems
213:                                .toArray(new TreeItem[selectedTreeItems.size()]);
214:                        for (int j = 0; j < array.length; j++) {
215:                            if (ChartsPlugin.DEBUG)
216:                                System.out.println(array[j].toString());
217:                            array[j].setChecked(true);
218:                        }
219:                        // Also select them.  This causes the tree to be expanded so that
220:                        // the user can see the selection.
221:                        tree.setSelection(array);
222:
223:                        return control;
224:                    }
225:
226:                    public void saveState(IMemento memento) {
227:                        // Save the selected accounts
228:                        Vector accounts = new Vector();
229:                        addChosenAccountsToVector(tree.getItems()[0], accounts);
230:                        for (Iterator iter = accounts.iterator(); iter
231:                                .hasNext();) {
232:                            String selectedAccountName = (String) iter.next();
233:                            memento.createChild("selectedAccount").putString(
234:                                    "name", selectedAccountName);
235:                        }
236:                    }
237:                };
238:
239:                try {
240:                    editor.addPage(formPage);
241:                } catch (PartInitException e) {
242:                    JMoneyPlugin.log(e);
243:                    // TODO: cleanly leave out this page.
244:                }
245:
246:                return formPage;
247:            }
248:
249:            /**
250:             * 
251:             */
252:            private void createChart() {
253:                final StackedChart chart;
254:                // Prepare the parameters
255:
256:                StackedChartParameters params = new StackedChartParameters();
257:
258:                Vector accounts = new Vector();
259:                addChosenAccountsToVector(tree.getItems()[0], accounts);
260:                params.setAccountList(accounts);
261:
262:                params.setDates(fromDate.getText(), toDate.getText());
263:                if (ChartsPlugin.DEBUG)
264:                    System.out.println("maxLevel: " + maxLevel.getText());
265:                params.setMaxLevel(Integer.parseInt(maxLevel.getText()));
266:
267:                if (radPeriodDay.getSelection())
268:                    params.setFrequence(StackedChartParameters.DAY);
269:                if (radPeriodMonth.getSelection())
270:                    params.setFrequence(StackedChartParameters.MONTH);
271:                if (radPeriodYear.getSelection())
272:                    params.setFrequence(StackedChartParameters.YEAR);
273:
274:                params.setIsStacked(chkIsStacked.getSelection());
275:                chart = new StackedAccountChart("Chart", session, params);
276:                final ChartPanel chartPanel = chart.getChartPanel();
277:                chartPanel.setPreferredSize(new Dimension(500, 270));
278:                // chart.createOrUpdateValues(params);
279:                chart.displayAsWindow();
280:            }
281:
282:            /**
283:             * 
284:             */
285:            private void addChosenAccountsToVector(TreeItem treeitem,
286:                    Vector vector) {
287:                for (int i = 0; i < treeitem.getItemCount(); i++) {
288:                    if (treeitem.getItems()[i].getChecked()) {
289:                        vector.add(((Account) treeitem.getItems()[i].getData())
290:                                .getFullAccountName());
291:                    }
292:                    addChosenAccountsToVector(treeitem.getItems()[i], vector);
293:                }
294:            }
295:
296:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.