Source Code Cross Referenced for DialogSupport.java in  » Swing-Library » abeille-forms-designer » org » netbeans » 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 » Swing Library » abeille forms designer » org.netbeans.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *                 Sun Public License Notice
003:         * 
004:         * The contents of this file are subject to the Sun Public License
005:         * Version 1.0 (the "License"). You may not use this file except in
006:         * compliance with the License. A copy of the License is available at
007:         * http://www.sun.com/
008:         * 
009:         * The Original Code is NetBeans. The Initial Developer of the Original
010:         * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011:         * Microsystems, Inc. All Rights Reserved.
012:         */
013:
014:        package org.netbeans.editor;
015:
016:        import java.awt.BorderLayout;
017:        import java.awt.Dialog;
018:        import java.awt.GridLayout;
019:        import java.awt.Insets;
020:        import java.awt.LayoutManager;
021:        import java.awt.event.ActionEvent;
022:        import java.awt.event.ActionListener;
023:        import java.awt.event.KeyEvent;
024:        import java.awt.event.WindowAdapter;
025:        import java.awt.event.WindowEvent;
026:
027:        import javax.swing.JButton;
028:        import javax.swing.JComponent;
029:        import javax.swing.JDialog;
030:        import javax.swing.JPanel;
031:        import javax.swing.KeyStroke;
032:        import javax.swing.WindowConstants;
033:        import javax.swing.border.EmptyBorder;
034:
035:        /**
036:         * DialogSupport is factory based class for creating dialogs of certain
037:         * behaviour. It is intended to be used whenever editor needs to popup a dialog.
038:         * It presents a way for changing the implementation of the dialog depending on
039:         * the enviroment the Editor is embeded in.
040:         * 
041:         * @author pnejedly
042:         * @version 1.0
043:         */
044:        public class DialogSupport {
045:
046:            private static DialogFactory factory;
047:
048:            /** Noone needs to instantiate the dialog support */
049:            private DialogSupport() {
050:            }
051:
052:            /**
053:             * The method for creating a dialog with specified properties.
054:             * 
055:             * @param title
056:             *            The title of created dialog.
057:             * @param panel
058:             *            The content of the dialog to be displayed.
059:             * @param modal
060:             *            Whether the dialog should be modal.
061:             * @param buttons
062:             *            The array of JButtons to be added to the dialog.
063:             * @param sidebuttons
064:             *            The buttons could be placed under the panel (false), or on the
065:             *            right side of the panel (true).
066:             * @param defaultIndex
067:             *            The index of default button in the buttons array, if <CODE>index <
068:             *            0</CODE>, no default button is set.
069:             * @param cancelIndex
070:             *            The index about cancel button - the button that will be
071:             *            <I>pressed</I> when closing the dialog.
072:             * @param listener
073:             *            The listener which will be notified of all button events.
074:             * @return newly created <CODE>Dialog</CODE>
075:             */
076:            public static Dialog createDialog(String title, JPanel panel,
077:                    boolean modal, JButton[] buttons, boolean sidebuttons,
078:                    int defaultIndex, int cancelIndex, ActionListener listener) {
079:                if (factory == null) {
080:                    factory = new DefaultDialogFactory();
081:                }
082:                return factory.createDialog(title, panel, modal, buttons,
083:                        sidebuttons, defaultIndex, cancelIndex, listener);
084:            }
085:
086:            /**
087:             * The method for setting custom factory for creating dialogs via the
088:             * {@link #createDialog(java.lang.String, javax.swing.JPanel, boolean, javax.swing.JButton[], boolean, int, int, java.awt.event.ActionListener) createDialog}
089:             * method. If no factory is set, the
090:             * {@link DialogSupport.DefaultDialogFactory DefaultDialogFactory} will be
091:             * used.
092:             * 
093:             * @param factory
094:             *            the {@link DialogSupport.DialogFactory DialogFactory}
095:             *            implementation that will be responsible for providing dialogs.
096:             * 
097:             * @see DialogSupport.DialogFactory
098:             * @see DialogSupport.DefaultDialogFactory
099:             */
100:            public static void setDialogFactory(DialogFactory factory) {
101:                DialogSupport.factory = factory;
102:            }
103:
104:            /**
105:             * DialogFactory implementation is a class responsible for providing proper
106:             * implementation of Dialog containing required widgets. It can provide the
107:             * dialog itself or delegate the functionality to another piece of code, e.g
108:             * some windowing system.
109:             */
110:            public static interface DialogFactory {
111:
112:                /**
113:                 * The method for creating a dialog with specified properties.
114:                 * 
115:                 * @param title
116:                 *            The title of created dialog.
117:                 * @param panel
118:                 *            The content of the dialog to be displayed.
119:                 * @param modal
120:                 *            Whether the dialog should be modal.
121:                 * @param buttons
122:                 *            The array of JButtons to be added to the dialog.
123:                 * @param sidebuttons
124:                 *            The buttons could be placed under the panel (false), or on
125:                 *            the right side of the panel (true).
126:                 * @param defaultIndex
127:                 *            The index of default button in the buttons array, if
128:                 *            <CODE>index < 0</CODE>, no default button is set.
129:                 * @param cancelIndex
130:                 *            The index of cancel button - the button that will be
131:                 *            <I>pressed</I> when closing the dialog.
132:                 * @param listener
133:                 *            The listener which will be notified of all button events.
134:                 * @return newly created <CODE>Dialog</CODE>
135:                 */
136:                public Dialog createDialog(String title, JPanel panel,
137:                        boolean modal, JButton[] buttons, boolean sidebuttons,
138:                        int defaultIndex, int cancelIndex,
139:                        ActionListener listener);
140:            }
141:
142:            /**
143:             * The DialogFactory that will be used to create Dialogs if no other
144:             * DialogFactory is set to DialogSupport.
145:             */
146:            private static class DefaultDialogFactory extends WindowAdapter
147:                    implements  DialogFactory, ActionListener {
148:
149:                private JButton cancelButton;
150:
151:                /**
152:                 * Create a panel with buttons that will be placed according to the
153:                 * required alignment
154:                 */
155:                JPanel createButtonPanel(JButton[] buttons, boolean sidebuttons) {
156:                    int count = buttons.length;
157:
158:                    JPanel outerPanel = new JPanel(new BorderLayout());
159:                    outerPanel.setBorder(new EmptyBorder(new Insets(
160:                            sidebuttons ? 5 : 0, sidebuttons ? 0 : 5, 5, 5)));
161:
162:                    LayoutManager lm = new GridLayout(
163:                            // GridLayout makes equal cells
164:                            sidebuttons ? count : 1, sidebuttons ? 1 : count,
165:                            5, 5);
166:
167:                    JPanel innerPanel = new JPanel(lm);
168:
169:                    for (int i = 0; i < count; i++)
170:                        innerPanel.add(buttons[i]);
171:
172:                    outerPanel.add(innerPanel, sidebuttons ? BorderLayout.NORTH
173:                            : BorderLayout.EAST);
174:                    return outerPanel;
175:                }
176:
177:                public Dialog createDialog(String title, JPanel panel,
178:                        boolean modal, JButton[] buttons, boolean sidebuttons,
179:                        int defaultIndex, int cancelIndex,
180:                        ActionListener listener) {
181:
182:                    // create the dialog with given content
183:                    JDialog d = new JDialog((javax.swing.JFrame) null, title,
184:                            modal);
185:                    d
186:                            .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
187:                    d.getContentPane().add(panel, BorderLayout.CENTER);
188:
189:                    // Add the buttons to it
190:                    JPanel buttonPanel = createButtonPanel(buttons, sidebuttons);
191:                    String buttonAlign = sidebuttons ? BorderLayout.EAST
192:                            : BorderLayout.SOUTH;
193:                    d.getContentPane().add(buttonPanel, buttonAlign);
194:
195:                    // add listener to buttons
196:                    if (listener != null) {
197:                        for (int i = 0; i < buttons.length; i++) {
198:                            buttons[i].addActionListener(listener);
199:                        }
200:                    }
201:
202:                    // register the default button, if available
203:                    if (defaultIndex >= 0) {
204:                        d.getRootPane().setDefaultButton(buttons[defaultIndex]);
205:                    }
206:
207:                    // register the cancel button helpers, if available
208:                    if (cancelIndex >= 0) {
209:                        cancelButton = buttons[cancelIndex];
210:                        // redirect the Esc key to Cancel button
211:                        d.getRootPane().registerKeyboardAction(
212:                                this ,
213:                                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0,
214:                                        true),
215:                                JComponent.WHEN_IN_FOCUSED_WINDOW);
216:
217:                        // listen on windowClosing and redirect it to Cancel button
218:                        d.addWindowListener(this );
219:                    }
220:
221:                    d.pack();
222:                    return d;
223:                }
224:
225:                public void actionPerformed(ActionEvent evt) {
226:                    cancelButton.doClick(10);
227:                }
228:
229:                public void windowClosing(WindowEvent evt) {
230:                    cancelButton.doClick(10);
231:                }
232:            }
233:
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.