Source Code Cross Referenced for ExportWin.java in  » Report » datavision-1.1.0 » jimm » datavision » gui » 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 » Report » datavision 1.1.0 » jimm.datavision.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision.gui;
002:
003:        import jimm.datavision.*;
004:        import jimm.datavision.layout.*;
005:        import jimm.datavision.layout.pdf.PDFLE;
006:        import jimm.datavision.layout.excel.ExcelLE;
007:        import jimm.util.XMLWriter;
008:        import jimm.util.I18N;
009:        import java.io.PrintWriter;
010:        import java.io.FileWriter;
011:        import java.io.FileOutputStream;
012:        import java.io.IOException;
013:        import java.awt.Frame;
014:        import java.awt.BorderLayout;
015:        import java.awt.event.ActionListener;
016:        import java.awt.event.ActionEvent;
017:        import java.util.prefs.Preferences;
018:        import javax.swing.*;
019:
020:        /**
021:         * This dialog lets the user export report results using one of the
022:         * layout engines.
023:         *
024:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
025:         */
026:        public class ExportWin extends JDialog implements  ActionListener {
027:
028:            protected static Preferences prefs = Preferences
029:                    .userNodeForPackage(ExportWin.class);
030:
031:            protected Report report;
032:            protected JComboBox combo;
033:
034:            /**
035:             * Constructor.
036:             *
037:             * @param owner the parent window to which this dialog belongs
038:             * @param report the report
039:             */
040:            public ExportWin(Frame owner, Report report) {
041:                super (owner, I18N.get("ExportWin.title"));
042:                this .report = report;
043:                buildWindow();
044:                pack();
045:                setVisible(true);
046:            }
047:
048:            /**
049:             * Builds the window contents.
050:             */
051:            protected void buildWindow() {
052:                // Panel containing list of layout engines
053:                combo = new JComboBox(layoutNames());
054:                String lastUsedEngine = prefs.get("last_used_engine", null);
055:                if (lastUsedEngine != null)
056:                    combo.setSelectedItem(lastUsedEngine);
057:
058:                JPanel comboPanel = new JPanel();
059:                comboPanel.setBorder(BorderFactory.createEmptyBorder(20, 20,
060:                        20, 20));
061:                comboPanel.add(combo);
062:
063:                // OK and Cancel Buttons
064:                JPanel buttonPanel = buildButtonPanel();
065:
066:                // Add list, cards, and buttons to window
067:                getContentPane().setLayout(new BorderLayout());
068:                getContentPane().add(comboPanel, BorderLayout.CENTER);
069:                getContentPane().add(buttonPanel, BorderLayout.SOUTH);
070:            }
071:
072:            /**
073:             * Builds and returns a panel containing the OK and Cancel
074:             *
075:             * @return a panel
076:             */
077:            protected JPanel buildButtonPanel() {
078:                JPanel buttonPanel = new JPanel();
079:                JButton button;
080:
081:                buttonPanel.add(button = new JButton(I18N.get("GUI.ok")));
082:                button.addActionListener(this );
083:                button.setDefaultCapable(true);
084:
085:                buttonPanel.add(button = new JButton(I18N.get("GUI.cancel")));
086:                button.addActionListener(this );
087:
088:                return buttonPanel;
089:            }
090:
091:            /**
092:             * Handles the OK and Cancel buttons.
093:             *
094:             * @param e action event
095:             */
096:            public void actionPerformed(ActionEvent e) {
097:                String cmd = e.getActionCommand();
098:                if (I18N.get("GUI.ok").equals(cmd)) {
099:                    String choice = (String) combo.getSelectedItem();
100:                    prefs.put("last_used_engine", choice);
101:                    dispose();
102:                    runReport(choice);
103:                } else if (I18N.get("GUI.cancel").equals(cmd))
104:                    dispose();
105:            }
106:
107:            protected String[] layoutNames() {
108:                String[] names = new String[9];
109:                int i = 0;
110:                names[i++] = I18N.get("ExportWin.le_comma");
111:                names[i++] = I18N.get("ExportWin.le_tab");
112:                names[i++] = I18N.get("ExportWin.le_docbook");
113:                names[i++] = I18N.get("ExportWin.le_html");
114:                names[i++] = I18N.get("ExportWin.le_latex");
115:                names[i++] = I18N.get("ExportWin.le_pdf");
116:                names[i++] = I18N.get("ExportWin.le_xml");
117:                names[i++] = I18N.get("ExportWin.le_xls");
118:                names[i++] = I18N.get("ExportWin.le_csshtml");
119:                return names;
120:            }
121:
122:            /**
123:             * Given the user's choice of layout engine, ask user for output file
124:             * and run the report.
125:             *
126:             * @param choice the combo box string that the user selected
127:             */
128:            protected void runReport(String choice) {
129:                String extension = null;
130:                if (I18N.get("ExportWin.le_comma").equals(choice))
131:                    extension = ".csv";
132:                else if (I18N.get("ExportWin.le_tab").equals(choice))
133:                    extension = ".tab";
134:                else if (I18N.get("ExportWin.le_docbook").equals(choice))
135:                    extension = ".sgml";
136:                else if (I18N.get("ExportWin.le_html").equals(choice))
137:                    extension = ".html";
138:                else if (I18N.get("ExportWin.le_latex").equals(choice))
139:                    extension = ".tex";
140:                else if (I18N.get("ExportWin.le_pdf").equals(choice))
141:                    extension = ".pdf";
142:                else if (I18N.get("ExportWin.le_xml").equals(choice))
143:                    extension = ".xml";
144:                else if (I18N.get("ExportWin.le_xls").equals(choice))
145:                    extension = ".xls";
146:                else if (I18N.get("ExportWin.le_csshtml").equals(choice))
147:                    extension = ".html";
148:
149:                String path = selectFile(extension);
150:                if (path == null) // Cancelled by user
151:                    return;
152:
153:                try {
154:                    LayoutEngine le = null;
155:                    if (I18N.get("ExportWin.le_comma").equals(choice))
156:                        le = new CharSepLE(
157:                                new PrintWriter(new FileWriter(path)), ',');
158:                    else if (I18N.get("ExportWin.le_tab").equals(choice))
159:                        le = new CharSepLE(
160:                                new PrintWriter(new FileWriter(path)), '\t');
161:                    else if (I18N.get("ExportWin.le_docbook").equals(choice))
162:                        le = new DocBookLE(
163:                                new PrintWriter(new FileWriter(path)));
164:                    else if (I18N.get("ExportWin.le_html").equals(choice))
165:                        le = new HTMLLE(new PrintWriter(new FileWriter(path)));
166:                    else if (I18N.get("ExportWin.le_latex").equals(choice))
167:                        le = new LaTeXLE(new PrintWriter(new FileWriter(path)));
168:                    else if (I18N.get("ExportWin.le_pdf").equals(choice))
169:                        le = new PDFLE(new FileOutputStream(path));
170:                    else if (I18N.get("ExportWin.le_xml").equals(choice))
171:                        le = new XMLLE(
172:                                new XMLWriter(new FileOutputStream(path)));
173:                    else if (I18N.get("ExportWin.le_xls").equals(choice))
174:                        le = new ExcelLE(new FileOutputStream(path), false);
175:                    else if (I18N.get("ExportWin.le_csshtml").equals(choice))
176:                        le = new CSSHTMLLE(
177:                                new PrintWriter(new FileWriter(path)));
178:
179:                    if (le != null) {
180:                        report.setLayoutEngine(le);
181:                        report.run();
182:                    }
183:                } catch (IOException e) {
184:                    ErrorHandler.error(I18N.get("ExportWin.err_msg"), e, I18N
185:                            .get("ExportWin.err_title"));
186:                }
187:            }
188:
189:            /**
190:             * Lets user select output file. I'd like to be able to give a default
191:             * file extension (thus the argument), but that will have to come later.
192:             *
193:             * @param extension default file name extension (unused)
194:             * @return the path to the selected file
195:             */
196:            protected String selectFile(String extension) {
197:                JFileChooser chooser = Designer.getChooser();
198:                Designer.setPrefsDir(chooser, "outputDir");
199:                if (chooser.showSaveDialog(this .getOwner()) == JFileChooser.APPROVE_OPTION) {
200:                    Designer.savePrefsDir(chooser, "outputDir");
201:                    //output should probably have it's own prefs
202:                    //Designer.prefsPutReportDir(chooser); // save report directory
203:                    return chooser.getSelectedFile().getPath();
204:                } else
205:                    return null;
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.