//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
*
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
//
// (c) 1997 Microsoft Corporation. All rights reserved.
//
package com.nexirius.util;
import java.applet.Applet;
import java.awt.*;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.RGBImageFilter;
import java.net.URL;
//
// This class assumes that in an Images directory containing numimages
// images is contained in the application/applet directory.
//
public class Images {
public Image img[] = null;
public Image imgf[] = null;
// APPLICATION Path
public Images(Frame frame, String imNames[], int numimages, boolean filter) {
MediaTracker tracker = new MediaTracker(frame);
Toolkit tk = frame.getToolkit();
img = new Image[numimages];
for (int i = 0; i < numimages; i++) {
img[i] = tk.getImage("Images\\" + imNames[i]);
tracker.addImage(img[i], 0);
}
try {
tracker.waitForAll();
} catch (InterruptedException e) {
}
if (filter)
filterImages(tracker, null, tk, numimages);
}
// APPLET Path
public Images(Applet applet, String imNames[], int numimages, boolean filter) {
MediaTracker tracker = new MediaTracker(applet);
URL url = applet.getCodeBase();
img = new Image[numimages];
for (int i = 0; i < numimages; i++) {
img[i] = applet.getImage(url, "Images/" + imNames[i]);
tracker.addImage(img[i], 0);
}
try {
tracker.waitForAll();
} catch (InterruptedException e) {
}
if (filter)
filterImages(tracker, applet, null, numimages);
}
private void filterImages(MediaTracker tracker, Applet applet, Toolkit tk, int numimages) {
imgf = new Image[numimages];
ImageFilter filter = new HotTrackImageFilter();
for (int i = 0; i < numimages; i++) {
if (applet != null)
imgf[i] = applet.createImage(new FilteredImageSource(img[i].getSource(),
filter));
else if (tk != null)
imgf[i] = tk.createImage(new FilteredImageSource(img[i].getSource(),
filter));
tracker.addImage(imgf[i], 0);
}
try {
tracker.waitForAll();
} catch (InterruptedException e) {
}
}
}
class HotTrackImageFilter extends RGBImageFilter {
public HotTrackImageFilter() {
// The filterOr's operation does not depend on the
// pixel's location, so IndexColorModels can be
// filtered directly.
canFilterIndexColorModel = true;
}
public int filterRGB(int x, int y, int rgb) {
// add some blue
int blue = (rgb & 0xff) + 60;
if (blue > 0xff) blue = 0xff;
return ((rgb & 0xffffff00) | blue);
}
}