Source Code Cross Referenced for DiagramEditorAppletPane.java in  » Web-Framework » argun » biz » hammurapi » web » diagrameditor » 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 » Web Framework » argun » biz.hammurapi.web.diagrameditor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        @license.gpl.text@
003:         */
004:
005:        /* 
006:         * This code is derived from 
007:         * JGraphPad, JGraphpadPane.java by Gaudenz Alder
008:         */
009:        package biz.hammurapi.web.diagrameditor;
010:
011:        import java.awt.BorderLayout;
012:        import java.beans.PropertyChangeEvent;
013:        import java.beans.PropertyChangeListener;
014:        import java.lang.reflect.Method;
015:        import java.util.Hashtable;
016:        import java.util.Iterator;
017:        import java.util.Map;
018:
019:        import javax.swing.ImageIcon;
020:        import javax.swing.JPanel;
021:        import javax.swing.SwingUtilities;
022:
023:        import org.jgraph.JGraph;
024:
025:        import com.jgraph.JGraphEditor;
026:        import com.jgraph.editor.JGraphEditorDiagram;
027:        import com.jgraph.editor.factory.JGraphEditorDiagramPane;
028:        import com.jgraph.pad.util.JGraphpadImageIcon;
029:        import com.jgraph.pad.util.JGraphpadMouseAdapter;
030:
031:        /**
032:         * Main application panel consisting of a menubar and toolbar, two tabbed panes,
033:         * one on the left and one on the bottom, a desktop pane in the center, and a
034:         * status bar.
035:         */
036:        public class DiagramEditorAppletPane extends JPanel {
037:
038:            /**
039:             * Nodename to be used for the desktop popup menu configuration.
040:             */
041:            public static String NODENAME_DESKTOPPOPUPMENU = "desktoppopupmenu";
042:
043:            /**
044:             * Nodename to be used for the desktop popup menu configuration.
045:             */
046:            public static String NODENAME_INTERNALFRAMEPOPUPMENU = "internalframepopupmenu";
047:
048:            /**
049:             * Defines the key used to identify the navigator split divider location.
050:             */
051:            public static String KEY_DESKTOPPANE = "desktopPane";
052:
053:            /**
054:             * Holds the desktop pane.
055:             */
056:            //protected JDesktopPane desktopPane = new JDesktopPane();
057:            private JGraphEditorDiagramPane diagramPane;
058:
059:            JGraph getGraph() {
060:                return diagramPane.getGraph();
061:            }
062:
063:            /**
064:             * Maps from diagrams to internal frames.
065:             */
066:            //protected Map internalFrames = new HashMap();
067:            /**
068:             * References the enclosing editor.
069:             */
070:            protected JGraphEditor editor;
071:
072:            /**
073:             * Constructs a new editor pane for the specified enclosing editor.
074:             * 
075:             * @param editor
076:             *            The editor that contains the pane.
077:             * @param newDiagram 
078:             */
079:            public DiagramEditorAppletPane(JGraphEditor editor,
080:                    JGraphEditorDiagram newDiagram) {
081:                setLayout(new BorderLayout());
082:                this .editor = editor;
083:                diagramPane = editor.getFactory().createDiagramPane(newDiagram);
084:                configureDiagramPane(diagramPane, newDiagram);
085:                diagramPane.addMouseListener(new JGraphpadMouseAdapter(editor,
086:                        NODENAME_DESKTOPPOPUPMENU));
087:                editor.getSettings().putObject(KEY_DESKTOPPANE, diagramPane);
088:                add(diagramPane, BorderLayout.CENTER);
089:                SwingUtilities.invokeLater(new Runnable() {
090:                    public void run() {
091:                        diagramPane.getGraph().requestFocus();
092:                    }
093:                });
094:            }
095:
096:            /**
097:             * Configures the newly created diagram pane to reflect the properties of
098:             * the specified diagram. This also installs a listener to keep the
099:             * properties of the diagram up-to-date with the graph for the next creation
100:             * after persistence.
101:             * 
102:             * @param diagramPane
103:             *            The diagram pane to be configured.
104:             * @param diagram
105:             *            The diagram to be configured.
106:             */
107:            protected void configureDiagramPane(
108:                    JGraphEditorDiagramPane diagramPane,
109:                    final JGraphEditorDiagram diagram) {
110:
111:                // Listens to JGraph properties
112:                diagramPane.getGraph().addPropertyChangeListener(
113:                        new PropertyChangeListener() {
114:
115:                            /*
116:                             * (non-Javadoc)
117:                             */
118:                            public void propertyChange(PropertyChangeEvent event) {
119:
120:                                // Checks if it's an interesting property and stores
121:                                // the interesting ones back in the diagram.
122:                                String name = event.getPropertyName();
123:                                if (name.equals(JGraph.ANTIALIASED_PROPERTY)
124:                                        || name
125:                                                .equals(JGraph.EDITABLE_PROPERTY)
126:                                        || name
127:                                                .equals(JGraph.GRID_COLOR_PROPERTY)
128:                                        || name
129:                                                .equals(JGraph.GRID_SIZE_PROPERTY)
130:                                        || name
131:                                                .equals(JGraph.GRID_VISIBLE_PROPERTY)
132:                                        || name
133:                                                .equals(JGraph.HANDLE_COLOR_PROPERTY)
134:                                        || name
135:                                                .equals(JGraph.HANDLE_SIZE_PROPERTY)
136:                                        || name
137:                                                .equals(JGraph.LOCKED_HANDLE_COLOR_PROPERTY)
138:                                        || name
139:                                                .equals(JGraph.PORTS_VISIBLE_PROPERTY)
140:                                        || name
141:                                                .equals(JGraph.PORTS_SCALED_PROPERTY)
142:                                        || name.equals(JGraph.SCALE_PROPERTY))
143:                                    if (event.getNewValue() == null) {
144:                                        diagram.getProperties().remove(
145:                                                "graph." + name);
146:                                    } else {
147:                                        diagram.getProperties().put(
148:                                                "graph." + name,
149:                                                event.getNewValue());
150:                                    }
151:                            }
152:                        });
153:
154:                // Listens to diagram pane properties
155:                diagramPane
156:                        .addPropertyChangeListener(new PropertyChangeListener() {
157:
158:                            /*
159:                             * (non-Javadoc)
160:                             */
161:                            public void propertyChange(PropertyChangeEvent event) {
162:
163:                                // Checks if it's an interesting property and stores
164:                                // the interesting ones back in the diagram.
165:                                String name = event.getPropertyName();
166:                                if (name
167:                                        .equals(JGraphEditorDiagramPane.PROPERTY_AUTOSCALEPOLICY)
168:                                        || name
169:                                                .equals(JGraphEditorDiagramPane.PROPERTY_BACKGROUNDIMAGE)
170:                                        || name
171:                                                .equals(JGraphEditorDiagramPane.PROPERTY_METRIC)
172:                                        || name
173:                                                .equals(JGraphEditorDiagramPane.PROPERTY_PAGEFORMAT)
174:                                        || name
175:                                                .equals(JGraphEditorDiagramPane.PROPERTY_PAGESCALE)
176:                                        || name
177:                                                .equals(JGraphEditorDiagramPane.PROPERTY_PAGEVISIBLE)
178:                                        || name
179:                                                .equals(JGraphEditorDiagramPane.PROPERTY_RULERSVISIBLE))
180:                                    if (event.getNewValue() == null) {
181:                                        diagram.getProperties().remove(
182:                                                "diagramPane." + name);
183:                                    } else {
184:                                        diagram.getProperties().put(
185:                                                "diagramPane." + name,
186:                                                event.getNewValue());
187:                                    }
188:                            }
189:                        });
190:
191:                // Tries to set all current properties from the diagram to the graph.
192:                // Note: A hashtable contains the object to resolve the prefixes.
193:                Map objects = new Hashtable();
194:                objects.put("diagramPane", diagramPane);
195:                objects.put("graph", diagramPane.getGraph());
196:
197:                Iterator it = diagram.getProperties().entrySet().iterator();
198:                while (it.hasNext()) {
199:                    Map.Entry entry = (Map.Entry) it.next();
200:                    setProperty(objects, String.valueOf(entry.getKey()), entry
201:                            .getValue());
202:                }
203:            }
204:
205:            /**
206:             * Utility method to set the property of an object using reflection.
207:             * 
208:             * @param objects
209:             *            Maps from prefixes to objects.
210:             * @param property
211:             *            The name of the property to be changed.
212:             * @param value
213:             *            The value of the property to be set.
214:             */
215:            public static void setProperty(Map objects, String property,
216:                    Object value) {
217:                // Analyze prefix
218:                int delim = property.indexOf('.');
219:                if (delim > 0) {
220:                    String prefix = property.substring(0, delim);
221:                    property = property.substring(delim + 1);
222:                    Object obj = objects.get(prefix);
223:                    if (obj != null) {
224:                        // Does type conversion to basic types
225:                        Class clazz = value.getClass();
226:                        if (clazz == Boolean.class)
227:                            clazz = boolean.class;
228:                        else if (clazz == Integer.class)
229:                            clazz = int.class;
230:                        else if (clazz == Long.class)
231:                            clazz = long.class;
232:                        else if (clazz == Float.class)
233:                            clazz = float.class;
234:                        else if (clazz == Double.class)
235:                            clazz = double.class;
236:                        else if (clazz == JGraphpadImageIcon.class)
237:                            clazz = ImageIcon.class;
238:                        String name = String.valueOf(property);
239:                        name = name.substring(0, 1).toUpperCase()
240:                                + name.substring(1);
241:                        try {
242:                            Method setter = obj.getClass().getMethod(
243:                                    "set" + name, new Class[] { clazz });
244:                            setter.invoke(obj, new Object[] { value });
245:                        } catch (Exception e) {
246:                            // ignore
247:                        }
248:                    }
249:                }
250:            }
251:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.