Util.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) 2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* Copyright (C) 1996 Active Software, Inc.
* All rights reserved.
*
* @(#) Util.java 1.43 - last change made 07/16/97
*/
/**
* Utilities needed by run-time.
*
* @version 1.32, 03/09/97
*/
public class Util {
// Relief constants
public static final int RELIEF_FLAT = 0;
public static final int RELIEF_RAISED = 1;
public static final int RELIEF_SUNKEN = 2;
public static final int RELIEF_RIDGE = 3;
public static final int RELIEF_GROOVE = 4;
public static final int WIN95_RAISED = 6;
public static final int WIN95_SUNKEN = 7;
public static final int WIN95_FIELD_BORDER = 8;
public static final int WIN95_WINDOW_BORDER = 9;
public static final int BLACK_BORDER = 10;
// Character constants
// codebase the user specified in the project - used at design time
// default class loader
private CustomClassLoader classLoader;
// Darkness constants
private static final double BFACTOR = 0.82;
private static final double DFACTOR = 0.7;
// Buffer size for reading files
private static final int BUFSIZE = 2048;
public Util() {
classLoader = new VBClassLoader();
}
/**
* Returns a brighter version of this color.
*
* This version is adjusted to compensate for border cases:
* If the base is white, the brighter color sometimes gets lost
* against the background, so the border of the panel (or whatever)
* is not seen. (Sun Bug # 4035733)
* The solution is to check if the "brighter" color
* is too bright, and if
* so, set it to a light grey.
*
*/
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
if (r > 250 && g > 250 && b > 250) {
// note: we use the JDK darker, which simply makes
// the color darker,
// rather than this.darker, which will turn
// values of 255 into
// 128.
}
/* JSTYLED */
return new Color(r, g, b);
}
/**
* Returns a darker version of this color.
*/
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
if (r == 255)
r = 128;
else
if (g == 255)
g = 128;
else
if (b == 255)
b = 128;
else
return new Color(r, g, b);
}
/**
* Draw a 3D rectable with the given relief and border width.
*/
public void draw3DRect(Graphics g, int x, int y, int w, int h,
for (int i = 0; i < bd; i++)
(i < bd2));
}
/**
* Draw a 3D rectable with the given relief and outer boolean.
*/
private void draw3DRect(Graphics g, int x, int y, int w, int h,
g.drawLine(x, y, x+w, y);
g.drawLine(x, y, x, y+h);
g.drawLine(x, y+h, x+w, y+h);
g.drawLine(x+w, y, x+w, y+h);
}
/**
* Returns an adjusted color for the given
* edge and the given relief.
*/
switch (relief) {
case RELIEF_RAISED:
if (isTopEdge)
else
break;
case RELIEF_SUNKEN:
if (isTopEdge)
else
break;
case RELIEF_RIDGE:
if (isTopEdge) {
if (isOuter)
else
} else {
if (isOuter)
else
}
break;
case RELIEF_GROOVE:
if (isTopEdge) {
if (isOuter)
else
} else {
if (isOuter)
else
}
break;
case WIN95_RAISED:
if (isTopEdge) {
if (isOuter)
else
} else {
if (isOuter)
else
}
break;
case WIN95_SUNKEN:
if (isTopEdge) {
if (isOuter)
else
} else {
if (isOuter)
else
}
break;
case WIN95_FIELD_BORDER:
if (isTopEdge) {
if (isOuter)
else
} else {
if (isOuter)
else
// was: base; // brighter(base);
}
break;
case WIN95_WINDOW_BORDER:
if (isTopEdge) {
if (isOuter)
else
} else {
if (isOuter)
else
}
break;
case BLACK_BORDER:
break;
case RELIEF_FLAT:
default:
break;
}
return color;
}
/**
* Get an image given a url. If we are on Windows 95, then we
* need to use a filter to get around the transparency bugs.
*/
}
/**
* Get an image given another. If we are on Windows 95, then we
* need to use a filter to get around the transparency bugs.
* Otherwise, just return the image directly.
*/
return null;
filter));
}
return image;
}
/**
* in the project,
* this method is called to update the value of "codebase" here.
* When we calculate an URL relative to codebase(such as the
* ImageLabel "image" attribute at design time, we use this
* codebase value.
*/
return true;
}
public CustomClassLoader getClassLoader() {
return (classLoader);
}
}
/**
* Returns a URL based on a relative path to a file or directory.
* If we are running under a browser, then a URL is created based
* off of the code base. Otherwise, a file URL will be created
* by searching the CLASSPATH for the file.
*/
// general info: determine delimiter and urlPrefix
} else {
}
// First see if the path is a full URL path
// Note that the user must specify "file:" for files
try {
// System.out.println(
// " detected full URL - URL=" + url);
return url;
}
catch (MalformedURLException ex) {
}
// Are we running as an applet? If running as the Visual Java
// applet in JWS can't use applet.getCodeBase because it is the
// codebase of Visual Java, not the users applet, so fall
// through
// and use the CLASSPATH
// Note: There's probably a better way to check if we're the
// Visual Java applet than checking for classname starting
// with "sun.jws"
"sun.jws"))) {
try {
}
catch (MalformedURLException ex) {
}
// System.out.println(" based on codebase="
// + s + " URL=" + url);
return url;
}
// Search the CLASSPATH for the file
try {
/* NOI18N */"java.class.path");
}
catch (SecurityException ex) {
"sunsoft.jws.visual.rt.base.Util.NeedAppletparam",
}
boolean keepGoing = true;
if (p == /* NOI18N */"")
p = /* NOI18N */".";
p = makeAbsolute(p);
p = p + separator;
p = p + path;
// Java allows the use of SLASH in the classpath,
// so we need
// convert SLASH to BACKSLASH.
char buf[] = p.toCharArray();
}
}
if (f.exists()) {
try {
// System.out.println(" based on
// classpath; found in " + p
// + "; URL=" + url +
// " classpath=" + classpath);
return url;
}
catch (MalformedURLException ex) {
// System.out.println(" based on
// classpath=" + classpath
// +
// " URL=null");
keepGoing = false;
}
}
}
// Search relative to project's codebase attrib
// (meant for design time only)
if (codebaseStr != null) {
} else {
}
if (f.exists()) {
}
try {
// System.out.println(" based on proj
// codebase=" + codebase + " URL=" + url);
return url;
}
catch (MalformedURLException e) {
}
}
// System.out.println(" all attempts
// failed - returning null");
return null;
}
"file.separator");
}
}
!= BACKSLASH))) {
}
} else {
}
return path;
}
/**
* Compares two objects and returns if they are equal.
* Will work with
* null objects
*/
} else {
}
}
/**
* Quicksort for strings. Could not get James Gosling's
* example working
* properly, or the "fixed" example, so wrote my own using
* algorithms
* book.
*/
}
if (p < r) {
if (q == r) {
q--;
}
}
}
int lo = p;
int hi = r;
while (true) {
hi--;
}
lo++;
}
} else return hi;
}
}
/**
* Quicksort for objects. The is a parameter for a
* QSortCompare object that is used to do the sorting.
*/
}
QSortCompare comp) {
if (p < r) {
if (q == r) {
q--;
}
}
}
QSortCompare comp) {
int lo = p;
int hi = r;
while (true) {
hi--;
}
lo++;
}
} else return hi;
}
}
/**
* A workaround routine for the Windows95 pack bug in 1.0.2
*
* @param c The component to pack
*/
c.pack();
c.pack();
}
}
}
/**
* 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 TransFilter extends RGBImageFilter {
"sunsoft.jws.visual.rt.base.Util.NullComp",
"TransWorkAroundFilter"));
canFilterIndexColorModel = false;
}
else
return (rgb);
}
}