home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
JPluginDialog.java
< prev
next >
Wrap
Text File
|
1998-10-25
|
11KB
|
389 lines
/*
* Copyright 1998 Symantec Corporation, All Rights Reserved.
*/
package com.symantec.itools.vcafe.openapi.pluginapi;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import com.sun.java.swing.*;
/**
* The API used to integrate a dialog window into Visual Cafe.
* By default, the application main frame wiindow will be made
* the parent for this dialog box.
*
* @author Symantec Internet Tools Division
* @version 1.0
* @since VCafe 3.0
*/
public class JPluginDialog extends PluginDialog implements WindowConstants, RootPaneContainer
{
private int defaultCloseOperation = HIDE_ON_CLOSE;
/**
* @see #getRootPane
* @see #setRootPane
*/
protected JRootPane rootPane;
/**
* @see #isRootPaneCheckingEnabled
* @see #setRootPaneCheckingEnabled
*/
protected boolean rootPaneCheckingEnabled = false;
/**
* Create a modal/modeless dialog
*
* @param modal true for modal and false for modeless dialog box
*/
public JPluginDialog()
{
this(null, "", true);
}
/**
* Create a modeless dialog with the given title
*
* @param title The title on the frame
*/
public JPluginDialog(String title)
{
this(null, title, false);
}
/**
* Create a modal/modeless dialog with the given title
*
* @param modal true for modal and false for modeless dialog box
* @param title The title on the frame
*/
public JPluginDialog(String title, boolean modal)
{
this(null, title, modal);
}
/**
* Create a modal/modeless dialog with the given title and parent
*
* @param parent the owner of the dialog
* @param modal true for modal and false for modeless dialog box
* @param title The title on the frame
*/
public JPluginDialog(Window parent, String title, boolean modal)
{
super(parent, title, modal);
dialogInit();
}
/** Called by the constructors to init the JPluginDialog properly. */
protected void dialogInit()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
setRootPane(createRootPane());
setRootPaneCheckingEnabled(true);
}
/** Called by the constructor methods to create the default rootPane. */
protected JRootPane createRootPane()
{
return new JRootPane();
}
/**
* Handles window events depending on the state of the
* <code>defaultCloseOperation</code> property.
*
* @see #setDefaultCloseOperation
*/
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
switch(defaultCloseOperation)
{
case HIDE_ON_CLOSE:
setVisible(false);
break;
case DISPOSE_ON_CLOSE:
setVisible(false);
dispose();
break;
case DO_NOTHING_ON_CLOSE:
default:
break;
}
}
}
/**
* Sets the operation which will happen by default when
* the user initiates a "close" on this dialog.
* The possible choices are:
* <ul>
* <li>DO_NOTHING_ON_CLOSE - do not do anything - require the
* program to handle the operation in the windowClosing
* method of a registered WindowListener object.
* <li>HIDE_ON_CLOSE - automatically hide the dialog after
* invoking any registered WindowListener objects
* <li>DISPOSE_ON_CLOSE - automatically hide and dispose the
* dialog after invoking any registered WindowListener objects
* </ul>
* <p>
* The value is set to HIDE_ON_CLOSE by default.
* @see java.awt.Window#addWindowListener
* @see #getDefaultCloseOperation
*
* @beaninfo
* preferred: true
* description: The dialog's default close operation.
*/
public void setDefaultCloseOperation(int operation)
{
this.defaultCloseOperation = operation;
}
/**
* Returns the operation which occurs when the user
* initiates a "close" on this dialog.
*
* @return an int indicating the window-close operation
* @see #setDefaultCloseOperation
*/
public int getDefaultCloseOperation()
{
return defaultCloseOperation;
}
/**
* @return true if add and setLayout should be checked
* @see #addImpl
* @see #setLayout
* @see #setRootPaneCheckingEnabled
*/
protected boolean isRootPaneCheckingEnabled()
{
return rootPaneCheckingEnabled;
}
/**
* If true then calls to add() and setLayout() will cause an exception
* to be thrown.
*
* @see #addImpl
* @see #setLayout
* @see #isRootPaneCheckingEnabled
* @beaninfo
* hidden: true
* description: Whether the add and setLayout methods throw exceptions when invoked.
*/
protected void setRootPaneCheckingEnabled(boolean enabled)
{
rootPaneCheckingEnabled = enabled;
}
/**
* Create an runtime exception with a message like:
* <pre>
* "Do not use JPluginDialog.add() use JPluginDialog.getContentPane().add() instead"
* </pre>
*/
private Error createRootPaneException(String op)
{
String type = getClass().getName();
return new Error(
"Do not use " + type + "." + op + "() use "
+ type + ".getContentPane()." + op + "() instead");
}
/**
* By default, children may not be added directly to a this component,
* they must be added to its contentPane instead. For example:
* <pre>
* thisComponent.getContentPane().add(child)
* </pre>
* An attempt to add to directly to this component will cause an
* runtime exception to be thrown. Subclasses can disable this
* behavior.
*
* @see #setRootPaneCheckingEnabled
* @exception Error if called with rootPaneChecking true
*/
protected void addImpl(Component comp, Object constraints, int index)
{
if(isRootPaneCheckingEnabled())
{
throw createRootPaneException("add");
}
else
{
super.addImpl(comp, constraints, index);
}
}
/**
* By default the layout of this component may not be set,
* the layout of its contentPane should be set instead.
* For example:
* <pre>
* thisComponent.getContentPane().setLayout(new BorderLayout())
* </pre>
* An attempt to set the layout of this component will cause an
* runtime exception to be thrown. Subclasses can disable this
* behavior.
*
* @see #setRootPaneCheckingEnabled
* @exception Error if called with rootPaneChecking true
*/
public void setLayout(LayoutManager manager)
{
if(isRootPaneCheckingEnabled())
{
throw createRootPaneException("setLayout");
}
else
{
super.setLayout(manager);
}
}
/**
* Returns the rootPane object for this dialog.
*
* @see #setRootPane
* @see RootPaneContainer#getRootPane
*/
public JRootPane getRootPane()
{
return rootPane;
}
/**
* Sets the rootPane property. This method is called by the constructor.
* @param root the rootPane object for this dialog
*
* @see #getRootPane
*
* @beaninfo
* hidden: true
* description: the RootPane object for this dialog.
*/
protected void setRootPane(JRootPane root)
{
if(rootPane != null)
{
remove(rootPane);
}
rootPane = root;
if(rootPane != null)
{
boolean checkingEnabled = isRootPaneCheckingEnabled();
try
{
setRootPaneCheckingEnabled(false);
add(rootPane, BorderLayout.CENTER);
}
finally
{
setRootPaneCheckingEnabled(checkingEnabled);
}
}
}
/**
* Returns the contentPane object for this dialog.
*
* @see #setContentPane
* @see RootPaneContainer#getContentPane
*/
public Container getContentPane()
{
return getRootPane().getContentPane();
}
/**
* Sets the contentPane property. This method is called by the constructor.
* @param contentPane the contentPane object for this dialog
*
* @exception java.awt.IllegalComponentStateException (a runtime
* exception) if the content pane parameter is null
* @see #getContentPane
* @see RootPaneContainer#setContentPane
*
* @beaninfo
* hidden: true
* description: The client area of the dialog where child
* components are normally inserted.
*/
public void setContentPane(Container contentPane)
{
getRootPane().setContentPane(contentPane);
}
/**
* Returns the layeredPane object for this dialog.
*
* @see #setLayeredPane
* @see RootPaneContainer#getLayeredPane
*/
public JLayeredPane getLayeredPane()
{
return getRootPane().getLayeredPane();
}
/**
* Sets the layeredPane property. This method is called by the constructor.
* @param layeredPane the layeredPane object for this dialog
*
* @exception java.awt.IllegalComponentStateException (a runtime
* exception) if the layered pane parameter is null
* @see #getLayeredPane
* @see RootPaneContainer#setLayeredPane
*
* @beaninfo
* hidden: true
* description: The pane which holds the various dialog layers.
*/
public void setLayeredPane(JLayeredPane layeredPane)
{
getRootPane().setLayeredPane(layeredPane);
}
/**
* Returns the glassPane object for this dialog.
*
* @see #setGlassPane
* @see RootPaneContainer#getGlassPane
*/
public Component getGlassPane()
{
return getRootPane().getGlassPane();
}
/**
* Sets the glassPane property.
* This method is called by the constructor.
* @param glassPane the glassPane object for this dialog
* @see #getGlassPane
* @see RootPaneContainer#setGlassPane
*
* @beaninfo
* hidden: true
* description: A transparent pane used for menu rendering.
*/
public void setGlassPane(Component glassPane)
{
getRootPane().setGlassPane(glassPane);
}
}