WindowShadow.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* Copyright (C) 1996 Active Software, Inc.
* All rights reserved.
*
* @(#) WindowShadow.java 1.119 - last change made 07/28/97
*/
/* BEGIN JSTYLED */
/**
* Wraps an AWT widget. The attributes available for this
* class are listed below. In the type column, type names beginning
* with "sunsoft.jws.visual.rt" have been abbreviated to begin with "rt".
*
* <pre>
name type default value
-----------------------------------------------------------------------
location java.awt.Point null
size java.awt.Dimension null
* < /pre>
*
* location: location for the window, if the location is set before
* the window is mapped, then when the window is mapped, it will come
* up at the specified location. If the location is set while the
* window is mapped, then window will immediately be moved to the new
* location.
* < p>
* size: desired size for the window, if set before mapping, the
* window will later be mapped with this size. However, the size
* dimensions are first checked to ensure that the dimensions are at
* least as big as the preferredSize. If set after mapping and
* non-null, the window will be resized to the new size after maxing
* with preferredSize. "get" returns the value for the desired size,
* NOT the actual size of the window. The "size" attribute does not
* take effect when in layout mode.
* < p>
* Check the super class for additional attributes.
*
* @see Window
* @version 1.119, 07/28/97
*/
/* END JSTYLED */
public class WindowShadow extends ContainerShadow {
private static final int PADX = 100;
private static final int PADY = 100;
private boolean packed = false;
public static void setDefaultLocation(Point p) {
defaultLocation = p;
}
public static Point getDefaultLocation() {
return defaultLocation;
}
public static void setDefaultSize(Dimension d) {
defaultSize = d;
}
public static Dimension getDefaultSize() {
return defaultSize;
}
private boolean layoutMode = false;
public WindowShadow() {
}
protected boolean useLayoutLocation() {
if (!layoutMode)
return false;
if (inDesignerRoot())
return true;
if (g == null)
return false;
if (DesignerAccess.getWindow(g) != this)
return false;
return (g.inDesignerRoot());
}
protected boolean useLayoutSize() {
return (layoutMode && inDesignerRoot());
}
return getFromTable(key);
if (useLayoutLocation()) {
// fix for Sun bug #4037679: layout window locations
// are not being remembered. This is because
// win.location() returns the location that the window
// was created with, rather than the screen location.
// So if the window moved, the location() method
// doesn't report the new location. However,
// locationOnScreen() only works if the window is
// actually showing. Otherwise it throws an exception.
// -- Simran. 5/7/97
try {
} catch (IllegalComponentStateException e) {
}
return loc;
} else
return getFromTable(key);
return getFromTable(key);
if (useLayoutSize())
else
return getFromTable(key);
} else {
}
}
Point p = getWindowLocation(false);
}
Point p = getWindowLocation(true);
}
} else {
}
}
// REMIND: if Window had a frame attribute like a dialog it could be
// instantiated here (but would probably only work on Windows 96 at
// the moment)
public void createBody() {};
protected void registerBody() {
double w[] = {1};
gridbag.columnWeights = w;
gridbag.rowWeights = w;
}
super.registerBody();
}
protected void postCreate() {
super.postCreate();
if (body instanceof RootWindow) {
if (layoutMode)
else
}
if (!doingShow())
}
protected void preDestroy() {
packed = false;
}
/**
* Returns true if the window's group is currently visible,
* and the window's visible attribute is set to true.
*/
public boolean isVisible() {
return false;
if (!v.booleanValue())
return false;
if (g != null)
return g.isShowing();
return true;
}
GBConstraints c =
if (c == null)
return;
}
GBConstraints c =
if (c == null)
return;
}
if (c == null)
c = new GBConstraints();
return;
int anchor =
}
}
public void pack() {
checkCreate();
// Get the body AFTER the call to checkCreate
if (!hasPeer) {
//
// Workaround for SGI: When a frame is shown with size
// (0,0), it will fill the entire screen area momentarily
// until reshape is called. This causes annoying
// flickering behavior.
//
}
preValidate();
}
// Reshape the window
// Validate the window.
// Set the packed flag to true
packed = true;
}
/**
* Shows the component. Calling showComponent does not affect the
* value of the visible attrbute. You should use "show" instead of
* "showComponent". The only reason this method exists is that
* Visual Java needs to use it in certain situations.
*/
public void showComponent() {
checkCreate();
// Pack the window if necessary
packed = false;
if (!packed)
pack();
// Show the window
// Usually, calling show() on a visible Window will bring it
// to the front. Unfortunately, it doesn't behave like this.
}
// Make sure the window shows up right away. This tends to make
// the user happier.
}
protected void checkCreate() {
// Call create if it hasn't already been called.
if (!isCreated()) {
doingShow = true;
create();
doingShow = false;
}
}
// Adjust the location the first time the dialog is mapped
// after the peer has been created. There is an AWT bug
// that screws up the location of the dialog, so we have
// to make this adjustment.
}
} else {
if (hasPeer)
else
}
}
return p;
}
if (layoutLocation) {
else
} else {
}
return location;
}
if (layoutSize) {
else
size = getDefaultSize();
} else {
} else {
}
}
return size;
}
// Constrain the window to fit on the screen
if (location.x > x)
location.x = x;
if (location.x < 0)
location.x = 0;
if (location.y > y)
location.y = y;
if (location.y < 0)
location.y = 0;
}
d.width -= 6;
d.height -= 6;
if (Global.isWindows95()) {
// Subtract some extra space for the icon bar
d.height -= 30;
}
return d;
}
comp.invalidate();
for (int i = 0; i < count; i++)
}
}
/**
* Disposes of the AWT top-level window so that window system
* resources are reclaimed.
*/
protected void destroyBody() {
//
// Cache the location when the window is destroyed.
//
// "put" is called directly because "set" won't work if
// "isPanel" is true.
//
if (useLayoutLocation()) {
}
}
/**
* "isPanel" flag. If this flag is set, then this frame exists only
* to allow the panel to be edited in the builder. When a saving or
* generation is performed, this window should be omitted.
*/
private boolean isPanel = false;
public boolean isPanel() {
return isPanel;
}
if (isPanel) {
} else {
// Ordering is important here. As soon as isPanel is
// changed, the nature of this window changes (and
// affects the isUniqueName call, for example.) While
// isPanel is still true, get("name") returns the name
// of the surrounded panel.
//
// It is possible that a new frame has been imported
// or created that has the same name as this one (that
// was surrounding a panel and was invisible in the
// hierarchy.) Until a frame has isPanel set to
// false, it is never included in a unique name check,
// so make sure that the window's name is unique in
// the Root tree. If the frame isn't in a Root tree
// then don't worry about it.
//
}
}
}
}
/**
* If the "isPanel" flag is set, all the attributes should come from
* the child panel, not the frame.
*/
public ContainerShadow getPanel() {
if (!isPanel)
return null;
if (getChildCount() == 0)
return null;
}
// Bug 4054883 Mark Davison July 9, 1997
// The next series of methods are implemented as a work around in which
// attributes are set on the VJLayout frame instead of the GBPanel
// if isPanel == false. This is just a quick and safe fix. The real solution
// is to get rid of the isPanel flag and associated behaviour altogether.
/**
* Caching method which returns the enclosing frame (most likely VJLayout)
*/
private Class getEnclosingFrameClass() {
if (enclosingFrame == null)
return enclosingFrame;
}
/**
* Tests to see if the object is an enclosing frame.
*/
return true;
else
return false;
}
/**
* Puts the attribute on the enclosed PanelShadow rather than on the
* WindowShadow.
* This bypasses the getPanel method because if VJLayout represents
* a Frame
* or Dialog, the attributes will be set on the VJLayout (which
* is incorrect).
*/
}
/**
* Retrieves the attributes from the panel thereby bypassing the
* isPanel flag.
*/
return null;
}
return;
// Don't let visible be set to false if we are the main
// container and we are running inside vjava.
if (inDesignerRoot() && isMainContainer()
&& !newValue.booleanValue()) {
/* JSTYLED */
throw new VJException(Global.getMsg("sunsoft.jws.visual.rt.awt.java.awt.WindowShadow.IllegalSetVisible"));
}
if (!doingShow()) {
}
}
} else {
// If the body is an enclosing frame, the atributes should not be
// set on the body.
if (isEnclosingFrame(body)) {
return;
}
}
}
}
else {
// If the body is an enclosing frame, the atributes should
// be retrieved from the panel.
if (isEnclosingFrame(body)) {
return getOnPanel(key);
}
}
}
else
}
else
}
else
return super.hasAttribute(key);
}
else
}
public AttributeList getAttributeList() {
return panel.getAttributeList();
else
return super.getAttributeList();
}
public void refetchAttributeList() {
else
super.refetchAttributeList();
}
public void layoutMode() {
super.layoutMode();
setLayout(true);
}
public void previewMode() {
super.previewMode();
setPreview(true);
}
public void setLayout(boolean shouldResize) {
if (layoutMode)
return;
layoutMode = true;
if (body instanceof RootWindow)
if (shouldResize) {
if (useLayoutLocation() || useLayoutSize()) {
}
}
}
}
}
public void setPreview(boolean shouldResize) {
if (!layoutMode)
return;
if (win instanceof RootWindow)
if (shouldResize) {
if (useLayoutLocation()) {
}
if (useLayoutSize()) {
}
if (useLayoutLocation() || useLayoutSize()) {
// fix for bug id 1263220 -kp commented out
// was in their originally
// Point p = getWindowLocation(false);
constrainToScreen(win, p, d);
}
}
}
}
layoutMode = false;
}
public Dimension previewSize() {
boolean isLayout = layoutMode;
if (isLayout) {
setPreview(false);
super.previewMode();
}
if (isLayout) {
setLayout(false);
super.layoutMode();
}
return size;
}
}
}
}
}