Source Code Cross Referenced for ExportPanel.java in  » Database-Client » QueryForm » org » glasser » qform » 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 » Database Client » QueryForm » org.glasser.qform 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         * Copyright (c) 1998 - 2003 David F. Glasser.  All rights
003:         * reserved.
004:         *
005:         * This file is part of the QueryForm Database Tool.
006:         *
007:         * The QueryForm Database Tool is free software; you can redistribute it
008:         * and/or modify it under the terms of the GNU General Public License as
009:         * published by the Free Software Foundation; either version 2 of the
010:         * License, or (at your option) any later version.
011:         *
012:         * The QueryForm Database Tool is distributed in the hope that it will
013:         * be useful, but WITHOUT ANY WARRANTY; without even the implied
014:         * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
015:         * See the GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with the QueryForm Database Tool; if not, write to:
019:         *
020:         *      The Free Software Foundation, Inc.,
021:         *      59 Temple Place, Suite 330
022:         *      Boston, MA  02111-1307  USA
023:         *
024:         * or visit http://www.gnu.org.
025:         *
026:         * ====================================================================
027:         *
028:         * This product includes software developed by the
029:         * Apache Software Foundation (http://www.apache.org/).
030:         *
031:         * ==================================================================== 
032:         */
033:        package org.glasser.qform;
034:
035:        import javax.swing.*;
036:        import org.glasser.util.*;
037:        import org.glasser.sql.*;
038:        import org.glasser.swing.*;
039:        import java.awt.event.*;
040:        import java.awt.*;
041:        import javax.swing.border.*;
042:        import javax.swing.event.*;
043:        import java.text.SimpleDateFormat;
044:
045:        public abstract class ExportPanel extends JPanel implements 
046:                ActionListener {
047:
048:            private String[] columnNames = null;
049:
050:            private Formatter[] formatters = null;
051:
052:            private JCheckBox[] checkboxes = null;
053:
054:            private JTextField[] nameFields = null;
055:
056:            private JComboBox[] formatterSelectors = null;
057:
058:            private Column[] cols = null;
059:
060:            protected abstract Object[] getFormatterChoices(int dataType);
061:
062:            public ExportPanel(TableInfo ti) {
063:
064:                cols = ti.getColumns();
065:                checkboxes = new JCheckBox[cols.length];
066:                nameFields = new JTextField[cols.length];
067:                formatterSelectors = new JComboBox[cols.length];
068:
069:                setLayout(new GridBagLayout());
070:                GridBagConstraints gc0 = new GridBagConstraints();
071:
072:                gc0.gridx = 0;
073:                gc0.fill = gc0.BOTH;
074:                gc0.anchor = gc0.CENTER;
075:                gc0.weightx = .5;
076:
077:                GridBagConstraints gc1 = (GridBagConstraints) gc0.clone();
078:                GridBagConstraints gc2 = (GridBagConstraints) gc0.clone();
079:
080:                gc1.gridx = 1;
081:                gc2.gridx = 2;
082:                gc0.weightx = 0;
083:
084:                for (int j = 0; j < cols.length; j++) {
085:                    gc0.gridy = j;
086:                    gc1.gridy = j;
087:                    gc2.gridy = j;
088:
089:                    IndexedCheckBox cb = new IndexedCheckBox(j);
090:                    checkboxes[j] = cb;
091:                    cb.setSelected(true);
092:
093:                    add(cb, gc0);
094:
095:                    // the column's data type will determine
096:                    // the choices that appear in the combo box.
097:                    int type = cols[j].getDataType();
098:
099:                    if (DBUtil.isBinaryType(type)) {
100:                        cb.setSelected(false);
101:                    }
102:
103:                    // It's necessary that the ActionListener be added to the
104:                    // checkbox after the possible call to setSelected() above.
105:                    cb.addActionListener(this );
106:
107:                    JTextField field = new JTextField();
108:                    field.setText(cols[j].getColumnName());
109:                    field.setEnabled(cb.isSelected());
110:                    field.setEditable(cb.isSelected());
111:                    nameFields[j] = field;
112:                    add(field, gc1);
113:
114:                    // populate the combo box with the appropriate choices for
115:                    // this data type and export type.
116:                    JComboBox cmb = new JComboBox(getFormatterChoices(type));
117:
118:                    cmb.setSelectedIndex(1);
119:
120:                    // this ActionListener will make the combo box editable whenever
121:                    // the user selects the first (blank line) item, and non-editable
122:                    // when one of the Formatter objects are selected from the list.
123:                    cmb.addActionListener(new ActionListener() {
124:
125:                        // this gets called when the user changes the selection on
126:                        // the combo box.
127:                        public void actionPerformed(ActionEvent e) {
128:
129:                            JComboBox combo = (JComboBox) e.getSource();
130:                            int selectedIndex = combo.getSelectedIndex();
131:                            Object o = combo.getSelectedItem();
132:
133:                            System.out.println("--ActionEvent:" + selectedIndex
134:                                    + "/" + o);
135:
136:                            if (selectedIndex < 0) {
137:                                return;
138:                            }
139:                            if (selectedIndex == 0) {
140:                                combo.setEditable(true);
141:                                combo.requestFocus();
142:                            } else {
143:                                combo.setEditable(false);
144:
145:                                // this works around an apparent swing bug where the selected
146:                                // index seems to get changed by the call to setEditable(false).
147:                                if (o != null)
148:                                    combo.setSelectedItem(o);
149:                            }
150:                        }
151:                    });
152:                    cmb.setEnabled(cb.isSelected());
153:                    formatterSelectors[j] = cmb;
154:                    add(cmb, gc2);
155:                }
156:
157:            }
158:
159:            /**
160:             * This gets called whenever a JCheckBox is toggled.
161:             */
162:            public void actionPerformed(ActionEvent e) {
163:
164:                // get the checkbox that fired this event, and read its index
165:                IndexedCheckBox chk = (IndexedCheckBox) e.getSource();
166:                int index = chk.index;
167:
168:                // enable/disable the text field and the combo box to match
169:                // the selected state of the checkbox.
170:                nameFields[index].setEnabled(chk.isSelected());
171:                nameFields[index].setEditable(chk.isSelected());
172:                JComboBox cmb = formatterSelectors[index];
173:                cmb.setEnabled(chk.isSelected());
174:                // the editable state of the combo box is not affected by
175:                // this event.
176:            }
177:
178:            public void update() {
179:
180:                columnNames = new String[checkboxes.length];
181:                this .formatters = new Formatter[checkboxes.length];
182:                for (int j = 0; j < checkboxes.length; j++) {
183:                    if (checkboxes[j].isSelected()) {
184:                        columnNames[j] = nameFields[j].getText();
185:                        Object o = formatterSelectors[j].getSelectedItem();
186:                        if (o == null) {
187:                            formatters[j] = new LiteralFormatter("");
188:                        } else if (o instanceof  Formatter) {
189:                            formatters[j] = (Formatter) o;
190:                        } else {
191:                            formatters[j] = new LiteralFormatter(o.toString());
192:                        }
193:                    }
194:                }
195:            }
196:
197:            public String[] getColumnNames() {
198:                return columnNames;
199:            }
200:
201:            public Formatter[] getFormatters() {
202:                return formatters;
203:            }
204:
205:            /**
206:             * This is a JCheckBox that knows what its index is in
207:             * the array of checkboxes.
208:             */
209:            public static class IndexedCheckBox extends JCheckBox {
210:
211:                public int index = 0;
212:
213:                public IndexedCheckBox(int index) {
214:                    super ();
215:                    this .index = index;
216:                }
217:            }
218:
219:            protected static class LiteralFormatter implements  Formatter {
220:
221:                String literal = null;
222:
223:                public LiteralFormatter(String literal) {
224:                    this .literal = literal;
225:                }
226:
227:                public String getFormattedString(Object o) {
228:                    return literal;
229:                }
230:            }
231:
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.