package DefileImages;
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.awt.image.FilteredImageSource;
import java.net.MalformedURLException;
import java.net.URL;
public class animation extends Applet implements Runnable
{
private Thread m_animation;
private Graphics m_Graphics;
private Image m_Images[];
private int m_nCurrImage;
private int m_nNextImage;
private int m_nImgWidth[];
private int m_nImgHeight[];
private boolean m_fAllLoaded;
private int m_numImages;
private String m_imageString[];
private URL m_docUrl;
private int m_transitionSteps;
private Image m_transImage1;
private Image m_transImage2;
private Image m_transImage[];
private int m_transitionTime;
private String m_url;
private String m_target;
private int m_time;
private String m_effectString;
private String m_image;
private int m_effect;
private final String PARAM_time = "time";
private final String PARAM_effect = "rotatoreffect";
private final String PARAM_image = "image";
private final String PARAM_url = "url";
private final String PARAM_target = "target";
public void stop()
{
if(m_animation != null)
{
m_animation.stop();
m_animation = null;
}
}
public boolean mouseEnter(Event event, int i, int j)
{
showStatus(m_url);
return true;
}
public boolean mouseExit(Event event, int i, int j)
{
showStatus("");
return true;
}
public void paint(Graphics g)
{
if(m_fAllLoaded)
{
Rectangle rectangle = g.getClipRect();
g.clearRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
displayImage(g, m_Images[m_nCurrImage], m_nImgWidth[m_nCurrImage], m_nImgHeight[m_nCurrImage]);
}
}
public boolean mouseUp(Event event, int i, int j)
{
return true;
}
public String[][] getParameterInfo()
{
String as[][] = {{"time", "int", "Display time in seconds" },
{"rotatoreffect", "String", "Transition effect"},
{"image" + 1, "String", "Image number 1"},
{"image" + 2, "String", "Image number 2"},
{"url", "String", "Url"},
{"target", "String", "Target frame"}
};
return as;
}
public void destroy()
{
}
private void displayImage(Graphics g, Image image, int i, int j)
{
if(!m_fAllLoaded)
{
return;
} else
{
g.drawImage(image, (size().width - i) / 2, (size().height - j) / 2, null);
return;
}
}
public animation()
{
m_transitionSteps = 4;
m_transImage = new Image[m_transitionSteps];
m_url = "";
m_target = "";
m_time = 3;
m_effectString = "";
m_image = "";
m_effect = 3;
}
public void start()
{
if(m_animation == null)
{
m_animation = new Thread(this);
m_animation.start();
}
}
public String getAppletInfo()
{
return "Name: animation\r\n" + "Author: VIM\r\n" + "Created with Eclipse";
}
public boolean mouseDown(Event event, int i, int j)
{
if(!m_url.equalsIgnoreCase("") && m_docUrl != null)
{
if(m_target.equalsIgnoreCase(""))
{
getAppletContext().showDocument(m_docUrl);
} else
{
getAppletContext().showDocument(m_docUrl, m_target);
}
}
return true;
}
public void run()
{
m_nCurrImage = 0;
if(!m_fAllLoaded)
{
repaint();
m_Graphics = getGraphics();
m_Images = new Image[m_numImages];
m_nImgWidth = new int[m_numImages];
m_nImgHeight = new int[m_numImages];
MediaTracker mediatracker = new MediaTracker(this);
for(int l = 0; l < m_numImages; l++)
{
m_Images[l] = getImage(getDocumentBase(), m_imageString[l]);
mediatracker.addImage(m_Images[l], 0);
}
try
{
mediatracker.waitForAll();
m_fAllLoaded = !mediatracker.isErrorAny();
}
catch(InterruptedException _ex) { }
if(!m_fAllLoaded)
{
stop();
return;
}
for(int i1 = 0; i1 < m_numImages; i1++)
{
m_nImgWidth[i1] = m_Images[i1].getWidth(this);
m_nImgHeight[i1] = m_Images[i1].getHeight(this);
}
} else
{
repaint();
}
do
{
try
{
int j1 = m_nImgWidth[m_nCurrImage];
int k1 = m_nImgHeight[m_nCurrImage];
int l1 = (size().width - j1) / 2;
int i2 = (size().height - k1) / 2;
m_nNextImage = m_nCurrImage + 1;
if(m_nNextImage == m_numImages)
{
m_nNextImage = 0;
}
int j2 = m_nImgWidth[m_nNextImage];
int k2 = m_nImgHeight[m_nNextImage];
int l2 = (size().width - j2) / 2;
int i3 = (size().height - k2) / 2;
int j3 = Math.max(j1, j2);
int k3 = Math.max(k1, k2);
int l3 = (size().width - j3) / 2;
int i4 = (size().height - k3) / 2;
m_transImage1 = createImage(j3, k3);
Graphics g = m_transImage1.getGraphics();
int j4 = l1 - l3;
int k4 = i2 - i4;
g.drawImage(m_Images[m_nCurrImage], j4, k4, null);
int l4 = m_effect != 0 ? m_transitionSteps : 1;
for(int i = 0; i < l4; i++)
{
m_transImage[i] = createImage(j3, k3);
}
m_transImage2 = createImage(j3, k3);
Graphics g1 = m_transImage2.getGraphics();
j4 = l2 - l3;
k4 = i3 - i4;
g1.drawImage(m_Images[m_nNextImage], j4, k4, null);
displayImage(m_Graphics, m_transImage1, j3, k3);
for(int j = 0; j < l4; j++)
{
applyEffect(j, m_transitionSteps, j3, k3, m_effect);
}
int i5 = m_time * 1000;
if(m_time == 0)
{
i5 = 50;
}
Thread.sleep(i5);
for(int k = 0; k < l4; k++)
{
displayImage(m_Graphics, m_transImage[k], j3, k3);
if(m_transitionTime > 0)
{
Thread.sleep(m_transitionTime);
}
}
m_nCurrImage = m_nNextImage;
}
catch(InterruptedException _ex)
{
stop();
}
} while(true);
}
public void init()
{
String s = getParameter("time");
if(s != null)
{
m_time = Integer.parseInt(s);
}
s = getParameter("rotatoreffect");
if(s != null)
{
m_effectString = s;
}
if(m_effectString.equalsIgnoreCase("none"))
{
m_effect = 0;
}
if(m_effectString.equalsIgnoreCase("blindsHorizontal"))
{
m_effect = 1;
} else
if(m_effectString.equalsIgnoreCase("blindsVertical"))
{
m_effect = 2;
} else
if(m_effectString.equalsIgnoreCase("dissolve"))
{
m_effect = 3;
} else
if(m_effectString.equalsIgnoreCase("boxIn"))
{
m_effect = 4;
} else
if(m_effectString.equalsIgnoreCase("boxOut"))
{
m_effect = 5;
}
m_numImages = 0;
m_imageString = new String[100];
int i = 1;
do
{
s = getParameter("image" + i);
if(s == null)
{
break;
}
m_imageString[m_numImages++] = s;
} while(++i <= 99);
s = getParameter("url");
if(s != null)
{
m_url = s;
}
s = getParameter("target");
if(s != null)
{
m_target = s;
}
try
{
m_docUrl = new URL(getDocumentBase(), m_url);
}
catch(MalformedURLException _ex) { }
}
public void applyEffect(int i, int j, int k, int l, int i1)
{
anime anime1 = new anime(i, j, k, l, i1);
FilteredImageSource filteredimagesource = new FilteredImageSource(m_transImage2.getSource(), anime1);
m_transImage[i] = createImage(filteredimagesource);
}
}
|