Source Code Cross Referenced for MaskImport.java in  » Database-Client » sqleonardo » nickyb » sqleonardo » environment » ctrl » content » 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 » sqleonardo » nickyb.sqleonardo.environment.ctrl.content 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SQLeonardo :: java database frontend
003:         * Copyright (C) 2004 nickyb@users.sourceforge.net
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License
007:         * as published by the Free Software Foundation; either version 2
008:         * of the License, or (at your option) any later version.
009:         * 
010:         * This program is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         * GNU General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * along with this program; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018:         *
019:         */
020:
021:        package nickyb.sqleonardo.environment.ctrl.content;
022:
023:        import java.awt.FlowLayout;
024:        import java.awt.GridLayout;
025:        import java.awt.event.ItemEvent;
026:        import java.awt.event.ItemListener;
027:        import java.io.FileInputStream;
028:        import java.io.FileNotFoundException;
029:        import java.io.IOException;
030:        import java.util.Vector;
031:
032:        import javax.swing.ButtonGroup;
033:        import javax.swing.JCheckBox;
034:        import javax.swing.JLabel;
035:        import javax.swing.JPanel;
036:        import javax.swing.JRadioButton;
037:        import javax.swing.JTextField;
038:        import javax.swing.border.TitledBorder;
039:
040:        import nickyb.sqleonardo.common.gui.BorderLayoutPanel;
041:        import nickyb.sqleonardo.environment.Application;
042:
043:        public class MaskImport extends AbstractMaskPerform {
044:            private AbstractChoice iChoice;
045:
046:            public void setEnabled(boolean b) {
047:                super .setEnabled(b);
048:                for (int i = 0; i < iChoice.getComponentCount(); i++)
049:                    iChoice.getComponent(i).setEnabled(b);
050:            }
051:
052:            void setType(short type, String tname, String fname) {
053:                if (iChoice != null)
054:                    remove(iChoice);
055:
056:                progress.setValue(0);
057:                progress.setMaximum(0);
058:
059:                if (type == TXT) {
060:                    if (!fname.endsWith(".txt"))
061:                        fname = fname + ".txt";
062:                    setComponentCenter(iChoice = new TxtChoice());
063:                }
064:
065:                lblFile.setText("file: " + fname);
066:            }
067:
068:            //	-----------------------------------------------------------------------------------------
069:            //	?????????????????????????????????????????????????????????????????????????????????????????
070:            //	-----------------------------------------------------------------------------------------
071:            void init() {
072:                super .init();
073:
074:                progress.setValue(0);
075:                progress.setMaximum(iChoice.open());
076:            }
077:
078:            void next() {
079:                String line = iChoice.nextln();
080:
081:                Object[] rowdata = new Object[view.getColumnCount()];
082:                iChoice.flush(line, rowdata);
083:
084:                view.addRow(rowdata, true);
085:                progress.setValue(progress.getValue() + line.length() + 1);
086:            }
087:
088:            boolean finished() {
089:                if (progress.getValue() == progress.getMaximum()) {
090:                    iChoice.close();
091:
092:                    view.onTableChanged(true);
093:                    view.getControl().doRefreshStatus();
094:
095:                    btnStop.setEnabled(false);
096:                    lblMsg.setText("ready!");
097:
098:                    return true;
099:                }
100:
101:                return false;
102:            }
103:
104:            //	-----------------------------------------------------------------------------------------
105:            //	-----------------------------------------------------------------------------------------
106:            private abstract class AbstractChoice extends BorderLayoutPanel {
107:                private FileInputStream stream;
108:
109:                JRadioButton rbAll;
110:                JRadioButton rbUser;
111:
112:                JTextField txtInterval;
113:
114:                AbstractChoice() {
115:                    setBorder(new TitledBorder("options"));
116:                }
117:
118:                /*		
119:                 void initComponents()
120:                 {
121:                 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
122:                 setComponentSouth(pnl);
123:
124:                 pnl.add(new JLabel("records:"));
125:                 pnl.add(rbAll	= new JRadioButton("all",true));
126:                 pnl.add(rbUser	= new JRadioButton("define:"));
127:                 pnl.add(txtInterval = new JTextField("1..",8));
128:                 txtInterval.setEditable(false);
129:                 txtInterval.setEnabled(false);
130:                
131:                 ButtonGroup bg = new ButtonGroup();
132:                 ItemListener il = new ItemListener()
133:                 {
134:                 public void itemStateChanged(ItemEvent e)
135:                 {
136:                 txtInterval.setEditable(rbUser.isSelected());
137:                 txtInterval.setEnabled(rbUser.isSelected());
138:                
139:                 if(rbAll.isSelected())
140:                 {
141:                 txtInterval.setText("1..");
142:                 }
143:                 }
144:                 };
145:                
146:                 bg.add(rbAll);			
147:                 bg.add(rbUser);
148:                
149:                 rbAll.addItemListener(il);
150:                 rbUser.addItemListener(il);
151:                 }
152:                 */
153:                int open() {
154:                    try {
155:                        stream = new FileInputStream(MaskImport.this .lblFile
156:                                .getText().substring(6));
157:                        return stream.available();
158:                    } catch (FileNotFoundException e) {
159:                        Application.println(e, true);
160:                    } catch (IOException e) {
161:                        Application.println(e, true);
162:                    }
163:
164:                    return 0;
165:                }
166:
167:                void close() {
168:                    try {
169:                        stream.close();
170:                    } catch (IOException e) {
171:                        Application.println(e, true);
172:                    }
173:                }
174:
175:                abstract void flush(String line, Object[] rowdata);
176:
177:                String nextln() {
178:                    try {
179:                        String line = new String("");
180:
181:                        int nChar;
182:                        while ((nChar = stream.read()) != -1
183:                                && (char) nChar != '\n')
184:                            line = line + (char) nChar;
185:
186:                        return line;
187:                    } catch (IOException e) {
188:                        Application.println(e, true);
189:                    }
190:
191:                    return null;
192:                }
193:            }
194:
195:            private class TxtChoice extends AbstractChoice {
196:                JCheckBox cbxHeader;
197:                JCheckBox cbxNull;
198:                JCheckBox cbxTrim;
199:
200:                JRadioButton rbTab;
201:                JRadioButton rbOther;
202:
203:                JTextField txtDelimiter;
204:
205:                TxtChoice() {
206:                    super ();
207:
208:                    JPanel pnl1 = new JPanel(new GridLayout(3, 1));
209:                    pnl1.add(cbxHeader = new JCheckBox("with header"));
210:                    pnl1.add(cbxNull = new JCheckBox("null if blanks"));
211:                    pnl1.add(cbxTrim = new JCheckBox("trim value"));
212:
213:                    JPanel pnl2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
214:                    pnl2.add(new JLabel("delimiter:"));
215:                    pnl2.add(rbTab = new JRadioButton("tab", true));
216:                    pnl2.add(rbOther = new JRadioButton("other"));
217:                    pnl2.add(txtDelimiter = new JTextField(";", 5));
218:                    txtDelimiter.setEditable(false);
219:                    txtDelimiter.setEnabled(false);
220:
221:                    JPanel pnl3 = new JPanel(new GridLayout(2, 1));
222:                    pnl3.add(pnl1);
223:                    pnl3.add(pnl2);
224:
225:                    JPanel pnl4 = new JPanel(new FlowLayout(FlowLayout.LEFT));
226:                    setComponentCenter(pnl4);
227:                    pnl4.add(pnl3);
228:
229:                    ButtonGroup bg = new ButtonGroup();
230:                    bg.add(rbTab);
231:                    bg.add(rbOther);
232:
233:                    rbTab.addItemListener(new ItemListener() {
234:                        public void itemStateChanged(ItemEvent e) {
235:                            txtDelimiter.setEditable(!rbTab.isSelected());
236:                            txtDelimiter.setEnabled(!rbTab.isSelected());
237:                        }
238:                    });
239:                }
240:
241:                private String getDelimiter() {
242:                    if (rbTab.isSelected())
243:                        return "\t";
244:                    return txtDelimiter.getText();
245:                }
246:
247:                int open() {
248:                    int bytes = super .open();
249:
250:                    if (cbxHeader.isSelected()) {
251:                        String line = nextln();
252:                        bytes = bytes - (line.length() + 1);
253:                    }
254:
255:                    return bytes;
256:                }
257:
258:                void flush(String line, Object[] rowdata) {
259:                    Vector vRow = new Vector();
260:
261:                    int bix = 0;
262:                    int eix = 0;
263:
264:                    while ((eix = line.indexOf(getDelimiter(), bix)) != -1) {
265:                        String value = line.substring(bix, eix);
266:                        bix = eix + getDelimiter().length();
267:
268:                        if (cbxNull.isSelected() && value.trim().length() == 0)
269:                            value = null;
270:                        if (cbxTrim.isSelected() && value != null)
271:                            value = value.trim();
272:
273:                        vRow.addElement(value);
274:                    }
275:
276:                    if (bix < line.length() - 1) {
277:                        String value = line.substring(bix);
278:
279:                        if (cbxNull.isSelected() && value.trim().length() == 0)
280:                            value = null;
281:                        if (cbxTrim.isSelected() && value != null)
282:                            value = value.trim();
283:
284:                        vRow.addElement(value);
285:                    }
286:
287:                    vRow.toArray(rowdata);
288:                }
289:            }
290:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.