KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > DialogSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.editor;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.*;
24 import javax.swing.*;
25
26 /**
27  * DialogSupport is factory based class for creating dialogs of certain
28  * behaviour. It is intended to be used whenever editor needs to popup a dialog.
29  * It presents a way for changing the implementation of the dialog depending
30  * on the enviroment the Editor is embeded in.
31  *
32  * @author pnejedly
33  * @version 1.0
34  * @deprecated See org.openide.spi.editor.lib2.DialogFactory. DialogSupport has
35  * no public replacement.
36  */

37 public class DialogSupport {
38
39     /** Noone needs to instantiate the dialog support */
40     private DialogSupport() {
41     }
42
43     /**
44      * The method for creating a dialog with specified properties.
45      * @param title The title of created dialog.
46      * @param panel The content of the dialog to be displayed.
47      * @param modal Whether the dialog should be modal.
48      * @param buttons The array of JButtons to be added to the dialog.
49      * @param sidebuttons The buttons could be placed under the panel (false),
50      * or on the right side of the panel (true).
51      * @param defaultIndex The index of default button in the buttons array,
52      * if <CODE>index < 0</CODE>, no default button is set.
53      * @param cancelIndex The index about cancel button - the button that will
54      * be <I>pressed</I> when closing the dialog.
55      * @param listener The listener which will be notified of all button
56      * events.
57      * @return newly created <CODE>Dialog</CODE>
58      */

59     public static Dialog JavaDoc createDialog( String JavaDoc title, JPanel panel, boolean modal,
60                 JButton[] buttons, boolean sidebuttons, int defaultIndex, int cancelIndex,
61                 ActionListener listener
62     ) {
63         return org.netbeans.modules.editor.lib2.DialogSupport.getInstance().createDialog(
64             title, panel, modal, buttons, sidebuttons, defaultIndex, cancelIndex, listener
65         );
66     }
67     
68     /** The method for setting custom factory for creating dialogs via
69      * the {@link #createDialog(java.lang.String, javax.swing.JPanel, boolean, javax.swing.JButton[], boolean, int, int, java.awt.event.ActionListener) createDialog} method.
70      * If no factory is set, the {@link DialogSupport.DefaultDialogFactory DefaultDialogFactory}
71      * will be used.
72      * @param factory the {@link DialogSupport.DialogFactory DialogFactory}
73      * implementation that will be responsible for providing dialogs.
74      *
75      * @see DialogSupport.DialogFactory
76      * @see DialogSupport.DefaultDialogFactory
77      */

78     public static void setDialogFactory( DialogFactory factory ) {
79         org.netbeans.modules.editor.lib2.DialogSupport.getInstance().setExternalDialogFactory(new Wrapper(factory));
80     }
81     
82     /**
83      * DialogFactory implementation is a class responsible for providing
84      * proper implementation of Dialog containing required widgets.
85      * It can provide the dialog itself or delegate the functionality
86      * to another piece of code, e.g some windowing system.
87      */

88     public static interface DialogFactory {
89         
90         /**
91          * The method for creating a dialog with specified properties.
92          * @param title The title of created dialog.
93          * @param panel The content of the dialog to be displayed.
94          * @param modal Whether the dialog should be modal.
95          * @param buttons The array of JButtons to be added to the dialog.
96          * @param sidebuttons The buttons could be placed under the panel (false),
97          * or on the right side of the panel (true).
98          * @param defaultIndex The index of default button in the buttons array,
99          * if <CODE>index < 0</CODE>, no default button is set.
100          * @param cancelIndex The index of cancel button - the button that will
101          * be <I>pressed</I> when closing the dialog.
102          * @param listener The listener which will be notified of all button
103          * events.
104          * @return newly created <CODE>Dialog</CODE>
105          */

106         public Dialog JavaDoc createDialog( String JavaDoc title, JPanel panel, boolean modal,
107                 JButton[] buttons, boolean sidebuttons, int defaultIndex,
108                 int cancelIndex, ActionListener listener );
109     } // End of DialogFactory interface
110

111     private static final class Wrapper implements org.netbeans.spi.editor.DialogFactory {
112         
113         private DialogFactory origFactory;
114         
115         public Wrapper(DialogFactory origFactory) {
116             this.origFactory = origFactory;
117         }
118         
119         public Dialog JavaDoc createDialog(
120             String JavaDoc title, JPanel panel, boolean modal,
121             JButton[] buttons, boolean sidebuttons, int defaultIndex,
122             int cancelIndex, ActionListener listener)
123         {
124             return origFactory.createDialog(title, panel, modal,
125                 buttons, sidebuttons, defaultIndex, cancelIndex, listener);
126         }
127     } // End of Wraper class
128

129 }
130
Popular Tags