001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.editor;
043:
044: import java.awt.Dialog;
045: import java.awt.event.*;
046: import javax.swing.*;
047:
048: /**
049: * DialogSupport is factory based class for creating dialogs of certain
050: * behaviour. It is intended to be used whenever editor needs to popup a dialog.
051: * It presents a way for changing the implementation of the dialog depending
052: * on the enviroment the Editor is embeded in.
053: *
054: * @author pnejedly
055: * @version 1.0
056: * @deprecated See org.openide.spi.editor.lib2.DialogFactory. DialogSupport has
057: * no public replacement.
058: */
059: public class DialogSupport {
060:
061: /** Noone needs to instantiate the dialog support */
062: private DialogSupport() {
063: }
064:
065: /**
066: * The method for creating a dialog with specified properties.
067: * @param title The title of created dialog.
068: * @param panel The content of the dialog to be displayed.
069: * @param modal Whether the dialog should be modal.
070: * @param buttons The array of JButtons to be added to the dialog.
071: * @param sidebuttons The buttons could be placed under the panel (false),
072: * or on the right side of the panel (true).
073: * @param defaultIndex The index of default button in the buttons array,
074: * if <CODE>index < 0</CODE>, no default button is set.
075: * @param cancelIndex The index about cancel button - the button that will
076: * be <I>pressed</I> when closing the dialog.
077: * @param listener The listener which will be notified of all button
078: * events.
079: * @return newly created <CODE>Dialog</CODE>
080: */
081: public static Dialog createDialog(String title, JPanel panel,
082: boolean modal, JButton[] buttons, boolean sidebuttons,
083: int defaultIndex, int cancelIndex, ActionListener listener) {
084: return org.netbeans.modules.editor.lib2.DialogSupport
085: .getInstance().createDialog(title, panel, modal,
086: buttons, sidebuttons, defaultIndex,
087: cancelIndex, listener);
088: }
089:
090: /** The method for setting custom factory for creating dialogs via
091: * the {@link #createDialog(java.lang.String, javax.swing.JPanel, boolean, javax.swing.JButton[], boolean, int, int, java.awt.event.ActionListener) createDialog} method.
092: * If no factory is set, the {@link DialogSupport.DefaultDialogFactory DefaultDialogFactory}
093: * will be used.
094: * @param factory 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: org.netbeans.modules.editor.lib2.DialogSupport.getInstance()
102: .setExternalDialogFactory(new Wrapper(factory));
103: }
104:
105: /**
106: * DialogFactory implementation is a class responsible for providing
107: * proper implementation of Dialog containing required widgets.
108: * It can provide the dialog itself or delegate the functionality
109: * to another piece of code, e.g some windowing system.
110: */
111: public static interface DialogFactory {
112:
113: /**
114: * The method for creating a dialog with specified properties.
115: * @param title The title of created dialog.
116: * @param panel The content of the dialog to be displayed.
117: * @param modal Whether the dialog should be modal.
118: * @param buttons The array of JButtons to be added to the dialog.
119: * @param sidebuttons The buttons could be placed under the panel (false),
120: * or on the right side of the panel (true).
121: * @param defaultIndex The index of default button in the buttons array,
122: * if <CODE>index < 0</CODE>, no default button is set.
123: * @param cancelIndex The index of cancel button - the button that will
124: * be <I>pressed</I> when closing the dialog.
125: * @param listener The listener which will be notified of all button
126: * events.
127: * @return newly created <CODE>Dialog</CODE>
128: */
129: public Dialog createDialog(String title, JPanel panel,
130: boolean modal, JButton[] buttons, boolean sidebuttons,
131: int defaultIndex, int cancelIndex,
132: ActionListener listener);
133: } // End of DialogFactory interface
134:
135: private static final class Wrapper implements
136: org.netbeans.spi.editor.DialogFactory {
137:
138: private DialogFactory origFactory;
139:
140: public Wrapper(DialogFactory origFactory) {
141: this .origFactory = origFactory;
142: }
143:
144: public Dialog createDialog(String title, JPanel panel,
145: boolean modal, JButton[] buttons, boolean sidebuttons,
146: int defaultIndex, int cancelIndex,
147: ActionListener listener) {
148: return origFactory.createDialog(title, panel, modal,
149: buttons, sidebuttons, defaultIndex, cancelIndex,
150: listener);
151: }
152: } // End of Wraper class
153:
154: }
|