import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.AbstractAction;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

import java.rmi.RemoteException;

import visad.*;
import visad.java3d.*;

/**
 Should throw an exception when you move the JFrame to a 2nd monitor and 
 then click the Open JDialog button
 */
public class TestBug
{
	private JFrame jFrame;
	
	public TestBug() throws VisADException, RemoteException
	{
		DisplayImplJ3D display = new DisplayImplJ3D("display1");
		JButton openButton = new JButton(new OpenAction());
		
		jFrame = new JFrame("Test 2 monitor bug");
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jFrame.getContentPane().add(display.getComponent(),
			BorderLayout.CENTER);
		jFrame.getContentPane().add(openButton, BorderLayout.SOUTH);
		jFrame.setSize(800, 600);
		jFrame.setVisible(true);
	}
	
	private class OpenAction extends AbstractAction
	{
		public OpenAction()
		{
			super("Open JDialog");
		}


		/**
		 * Open a JDialog with another DisplayImplJ3D inside
		 */
		public void actionPerformed(ActionEvent actionEvent)
		{
			try {
				DisplayImplJ3D disp = new DisplayImplJ3D(
					"display2");
				
				JDialog dialog = new JDialog(jFrame,
					"A JDialog");
				dialog.getContentPane().add(
					disp.getComponent());
				dialog.setSize(800, 600);
				dialog.setVisible(true);
				
			} catch (VisADException ve) {
				System.err.println("TestBug.openingDialog:  "
					+ ve);
			} catch (RemoteException re) {
				System.err.println("TestBug.openingDialog: "
					+ re);
			}
		}
	}
	
	public static void main(String[] args) throws VisADException, 
		RemoteException
	{
		TestBug test = new TestBug();
	}
}
