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


001:        /* 
002:         * $Id: JGraphpadEPSAction.java,v 1.2 2005/08/07 10:28:29 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.epsplugin;
011:
012:        import java.awt.Component;
013:        import java.awt.Dimension;
014:        import java.awt.event.ActionEvent;
015:        import java.awt.geom.Rectangle2D;
016:        import java.io.File;
017:        import java.io.IOException;
018:        import java.io.OutputStream;
019:        import java.net.URL;
020:
021:        import javax.swing.RepaintManager;
022:
023:        import org.jgraph.JGraph;
024:        import org.jibble.epsgraphics.EpsGraphics2D;
025:
026:        import com.jgraph.JGraphEditor;
027:        import com.jgraph.editor.JGraphEditorAction;
028:        import com.jgraph.pad.action.JGraphpadFileAction;
029:
030:        /**
031:         * Implements all actions that require EPSGraphics in the classpath.
032:         */
033:        public class JGraphpadEPSAction extends JGraphpadFileAction {
034:
035:            /**
036:             * Specifies the name for the <code>saveEPS</code> action.
037:             */
038:            public static final String NAME_SAVEEPS = "saveEPS";
039:
040:            /**
041:             * Constructs a new Batik action for the specified name.
042:             */
043:            public JGraphpadEPSAction(String name, JGraphEditor editor) {
044:                super (name, editor);
045:            }
046:
047:            /**
048:             * Executes the action based on the action name.
049:             * 
050:             * @param e
051:             *            The object that describes the event.
052:             */
053:            public void actionPerformed(ActionEvent e) {
054:                Component component = getPermanentFocusOwner();
055:                try {
056:                    if (component instanceof  JGraph) {
057:                        JGraph graph = (JGraph) component;
058:                        if (getName().equals(NAME_SAVEEPS))
059:                            doSaveEPS(graph, 5, dlgs.fileDialog(
060:                                    getPermanentFocusOwnerOrParent(),
061:                                    getString("SaveEPSFile"), false, ".eps",
062:                                    getString("EPSFileDescription"),
063:                                    lastDirectory));
064:                    }
065:                } catch (IOException e1) {
066:                    dlgs.errorDialog(getPermanentFocusOwner(), e1
067:                            .getLocalizedMessage());
068:                }
069:            }
070:
071:            /**
072:             * Saves the specified graph as an EPS vector graphics file.
073:             * 
074:             * @param graph
075:             *            The graph to write as an EPS file.
076:             * @param inset
077:             *            The inset to use for the EPS graphics.
078:             * @param filename
079:             *            The filename to write the EPS.
080:             */
081:            public void doSaveEPS(JGraph graph, int inset, String filename)
082:                    throws IOException {
083:                if (filename != null) {
084:                    OutputStream out = editor.getModel().getOutputStream(
085:                            filename);
086:                    Object[] cells = graph.getDescendants(graph.getRoots());
087:                    if (cells.length > 0) {
088:                        EpsGraphics2D graphics = new EpsGraphics2D();
089:                        graphics.setColor(graph.getBackground());
090:                        Rectangle2D bounds = graph.toScreen(graph
091:                                .getCellBounds(cells));
092:                        Dimension d = bounds.getBounds().getSize();
093:                        graphics.fillRect(0, 0, d.width + 2 * inset, d.height
094:                                + 2 * inset);
095:                        graphics.translate(-bounds.getX() + inset, -bounds
096:                                .getY()
097:                                + inset);
098:
099:                        // Paints the graph to the svg generator with no double
100:                        // buffering enabled to make sure we get a vector image.
101:                        RepaintManager currentManager = RepaintManager
102:                                .currentManager(graph);
103:                        currentManager.setDoubleBufferingEnabled(false);
104:                        graph.paint(graphics);
105:                        out.write(graphics.toString().getBytes());
106:                        currentManager.setDoubleBufferingEnabled(true);
107:                    }
108:
109:                    out.close();
110:                    if (JGraphEditor.isURL(filename)) {
111:                        URL url = new URL(filename);
112:                        post(url, url.getFile(), MIME_HTML, out);
113:                    } else
114:                        lastDirectory = new File(filename).getParentFile();
115:                }
116:            }
117:
118:            /**
119:             * Bundle of all actions in this class.
120:             */
121:            public static class AllActions implements  Bundle {
122:
123:                /**
124:                 * Holds the actions. The actions are constructed in the constructor as
125:                 * they require an editor instance.
126:                 */
127:                public JGraphEditorAction actionSaveEPS;
128:
129:                /**
130:                 * Constructs the action bundle for the specified editor.
131:                 * 
132:                 * @param editor
133:                 *            The enclosing editor for this bundle.
134:                 */
135:                public AllActions(JGraphEditor editor) {
136:                    actionSaveEPS = new JGraphpadEPSAction(NAME_SAVEEPS, editor);
137:                }
138:
139:                /*
140:                 * (non-Javadoc)
141:                 */
142:                public JGraphEditorAction[] getActions() {
143:                    return new JGraphEditorAction[] { actionSaveEPS };
144:                }
145:
146:                /*
147:                 * (non-Javadoc)
148:                 */
149:                public void update() {
150:                    Component component = getPermanentFocusOwner();
151:                    boolean e = component instanceof  JGraph;
152:                    actionSaveEPS.setEnabled(e);
153:                }
154:
155:            }
156:
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.