ImageLabel.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.
*
* @(#) ImageLabel.java 1.30 - last change made 07/25/97
*/
/**
* An image label. It greys itself out when disabled.
*
* @(#) @(#) ImageLabel.java 1.30 - last change made 07/25/97
*/
public class ImageLabel extends Canvas {
/**
* The original image set in the constructor or in setImage().
*/
/**
* The massaged image (after the win95 work-around.)
*/
/* BEGIN JSTYLED */
/**
* The image to use when the component is disabled.
* This is the upImg
* stippled with the background color.
*/
/* END JSTYLED */
protected int padWidth = 0;
protected int defaultWidth;
protected int defaultHeight;
protected int imgWidth = -1;
protected int imgHeight = -1;
}
defaultWidth = w;
defaultHeight = h;
}
public void setPadWidth(int w) {
padWidth = w;
repaint();
}
public int getPadWidth() {
return (padWidth);
}
public void setDefaultWidth(int w) {
if (w <= 0)
return;
defaultWidth = w;
}
public int getDefaultWidth() {
return defaultWidth;
}
public void setDefaultHeight(int h) {
if (h <= 0)
return;
defaultHeight = h;
}
public int getDefaultHeight() {
return defaultHeight;
}
private void setUpImages() {
imgWidth = -1;
imgHeight = -1;
if (getBackground() != null) {
// WORK-AROUND: create an image filter
// for transparent gifs on Win95
1.0) {
getBackground());
wfilter));
}
// start the loading of the main image
prepareImage(upImg, this);
// width and height might be immediately
// available if already loaded
}
} else {
}
getBackground() != null) {
// create a checkerboard image for disabled
// version of the button
getBackground());
}
}
setUpImages();
repaint();
}
return (origImg);
}
public Dimension minimumSize() {
}
else
} else {
// return(new Dimension(0, 0));
}
}
public Dimension preferredSize() {
return minimumSize();
}
/**
* Overrides Component setBackground in order to redo the images,
* because of the transparent gif workaround and also because the
* disabled image relies on the background color.
*/
super.setBackground(bg);
// this isn't just a work-around for Win95,
// but on ALL platforms
// the disabled image must be redone when
// the background color changes
setUpImages();
}
}
/* BEGIN JSTYLED */
/* Invalidate all of a component's containers and then validate the
* Window at the top. Call this when the size of a component
* changes and you wish to make the window that contains it resize
* to accomodate the new size.
*/
/* END JSTYLED */
protected void updateWindow(Component c) {
while (c != null) {
c.invalidate();
if (c instanceof Window) {
c.validate();
break;
}
c = c.getParent();
}
}
/**
* Figures out if this component needs to be resized.
*/
protected void updateSize(int w, int h) {
if (w >= 0 && h >= 0) {
padWidth * 2) {
updateWindow(this);
}
}
}
/**
* By overriding update we insure that this component won't be
* completely cleared with the background color each time it's
* updated (while loading.) We'd like less flickering than that.
*/
g = getGraphics();
synchronized (DesignerAccess.mutex) {
g.setColor(getBackground());
// clear only the areas around the image (to
// avoid having the image
// flicker as it is loaded scanline-by-scanline)
if (x > 0)
if (y > 0)
} else {
// there is no image, so clear the whole area
}
g.setColor(getForeground());
}
paint(g);
}
/* BEGIN JSTYLED */
/**
* Draw the image in the center of the available area.
* No background
* clearing is done here (that job belongs to update().)
*/
/* END JSTYLED */
g = getGraphics();
synchronized (DesignerAccess.mutex) {
} else {
g.setColor(getForeground());
}
}
}
int x, int y, int w, int h) {
boolean updateSize = false;
imgWidth = w;
updateSize = true;
}
imgHeight = h;
updateSize = true;
}
// As soon as the size is known this
// component needs to resize itself.
// This repaint is needed for images
// that are already loaded, and
// are being loaded a second time.
// In this situation, the
// update for the width and height comes
// in after all the other
// updates. The call to super.imageUpdate
// does not do a repaint
// when the size changes, so we need to do one here.
repaint();
}
}
}
public void enable() {
if (!isEnabled()) {
super.enable();
repaint();
}
}
public void disable() {
if (isEnabled()) {
super.disable();
repaint();
}
}
public void addNotify() {
super.addNotify();
setUpImages();
}
}
/**
* A Work-around filter.
*
* Transparent gifs don't display properly on Windows 95.
* The work-around
* is to replace transparent pixels with the background color of the
* component they're being displayed in before drawing them.
*/
class TransWorkAroundFilter extends RGBImageFilter {
canFilterIndexColorModel = false;
} else {
throw new Error(
/* JSTYLED */
}
}
else
return (rgb);
}
}
/**
* Checkerboard color filter.
*
* Use for creating a greyed-out version of another image. Supply the
* color for the checkerboard spaces. Every other pixel will still be
* in the original color of the image.
*/
class CheckerboardFilter extends RGBImageFilter {
canFilterIndexColorModel = false;
} else {
throw new Error(
/* JSTYLED */
}
}
if (y % 2 == x % 2)
return (rgb);
else
}
}