Source Code Cross Referenced for MessageDialog.java in  » UML » jrefactory » org » acm » seguin » pmd » swingui » 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 » UML » jrefactory » org.acm.seguin.pmd.swingui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.acm.seguin.pmd.swingui;
002:
003:        import javax.swing.JButton;
004:        import javax.swing.JDialog;
005:        import javax.swing.JPanel;
006:        import javax.swing.JTextArea;
007:        import javax.swing.UIManager;
008:        import javax.swing.border.CompoundBorder;
009:        import javax.swing.border.EmptyBorder;
010:        import javax.swing.border.EtchedBorder;
011:        import java.awt.BorderLayout;
012:        import java.awt.Color;
013:        import java.awt.Dialog;
014:        import java.awt.FlowLayout;
015:        import java.awt.Frame;
016:        import java.awt.Rectangle;
017:        import java.awt.Window;
018:        import java.awt.event.ActionEvent;
019:        import java.awt.event.ActionListener;
020:        import java.io.ByteArrayOutputStream;
021:        import java.io.PrintStream;
022:
023:        /**
024:         *
025:         * @author Donald A. Leckie
026:         * @since August 17, 2002
027:         * @version $Revision: 1.1 $, $Date: 2003/07/29 20:51:59 $
028:         */
029:        public class MessageDialog extends JDialog {
030:
031:            private JTextArea m_messageArea;
032:            private Exception m_exception;
033:            private boolean m_yesButtonWasPressed;
034:
035:            /**
036:             *******************************************************************************
037:             *
038:             * @param parentWindow
039:             * @param title
040:             * @param job
041:             */
042:            private MessageDialog(Frame parentWindow, String title,
043:                    String message) {
044:                super (parentWindow, title, true);
045:
046:                initialize(parentWindow, message);
047:            }
048:
049:            /**
050:             *******************************************************************************
051:             *
052:             * @param parentWindow
053:             * @param title
054:             * @param job
055:             */
056:            private MessageDialog(Dialog parentWindow, String title,
057:                    String message) {
058:                super (parentWindow, title, true);
059:
060:                initialize(parentWindow, message);
061:            }
062:
063:            /**
064:             *******************************************************************************
065:             *
066:             * @param parentWindow
067:             * @param message
068:             */
069:            private void initialize(Window parentWindow, String message) {
070:                int dialogWidth = 600;
071:                int dialogHeight = 150;
072:                Rectangle parentWindowBounds = parentWindow.getBounds();
073:                int x = parentWindowBounds.x
074:                        + (parentWindowBounds.width - dialogWidth) / 2;
075:                int y = parentWindowBounds.y
076:                        + (parentWindowBounds.height - dialogHeight) / 2;
077:
078:                setBounds(x, y, dialogWidth, dialogHeight);
079:
080:                EtchedBorder etchedBorder;
081:                EmptyBorder emptyBorder;
082:                CompoundBorder compoundBorder;
083:                JPanel basePanel;
084:
085:                basePanel = new JPanel();
086:                etchedBorder = new EtchedBorder(EtchedBorder.LOWERED);
087:                emptyBorder = new EmptyBorder(15, 15, 15, 15);
088:                compoundBorder = new CompoundBorder(etchedBorder, emptyBorder);
089:
090:                basePanel.setBorder(compoundBorder);
091:                basePanel.setLayout(new BorderLayout());
092:                getContentPane().add(basePanel, BorderLayout.CENTER);
093:
094:                m_messageArea = ComponentFactory.createTextArea(message);
095:
096:                m_messageArea.setFont(UIManager.getFont("messageFont"));
097:                m_messageArea.setEditable(false);
098:                basePanel.add(m_messageArea, BorderLayout.CENTER);
099:            }
100:
101:            /**
102:             *******************************************************************************
103:             *
104:             */
105:            private void addCloseButton() {
106:                JButton closeButton = ComponentFactory.createButton("Close");
107:                JPanel buttonPanel = new JPanel(new FlowLayout());
108:
109:                closeButton = ComponentFactory.createButton("Close");
110:                closeButton.setForeground(Color.white);
111:                closeButton.setBackground(Color.blue);
112:                closeButton.addActionListener(new CloseButtonActionListener());
113:
114:                buttonPanel.add(closeButton);
115:            }
116:
117:            /**
118:             *******************************************************************************
119:             *
120:             */
121:            private void addAnswerButtons() {
122:                JButton yesButton;
123:                JButton noButton;
124:                JPanel buttonPanel;
125:
126:                buttonPanel = new JPanel(new FlowLayout());
127:
128:                yesButton = ComponentFactory.createButton("Yes");
129:                yesButton.setForeground(Color.white);
130:                yesButton.setBackground(UIManager.getColor("pmdGreen"));
131:                yesButton.addActionListener(new YesButtonActionListener());
132:                buttonPanel.add(yesButton);
133:
134:                noButton = ComponentFactory.createButton("No");
135:                noButton.setForeground(Color.white);
136:                noButton.setBackground(Color.red);
137:                noButton.addActionListener(new NoButtonActionListener());
138:                buttonPanel.add(noButton);
139:
140:                getContentPane().add(buttonPanel, BorderLayout.SOUTH);
141:            }
142:
143:            /**
144:             *******************************************************************************
145:             *
146:             * @param parentWindow
147:             * @param message
148:             * @param exception
149:             */
150:            public static void show(Window parentWindow, String message,
151:                    Exception exception) {
152:                if (exception == null) {
153:                    show(parentWindow, message);
154:                } else {
155:                    ByteArrayOutputStream stream = new ByteArrayOutputStream(
156:                            5000);
157:                    PrintStream printStream = new PrintStream(stream);
158:
159:                    exception.printStackTrace(printStream);
160:
161:                    if (message == null) {
162:                        message = stream.toString();
163:                    } else {
164:                        message = message + "\n" + stream.toString();
165:                    }
166:
167:                    printStream.close();
168:
169:                    MessageDialog dialog;
170:
171:                    if (parentWindow instanceof  Frame) {
172:                        dialog = new MessageDialog((Frame) parentWindow,
173:                                "Exception", message);
174:                    } else {
175:                        dialog = new MessageDialog((Dialog) parentWindow,
176:                                "Exception", message);
177:                    }
178:
179:                    dialog.addCloseButton();
180:                    dialog.setVisible(true);
181:                }
182:            }
183:
184:            /**
185:             *******************************************************************************
186:             *
187:             * @param parentWindow
188:             * @param message
189:             */
190:            protected static boolean answerIsYes(Window parentWindow,
191:                    String message) {
192:                MessageDialog dialog = setup(parentWindow, message);
193:
194:                dialog.addAnswerButtons();
195:                dialog.setVisible(true);
196:
197:                return dialog.m_yesButtonWasPressed;
198:            }
199:
200:            /**
201:             *******************************************************************************
202:             *
203:             * @param parentWindow
204:             * @param message
205:             */
206:            public static void show(Window parentWindow, String message) {
207:                MessageDialog dialog;
208:
209:                dialog = setup(parentWindow, message);
210:                dialog.addCloseButton();
211:                dialog.setVisible(true);
212:            }
213:
214:            /**
215:             *******************************************************************************
216:             *
217:             * @param parentWindow
218:             * @param message
219:             */
220:            private static MessageDialog setup(Window parentWindow,
221:                    String message) {
222:                if (message == null) {
223:                    message = "There is no message.";
224:                }
225:
226:                MessageDialog dialog;
227:                String title;
228:
229:                title = "Information";
230:
231:                if (parentWindow instanceof  Frame) {
232:                    dialog = new MessageDialog((Frame) parentWindow, title,
233:                            message);
234:                } else {
235:                    dialog = new MessageDialog((Dialog) parentWindow, title,
236:                            message);
237:                }
238:
239:                return dialog;
240:            }
241:
242:            /**
243:             *******************************************************************************
244:             *******************************************************************************
245:             *******************************************************************************
246:             */
247:            private class CloseButtonActionListener implements  ActionListener {
248:
249:                /**
250:                 ************************************************************************
251:                 *
252:                 * @param event
253:                 */
254:                public void actionPerformed(ActionEvent event) {
255:                    MessageDialog.this .setVisible(false);
256:                }
257:            }
258:
259:            /**
260:             *******************************************************************************
261:             *******************************************************************************
262:             *******************************************************************************
263:             */
264:            private class YesButtonActionListener implements  ActionListener {
265:
266:                /**
267:                 ************************************************************************
268:                 *
269:                 * @param event
270:                 */
271:                public void actionPerformed(ActionEvent event) {
272:                    MessageDialog.this .m_yesButtonWasPressed = true;
273:                    MessageDialog.this .setVisible(false);
274:                }
275:            }
276:
277:            /**
278:             *******************************************************************************
279:             *******************************************************************************
280:             *******************************************************************************
281:             */
282:            private class NoButtonActionListener implements  ActionListener {
283:
284:                /**
285:                 ************************************************************************
286:                 *
287:                 * @param event
288:                 */
289:                public void actionPerformed(ActionEvent event) {
290:                    MessageDialog.this .m_yesButtonWasPressed = false;
291:                    MessageDialog.this .setVisible(false);
292:                }
293:            }
294:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.