Source Code Cross Referenced for Dialog.java in  » XML-UI » xmlgui » org » beryl » gui » widgets » 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 » XML UI » xmlgui » org.beryl.gui.widgets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Beryl - A web platform based on XML, XSLT and Java
003:         * This file is part of the Beryl XML GUI
004:         *
005:         * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107  USA
020:         */
021:
022:        package org.beryl.gui.widgets;
023:
024:        import java.awt.BorderLayout;
025:        import java.awt.Component;
026:        import java.awt.Dimension;
027:        import java.awt.Point;
028:        import java.awt.event.WindowAdapter;
029:        import java.awt.event.WindowEvent;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:
033:        import javax.swing.BorderFactory;
034:        import javax.swing.JButton;
035:        import javax.swing.JDialog;
036:        import javax.swing.JFrame;
037:        import javax.swing.JPanel;
038:        import javax.swing.border.Border;
039:
040:        import org.beryl.gui.GUIEvent;
041:        import org.beryl.gui.GUIEventListener;
042:        import org.beryl.gui.GUIException;
043:        import org.beryl.gui.GUIUtils;
044:        import org.beryl.gui.Widget;
045:        import org.beryl.gui.WidgetInfo;
046:
047:        public class Dialog extends Widget {
048:            protected static WidgetInfo dialogInfo = null;
049:            private static final Border windowBorder = BorderFactory
050:                    .createEmptyBorder(WINDOW_BORDER_SPACING,
051:                            WINDOW_BORDER_SPACING, WINDOW_BORDER_SPACING,
052:                            WINDOW_BORDER_SPACING);
053:            private JDialog dialog = null;
054:            private Panel panel = null;
055:            private Button defaultButton = null;
056:            private JButton jDefaultButton = null;
057:            private boolean isModal = true;
058:            private String title = null;
059:            private HashMap closeListeners = null;
060:            private HashMap openListeners = null;
061:            private Point location = null;
062:            private String helpid = null;
063:            private boolean resizable = true;
064:
065:            static {
066:                dialogInfo = new WidgetInfo(Dialog.class, widgetInfo);
067:                dialogInfo.addProperty("border", "border", BorderFactory
068:                        .createEmptyBorder());
069:                dialogInfo.addProperty("defaultCloseOperation", "enum",
070:                        new Integer(JFrame.DISPOSE_ON_CLOSE));
071:                dialogInfo.addProperty("layout", "layout", new BorderLayout());
072:                dialogInfo
073:                        .addProperty("location", "point", new Point(100, 100));
074:                dialogInfo.addProperty("resizable", "bool", Boolean.TRUE);
075:                dialogInfo.addProperty("size", "dimension", new Dimension(100,
076:                        100));
077:                dialogInfo.addProperty("spacing", "int", new Integer(
078:                        WINDOW_BORDER_SPACING));
079:                dialogInfo.addProperty("title", "istring", "");
080:                dialogInfo.addEvent("close");
081:                dialogInfo.addEvent("open");
082:                dialogInfo.removeProperty("enabled");
083:                dialogInfo.setSupportsAnchor(false);
084:            };
085:
086:            public Dialog(Widget parent, String name) throws GUIException {
087:                super (parent, name);
088:                panel = new Panel(this , null);
089:                closeListeners = new HashMap();
090:                openListeners = new HashMap();
091:                ((JPanel) panel.getWidget()).setBorder(windowBorder);
092:                GUIUtils.register(this );
093:                addChild(panel);
094:            }
095:
096:            public Object getProperty(String name) throws GUIException {
097:                if (name.equals("default")) {
098:                    return defaultButton;
099:                } else {
100:                    return super .getProperty(name);
101:                }
102:            }
103:
104:            public void setProperty(String name, Object value)
105:                    throws GUIException {
106:                if ("layout".equals(name) || "border".equals(name)
107:                        || "spacing".equals(name) || "background".equals(name)) {
108:                    panel.setProperty(name, value);
109:                } else if ("size".equals(name)) {
110:                    /* Workaround: This makes the content and not the window have the 
111:                     * requested size. Therefore the window content and the window decoration
112:                     * will be bigger than they would be using the normal setSize() */
113:                    ((JPanel) panel.getRealWidget())
114:                            .setPreferredSize((Dimension) value);
115:                    if (dialog != null)
116:                        dialog.pack();
117:                } else if ("helpid".equals(name)) {
118:                    helpid = (String) value;
119:                } else if ("modal".equals(name)) {
120:                    isModal = ((Boolean) value).booleanValue();
121:                } else if ("visible".equals(name)) {
122:                    throw new GUIException(
123:                            "Visible is not a settable property, use Dialog's 'show' method instead");
124:                } else if ("location".equals(name)) {
125:                    location = (Point) value;
126:                    if (dialog != null)
127:                        dialog.setLocation((Point) value);
128:                } else if ("resizable".equals(name)) {
129:                    resizable = ((Boolean) value).booleanValue();
130:                    if (dialog != null)
131:                        dialog.setResizable(resizable);
132:                } else if ("default".equals(name)) {
133:                    defaultButton = (Button) value;
134:                    jDefaultButton = (JButton) defaultButton.getRealWidget();
135:                    if (dialog != null)
136:                        dialog.getRootPane().setDefaultButton(jDefaultButton);
137:                } else if ("title".equals(name)) {
138:                    title = (String) value;
139:                    if (dialog != null)
140:                        dialog.setTitle(title);
141:                } else {
142:                    if (dialog == null)
143:                        throw new GUIException("Property '" + name
144:                                + "' is not yet supported by Dialog");
145:                    super .setProperty(name, value);
146:                }
147:            }
148:
149:            protected void finalize() {
150:                GUIUtils.unregister(this );
151:            }
152:
153:            public void addChild(Widget widget, Object constraint)
154:                    throws GUIException {
155:                panel.addChild(widget, constraint);
156:            }
157:
158:            public void removeChildWidget(Widget widget) throws GUIException {
159:                panel.removeChildWidget(widget);
160:            }
161:
162:            public void addListener(String event, String name,
163:                    GUIEventListener listener) throws GUIException {
164:                if ("close".equals(event)) {
165:                    closeListeners.put(name, listener);
166:                } else if ("open".equals(event)) {
167:                    openListeners.put(name, listener);
168:                } else {
169:                    super .addListener(event, name, listener);
170:                }
171:            }
172:
173:            public void hide() {
174:                dialog.hide();
175:            }
176:
177:            public void initDialog(Widget parent) throws GUIException {
178:                if (parent == null)
179:                    dialog = new JDialog(); // this is perfectly valid
180:                else if (parent instanceof  Dialog)
181:                    dialog = new JDialog((JDialog) parent.getRealWidget(),
182:                            isModal);
183:                else if (parent instanceof  Frame)
184:                    dialog = new JDialog((JFrame) parent.getRealWidget(),
185:                            isModal);
186:                else if (parent instanceof  Wizard)
187:                    dialog = new JDialog((JFrame) parent.getRealWidget(),
188:                            isModal);
189:                else
190:                    throw new GUIException(
191:                            "Invalid parent (no Dialog/Frame/Wizard/null)");
192:            }
193:
194:            public void show() throws GUIException {
195:                if (dialog != null) {
196:                    JPanel jpanel = (JPanel) panel.getWidget();
197:                    dialog.getContentPane().add(jpanel);
198:                    if (jDefaultButton != null)
199:                        dialog.getRootPane().setDefaultButton(jDefaultButton);
200:                    if (title != null)
201:                        dialog.setTitle(title);
202:                    dialog.pack();
203:
204:                    /* Workaround for Bug 4102292
205:                     * http://developer.java.sun.com/developer/bugParade/bugs/4102292.html
206:                     */
207:                    if (location == null) {
208:                        Dimension ss = dialog.getToolkit().getScreenSize();
209:                        Dimension fs = dialog.getSize();
210:                        dialog.setLocation((ss.width - fs.width) / 2,
211:                                (ss.height - fs.height) / 2);
212:                    } else {
213:                        dialog.setLocation(location);
214:                    }
215:                    dialog.setResizable(resizable);
216:
217:                    for (Iterator i = closeListeners.keySet().iterator(); i
218:                            .hasNext();) {
219:                        final String name = (String) i.next();
220:                        final GUIEventListener listener = (GUIEventListener) closeListeners
221:                                .get(name);
222:                        dialog.addWindowListener(new WindowAdapter() {
223:                            public void windowClosing(WindowEvent e) {
224:                                listener.eventOccured(new GUIEvent(Dialog.this ,
225:                                        name, e));
226:                            }
227:                        });
228:                    }
229:                    for (Iterator i = openListeners.keySet().iterator(); i
230:                            .hasNext();) {
231:                        final String name = (String) i.next();
232:                        final GUIEventListener listener = (GUIEventListener) openListeners
233:                                .get(name);
234:                        dialog.addWindowListener(new WindowAdapter() {
235:                            public void windowOpened(WindowEvent e) {
236:                                listener.eventOccured(new GUIEvent(Dialog.this ,
237:                                        name, e));
238:                            }
239:                        });
240:                    }
241:                } else {
242:                    throw new GUIException("Initialize dialog first!");
243:                }
244:                if (helpid != null) {
245:                    if (helpBroker == null)
246:                        throw new GUIException(
247:                                "JavaHelp has not been activated");
248:                    if (helpid != null)
249:                        helpBroker.enableHelpKey(dialog.getRootPane(),
250:                                (String) helpid, null);
251:                }
252:
253:                dialog.show();
254:            }
255:
256:            /**
257:             * Set the initial focus of the dialog
258:             */
259:            public void setInitialFocus(final Widget widget)
260:                    throws GUIException {
261:                if (dialog == null)
262:                    throw new GUIException(
263:                            "The dialog has not yet been created. Call setInitialFocus() after initDialog()");
264:                dialog.addWindowListener(new WindowAdapter() {
265:                    public void windowOpened(WindowEvent e) {
266:                        widget.requestFocus();
267:                        e.getWindow().removeWindowListener(this );
268:                    }
269:                });
270:            }
271:
272:            public Widget getChild(int index) {
273:                return (Widget) panel.getChild(index);
274:            }
275:
276:            public int getChildIndex(Widget child) {
277:                return panel.getChildIndex(child);
278:            }
279:
280:            public int getChildCount() {
281:                return panel.getChildCount();
282:            }
283:
284:            public void dispose() {
285:                dialog.dispose();
286:            }
287:
288:            public void revalidate() throws GUIException {
289:                panel.revalidate();
290:            }
291:
292:            public Panel getPanel() {
293:                return panel;
294:            }
295:
296:            public Component getWidget() {
297:                return dialog;
298:            }
299:
300:            public WidgetInfo getWidgetInfo() {
301:                return dialogInfo;
302:            }
303:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.