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


001:        /* 
002:         * $Id: JGraphEditorAction.java,v 1.4 2007/07/27 14:15:59 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;
011:
012:        import java.awt.Component;
013:        import java.awt.Frame;
014:        import java.awt.KeyboardFocusManager;
015:        import java.awt.Window;
016:        import java.awt.event.ActionEvent;
017:
018:        import javax.swing.AbstractAction;
019:        import javax.swing.Action;
020:        import javax.swing.JFrame;
021:        import javax.swing.SwingUtilities;
022:
023:        import org.jgraph.JGraph;
024:
025:        import com.jgraph.editor.factory.JGraphEditorDiagramPane;
026:        import com.jgraph.editor.factory.JGraphEditorNavigator;
027:        import com.jgraph.pad.factory.JGraphpadPane;
028:
029:        /**
030:         * The base class for all actions in a JGraph editor kit. An action may be
031:         * toggleable, in which case the UI factory will create an element that displays
032:         * the action's selection state, and listen to changes of this state to update
033:         * the element. The enabled state will also be listened to and the UI elements
034:         * will be updated accordingly.
035:         */
036:        public abstract class JGraphEditorAction extends AbstractAction {
037:
038:            /**
039:             * Bean property name for <code>isSelected</code>
040:             */
041:            public final static String PROPERTY_ISSELECTED = new String(
042:                    "isSelected");
043:
044:            /**
045:             * Bean property name for <code>isVisible</code>
046:             */
047:            public final static String PROPERTY_ISVISIBLE = new String(
048:                    "isVisible");
049:
050:            /**
051:             * Holds the toggleable state.
052:             */
053:            protected boolean isToggleAction;
054:
055:            public void setEnabled(boolean newValue) {
056:                super .setEnabled(newValue);
057:            }
058:
059:            /**
060:             * Constructs a new action for the specified name
061:             * 
062:             * @param name
063:             *            The name of the new action.
064:             */
065:            public JGraphEditorAction(String name) {
066:                this (name, false);
067:            }
068:
069:            /**
070:             * Constructs a new action for the specified <code>name</code> and
071:             * <code>isToggleAction</code> state.
072:             * 
073:             * @param name
074:             *            The name of the new action.
075:             * @param isToggleAction
076:             *            Whether the action is a toggle action.
077:             */
078:            public JGraphEditorAction(String name, boolean isToggleAction) {
079:                super (name);
080:                setToggleAction(isToggleAction);
081:            }
082:
083:            /**
084:             * Returns the name.
085:             */
086:            public String getName() {
087:                return String.valueOf(getValue(Action.NAME));
088:            }
089:
090:            /**
091:             * Returns whether the UI elements should display the selection state.
092:             * 
093:             * @return Returns true if the action is toggleable.
094:             */
095:            public boolean isToggleAction() {
096:                return isToggleAction;
097:            }
098:
099:            /**
100:             * Sets whether the UI elements should display the selection state.
101:             * 
102:             * @param isToggleAction
103:             *            The isToggleAction state to set.
104:             */
105:            public void setToggleAction(boolean isToggleAction) {
106:                this .isToggleAction = isToggleAction;
107:            }
108:
109:            /**
110:             * Returns the selection state.
111:             * 
112:             * @return Returns true if the action is selected.
113:             */
114:            public boolean isSelected() {
115:                Boolean isSelected = (Boolean) getValue(PROPERTY_ISSELECTED);
116:                if (isSelected != null)
117:                    return isSelected.booleanValue();
118:                return false;
119:            }
120:
121:            /**
122:             * Sets the selection state. Dispatches a change event.
123:             * 
124:             * @param selected
125:             *            The selected state to set.
126:             * 
127:             * @see Action#putValue(java.lang.String, java.lang.Object)
128:             */
129:            public void setSelected(boolean selected) {
130:                putValue(PROPERTY_ISSELECTED, new Boolean(selected));
131:            }
132:
133:            /**
134:             * Returns the visible state.
135:             * 
136:             * @return Returns true if the action is visible.
137:             */
138:            public boolean isVisible() {
139:                Boolean isVisible = (Boolean) getValue(PROPERTY_ISVISIBLE);
140:                if (isVisible != null)
141:                    return isVisible.booleanValue();
142:                return false;
143:            }
144:
145:            /**
146:             * Sets the visible state. Dispatches a change event.
147:             * 
148:             * @param visible
149:             *            The visible state to set.
150:             * 
151:             * @see Action#putValue(java.lang.String, java.lang.Object)
152:             */
153:            public void setVisible(boolean visible) {
154:                putValue(PROPERTY_ISVISIBLE, new Boolean(visible));
155:            }
156:
157:            /**
158:             * Shortcut method to {@link JGraphEditorResources#getString(String)}.
159:             * 
160:             * @param key
161:             *            The key to return the resource string for.
162:             */
163:            public static String getString(String key) {
164:                return JGraphEditorResources.getString(key);
165:            }
166:
167:            /**
168:             * Returns the frame for <code>event</code> if the even source is a
169:             * Component or the active frame.
170:             * 
171:             * @param event
172:             *            The event to get the frame from.
173:             * @return Returns the frame for <code>event</code> or the active frame.
174:             * 
175:             * @see #getActiveFrame()
176:             */
177:            public static Frame getFrame(ActionEvent event) {
178:                Window wnd = null;
179:                if (event != null && event.getSource() instanceof  Component)
180:                    wnd = SwingUtilities.windowForComponent((Component) event
181:                            .getSource());
182:                Frame frame = (wnd instanceof  Frame) ? (Frame) wnd
183:                        : getActiveFrame();
184:                return frame;
185:            }
186:
187:            /**
188:             * Returns the permanent focus owner.
189:             * 
190:             * @return Returns the permanent focus owner.
191:             * 
192:             * @see KeyboardFocusManager#getPermanentFocusOwner()
193:             */
194:            public static Component getPermanentFocusOwner() {
195:                return KeyboardFocusManager.getCurrentKeyboardFocusManager()
196:                        .getPermanentFocusOwner();
197:            }
198:
199:            /**
200:             * Returns the permanent focus owner or the parent scroll pane of it.
201:             * 
202:             * @return Returns the permanent focus owner or its parent scroll pane.
203:             * 
204:             * @see KeyboardFocusManager#getPermanentFocusOwner()
205:             */
206:            public static Component getPermanentFocusOwnerOrParent() {
207:                Component comp = KeyboardFocusManager
208:                        .getCurrentKeyboardFocusManager()
209:                        .getPermanentFocusOwner();
210:                Component tmp = JGraphEditorNavigator.getParentScrollPane(comp);
211:                if (tmp != null)
212:                    comp = tmp;
213:                return comp;
214:            }
215:
216:            /**
217:             * Returns the permanent focus owner graph.
218:             * 
219:             * @return Returns the permanent focus owner graph.
220:             * 
221:             * @see KeyboardFocusManager#getPermanentFocusOwner()
222:             */
223:            public static JGraph getPermanentFocusOwnerGraph() {
224:                return getParentGraph(KeyboardFocusManager
225:                        .getCurrentKeyboardFocusManager()
226:                        .getPermanentFocusOwner());
227:            }
228:
229:            /**
230:             * Returns the diagram for the diagram pane that has the focus.
231:             * 
232:             * @return Returns the focused diagram.
233:             */
234:            public static JGraphEditorDiagram getPermanentFocusOwnerDiagram() {
235:                JGraphEditorDiagramPane diagramPane = getPermanentFocusOwnerDiagramPane();
236:                if (diagramPane != null)
237:                    return diagramPane.getDiagram();
238:                return null;
239:            }
240:
241:            /**
242:             * Returns the diagram pane that contains the permanent focus owner.
243:             */
244:            public static JGraphEditorDiagramPane getPermanentFocusOwnerDiagramPane() {
245:                return JGraphEditorDiagramPane
246:                        .getParentDiagramPane(getPermanentFocusOwner());
247:            }
248:
249:            /**
250:             * Returns the first active frame.
251:             * 
252:             * @return Returns the active frame.
253:             * 
254:             * @see Window#isActive()
255:             */
256:            public static Frame getActiveFrame() {
257:                Frame[] frames = JFrame.getFrames();
258:                for (int i = 0; i < frames.length; i++)
259:                    if (frames[i].isActive())
260:                        return frames[i];
261:                return null;
262:            }
263:
264:            /**
265:             * Returns the JGraphpadPane inside the active frame.
266:             * 
267:             * @return Returns the JGraphpad pane for the given frame.
268:             */
269:            public static JGraphpadPane getJGraphpadPane() {
270:                Frame frame = getActiveFrame();
271:
272:                if (frame instanceof  JFrame) {
273:                    return getJGraphpadPane((JFrame) frame);
274:                }
275:
276:                return null;
277:            }
278:
279:            /**
280:             * Returns the JGraphpadPane inside the given frame.
281:             * 
282:             * @return Returns the JGraphpad pane for the given frame.
283:             */
284:            public static JGraphpadPane getJGraphpadPane(JFrame frame) {
285:                int childCount = frame.getContentPane().getComponentCount();
286:
287:                for (int i = 0; i < childCount; i++) {
288:                    try {
289:                        Component comp = frame.getContentPane().getComponent(i);
290:
291:                        if (comp instanceof  JGraphpadPane) {
292:                            return (JGraphpadPane) comp;
293:                        }
294:                    } catch (Exception e) {
295:                        e.printStackTrace();
296:                    }
297:                }
298:
299:                return null;
300:            }
301:
302:            /**
303:             * Returns the parent diagram pane of the specified component, or the
304:             * component itself if it is a editor diagram pane.
305:             * 
306:             * @return Returns the parent editor diagram pane of <code>component</code>.
307:             */
308:            public static JGraph getParentGraph(Component component) {
309:                while (component != null) {
310:                    if (component instanceof  JGraph)
311:                        return (JGraph) component;
312:                    component = component.getParent();
313:                }
314:                return null;
315:            }
316:
317:            /**
318:             * An interface to manage a set of actions as a single entity.
319:             * 
320:             * @see JGraphEditorKit#addBundle(JGraphEditorAction.Bundle)
321:             */
322:            public interface Bundle {
323:
324:                /**
325:                 * Returns all actions contained in the bundle.
326:                 * 
327:                 * @return Returns all actions.
328:                 */
329:                public JGraphEditorAction[] getActions();
330:
331:                /**
332:                 * Updates all action states.
333:                 */
334:                public void update();
335:
336:            }
337:
338:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.