Source Code Cross Referenced for JGraphpadTWikiAction.java in  » Graphic-Library » jgraphpad » com » jgraph » twikiplugin » 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 » Graphic Library » jgraphpad » com.jgraph.twikiplugin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * $Id: JGraphpadTWikiAction.java,v 1.7 2005/10/09 12:00:04 gaudenz Exp $
003:         * Copyright (c) 2001-2005, Gaudenz Alder
004:         * 
005:         * All rights reserved.
006:         * 
007:         * See LICENSE file for license details. If you are unable to locate
008:         * this file please contact info (at) jgraph (dot) com.
009:         */
010:        package com.jgraph.twikiplugin;
011:
012:        import java.awt.event.ActionEvent;
013:        import java.awt.image.BufferedImage;
014:        import java.io.IOException;
015:        import java.io.OutputStream;
016:        import java.net.URL;
017:        import java.util.zip.GZIPOutputStream;
018:
019:        import javax.imageio.ImageIO;
020:
021:        import org.jgraph.JGraph;
022:
023:        import com.jgraph.JGraphEditor;
024:        import com.jgraph.codecplugin.JGraphpadCodecAction;
025:        import com.jgraph.editor.JGraphEditorAction;
026:        import com.jgraph.editor.JGraphEditorFile;
027:        import com.jgraph.editor.JGraphEditorResources;
028:        import com.jgraph.editor.factory.JGraphEditorDiagramPane;
029:
030:        /**
031:         * Implements all actions that require the browser launcher.
032:         */
033:        public class JGraphpadTWikiAction extends JGraphpadCodecAction {
034:
035:            /**
036:             * Specifies the name for the <code>uploadToTWiki</code> action.
037:             */
038:            public static final String NAME_UPLOADTOTWIKI = "uploadToTWiki";
039:
040:            /**
041:             * Specifies the name for the <code>uploadAndExit</code> action.
042:             */
043:            public static final String NAME_UPLOADANDEXIT = "uploadAndExit";
044:
045:            /**
046:             * Constructs a new file action for the specified name and editor.
047:             * 
048:             * @param name
049:             *            The name of the action to be created.
050:             * @param editor
051:             *            The enclosing editor for the action.
052:             */
053:            public JGraphpadTWikiAction(String name, JGraphEditor editor) {
054:                super (name, editor);
055:            }
056:
057:            /**
058:             * Executes the action based on the action name.
059:             * 
060:             * @param e
061:             *            The object that describes the event.
062:             */
063:            public void actionPerformed(ActionEvent e) {
064:                try {
065:                    JGraphEditorFile file = getPermanentFocusOwnerFile();
066:                    JGraph graph = getPermanentFocusOwnerGraph();
067:                    if (file != null && graph != null) {
068:                        if (getName().equals(NAME_UPLOADTOTWIKI)) {
069:                            doUploadToTWiki(file, graph, 0);
070:                        } else if (getName().equals(NAME_UPLOADANDEXIT)) {
071:                            doUploadToTWiki(file, graph, 0);
072:                            doExit();
073:                        }
074:                    }
075:                } catch (Exception e1) {
076:                    e1.printStackTrace();
077:                    dlgs.errorDialog(getPermanentFocusOwner(), e1
078:                            .getLocalizedMessage());
079:                }
080:            }
081:
082:            protected void doUploadToTWiki(JGraphEditorFile file, JGraph graph,
083:                    int inset) throws IOException {
084:                String uploadURL = (String) editor.getSettings().getObject(
085:                        "upload");
086:                if (uploadURL != null) {
087:                    // Contains Full URL
088:                    String filepath = file.getFilename();
089:                    int lastSlash = filepath.lastIndexOf("/");
090:                    // Contains basedir URL
091:                    String baseurl = filepath.substring(0, lastSlash);
092:                    // Contains filename with extension
093:                    String filename = filepath.substring(lastSlash + 1);
094:
095:                    // Contains filename without extension
096:                    String basename = filename;
097:                    if (basename.toLowerCase().endsWith(".gz"))
098:                        basename = basename.substring(0, basename.length() - 4);
099:                    if (basename.toLowerCase().endsWith(".xml"))
100:                        basename = basename.substring(0, basename.length() - 4);
101:
102:                    // Writes diagram file. Do not use
103:                    // editor.getModel().getOutputStream()
104:                    // for the file is we need to keep a reference to the innermost
105:                    // bytearrayoutputstream for passing to the post method!
106:                    OutputStream out = JGraphEditorResources
107:                            .getOutputStream(filepath);
108:                    OutputStream inner = out;
109:                    if (filename.toLowerCase().endsWith((".gz")))
110:                        out = new GZIPOutputStream(out);
111:                    editor.getModel().writeObject(file, out);
112:                    out.flush();
113:                    out.close();
114:
115:                    // Posts inner output stream
116:                    post(new URL(uploadURL), filename, (filename.toLowerCase()
117:                            .endsWith(".gz")) ? "application/octet-stream"
118:                            : MIME_PLAINTEXT, inner);
119:
120:                    // Writes map file
121:                    String mapFilename = baseurl + "/" + basename + ".map";
122:                    out = editor.getModel().getOutputStream(mapFilename);
123:                    int written = writeMap(graph, basename, inset, out);
124:                    out.flush();
125:                    out.close();
126:                    if (written > 0) {
127:                        post(new URL(uploadURL), mapFilename, MIME_PLAINTEXT,
128:                                out);
129:                    }
130:
131:                    // Writes PNG image
132:                    String imgFilename = baseurl + "/" + basename + ".png";
133:                    out = editor.getModel().getOutputStream(imgFilename);
134:                    JGraphEditorDiagramPane diagramPane = JGraphEditorDiagramPane
135:                            .getParentDiagramPane(graph);
136:                    BufferedImage img = diagramPane.getImage(null, inset);
137:
138:                    // Note: Use JGraphpadImageEncoder.writeGIF(img, out) for GIF files,
139:                    // this is OK for all built-in types (eg. JPG, BMP and PNG).
140:                    ImageIO.write(img, "png", out);
141:                    out.flush();
142:                    out.close();
143:                    post(new URL(uploadURL), imgFilename, "image/png", out);
144:
145:                    file.setNew(false);
146:                    file.setModified(false);
147:                }
148:            }
149:
150:            /**
151:             * Bundle of all actions in this class.
152:             */
153:            public static class AllActions implements  Bundle {
154:
155:                /**
156:                 * Holds the actions. The actions are constructed in the constructor as
157:                 * they require an editor instance.
158:                 */
159:                public JGraphEditorAction actionUploadToTWiki,
160:                        actionUploadAndExit;
161:
162:                /**
163:                 * Constructs the action bundle for the specified editor.
164:                 * 
165:                 * @param editor
166:                 *            The enclosing editor for this bundle.
167:                 */
168:                public AllActions(JGraphEditor editor) {
169:                    actionUploadToTWiki = new JGraphpadTWikiAction(
170:                            NAME_UPLOADTOTWIKI, editor);
171:                    actionUploadAndExit = new JGraphpadTWikiAction(
172:                            NAME_UPLOADANDEXIT, editor);
173:                }
174:
175:                /*
176:                 * (non-Javadoc)
177:                 */
178:                public JGraphEditorAction[] getActions() {
179:                    return new JGraphEditorAction[] { actionUploadToTWiki,
180:                            actionUploadAndExit };
181:                }
182:
183:                /*
184:                 * (non-Javadoc)
185:                 */
186:                public void update() {
187:                    // always enabled
188:                }
189:
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.