Removed remote image capability (image manipulatino via RMI)

This commit is contained in:
hns 2002-06-11 17:02:04 +00:00
parent 47debc3784
commit c0417d5a6a
7 changed files with 48 additions and 317 deletions

View file

@ -1,24 +0,0 @@
// IRemoteGenerator.java
// Copyright (c) Hannes Wallnöfer 1999-2000
package helma.image;
import java.util.*;
import java.rmi.*;
import java.io.*;
/**
* RMI interface for accessing remote image generators.
*/
public interface IRemoteGenerator extends Remote {
public IRemoteImage createPaintableImage (int w, int h) throws RemoteException;
public IRemoteImage createPaintableImage (byte src[]) throws RemoteException;
public IRemoteImage createPaintableImage (String urlstring) throws RemoteException;
public IRemoteImage createImage (byte src[]) throws RemoteException;
}

View file

@ -1,34 +0,0 @@
// ActivatedImageWrapper.java
// Copyright (c) Hannes Wallnöfer 1999-2000
package helma.image;
import java.util.*;
import java.rmi.*;
import java.io.*;
/**
* RMI interface for accessing images on remote image servers.
*/
public interface IRemoteImage extends Remote {
public void setFont (String name, int style, int size) throws RemoteException;
public void setColor (int color) throws RemoteException;
public void setColor (int r, int g, int b) throws RemoteException;
public void reduceColors (int colors) throws RemoteException;
public void drawString (String str, int x, int y) throws RemoteException;
public void drawRect (int x, int y, int w, int h) throws RemoteException;
public void drawLine (int x1, int y1, int x2, int y2) throws RemoteException;
public void fillRect (int x, int y, int w, int h) throws RemoteException;
public int getWidth () throws RemoteException;
public int getHeight () throws RemoteException;
public void crop (int x, int y, int w, int h) throws RemoteException;
public void resize (int w, int h) throws RemoteException;
public void saveAs (String filename) throws RemoteException;
}

View file

@ -29,8 +29,8 @@ public class ImageGenerator extends Window {
}
}
);
this.setBounds (0, 0, 0, 0);
this.setVisible (true);
setBounds (0, 0, 0, 0);
setVisible (true);
}
public ImageWrapper createPaintableImage (int w, int h) {

View file

@ -1,94 +0,0 @@
// RemoteImage.java
// Copyright (c) Hannes Wallnöfer 1999-2000
package helma.image;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
/**
* Implementation of an image that is accessible via RMI.
*/
public class RemoteImage extends UnicastRemoteObject implements IRemoteImage {
ImageWrapper wrapped;
public RemoteImage (ImageWrapper wrapped) throws RemoteException {
this.wrapped = wrapped;
}
public void setFont (String name, int style, int size) {
wrapped.setFont (name, style, size);
}
public void setColor (int red, int green, int blue) {
wrapped.setColor (red, green, blue);
}
public void setColor (int color) {
wrapped.setColor (color);
}
public void drawString (String str, int x, int y) {
wrapped.drawString (str, x, y);
}
public void drawLine (int x1, int y1, int x2, int y2) {
wrapped.drawLine (x1, y1, x2, y2);
}
public void drawRect (int x, int y, int w, int h) {
wrapped.drawRect (x, y, w, h);
}
public void drawImage (String filename, int x, int y) {
wrapped.drawImage (filename, x, y);
}
public void fillRect (int x, int y, int w, int h) {
wrapped.fillRect (x, y, w, h);
}
public int getWidth () {
return wrapped.getWidth();
}
public int getHeight () {
return wrapped.getHeight();
}
public void crop (int x, int y, int w, int h) {
wrapped.crop (x, y, w, h);
}
public void resize (int w, int h) {
wrapped.resize (w, h);
}
public void reduceColors (int colors) {
wrapped.reduceColors (colors);
}
public void saveAs (String filename) {
wrapped.saveAs (filename);
}
public void fillString (String str) {
wrapped.fillString (str);
}
public void fillString (String str, int x, int y, int w, int h) {
wrapped.fillString (str, x, y, w, h);
}
}

View file

@ -1,90 +0,0 @@
// Server.java
// Copyright (c) Hannes Wallnöfer 1999-2000
package helma.image;
import java.awt.*;
import java.util.*;
import java.io.*;
import java.net.URL;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
/**
* Implementation of RMI Image Generator. This accepts only connection from localhost.
*/
public class Server extends UnicastRemoteObject implements IRemoteGenerator {
static int port = 3033;
ImageGenerator imggen;
public static void main (String args[]) throws Exception {
new Server ();
}
public Server () throws Exception {
imggen = new ImageGenerator ();
// the following seems not to be necessary after all ...
// System.setSecurityManager(new RMISecurityManager());
System.out.println ("Starting server on port "+port);
LocateRegistry.createRegistry (port);
try {
Naming.bind ("//:"+port+"/server", this);
} catch (Exception x) {
System.out.println ("error binding remote objects: " + x);
}
}
public IRemoteImage createPaintableImage (int x, int y) throws RemoteException {
try {
String client = RemoteServer.getClientHost ();
if (!InetAddress.getLocalHost ().equals (InetAddress.getByName (client)))
throw new RemoteException ("Access Denied");
} catch (ServerNotActiveException ignore) {
} catch (UnknownHostException ignore) {}
return new RemoteImage (imggen.createPaintableImage (x, y));
}
public IRemoteImage createPaintableImage (byte[] bytes) throws RemoteException {
try {
String client = RemoteServer.getClientHost ();
if (!InetAddress.getLocalHost ().equals (InetAddress.getByName (client)))
throw new RemoteException ("Access Denied");
} catch (ServerNotActiveException ignore) {
} catch (UnknownHostException ignore) {}
return new RemoteImage (imggen.createPaintableImage (bytes));
}
public IRemoteImage createPaintableImage (String url) throws RemoteException {
try {
String client = RemoteServer.getClientHost ();
if (!InetAddress.getLocalHost ().equals (InetAddress.getByName (client)))
throw new RemoteException ("Access Denied");
} catch (ServerNotActiveException ignore) {
} catch (UnknownHostException ignore) {}
return new RemoteImage (imggen.createPaintableImage (url));
}
public IRemoteImage createImage (byte[] bytes) throws RemoteException {
try {
String client = RemoteServer.getClientHost ();
if (!InetAddress.getLocalHost ().equals (InetAddress.getByName (client)))
throw new RemoteException ("Access Denied");
} catch (ServerNotActiveException ignore) {
} catch (UnknownHostException ignore) {}
return new RemoteImage (imggen.createImage (bytes));
}
}

View file

@ -11,15 +11,15 @@ import Acme.JPM.Encoders.GifEncoder;
import java.io.IOException;
import java.io.FileOutputStream;
/**
/**
* A wrapper for an image that uses the Sun version of JIMI available at
* http://java.sun.com/products/jimi.
*/
public class SunImageWrapper extends ImageWrapper {
public SunImageWrapper (Image img, Graphics g, int width, int height,
ImageGenerator imggen) throws ClassNotFoundException {
ImageGenerator imggen) throws ClassNotFoundException {
super (img, g, width, height, imggen);
Class.forName ("com.sun.jimi.core.Jimi");
}
@ -27,7 +27,7 @@ public class SunImageWrapper extends ImageWrapper {
public void reduceColors (int colors) {
try {
ColorReducer redux = new ColorReducer (colors, true);
ColorReducer redux = new ColorReducer (colors, true);
img = redux.getColorReducedImage (img);
} catch (Exception x) {
throw new RuntimeException (x.getMessage ());
@ -35,7 +35,7 @@ public class SunImageWrapper extends ImageWrapper {
}
public void saveAs (String filename) {
try {
try {
if (filename.toLowerCase().endsWith (".gif")) {
// sun's jimi package doesn't encode gifs, use Acme encoder
FileOutputStream fout = new FileOutputStream (filename);

View file

@ -18,7 +18,7 @@ import java.util.*;
import java.rmi.Naming;
/**
/**
* Extension to do Image manipulation from HOP.
*/
@ -26,7 +26,7 @@ public class ImageExtension extends Extension {
protected Evaluator evaluator = null;
static boolean remote = false;
static ImageGenerator imggen;
public ImageExtension () {
@ -37,97 +37,70 @@ public class ImageExtension extends Extension {
class GlobalObjectImage extends BuiltinFunctionObject {
ImageExtension imagex;
ImageGenerator imggen;
GlobalObjectImage (String name, Evaluator evaluator, FunctionPrototype fp, ImageExtension imagex) {
super(fp, evaluator, name, 1);
this.imagex = imagex;
}
public ESValue callFunction(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
return doConstruct(thisObject, arguments);
}
public ESObject doConstruct(ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
Object img = null;
IRemoteGenerator rgen = null;
Object img = null;
try {
if (imggen == null && !remote) {
try {
imggen = new ImageGenerator ();
} catch (UnsatisfiedLinkError noawt) {
remote = true;
}
}
try {
if (imggen == null) {
try {
imggen = new ImageGenerator ();
} catch (UnsatisfiedLinkError noawt) {
System.err.println ("Error creating Image: "+noawt);
}
}
if (remote)
rgen = (IRemoteGenerator) Naming.lookup ("//localhost:3033/server");
if (arguments.length == 1) {
if (arguments[0] instanceof ESArrayWrapper) {
Object obj = ((ESArrayWrapper) arguments[0]).toJavaObject ();
if (obj instanceof byte[]) {
img = imggen.createImage ((byte[]) obj);
}
} else if (arguments[0] instanceof ESString) {
String imgurl = arguments[0].toString ();
img = imggen.createPaintableImage (imgurl);
}
} else if (arguments.length == 2) {
if (arguments[0] instanceof ESWrapper && arguments[1] instanceof ESWrapper) {
// create a new image from an existing one and an image filter
Object image = arguments[0].toJavaObject ();
Object filter = arguments[1].toJavaObject ();
img = imggen.createPaintableImage ((ImageWrapper) image, (ImageFilter) filter);
} else if (arguments[0].isNumberValue () && arguments[1].isNumberValue ()) {
img = imggen.createPaintableImage (arguments[0].toInt32(), arguments[1].toInt32());
}
}
} catch (Exception error) {
System.err.println ("Error creating Image: "+error);
}
if (arguments.length == 1) {
if (arguments[0] instanceof ESArrayWrapper) {
Object obj = ((ESArrayWrapper) arguments[0]).toJavaObject ();
if (obj instanceof byte[]) {
img = remote ?
(Object) rgen.createImage ((byte[]) obj) :
(Object) imggen.createImage ((byte[]) obj);
}
} else if (arguments[0] instanceof ESString) {
String imgurl = arguments[0].toString ();
img = remote ?
(Object) rgen.createPaintableImage (imgurl) :
(Object) imggen.createPaintableImage (imgurl);
}
} else if (arguments.length == 2) {
if (arguments[0] instanceof ESWrapper && arguments[1] instanceof ESWrapper) {
// create a new image from an existing one and an image filter
Object image = arguments[0].toJavaObject ();
Object filter = arguments[1].toJavaObject ();
img = imggen.createPaintableImage ((ImageWrapper) image, (ImageFilter) filter);
} else if (arguments[0].isNumberValue () && arguments[1].isNumberValue ()) {
img = remote ?
(Object) rgen.createPaintableImage (arguments[0].toInt32(), arguments[1].toInt32()) :
(Object) imggen.createPaintableImage (arguments[0].toInt32(), arguments[1].toInt32());
}
}
} catch (Exception error) {
System.err.println ("Error creating Image: "+error);
}
if (img == null)
throw new EcmaScriptException ("Error creating image: Bad parameters or setup problem.");
if (img == null)
throw new EcmaScriptException ("Error creating image: Bad parameters or setup problem.");
return new ESWrapper (img, this.evaluator);
return new ESWrapper (img, this.evaluator);
}
}
/**
* Called by the evaluator after the extension is loaded.
*/
public void initializeExtension(Evaluator evaluator) throws EcmaScriptException {
this.evaluator = evaluator;
GlobalObject go = evaluator.getGlobalObject();
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
ESObject image = new GlobalObjectImage ("Image", evaluator, fp, this); // the Image constructor
go.putHiddenProperty("Image", image); // register the constructor for a Image object.
}
}
}