package yi.iu.ui;
/*
	A basic extension of the java.awt.Frame class
 */

import java.awt.*;
import java.applet.*;
import java.net.*;
import symantec.itools.multimedia.ImageViewer;


public class BrowseFrame extends Frame
{
	public BrowseFrame()
	{
		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		setLayout(null);
		setSize(400,300);
		setVisible(false);
		add(imageViewer);
		imageViewer.setBounds(0,0,400,300);
		setTitle("Zoom in Frame");
		//}}

		//{{INIT_MENUS
		//}}

		//{{REGISTER_LISTENERS
		SymWindow aSymWindow = new SymWindow();
		this.addWindowListener(aSymWindow);
		//}}
	}

	public BrowseFrame(Applet applet, String imageName)
	{
		try {
		    URL url= new URL(imageName);
		    Image image= applet.getImage(url);
		    imageViewer.setImage(image);
		    int width= image.getWidth(this);
		    int height= image.getHeight(this);
		    setLayout(null);
		    setSize(width,height);
		    setVisible(false);
		    add(imageViewer);
		    imageViewer.setBounds(0,0,width,height);
		    setTitle(imageName);
        }
        catch (Exception e) {
            //status.append(e.toString() + "\r\n");
        }
		SymWindow aSymWindow = new SymWindow();
		this.addWindowListener(aSymWindow);
	}

    /**
     * Shows or hides the component depending on the boolean flag b.
     * @param b  if true, show the component; otherwise, hide the component.
     * @see java.awt.Component#isVisible
     */
    public void setVisible(boolean b)
	{
		if(b)
		{
			setLocation(50, 50);
		}
		super.setVisible(b);
	}

	static public void main(String args[])
	{
		(new BrowseFrame()).setVisible(true);
	}
	
	public void addNotify()
	{
	    // Record the size of the window prior to calling parents addNotify.
	    Dimension d = getSize();
	    
		super.addNotify();

		if (fComponentsAdjusted)
			return;

		// Adjust components according to the insets
		Insets insets = getInsets();
		setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
		Component components[] = getComponents();
		for (int i = 0; i < components.length; i++)
		{
			Point p = components[i].getLocation();
			p.translate(insets.left, insets.top);
			components[i].setLocation(p);
		}
		fComponentsAdjusted = true;
	}

    // Used for addNotify check.
	boolean fComponentsAdjusted = false;

	//{{DECLARE_CONTROLS
	symantec.itools.multimedia.ImageViewer imageViewer = new symantec.itools.multimedia.ImageViewer();
	//}}

	//{{DECLARE_MENUS
	//}}

	class SymWindow extends java.awt.event.WindowAdapter
	{
		public void windowClosing(java.awt.event.WindowEvent event)
		{
			Object object = event.getSource();
			if (object == BrowseFrame.this)
				ZoomInFrame_WindowClosing(event);
		}
	}
	
	void ZoomInFrame_WindowClosing(java.awt.event.WindowEvent event)
	{
		setVisible(false);		 // hide the Frame
		this.dispose();
	}
}
