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


001:        /* 
002:         * $Id: JGraphEditorToolbox.java,v 1.5 2006/02/03 17:31:13 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.editor.factory;
011:
012:        import java.awt.Graphics;
013:        import java.awt.event.MouseEvent;
014:
015:        import javax.swing.AbstractButton;
016:        import javax.swing.JToolBar;
017:
018:        import org.jgraph.JGraph;
019:        import org.jgraph.graph.BasicMarqueeHandler;
020:        import org.w3c.dom.Node;
021:
022:        import com.jgraph.editor.JGraphEditorFactory;
023:        import com.jgraph.editor.JGraphEditorTool;
024:
025:        /**
026:         * A toolbox that contains a set of tools to be installed as marquee handlers in
027:         * a graph. Toolboxes are created using the built-in
028:         * {@link JGraphEditorFactory#createToolbox(Node)}.
029:         */
030:        public class JGraphEditorToolbox extends JToolBar {
031:
032:            /**
033:             * Specifies whether the toolbox should select the default button after a
034:             * gesture with another tool if the default button exists. By default, the
035:             * default button is assigned to be the first inserted button (see
036:             * JGraphEditorFactory.configureToolbox) and the default for this value is
037:             * false.
038:             */
039:            public static boolean SWITCH_BACK = false;
040:
041:            /**
042:             * Holds the marquee redirector.
043:             */
044:            protected BasicMarqueeHandler redirector = new MarqueeRedirector();
045:
046:            /**
047:             * References the previous marquee handler.
048:             */
049:            protected BasicMarqueeHandler previousMarqueeHandler = null;
050:
051:            /**
052:             * References the tool that is currently selected, ie the tool that is used
053:             * to interact with the graph.
054:             */
055:            protected JGraphEditorTool selectionTool;
056:
057:            /**
058:             * References the default tool button which is activated after the use of
059:             * any other tool.
060:             */
061:            protected AbstractButton defaultButton;
062:
063:            /**
064:             * References the graph that is currently installed, ie the graph that is
065:             * used to interact with the selection tool.
066:             */
067:            protected JGraph graph;
068:
069:            /**
070:             * Constructs a new toolbox.
071:             */
072:            public JGraphEditorToolbox() {
073:                super ();
074:            }
075:
076:            /**
077:             * Returns the installed graph.
078:             * 
079:             * @return Returns the installed graph.
080:             */
081:            public JGraph getGraph() {
082:                return graph;
083:            }
084:
085:            /**
086:             * Sets the installed graph and restores the marquee handler on the
087:             * previously installed graph.
088:             * 
089:             * @param newGraph
090:             *            The graph to be installed.
091:             */
092:            public void setGraph(JGraph newGraph) {
093:                JGraph oldGraph = getGraph();
094:                if (oldGraph != newGraph) {
095:                    if (oldGraph != null)
096:                        oldGraph.setMarqueeHandler(previousMarqueeHandler);
097:                    previousMarqueeHandler = newGraph.getMarqueeHandler();
098:                    newGraph.setMarqueeHandler(redirector);
099:                    this .graph = newGraph;
100:                }
101:            }
102:
103:            /**
104:             * Sets the default tool, which is activated after single use of any other
105:             * tool.
106:             * 
107:             * @param defaultTool
108:             *            The default tool to be used.
109:             */
110:            public void setDefaultButton(AbstractButton defaultButton) {
111:                this .defaultButton = defaultButton;
112:            }
113:
114:            /**
115:             * Returns the selected tool.
116:             * 
117:             * @return Returns the selected tool.
118:             */
119:            public JGraphEditorTool getSelectionTool() {
120:                return selectionTool;
121:            }
122:
123:            /**
124:             * Sets the selected tool.
125:             * 
126:             * @param selectionTool
127:             *            The tool to be selected.
128:             */
129:            public void setSelectionTool(JGraphEditorTool selectionTool) {
130:                this .selectionTool = selectionTool;
131:            }
132:
133:            /**
134:             * A class that redirects marquee events to the marquee handler it replaces
135:             * or to the selection tool of the enclosing toolbox depending on the return
136:             * value of {@link BasicMarqueeHandler#isForceMarqueeEvent(MouseEvent)} of
137:             * the {@link JGraphEditorToolbox#previousMarqueeHandler}.
138:             */
139:            public class MarqueeRedirector extends BasicMarqueeHandler {
140:
141:                /**
142:                 * Indicates whether the initial isForceMarqueeEvent returned true.
143:                 */
144:                protected boolean redirect = false;
145:
146:                /**
147:                 * Returns true if the tool wants to take control of an interaction, ie.
148:                 * if it handles the sequence of events, or if the previous marquee
149:                 * handler wants to do so.
150:                 * 
151:                 * @param event
152:                 *            The object that describes the event.
153:                 * @return Returns the true if the event is handled.
154:                 */
155:                public boolean isForceMarqueeEvent(MouseEvent event) {
156:                    if (previousMarqueeHandler != null
157:                            && previousMarqueeHandler
158:                                    .isForceMarqueeEvent(event)) {
159:                        redirect = true;
160:                        return true;
161:                    } else if (selectionTool != null)
162:                        return selectionTool.isAlwaysActive()
163:                                || selectionTool.isForceMarqueeEvent(event);
164:                    return false;
165:                }
166:
167:                /**
168:                 * Overrides the basic marquee handler by redirecting to the previous
169:                 * marquee handler or selection tool's mousePressed method.
170:                 * 
171:                 * @param event
172:                 *            The object that describes the event.
173:                 */
174:                public void mousePressed(MouseEvent event) {
175:                    if (redirect || selectionTool == null)
176:                        previousMarqueeHandler.mousePressed(event);
177:                    else
178:                        selectionTool.mousePressed(event);
179:                }
180:
181:                /**
182:                 * Overrides the basic marquee handler by redirecting to the previous
183:                 * marquee handler or selection tool's mouseDragged method.
184:                 * 
185:                 * @param event
186:                 *            The object that describes the event.
187:                 */
188:                public void mouseDragged(MouseEvent event) {
189:                    if (redirect || selectionTool == null)
190:                        previousMarqueeHandler.mouseDragged(event);
191:                    else
192:                        selectionTool.mouseDragged(event);
193:                }
194:
195:                /**
196:                 * Overrides the basic marquee handler by redirecting to the previous
197:                 * marquee handler or selection tool's mouseReleased method.
198:                 * 
199:                 * @param event
200:                 *            The object that describes the event.
201:                 */
202:                public void mouseReleased(MouseEvent event) {
203:                    if (redirect || selectionTool == null) {
204:                        redirect = false;
205:                        previousMarqueeHandler.mouseReleased(event);
206:                    } else
207:                        selectionTool.mouseReleased(event);
208:
209:                    // Switches back to the default button
210:                    if (SWITCH_BACK && defaultButton != null
211:                            && !defaultButton.isSelected()) {
212:                        defaultButton.setSelected(true);
213:                    }
214:                }
215:
216:                /**
217:                 * Overrides the basic marquee handler to display the selection tool
218:                 * cursor and redirect to the selection tool.
219:                 * 
220:                 * @param event
221:                 *            The object that describes the event.
222:                 */
223:                public void mouseMoved(MouseEvent event) {
224:                    if (selectionTool == null
225:                            || previousMarqueeHandler != null
226:                            && previousMarqueeHandler
227:                                    .isForceMarqueeEvent(event))
228:                        previousMarqueeHandler.mouseMoved(event);
229:                    else
230:                        selectionTool.mouseMoved(event);
231:                }
232:
233:                /**
234:                 * Overrides the paint method to redirect to the selection tool.
235:                 * 
236:                 * @param graph
237:                 *            The graph to perform the preview in.
238:                 * @param g
239:                 *            The graphics object to be used for painting.
240:                 */
241:                public void paint(JGraph graph, Graphics g) {
242:                    if (redirect || selectionTool == null)
243:                        previousMarqueeHandler.paint(graph, g);
244:                    else
245:                        selectionTool.paint(graph, g);
246:                }
247:
248:                /**
249:                 * Overrides the overlay method to redirect to the selection tool.
250:                 * 
251:                 * @param graph
252:                 *            The graph to perform the preview in.
253:                 * @param g
254:                 *            The graphics object to be used for painting.
255:                 * @param clear
256:                 *            Specifies if the canvas should be cleared.
257:                 */
258:                public void overlay(JGraph graph, Graphics g, boolean clear) {
259:                    if (redirect || selectionTool == null)
260:                        previousMarqueeHandler.overlay(graph, g, clear);
261:                    else
262:                        selectionTool.overlay(graph, g, clear);
263:                }
264:
265:            }
266:
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.