// (c) MIT 2003.  All rights reserved.

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	MDoneSurfaceMutator.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	Mar 99
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:     Mechanical engineering 
//
// HISTORY:     Mar 99  archon  created
//
////////////////////////////////////////////////////////////////////////////////

package rec.meche;

import java.util.*;
import javax.swing.*;
import rec.sys.*;
import rec.core.widgets.*;

public class MDoneSurfaceMutator implements SurfaceMutator
{
  public MDoneSurfaceMutator()
  {
  }

  //////////////////////////////////////////////////////////////////////////////

  public void mutateSurface( Surface s )
  {
    // Do the standard clean up code.

    (new MCleanUpSurfaceMutator()).mutateSurface( s );

    // Repaint the changes.

    s.getScreen().repaint();

    Iterator iter = s.getWidgetsIterator();

    if( iter == null )
      return;

    while( iter.hasNext() ) {

      Widget vw = (Widget)iter.next();

      // Throw up a dialog box and tell user that there are unknown and/or
      //   unfinished parts on the surface.

      if( vw instanceof WMSpring ) {
	messageBox( s, "Please complete the spring part." );
	break;
      }

      if( vw instanceof WMBall ) {
	messageBox( s, "Please connect a socket to the ball." );
	break;
      }

      if( vw instanceof WMSocket ) {
	messageBox( s, "Please connect a ball to the socket." );
	break;
      }

      if( !( vw instanceof WPart ) ) {
	messageBox( s, "Unrecognized part." );
	break;
      }
    }
  }

  //////////////////////////////////////////////////////////////////////////////

  private static void messageBox( Surface s, String msg )
  {
    Object[] options = { "OK" };

    JOptionPane.showOptionDialog( s.getScreen(),
				  "Incomplete Drawing: " + msg,
				  "Done",
				  JOptionPane.DEFAULT_OPTION,
				  JOptionPane.WARNING_MESSAGE,
				  null,
				  options,
				  options[0] );
  }
}

////////////////////////////////////////////////////////////////////////////////
