home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.multimedia;
-
- import java.awt.Canvas;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.net.MalformedURLException;
- import java.net.URL;
-
- public strictfp class ImageViewer extends Canvas {
- protected Image image;
- protected String fileName;
- protected URL url;
- protected boolean centerMode;
-
- public ImageViewer() {
- this.image = null;
- this.fileName = null;
- this.url = null;
- this.centerMode = true;
- }
-
- public ImageViewer(String str) throws MalformedURLException {
- this.setFileName(str);
- }
-
- public ImageViewer(URL url) {
- this.setURL(url);
- }
-
- public ImageViewer(Image img) {
- this.setImage(img);
- }
-
- public void setFileName(String str) {
- try {
- this.fileName = str;
- this.setURL(new URL(this.fileName));
- } catch (MalformedURLException var2) {
- }
-
- ((Component)this).repaint();
- }
-
- public String getFileName() {
- return this.fileName;
- }
-
- public void setURL(URL aUrl) {
- this.url = aUrl;
- this.fileName = null;
- Image loadedImage = ((Component)this).getToolkit().getImage(this.url);
- if (loadedImage != null) {
- this.setImage(loadedImage);
- ((Component)this).repaint();
- }
-
- }
-
- public URL getURL() {
- return this.url;
- }
-
- public void setCenterMode(boolean flag) {
- if (this.centerMode != flag) {
- this.centerMode = flag;
- ((Component)this).repaint();
- }
-
- }
-
- public boolean getCenterMode() {
- return this.centerMode;
- }
-
- public void setImage(Image img) {
- this.fileName = null;
- this.image = img;
- if (img != null) {
- try {
- MediaTracker tracker = new MediaTracker(this);
- tracker.addImage(this.image, 0);
- tracker.waitForID(0);
- } catch (InterruptedException var3) {
- }
- } else {
- ((Component)this).repaint();
- }
- }
-
- public Image getImage() {
- return this.image;
- }
-
- public void paint(Graphics g) {
- if (this.image != null) {
- Dimension dim = ((Component)this).size();
- g.clipRect(0, 0, dim.width, dim.height);
- int x = 0;
- int y = 0;
- if (this.centerMode) {
- x += (dim.width - this.image.getWidth(this)) / 2;
- y += (dim.height - this.image.getHeight(this)) / 2;
- }
-
- g.drawImage(this.image, x, y, this);
- }
-
- }
-
- public Dimension preferredSize() {
- return this.image != null ? new Dimension(this.image.getWidth(this), this.image.getHeight(this)) : new Dimension(10, 10);
- }
-
- public Dimension minimumSize() {
- return this.preferredSize();
- }
- }
-