Source Code Cross Referenced for IWriter.java in  » Net » hyperpool-0.4.0 » vicazh » hyperpool » 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 » Net » hyperpool 0.4.0 » vicazh.hyperpool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package vicazh.hyperpool;
002:
003:        import java.awt.*;
004:        import java.awt.event.*;
005:        import javax.swing.*;
006:        import javax.xml.transform.*;
007:        import java.beans.*;
008:        import java.io.*;
009:        import java.util.logging.*;
010:
011:        /**
012:         * The graphic object writer
013:         * 
014:         * @author Victor Zhigunov
015:         * @version 0.4.0
016:         */
017:        public class IWriter implements  ActionListener, PropertyChangeListener,
018:                WindowListener {
019:            private JDialog dialog;
020:
021:            private JOptionPane optionPane;
022:
023:            private JFileChooser chooser;
024:
025:            private Component parent;
026:
027:            private JMenuItem menuSave;
028:
029:            private AbstractButton buttonSave;
030:
031:            private JDialog dialogReplace;
032:
033:            private JOptionPane optionPaneReplace;
034:
035:            /**
036:             * @param dialog
037:             *            save dialog
038:             * @param chooser
039:             *            file chooser
040:             * @param parent
041:             *            parent component
042:             * @param menuSave
043:             *            save menu item
044:             * @param buttonSave
045:             *            save button
046:             * @param dialogReplace
047:             *            replace dialog
048:             */
049:            public IWriter(JDialog dialog, JFileChooser chooser,
050:                    Component parent, JMenuItem menuSave,
051:                    AbstractButton buttonSave, JDialog dialogReplace)
052:                    throws TransformerException {
053:                this .dialog = dialog;
054:                optionPane = (JOptionPane) dialog.getContentPane();
055:                optionPane.addPropertyChangeListener(this );
056:                this .chooser = chooser;
057:                this .parent = parent;
058:                this .menuSave = menuSave;
059:                menuSave.addActionListener(this );
060:                this .buttonSave = buttonSave;
061:                buttonSave.addActionListener(this );
062:                this .dialogReplace = dialogReplace;
063:                optionPaneReplace = (JOptionPane) dialogReplace
064:                        .getContentPane();
065:                optionPaneReplace.addPropertyChangeListener(this );
066:            }
067:
068:            private ICom com;
069:
070:            /**
071:             * @param com
072:             *            communicator
073:             */
074:            public void setCom(ICom com) {
075:                this .com = com;
076:            }
077:
078:            byte[] data;
079:
080:            private File out;
081:
082:            public void actionPerformed(ActionEvent e) {
083:                try {
084:                    Object source = e.getSource();
085:                    if (source == menuSave || source == buttonSave) {
086:                        data = com.get();
087:                        Writer.put(data, out);
088:                    } else if (e.getActionCommand().equals("saveas")) {
089:                        if (chooser.showSaveDialog(parent) != JFileChooser.APPROVE_OPTION)
090:                            return;
091:                        File f = getSelectedFile();
092:                        if (f.exists()) {
093:                            dialogReplace.setLocationRelativeTo(dialogReplace
094:                                    .getOwner());
095:                            dialogReplace.setVisible(true);
096:                            Object value = optionPaneReplace.getValue();
097:                            if (value == JOptionPane.UNINITIALIZED_VALUE)
098:                                return;
099:                            optionPaneReplace
100:                                    .setValue(JOptionPane.UNINITIALIZED_VALUE);
101:                            if (((Integer) value).intValue() != JOptionPane.YES_OPTION)
102:                                return;
103:                        }
104:                        setOut(f);
105:                        data = com.get();
106:                        Writer.put(data, out);
107:                    } else
108:                        windowClosing(null);
109:                } catch (Exception ex) {
110:                    Start.logger.log(Level.SEVERE, ex.getMessage(), ex);
111:                }
112:            }
113:
114:            public void windowClosing(WindowEvent e) {
115:                try {
116:                    if (!com.isConnect() || check() != Status.CANCEL)
117:                        System.exit(0);
118:                } catch (Exception ex) {
119:                    Start.logger.log(Level.SEVERE, ex.getMessage(), ex);
120:                }
121:            }
122:
123:            enum Status {
124:                EMPTY, OK, CANCEL
125:            };
126:
127:            Status check() throws IOException, TransformerException {
128:                byte[] d = com.get();
129:                if (d == null)
130:                    return Status.EMPTY;
131:                if (data != null && new String(d).equals(new String(data)))
132:                    return Status.OK;
133:                dialog.setLocationRelativeTo(dialog.getOwner());
134:                dialog.setVisible(true);
135:                Object value = optionPane.getValue();
136:                if (value == JOptionPane.UNINITIALIZED_VALUE)
137:                    return Status.CANCEL;
138:                optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
139:                switch (((Integer) value).intValue()) {
140:                case JOptionPane.NO_OPTION:
141:                    return Status.OK;
142:                case JOptionPane.OK_OPTION:
143:                    if (out == null) {
144:                        if (chooser.showSaveDialog(parent) != JFileChooser.APPROVE_OPTION)
145:                            return Status.CANCEL;
146:                        out = getSelectedFile();
147:                    }
148:                    Writer.put(d, out);
149:                    return Status.OK;
150:                }
151:                return Status.CANCEL;
152:            }
153:
154:            private File getSelectedFile() {
155:                File f = chooser.getSelectedFile();
156:                String end = '.' + ((IFileFilter) chooser.getFileFilter()).extension;
157:                return f.getName().endsWith(end) ? f : new File(f
158:                        .getAbsolutePath()
159:                        + end);
160:            }
161:
162:            public void propertyChange(PropertyChangeEvent e) {
163:                Component c = ((JComponent) e.getSource())
164:                        .getTopLevelAncestor();
165:                String prop = e.getPropertyName();
166:                if (c.isVisible()
167:                        && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop
168:                                .equals(JOptionPane.INPUT_VALUE_PROPERTY)))
169:                    c.setVisible(false);
170:            }
171:
172:            public void windowOpened(WindowEvent e) {
173:            }
174:
175:            public void windowDeactivated(WindowEvent e) {
176:            }
177:
178:            public void windowActivated(WindowEvent e) {
179:            }
180:
181:            public void windowDeiconified(WindowEvent e) {
182:            }
183:
184:            public void windowIconified(WindowEvent e) {
185:            }
186:
187:            public void windowClosed(WindowEvent e) {
188:            }
189:
190:            /**
191:             * Set the xml result file
192:             * 
193:             * @param out
194:             *            xml result file
195:             */
196:            public void setOut(File out) throws TransformerException {
197:                this .out = out;
198:                if (out != null) {
199:                    menuSave.setEnabled(true);
200:                    buttonSave.setEnabled(true);
201:                }
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.