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


001:        /* 
002:         * $Id: JGraphpadL2FPropertySheet.java,v 1.4 2005/08/28 21:28:32 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.l2fplugin;
011:
012:        import java.awt.Component;
013:        import java.awt.geom.Point2D;
014:        import java.awt.geom.Rectangle2D;
015:        import java.beans.PropertyChangeEvent;
016:        import java.beans.PropertyChangeListener;
017:        import java.util.Iterator;
018:        import java.util.List;
019:        import java.util.Map;
020:
021:        import org.jgraph.JGraph;
022:        import org.jgraph.graph.GraphConstants;
023:        import org.jgraph.graph.PortView;
024:        import org.w3c.dom.Node;
025:
026:        import com.jgraph.editor.JGraphEditorResources;
027:        import com.jgraph.editor.factory.JGraphEditorFactoryMethod;
028:        import com.jgraph.pad.graph.JGraphpadBusinessObject;
029:        import com.jgraph.pad.util.JGraphpadFocusManager;
030:        import com.l2fprod.common.propertysheet.DefaultProperty;
031:        import com.l2fprod.common.propertysheet.Property;
032:        import com.l2fprod.common.propertysheet.PropertySheetPanel;
033:
034:        /**
035:         * Property sheet to display cell and user object properties.
036:         */
037:        public class JGraphpadL2FPropertySheet extends PropertySheetPanel {
038:
039:            /**
040:             * Constructs a new property sheet.
041:             */
042:            public JGraphpadL2FPropertySheet() {
043:                setSortingProperties(true);
044:                setBorder(null);
045:            }
046:
047:            /**
048:             * Updates the display properties to show the properties of the selection
049:             * cell in the specified graph.
050:             * 
051:             * @param graph
052:             *            The graph to display the selection cell properties for.
053:             */
054:            public void update(JGraph graph) {
055:                if (graph != null && !graph.isSelectionEmpty()) {
056:                    Object cell = graph.getSelectionCell();
057:                    Map attrs = graph.getModel().getAttributes(cell);
058:                    Property[] properties = createProperties(
059:                            JGraphEditorResources.getString("Graph"), attrs,
060:                            createPropertyChangeListener(graph, cell));
061:
062:                    // Adds the business object properties to the array
063:                    Object obj = graph.getModel().getValue(cell);
064:                    if (obj instanceof  JGraphpadBusinessObject) {
065:                        Property[] tmp1 = createProperties(
066:                                JGraphEditorResources.getString("Business"),
067:                                ((JGraphpadBusinessObject) obj).getProperties(),
068:                                createPropertyChangeListener(graph, obj));
069:                        Property[] tmp2 = properties;
070:                        properties = new Property[tmp1.length + tmp2.length];
071:                        System.arraycopy(tmp1, 0, properties, 0, tmp1.length);
072:                        System.arraycopy(tmp2, 0, properties, tmp1.length,
073:                                tmp2.length);
074:                    }
075:                    setProperties(properties);
076:                } else {
077:                    // Resets properties
078:                    //setProperties(new Property[0]);
079:                }
080:            }
081:
082:            /**
083:             * Creates an array of properties out of the key, value pairs in the
084:             * specified map using the specified category.
085:             * 
086:             * @param map
087:             *            The map that contains the key, value pairs to be added.
088:             * @param category
089:             *            The category of the new properties.
090:             * @return Returns an array of properties for <code>map</code>.
091:             */
092:            protected Property[] createProperties(String category, Map map,
093:                    PropertyChangeListener listener) {
094:                Property[] properties = new Property[map.size()];
095:                Iterator it = map.entrySet().iterator();
096:                int i = 0;
097:                while (it.hasNext()) {
098:                    Map.Entry entry = (Map.Entry) it.next();
099:                    properties[i++] = createProperty(category, String
100:                            .valueOf(entry.getKey()), entry.getValue(),
101:                            listener);
102:                }
103:                return properties;
104:            }
105:
106:            /**
107:             * Creates a new property using the specified name, value and category.
108:             * 
109:             * @param name
110:             *            The name of the property to be created.
111:             * @param value
112:             *            The value of the property to be created.
113:             * @param category
114:             *            The category of the new property.
115:             * @return Returns a new property.
116:             */
117:            protected Property createProperty(String category, String name,
118:                    Object value, PropertyChangeListener listener) {
119:                DefaultProperty property = new DefaultProperty();
120:                property.setDisplayName(name);
121:                property.setShortDescription(name);
122:                property.setName(name);
123:                property.setType(value.getClass());
124:                property.setValue(convertValue(value));
125:                property.setEditable(listener != null);
126:                property.setCategory(category);
127:                if (listener != null)
128:                    property.addPropertyChangeListener(listener);
129:                return property;
130:            }
131:
132:            /**
133:             * Converts the value to a string representation if it is not supported as
134:             * an editable value by the property sheet.
135:             */
136:            public Object convertValue(Object value) {
137:                if (value instanceof  Rectangle2D) {
138:                    Rectangle2D rect = (Rectangle2D) value;
139:                    value = "[x=" + rect.getX() + ", y=" + rect.getY() + ", w="
140:                            + rect.getWidth() + ", h=" + rect.getHeight() + "]";
141:                } else if (value instanceof  PortView) {
142:                    PortView pv = (PortView) value;
143:                    Point2D p = pv.getLocation();
144:                    value = "port[null]";
145:                    if (p != null)
146:                        value = "port[x=" + p.getX() + ", y=" + p.getY() + "]";
147:                } else if (value instanceof  Point2D) {
148:                    Point2D p = (Point2D) value;
149:                    value = "[x=" + p.getX() + ", y=" + p.getY() + "]";
150:                } else if (value instanceof  List) {
151:                    String entries = "";
152:                    Iterator it = ((List) value).iterator();
153:                    if (it.hasNext())
154:                        entries = String.valueOf(convertValue(it.next()));
155:                    while (it.hasNext())
156:                        entries += ", "
157:                                + String.valueOf(convertValue(it.next()));
158:                    value = entries;
159:                }
160:                return value;
161:            }
162:
163:            /**
164:             * Creates a property change listener that uses the specified keyCell to add
165:             * an entry to the nested map for the changed attributes.
166:             * 
167:             * @param graph
168:             *            The graph to be used for changing the key cell.
169:             * @param keyCell
170:             *            The object to be used as a key in the nested map.
171:             */
172:            protected PropertyChangeListener createPropertyChangeListener(
173:                    final JGraph graph, final Object keyCell) {
174:                return new PropertyChangeListener() {
175:                    public void propertyChange(PropertyChangeEvent arg0) {
176:                        Property source = (Property) arg0.getSource();
177:                        Map nested = GraphConstants.createAttributes(keyCell,
178:                                source.getName(), arg0.getNewValue());
179:
180:                        // Checks if we're dealing with a business object and
181:                        // redirect the edit call to the model if we do.
182:                        if (!graph.getModel().contains(keyCell))
183:                            graph.getModel().edit(nested, null, null, null);
184:                        else
185:                            graph.getGraphLayoutCache().edit(nested, null,
186:                                    null, null);
187:                    }
188:                };
189:            }
190:
191:            public static class FactoryMethod extends JGraphEditorFactoryMethod {
192:
193:                /**
194:                 * Defines the default name for factory methods of this kind.
195:                 */
196:                public static String NAME = "createPropertySheet";
197:
198:                /**
199:                 * Constructs a new factory method using {@link #NAME}.
200:                 */
201:                public FactoryMethod() {
202:                    super (NAME);
203:                }
204:
205:                /*
206:                 * (non-Javadoc)
207:                 */
208:                public Component createInstance(Node configuration) {
209:                    final JGraphpadL2FPropertySheet propertySheet = new JGraphpadL2FPropertySheet();
210:                    propertySheet.setSortingCategories(true);
211:                    propertySheet.setFocusable(false);
212:                    // Updates the property sheet on selection, model and layout cache
213:                    // changes.
214:                    final JGraphpadFocusManager focusedGraph = JGraphpadFocusManager
215:                            .getCurrentGraphFocusManager();
216:                    focusedGraph
217:                            .addPropertyChangeListener(new PropertyChangeListener() {
218:                                public void propertyChange(PropertyChangeEvent e) {
219:                                    String prop = e.getPropertyName();
220:                                    JGraph graph = focusedGraph
221:                                            .getFocusedGraph();
222:                                    if (JGraphpadFocusManager.SELECTION_CHANGE_NOTIFICATION
223:                                            .equals(prop)
224:                                            || JGraphpadFocusManager.MODEL_CHANGE_NOTIFICATION
225:                                                    .equals(prop)
226:                                            || JGraphpadFocusManager.UNDOABLE_CHANGE_NOTIFICATION
227:                                                    .equals(prop)
228:                                            || JGraphpadFocusManager.FOCUSED_GRAPH_PROPERTY
229:                                                    .equals(prop)) {
230:
231:                                        // This is fired when switching from the graph
232:                                        // to the property panel for example and should
233:                                        // be ignored.
234:                                        if (prop
235:                                                .equals(JGraphpadFocusManager.FOCUSED_GRAPH_PROPERTY)
236:                                                && e.getNewValue() == null)
237:                                            return;
238:                                        propertySheet.update(graph);
239:                                    }
240:                                }
241:                            });
242:
243:                    return propertySheet;
244:                }
245:
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.