home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
JPluginFrame.java
< prev
next >
Wrap
Text File
|
1998-10-25
|
13KB
|
426 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 frame window into Visual Cafe
* @see PluginFrame
*
* @author Symantec Internet Tools Division
* @version 1.0
* @since VCafe 3.0
*/
public class JPluginFrame extends PluginFrame implements WindowConstants, RootPaneContainer
{
private int defaultCloseOperation = HIDE_ON_CLOSE;
/**
* The JRootPane instance that manages the <code>contentPane</code>
* and optional <code>menuBar</code> for this frame, as well as the
* <code>glassPane</code>.
*
* @see JRootPane
* @see RootPaneContainer
*/
protected JRootPane rootPane;
/**
* If true then calls to <code>add</code> and <code>setLayout</code>
* cause an exception to be thrown.
*
* @see #isRootPaneCheckingEnabled
* @see #setRootPaneCheckingEnabled
*/
protected boolean rootPaneCheckingEnabled = false;
/**
* Constructs a new Frame that is initially invisible.
*
* @see Component#setSize
* @see Component#setVisible
*/
public JPluginFrame()
{
super();
frameInit();
}
/**
* Constructs a new, initially invisible Frame with the specified
* title.
*
* @param title the title for the frame
* @see Component#setSize
* @see Component#setVisible
*/
public JPluginFrame(String title)
{
super(title);
frameInit();
}
/** Called by the constructors to init the JPluginFrame properly. */
protected void frameInit()
{
enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK);
setRootPane(createRootPane());
setBackground(UIManager.getColor("control"));
setRootPaneCheckingEnabled(true);
}
/** Called by the constructor methods to create the default rootPane. */
protected JRootPane createRootPane()
{
return new JRootPane();
}
/**
* Processes key events occurring on this component and, if appropriate,
* passes them on to components in the frame which have registered
* interest in them.
*
* @param e the key event
* @see java.awt.Component#processKeyEvent
*/
protected void processKeyEvent(KeyEvent e)
{
super.processKeyEvent(e);
if(!e.isConsumed())
{
JComponentHelper.processKeyBindingsForAllComponents(e,this,new Vector(),e.getID() == KeyEvent.KEY_PRESSED);
}
}
/**
* Processes window events occurring on this component.
* Hides the window or disposes of it, as specified by the setting
* of the <code>defaultCloseOperation</code> property.
*
* @param e the window event
* @see #setDefaultCloseOperation
* @see java.awt.Window#processWindowEvent
*/
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 frame.
* The possible choices are:
* <p>
* <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 frame after
* invoking any registered WindowListener objects
* <li>DISPOSE_ON_CLOSE - automatically hide and dispose the
* frame 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
* enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE
* HIDE_ON_CLOSE WindowConstants.HIDE_ON_CLOSE
* DISPOSE_ON_CLOSE WindowConstants.DISPOSE_ON_CLOSE
* description: The frame'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 frame.
*
* @return an int indicating the window-close operation
* @see #setDefaultCloseOperation
*/
public int getDefaultCloseOperation()
{
return defaultCloseOperation;
}
/**
* Just calls <code>paint(g)</code>. This method was overridden to
* prevent an unneccessary call to clear the background.
*
* @param g the Graphics context in which to paint
*/
public void update(Graphics g)
{
paint(g);
}
/**
* Returns whether calls to <code>add</code> and
* <code>setLayout</code> cause an exception to be thrown.
*
* @return true if <code>add</code> and <code>setLayout</code>
* are checked
*
* @see #addImpl
* @see #setLayout
* @see #setRootPaneCheckingEnabled
*/
protected boolean isRootPaneCheckingEnabled()
{
return rootPaneCheckingEnabled;
}
/**
* Determines whether calls to <code>add</code> and
* <code>setLayout</code> cause an exception to be thrown.
*
* @param enabled a boolean value, true if checking is to be
* enabled, which cause the exceptions 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;
}
/**
* Creates a runtime exception with a message like:
* <pre>
* "Do not use JPluginFrame.add() use JPluginFrame.getContentPane().add() instead"
* </pre>
*
* @param op a String indicating the attempted operation. In the
* example above, the operation string is "add"
*/
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>
* thiComponent.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 frame.
*
* @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 frame
*
* @see #getRootPane
*
* @beaninfo
* hidden: true
* description: the RootPane object for this frame.
*/
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 frame.
*
* @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 frame
*
* @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 frame where child
* components are normally inserted.
*/
public void setContentPane(Container contentPane)
{
getRootPane().setContentPane(contentPane);
}
/**
* Returns the layeredPane object for this frame.
*
* @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 frame
*
* @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 frame layers.
*/
public void setLayeredPane(JLayeredPane layeredPane)
{
getRootPane().setLayeredPane(layeredPane);
}
/**
* Returns the glassPane object for this frame.
*
* @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 frame
*
* @see #getGlassPane
* @see RootPaneContainer#setGlassPane
*
* @beaninfo
* hidden: true
* description: A transparent pane used for menu rendering.
*/
public void setGlassPane(Component glassPane)
{
getRootPane().setGlassPane(glassPane);
}
}