home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
Source.bin
/
TransparencyTrickUtils.java
< prev
next >
Wrap
Text File
|
1998-03-18
|
4KB
|
127 lines
package symantec.itools.awt;
import java.awt.*;
// 02/03/97 LAB Fixed a type-o in the NOTE below.
// 02/15/97 RKM Put gc and runFinalization in paintComponent
// 02/16/97 RKM Changed paint call to update as per David E's suggestion
// 07/13/97 LAB Deprecated because it's not needed in JDK 1.1.
// Added version and author tags.
//
// NOTE: If you use this routine, you need to implement TransparencyTrick.
// Otherwise intersecting your component with another componet that uses
// these routines will result in a lock up
//
/**
* @deprecated
* This is no longer used or supported as of JDK 1.1 since the new JDK allows
* "Lightweight" components which are "Transparent" in nature by default.
*
* This class implements a painting method that is used to simulate transparent
* Components. If you use this class you also need to implement TransparencyTrick.
* Otherwise visually intersecting your Component with another Component that uses
* these routines will result in a lock up.
*
* @version 1.1, July 14, 1997
* @author Symantec
*/
public class TransparencyTrickUtils
{
private TransparencyTrickUtils() {
}
//
// Implements transparency the bast we can under AWT
//
/**
* @deprecated
* This is no longer used or supported as of JDK 1.1 since the new JDK allows
* "Lightweight" components which are "Transparent" in nature by default.
*
* This method implements the painting of transparent components.
* It does this by painting the component's parent and all the other
* components that intersect with the invisible component.
* @param drawingComponent the invisible component "being drawn"
* @param g the graphics context to use for drawing
*/
public static void paintComponentsBehind
(Component drawingComponent,
Graphics g)
{
Rectangle myBounds = drawingComponent.bounds();
//First fill my background with myParent
Container myParent = drawingComponent.getParent();
paintComponent(drawingComponent, (Component)myParent, myBounds, g);
//Now draw any intersecting components
Component[] list = myParent.getComponents();
for (int i = 0; i < list.length; ++i) {
Component c = list[i];
if (c != drawingComponent)
paintComponent(drawingComponent, c, myBounds, g);
}
}
//
// A utility of paintComponentsBehind
//
/**
* @deprecated
* This is no longer used or supported as of JDK 1.1 since the new JDK allows
* "Lightweight" components which are "Transparent" in nature by default.
*
* This method paints one component that intersects with the invisible
* component. It is a utility routine called by paintComponentsBehind().
* @param drawingComponent the invisible component "being drawn"
* @param intersectingComponent the component that intersects the drawingComponent
* @param myBounds the bounds of the invisible component
* @param g the graphics context to use for drawing
* @see #paintComponentsBehind
*/
public static void paintComponent
(Component drawingComponent,
Component intersectingComponent,
Rectangle myBounds,
Graphics g)
{
//If it's an invisible button, don't draw this component (avoid recursion)
if (intersectingComponent instanceof TransparencyTrick)
return;
//Make certain intersectingComponent really does intersect us
Rectangle icBounds = intersectingComponent.bounds();
if (icBounds.intersects(myBounds)) {
Image img = drawingComponent.createImage(icBounds.width, icBounds.height);
if (img != null) {
//Get the graphics object representing the image
Graphics imageGraphics = img.getGraphics();
if (imageGraphics != null) {
//Draw the intersecting component into the offscreen image
intersectingComponent.update(imageGraphics);
//Draw it to the screen
g.drawImage(img, icBounds.x - myBounds.x, icBounds.y - myBounds.y, null);
imageGraphics.dispose();
}
//No use in waiting for the garbage collector, we know it's garbage
img.flush();
//Flush should call ImageRepresentation.dispose, but it is not,
//so we'll have to make certain the finalize for the ImageRepresentation gets called
//Since this is a big problem on the Macintosh, we'll only do it for them
if (symantec.itools.lang.OS.isMacintosh())
{
System.gc();
System.runFinalization();
}
}
}
}
}