Source Code Cross Referenced for WingMessageBox.java in  » Web-Framework » wingS » com » javujavu » javux » wings » dialogs » 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 » Web Framework » wingS » com.javujavu.javux.wings.dialogs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *	Javu WingS - Lightweight Java Component Set
003:         *	Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004:         *	e-mail: ksadlocha@programics.com
005:         *
006:         *	This library is free software; you can redistribute it and/or
007:         *	modify it under the terms of the GNU Lesser General Public
008:         *	License as published by the Free Software Foundation; either
009:         *	version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *	This library is distributed in the hope that it will be useful,
012:         *	but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *	Lesser General Public License for more details.
015:         *
016:         *	You should have received a copy of the GNU Lesser General Public
017:         *	License along with this library; if not, write to the Free Software
018:         *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:
021:        package com.javujavu.javux.wings.dialogs;
022:
023:        import java.awt.Container;
024:        import java.awt.Frame;
025:        import java.awt.GridBagConstraints;
026:        import java.awt.GridBagLayout;
027:        import java.awt.GridLayout;
028:        import java.awt.Insets;
029:        import java.awt.event.ActionEvent;
030:        import java.awt.event.ActionListener;
031:        import java.awt.event.KeyEvent;
032:        import java.awt.event.WindowEvent;
033:        import com.javujavu.javux.wings.ShortcutAdapter;
034:        import com.javujavu.javux.wings.WingButton;
035:        import com.javujavu.javux.wings.WingComponent;
036:        import com.javujavu.javux.wings.WingDialog;
037:        import com.javujavu.javux.wings.WingLabel;
038:        import com.javujavu.javux.wings.WingPanel;
039:        import com.javujavu.javux.wings.WingScrollPane;
040:        import com.javujavu.javux.wings.WingSkin;
041:
042:        /**
043:         * This class creates, displays, and operates a message box.
044:         * The message box contains an application-defined message and title,
045:         * plus any combination of push buttons 
046:         * <br>
047:         * <b>This class is thread safe.</b>
048:         **/
049:        public class WingMessageBox extends WingDialog implements 
050:                ActionListener {
051:            public static final int OKYES = 1;
052:            public static final int NO = 2;
053:            public static final int CANCEL = 3;
054:
055:            protected WingButton bYes;
056:            protected WingButton bNo;
057:            protected WingButton bCancel;
058:            protected ShortcutAdapter sCancel;
059:            public int result;
060:
061:            public WingMessageBox(Frame owner, String title, Object content,
062:                    Object labelOKYes, Object labelNo, Object labelCancel) {
063:                this (null, owner, title, content, labelOKYes, labelNo,
064:                        labelCancel, 5, true, GridBagConstraints.HORIZONTAL,
065:                        GridBagConstraints.BOTH, WingLabel.LEFT);
066:            }
067:
068:            public WingMessageBox(String styleId, Frame owner, String title,
069:                    Object content, Object labelOKYes, Object labelNo,
070:                    Object labelCancel, int gap, boolean scrollContent,
071:                    int fill, int scrollFill, int labelAlignment) {
072:                super (owner, true);
073:                getRootPane().setStyleId(styleId);
074:
075:                WingPanel pButtons = new WingPanel(new GridLayout(1, 0, gap,
076:                        gap));
077:                pButtons.setStyleId(styleId);
078:                if (labelOKYes != null) {
079:                    pButtons.add(bYes = new WingButton(labelOKYes));
080:                    bYes.setStyleId(WingSkin.catKeys(styleId, "yes"));
081:                    bYes.setShortcut(KeyEvent.VK_ENTER, 0);
082:                }
083:                if (labelNo != null) {
084:                    pButtons.add(bNo = new WingButton(labelNo));
085:                    bNo.setStyleId(WingSkin.catKeys(styleId, "no"));
086:                    if (labelCancel == null)
087:                        bNo.setShortcut(KeyEvent.VK_ESCAPE, 0);
088:                }
089:                if (labelCancel != null) {
090:                    pButtons.add(bCancel = new WingButton(labelCancel));
091:                    bCancel.setStyleId(WingSkin.catKeys(styleId, "cancel"));
092:                    bCancel.setShortcut(KeyEvent.VK_ESCAPE, 0);
093:                }
094:                if (labelNo == null && labelCancel == null) {
095:                    getRootPane().addShortcut(
096:                            sCancel = new ShortcutAdapter(KeyEvent.VK_ESCAPE,
097:                                    0, this ));
098:                }
099:
100:                WingPanel pContent = new WingPanel(new GridBagLayout());
101:                pContent.setStyleId(styleId);
102:                GridBagConstraints c = new GridBagConstraints();
103:
104:                double weightx = (fill == GridBagConstraints.HORIZONTAL || fill == GridBagConstraints.BOTH) ? 1.0
105:                        : 0.0;
106:                double weighty = (fill == GridBagConstraints.VERTICAL || fill == GridBagConstraints.BOTH) ? 1.0
107:                        : 0.0;
108:                double scrollWeightx = (scrollFill == GridBagConstraints.HORIZONTAL || scrollFill == GridBagConstraints.BOTH) ? 1.0
109:                        : 0.0;
110:                double scrollWeighty = (scrollFill == GridBagConstraints.VERTICAL || scrollFill == GridBagConstraints.BOTH) ? 1.0
111:                        : 0.0;
112:                c.gridy = 0;
113:                int i = 0;
114:                Object[] rows = (content instanceof  Object[]) ? (Object[]) content
115:                        : null;
116:                while (true) {
117:                    Object row = (rows != null) ? rows[i] : content;
118:                    Object[] cols = (row instanceof  Object[]) ? (Object[]) row
119:                            : null;
120:
121:                    int j = 0;
122:                    c.gridx = 0;
123:                    while (true) {
124:                        c.insets = new Insets((i == 0) ? gap : 0,
125:                                (j == 0) ? gap : 0, gap, gap);
126:                        c.gridwidth = (cols != null && j < cols.length - 1) ? 1
127:                                : GridBagConstraints.REMAINDER;
128:                        Object item = (cols != null) ? cols[j] : row;
129:
130:                        if (item instanceof  WingScrollPane) {
131:                            c.fill = scrollFill;
132:                            c.weightx = scrollWeightx;
133:                            c.weighty = scrollWeighty;
134:                        } else {
135:                            c.fill = fill;
136:                            c.weightx = weightx;
137:                            c.weighty = weighty;
138:                        }
139:                        if (item instanceof  WingComponent) {
140:                            pContent.add((WingComponent) item, c);
141:                        } else {
142:                            WingLabel l = new WingLabel(item, labelAlignment);
143:                            l.setStyleId(styleId);
144:                            pContent.add(l, c);
145:                        }
146:
147:                        c.gridx++;
148:                        j++;
149:                        if (cols == null || j == cols.length)
150:                            break;
151:                    }
152:                    c.gridy++;
153:                    i++;
154:                    if (rows == null || i == rows.length)
155:                        break;
156:                }
157:
158:                WingPanel p = new WingPanel(new GridBagLayout());
159:                p.setStyleId(styleId);
160:                c = new GridBagConstraints();
161:                c.fill = GridBagConstraints.BOTH;
162:                c.weightx = 1.0;
163:                c.weighty = 1.0;
164:                c.gridwidth = GridBagConstraints.REMAINDER;
165:                if (scrollContent) {
166:                    p.add(new WingScrollPane(pContent, false), c);
167:                } else {
168:                    p.add(pContent, c);
169:                }
170:                int buttonCount = pButtons.getComponentCount();
171:                c.fill = GridBagConstraints.NONE;
172:                c.weightx = 0.0;
173:                c.weighty = 0.0;
174:                c.ipadx = buttonCount * 2 * gap;
175:                c.anchor = (buttonCount > 1) ? GridBagConstraints.EAST
176:                        : GridBagConstraints.CENTER;
177:                c.insets = new Insets(gap, gap, gap, gap);
178:                p.add(pButtons, c);
179:
180:                setContentPane(p);
181:                setTitle(title);
182:                p.addActionListener(this );
183:                enableEvents(WindowEvent.WINDOW_EVENT_MASK);
184:            }
185:
186:            public int showMessage(Container origin) {
187:                return showMessage(origin, 0, 0);
188:            }
189:
190:            public int showMessage(Container origin, int minWidth, int minHeight) {
191:                super .packAndCenter(origin, minWidth, minHeight);
192:                setVisible(true);
193:                return result;
194:            }
195:
196:            public void actionPerformed(ActionEvent e) {
197:                Object src = e.getSource();
198:                if (src == bYes)
199:                    accept();
200:                else if (src == bNo)
201:                    close(NO);
202:                else if (src == bCancel || src == sCancel)
203:                    close(CANCEL);
204:            }
205:
206:            protected void processWindowEvent(WindowEvent e) {
207:                if (e.getID() == WindowEvent.WINDOW_CLOSING)
208:                    close(CANCEL);
209:                super .processWindowEvent(e);
210:            }
211:
212:            public void accept() {
213:                close(OKYES);
214:            }
215:
216:            public void close(int result) {
217:                this .result = result;
218:                setVisible(false);
219:                dispose();
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.