Source Code Cross Referenced for FrameControllerList.java in  » Development » rapla » org » rapla » gui » toolkit » 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 » Development » rapla » org.rapla.gui.toolkit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*--------------------------------------------------------------------------*
002:         | Copyright (C) 2006 Christopher Kohlhaas                                  |
003:         |                                                                          |
004:         | This program is free software; you can redistribute it and/or modify     |
005:         | it under the terms of the GNU General Public License as published by the |
006:         | Free Software Foundation. A copy of the license has been included with   |
007:         | these distribution in the COPYING file, if not go to www.fsf.org         |
008:         |                                                                          |
009:         | As a special exception, you are granted the permissions to link this     |
010:         | program with every library, which license fulfills the Open Source       |
011:         | Definition as published by the Open Source Initiative (OSI).             |
012:         *--------------------------------------------------------------------------*/
013:        package org.rapla.gui.toolkit;
014:
015:        import java.awt.Component;
016:        import java.awt.Container;
017:        import java.awt.Dimension;
018:        import java.awt.Point;
019:        import java.awt.Toolkit;
020:        import java.awt.Window;
021:        import java.util.ArrayList;
022:        import java.util.Stack;
023:
024:        import org.apache.avalon.framework.logger.LogEnabled;
025:        import org.apache.avalon.framework.logger.Logger;
026:        import org.rapla.components.util.Assert;
027:        import org.rapla.components.util.Tools;
028:
029:        /**All rapla-windows are registered on the FrameControllerList.
030:         The FrameControllerList is responsible for positioning the windows
031:         and closing all open windows on exit.
032:         */
033:        final public class FrameControllerList implements  LogEnabled {
034:            public final static String ROLE = FrameControllerList.class
035:                    .getName();
036:            private Stack openFrameController = new Stack();
037:            private Window mainWindow = null;
038:            Point center;
039:            Logger logger = null;
040:            ArrayList listenerList = new ArrayList();
041:
042:            public FrameControllerList() {
043:                Dimension screenSize = Toolkit.getDefaultToolkit()
044:                        .getScreenSize();
045:                center = new Point(screenSize.width / 2, screenSize.height / 2);
046:            }
047:
048:            public void enableLogging(Logger logger) {
049:                this .logger = logger;
050:            }
051:
052:            protected Logger getLogger() {
053:                return logger;
054:            }
055:
056:            /** the center will be used by the
057:                <code>centerWindow()</code> function. */
058:            public void setCenter(Container window) {
059:                center.x = window.getLocationOnScreen().x
060:                        + window.getSize().width / 2;
061:                center.y = window.getLocationOnScreen().y
062:                        + window.getSize().height / 2;
063:            }
064:
065:            /** the center will be used by the
066:                <code>centerWindow(Window)</code> function.
067:                @see #centerWindow(Window)
068:             */
069:            public void setCenter(Point center) {
070:                this .center = center;
071:            }
072:
073:            /** the main-window will be used by the
074:                <code>placeRelativeToMain(Window)</code> function.
075:                @see #placeRelativeToMain(Window)
076:             */
077:            public void setMainWindow(Window window) {
078:                this .mainWindow = window;
079:            }
080:
081:            public Window getMainWindow() {
082:                return mainWindow;
083:            }
084:
085:            /** places the window relative to the main-window if set.
086:                Otherwise the the <code>centerWindow(Window)</code> method is called.
087:                @param newWindow the window to place
088:             */
089:            public void placeRelativeToMain(Window newWindow) {
090:                if (getLogger() != null && getLogger().isDebugEnabled()
091:                        && mainWindow != null)
092:                    getLogger().debug(
093:                            "placeRelativeToMainWindow("
094:                                    + Tools.left(mainWindow.toString(), 60)
095:                                    + ")");
096:                if (mainWindow == null)
097:                    centerWindow(newWindow);
098:                else
099:                    placeRelativeToWindow(newWindow, mainWindow);
100:            }
101:
102:            /** adds a window to the FrameControllerList */
103:            public void add(FrameController c) {
104:                Assert.notNull(c);
105:                Assert.isTrue(!openFrameController.contains(c),
106:                        "Duplicated Entries are not allowed");
107:                openFrameController.add(c);
108:            }
109:
110:            /** removes a window from the FrameControllerList */
111:            public void remove(FrameController c) {
112:                openFrameController.remove(c);
113:                String s = c.toString();
114:                if (getLogger() != null && getLogger().isDebugEnabled())
115:                    getLogger().debug(
116:                            "Frame closed " + Tools.left(s, 60) + "...");
117:                fireFrameClosed(c);
118:                if (openFrameController.size() == 0)
119:                    fireListEmpty();
120:            }
121:
122:            /** closes all windows registered on the FrameControllerList */
123:            public void closeAll() {
124:                while (!openFrameController.empty()) {
125:                    FrameController c = (FrameController) openFrameController
126:                            .peek();
127:                    int size = openFrameController.size();
128:                    c.close();
129:                    if (size <= openFrameController.size())
130:                        getLogger().error(
131:                                "removeFrameController() not called in close() in "
132:                                        + c);
133:                }
134:            }
135:
136:            public void addFrameControllerListener(
137:                    FrameControllerListener listener) {
138:                listenerList.add(listener);
139:            }
140:
141:            public void removeFrameControllerListener(
142:                    FrameControllerListener listener) {
143:                listenerList.remove(listener);
144:            }
145:
146:            public FrameControllerListener[] getFrameControllerListeners() {
147:                synchronized (listenerList) {
148:                    return (FrameControllerListener[]) listenerList
149:                            .toArray(new FrameControllerListener[] {});
150:                }
151:            }
152:
153:            protected void fireFrameClosed(FrameController controller) {
154:                if (listenerList.size() == 0)
155:                    return;
156:                FrameControllerListener[] listeners = getFrameControllerListeners();
157:                for (int i = 0; i < listeners.length; i++) {
158:                    listeners[i].frameClosed(controller);
159:                }
160:            }
161:
162:            protected void fireListEmpty() {
163:                if (listenerList.size() == 0)
164:                    return;
165:                FrameControllerListener[] listeners = getFrameControllerListeners();
166:                for (int i = 0; i < listeners.length; i++) {
167:                    listeners[i].listEmpty();
168:                }
169:            }
170:
171:            /** centers the window around the specified center */
172:            public void centerWindow(Window window) {
173:                Dimension preferredSize = window.getSize();
174:                int x = center.x - (preferredSize.width / 2);
175:                int y = center.y - (preferredSize.height / 2);
176:                fitIntoScreen(x, y, window);
177:            }
178:
179:            /** centers the window around the specified center */
180:            static public void centerWindowOnScreen(Window window) {
181:                Dimension screenSize = Toolkit.getDefaultToolkit()
182:                        .getScreenSize();
183:                Dimension preferredSize = window.getSize();
184:                int x = screenSize.width / 2 - (preferredSize.width / 2);
185:                int y = screenSize.height / 2 - (preferredSize.height / 2);
186:                fitIntoScreen(x, y, window);
187:            }
188:
189:            /** Tries to place the window, that it fits into the screen. */
190:            static public void fitIntoScreen(int x, int y, Component window) {
191:                Dimension screenSize = Toolkit.getDefaultToolkit()
192:                        .getScreenSize();
193:                Dimension windowSize = window.getSize();
194:                if (x + windowSize.width > screenSize.width)
195:                    x = screenSize.width - windowSize.width;
196:
197:                if (y + windowSize.height > screenSize.height)
198:                    y = screenSize.height - windowSize.height;
199:
200:                if (x < 0)
201:                    x = 0;
202:                if (y < 0)
203:                    y = 0;
204:                window.setLocation(x, y);
205:            }
206:
207:            /** places the window relative to the owner-window.
208:                The newWindow will be placed in the middle of the owner-window.
209:                @param newWindow the window to place
210:                @param owner the window to place into
211:             */
212:            public static void placeRelativeToWindow(Window newWindow,
213:                    Window owner) {
214:                placeRelativeToComponent(newWindow, owner, null);
215:            }
216:
217:            public static void placeRelativeToComponent(Window newWindow,
218:                    Component component, Point point) {
219:                if (component == null)
220:                    return;
221:                Dimension dlgSize = newWindow.getSize();
222:                Dimension parentSize = component.getSize();
223:                Point loc = component.getLocationOnScreen();
224:
225:                if (point != null) {
226:                    int x = loc.x + point.x - (dlgSize.width) / 2;
227:                    int y = loc.y + point.y - ((dlgSize.height) * 2) / 3;
228:                    //System.out.println (loc + ",  " + point + " x: " + x + " y: " + y);
229:                    fitIntoScreen(x, y, newWindow);
230:                } else {
231:                    int x = (parentSize.width - dlgSize.width) / 2 + loc.x;
232:                    int y = loc.y + 10;
233:                    fitIntoScreen(x, y, newWindow);
234:                }
235:            }
236:
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.