import java.awt.*;
import java.awt.Color;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.lang.StringBuffer;

import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.text.*;
import com.sun.java.swing.tree.*;

//--------------------------
// Clase se, principal.
//--------------------------
class s {
        VentInicio VentI = new VentInicio("SEABDsWeb, Sistema Editor de Aplicaciones de BDs Web, para SiMBaDD");
       // ManipulaArch oMArch = new ManipulaArch();

      FrameVenProy FVenProy = new FrameVenProy(" ");

      //  FrameArbolVentProy FArbolVentProy = new FrameArbolVentProy("Arbol de la Estructura de Ventanas del Proyecto");
      //  FrameRelacArbolVP FRelacArbolVP = new FrameRelacArbolVP("Arbol de la Lista de Ventanas (Base) del Proyecto");
      //  FrameBarraMenu FBarraMenu = new FrameBarraMenu("Agregar Menú a la Barra de Menú");
      //  FrameSubMenu FSubMenu = new FrameSubMenu("Agregar Submenú a los Menús de la Barra de Menú");
        FrameEtiqueta FEtiqueta = new FrameEtiqueta("Características de Etiqueta (Label)");
	FrameCampoTexto FCampoTexto = new FrameCampoTexto("Características de Campo de Texto");
	FrameBoton FBoton = new FrameBoton("Características de Botón");
      //  GenerarCodigo GenCod = new GenerarCodigo("Generación de Código, especificar datos");

    s() {
      //  VentI.guardarRuta();
        VentI.setBounds(0,0,700,55);
        VentI.show();
    }

    static public void main(String[] args)
     {
      new s();
    }



//******************
// SubClases.
//******************

	//----------------------------------------------------------------------------------------
	// Clase VentInicio, Ventana inicial, la Vent. Ppal. del Editor. 
	//----------------------------------------------------------------------------------------  
	class VentInicio extends FrameGral {
	  boolean archNuevoAbierto = false; 
	  CheckboxMenuItem pruebaCB = new CheckboxMenuItem("Probar Componentes");
        CheckboxMenuItem ElimUno = new CheckboxMenuItem("Eliminar Un Componente  Ctrl+Shift+MouseDown");
	  Label TipoVent;
	  Label BDVent;
	  Label identVent;
        public Menu mpa = new Menu("Archivo");
        public Menu mpb = new Menu("Edición");
        public Menu mpc = new Menu("Adición");
        public Menu mpe = new Menu("Código");
        public Menu mpd = new Menu("Ayuda");
        MenuItem mpbb = new MenuItem("Estructura de Menús");
        MenuItem mpbd = new MenuItem("Ubicación y Dimensiones de Ventana");
        MenuItem mpbg = new MenuItem("Lista de Ventanas");
        MenuItem mpca = new MenuItem("Campo de Texto");
        MenuItem mpcb = new MenuItem("Fondo (Background)");
        MenuItem mpcc = new MenuItem("Botón");
        MenuItem mpcd = new MenuItem("Menús");
        MenuItem mpce = new MenuItem("Submenús");
        MenuItem mpea = new MenuItem("Generar Código");
        MenuItem msaa = new MenuItem("Nuevo", new MenuShortcut(KeyEvent.VK_N));
        MenuItem msab = new MenuItem("Abrir", new MenuShortcut(KeyEvent.VK_A));
        MenuItem msac = new MenuItem("Guardar", new MenuShortcut(KeyEvent.VK_G));
        MenuItem msad = new MenuItem("Guardar como", new MenuShortcut(KeyEvent.VK_O));
        MenuItem msae = new MenuItem("Cerrar", new MenuShortcut(KeyEvent.VK_C));
        MenuItem msag = new MenuItem("Salir", new MenuShortcut(KeyEvent.VK_S));
	  int ContVentAbiertas = 0;	//Num. de Vents. que se encuentran abiertas (Visibles). 

             //Del Frame FrameArbolVentProy. 
          Nodo EstrucArbol = new Nodo("Estructura de Ventanas", 0, 0);
             //Del Frame FrameRelacArbolVP.
          Nodo RelaciArbol = new Nodo("Lista de Ventanas", 0, 0);
             //Nodo que se encuentra en Edición en determinado momento. 
          Nodo NodoEdicion = new Nodo(" ", 0, 0);
	  DefaultMutableTreeNode TreeNodeEdicion = null;

	public VentInicio(String title) {
        super(title);
        MenuBar mb = new MenuBar();
	  Menu mpb2;
	  MenuItem mpb2ia, mpb2ib, mpb2ic, mpb2id, mpb2ie, mpb2if;

        ActionListener actionListener = new EventosAccion();
 	  // Inicializa el Menu de Archivo.
        msaa.setActionCommand("Nuevo");
	  msaa.setEnabled(true);   
        msaa.addActionListener(this);
	  mpa.add(msaa);
        msab.setActionCommand("Abrir");
	  msab.setEnabled(true);   
        msab.addActionListener(this);
	  mpa.add(msab);
	  mpa.addSeparator();      //----, Separador de menu.
        msac.setActionCommand("Guardar");
	  msac.setEnabled(false);
        msac.addActionListener(this);
	  mpa.add(msac);
        msad.setActionCommand("Guardar como");
	  msad.setEnabled(false);   
        msad.addActionListener(this);
	  mpa.add(msad);
        msae.setActionCommand("Cerrar");
	  msae.setEnabled(false);
        msae.addActionListener(this);
	  mpa.add(msae);
	  mpa.addSeparator();      //----, Separador de menu.
        msag.setActionCommand("Salir");
        msag.addActionListener(this);
	  mpa.add(msag);
        mpa.setEnabled(true);   
        mb.add(mpa);
        // Inicializa Menú de Edición. 
        pruebaCB.addItemListener(new EventosItem());  
        mpb.add(pruebaCB);       //Prueba.
        pruebaCB.setEnabled(false);  
  	  mpb.addSeparator();      //----, Separador de menu. 	  
        mpb.add(ElimUno);        //Elimina UN Componente.
        ElimUno.setEnabled(true);     //false);   
  	  mpb.addSeparator();      //----, Separador de menu.
	    mpb2 = new Menu("Ventanas");	
		mpb2ia = new MenuItem("Altas");
		mpb2.add(mpb2ia);
		mpb2ib = new MenuItem("Bajas");
		mpb2.add(mpb2ib);
		mpb2ic = new MenuItem("Modificaciones");
		mpb2.add(mpb2ic);
		mpb2id = new MenuItem("Consultas");
		mpb2.add(mpb2id);
		mpb2.addSeparator();      //----, Separador de menu.
		mpb2if = new MenuItem("Menú");		
		mpb2.add(mpb2if);
		mpb2.addSeparator();      //----, Separador de menu.
		mpb2ie = new MenuItem("Mensajes");
		mpb2.add(mpb2ie);
	    mpb2.addActionListener(this);
	  mpb.add(mpb2);
	    mpbg.setActionCommand("Lista de Ventanas");
	    mpbg.addActionListener(this);
	  mpb.add(mpbg);
	    mpbb.setActionCommand("Estructura de Menús");
	    mpbb.addActionListener(this);
	  mpb.add(mpbb);
  	  mpb.addSeparator();      //----, Separador de menu.
          mpbd.setActionCommand("Ubicación y Dimensiones de Ventana");
            mpbd.setEnabled(true);       //false);   
          mpbd.addActionListener(this);
	  mpb.add(mpbd);
        mb.add(mpb);
        mpb.setEnabled(true);   //false);   
        mpb.addActionListener(actionListener);

        // Inicializa Menú de Adición. 
	    mpcc.setActionCommand("Botón");
          mpcc.addActionListener(this);
	  mpc.add(mpcc);
	  mpc.add("Etiqueta");
	    mpca.setActionCommand("Campo de Texto");
          mpca.addActionListener(this);
	  mpc.add(mpca);
  	  mpc.addSeparator();      //----, Separador de menu.
          mpcd.setActionCommand("Menús");
          mpcd.addActionListener(this);
	  mpc.add(mpcd);
          mpce.setActionCommand("Submenús");
          mpce.addActionListener(this);
	  mpc.add(mpce);
	  mpc.addSeparator();
	    mpcb.setActionCommand("Fondo (Background)");
          mpcb.addActionListener(this);
	  mpc.add(mpcb);

        mpc.setEnabled(true);     //false);

          mpc.addActionListener(actionListener);
        mb.add(mpc);

	  //Inicializa menu Códigio.
	  mpea.setActionCommand("Generar Código");
        mpea.addActionListener(this);
        mpe.add(mpea);
        mpe.setEnabled(true);    //false);
        mb.add(mpe);

	  //Inicializa menu Ayuda.
        mpd.add("Objetivo");
	  mpd.add("Operación");
	  mpd.add("Acerca del SW");
        mpd.addActionListener(actionListener);
        mb.add(mpd);

        // Coloca la barra de Menú en el frame.
        setMenuBar(mb);

        // Remueve el manejador de Layout, que existe por default.
        setLayout(null);
        }

	// Se sobreescribe el método de cierre de ventana.
	public void windowClosing(WindowEvent evt) {
		if (archNuevoAbierto) {
                     //   SalirSalvar SalSalv  = new SalirSalvar();
                     //   SalSalv.setBounds(200,70,250,120);
                     //   SalSalv.show();
		} else {
			System.exit( 0 );
		}
	}

	public void actionPerformed(ActionEvent evt) {
        String arg = evt.getActionCommand();
        FileDialog fd;
	  Frame window;
        if (evt.getSource() instanceof MenuItem) {
            MenuItem mi = (MenuItem)evt.getSource();
            MenuShortcut ms = mi.getShortcut();
        }
		if ("Nuevo".equals(arg)) {
		  boolean correcto = false;
		  int i = 0;
	        fd = new FileDialog(this, "Nuevo Proyecto, Guardar como", FileDialog.SAVE);
               // fd.setDirectory(oMArch.RutaPpal);
       	  fd.setFile("Proy.pro");	//Especifica el Nombre del "archivo".
	        fd.show();
		  if(fd.getFile() != null) {
			do {
				if (!Character.isLetterOrDigit(fd.getFile().charAt(i)) && ('_' != fd.getFile().charAt(i)) && ('-' != fd.getFile().charAt(i))) {
					if ('.' == fd.getFile().charAt(i)) {
						correcto = true;
					} else {
						correcto = false;
					}
				}
				i++;
			} while (i != fd.getFile().length());
			if (correcto) {
				if (!(".pro".equals((fd.getFile().substring(fd.getFile().length()-4 , fd.getFile().length()))))) {
					correcto = false;
				}
			}
			if (correcto) {
                       //         oMArch.archivo = fd.getFile();
                       //         GenCod.NombreProyecto = fd.getFile().substring(0 , fd.getFile().length()-4);

                        /*        if (oMArch.GuardarArch(oMArch.RutaPpal, oMArch.archivo)) {
                                        EstrucArbol = new Nodo("Estructura de Ventanas", 0, 0);
					RelaciArbol = new Nodo("Lista de Ventanas", 0, 0);
					FEtiqueta = new FrameEtiqueta("Características de Etiqueta (Label)");
					FCampoTexto = new FrameCampoTexto("Características de Campo de Texto");
					FBoton = new FrameBoton("Características de Botón");
                         
				}
                          */

                        		mpb.setEnabled(true);	// Menú principal Edicion.
                                        mpc.setEnabled(true);  //false);  // Menú principal Adición.
					mpe.setEnabled(true);	// Menú principal Código.
					msaa.setEnabled(false);	// Submenú principal Nuevo.
					msab.setEnabled(false);	// Submenú principal Abrir.
					msac.setEnabled(true);	// Submenú principal Guardar.
					msad.setEnabled(true);	// Submenú principal Guardar Como.
					msae.setEnabled(true);	// Submenú principal Cerrar.
					archNuevoAbierto = true;

                        } else {
                               // ErrMen ErrorM = new ErrMen("ERROR...", "---ERROR: Falta, extención \".pro\" para el archivo...");
			}
		  }
            } else if ("Abrir".equals(arg)) {
	        fd = new FileDialog(this, null, FileDialog.LOAD);
               // fd.setDirectory(oMArch.RutaPpal);
	        fd.show();
		  if(fd.getFile() != null) {
			File arch2 = new File(fd.getDirectory() + fd.getFile());
			if (arch2.exists()) {
                         /*       oMArch.RutaPpal = fd.getDirectory();
				oMArch.archivo = fd.getFile();
				GenCod.NombreProyecto = fd.getFile().substring(0 , fd.getFile().length()-4);
				msad.setEnabled(true);
				oMArch.AbreArch(oMArch.RutaPpal, oMArch.archivo);
                         */
                        	mpb.setEnabled(true);	// Menú principal Edicion.
				mpc.setEnabled(false);	// Menú principal Adición.
				mpe.setEnabled(true);	// Menú principal Código.
				msaa.setEnabled(false);	// Submenú principal Nuevo.
				msab.setEnabled(false);	// Submenú principal Abrir.
				msac.setEnabled(true);	// Submenú principal Guardar.
				msad.setEnabled(true);	// Submenú principal Guardar Como.
				msae.setEnabled(true);	// Submenú principal Cerrar.
				archNuevoAbierto = true;
			} else {
//				System.out.println("---ERROR: Incorrecto, archivo inexistente...");
                         //     ErrMen ErrorM = new ErrMen("ERROR...", "---ERROR: Incorrecto, archivo inexistente...");
			}
		  }
            } else if ("Cerrar".equals(arg)) {
                /*
                  if (oMArch.GuardarArch(oMArch.RutaPpal, oMArch.archivo)) {
			if (ContVentAbiertas >= 1) {
				FVenProy.setVisible(false);
			}
                        FArbolVentProy.setVisible(false);
			FRelacArbolVP.setVisible(false);
			FEtiqueta.setVisible(false);
			FCampoTexto.setVisible(false);
			FBoton.setVisible(false);
                
                	mpb.setEnabled(false);	// Menú principal Edicion.
			mpc.setEnabled(false);	// Menú principal Adición.
			mpe.setEnabled(false);	// Menú principal Código.
			msaa.setEnabled(true);	// Submenú principal Nuevo.
			msab.setEnabled(true);	// Submenú principal Abrir.
			msac.setEnabled(false);	// Submenú principal Guardar.
			msad.setEnabled(false);	// Submenú principal Guardar Como.
			msae.setEnabled(false);	// Submenú principal Cerrar.
			archNuevoAbierto = false;
			pruebaCB.setEnabled(false);	// Submenú principal Prueba Componente.
			ElimUno.setEnabled(false);	// Submenú principal Eliminar Un Componente.
			mpbd.setEnabled(false);	// Submenú principal Ubicación y Dimención de Vent.
			mpcd.setEnabled(false);	// Submenú principal Barra de Menú.
			mpce.setEnabled(false);	// Submenú principal "Submenús".
		  }
                */
            } else if ("Guardar".equals(arg)) {
                //  oMArch.GuardarArch(oMArch.RutaPpal, oMArch.archivo);
            } else if ("Guardar como".equals(arg)) {
	        fd = new FileDialog(this, null, FileDialog.SAVE);
               // fd.setDirectory(oMArch.RutaPpal);
               // fd.setFile(oMArch.archivo);
	        fd.show();
		  fd.setFile(fd.getFile());
		  if(fd.getFile() != null) {
                     //   oMArch.GuardarArch(oMArch.RutaPpal, fd.getFile());
		  }
            } else if ("Salir".equals(arg)) {
		  if (archNuevoAbierto) {
                    /*    SalirSalvar SalSalv  = new SalirSalvar();
			SalSalv.setBounds(200,70,250,120);
			SalSalv.show();
                    */
		  } else {
			System.exit( 0 );
		  }
            } else if ("Estructura de Menús".equals(arg)) {
               /*   FArbolVentProy.setVisible(false);
		  FArbolVentProy = new FrameArbolVentProy("Arbol de la Estructura de Ventanas del Proyecto");
		  FArbolVentProy.setBounds(80,70,700,400);
		  FArbolVentProy.show();
               */
            } else if ("Lista de Ventanas".equals(arg)) {
               /*
        	  FRelacArbolVP.setVisible(false);
		  FRelacArbolVP = new FrameRelacArbolVP("Arbol de la Lista de Ventanas (Base) del Proyecto");
		  FRelacArbolVP.setBounds(80,70,400,400);
		  FRelacArbolVP.show();
               */
            }

                else if ("Botón".equals(arg)) {
		  FBoton.setBounds(150,40,300,170);
		  FBoton.show();
		} else if ("Campo de Texto".equals(arg)) {
		  FCampoTexto.tfd.setText("");
	  	  FCampoTexto.setBounds(150,40,290,230);
		  FCampoTexto.show();
		}
            
	}

	class EventosAccion implements ActionListener {
        public void actionPerformed(ActionEvent evt) {
        String arg = evt.getActionCommand();
	  Frame window;
           if ("Etiqueta".equals(arg)) {
	  	  FEtiqueta.setBounds(150,40,500,240);
		  FEtiqueta.show();	
            } else if ("Objetivo".equals(arg)) {
		  window = new FrameGral("Ayuda, Objetivo");
		  Panel p = new Panel();
                  p.setLayout(new GridLayout(3, 0));
		  p.add(new Label("        Producir \"interfaces al usuario\", para aplicaciones de bases de datos localizadas en"));
		  p.add(new Label("   un determinado sitio Web, que puedan ser accesadas a través de internet. Por lo cual")); 
		  p.add(new Label("   tales interfaces son un sistema de páginas Web."));
		  window.add(p, BorderLayout.CENTER); 
	  	  window.setBounds(180,40,520,100);
		  window.show();
            } else if("Operación".equals(arg)) {
		  window = new FrameGral("Ayuda, Objetivo");
		  Panel p = new Panel();
                  p.setLayout(new GridLayout(6, 0));
		  p.add(new Label("          PASOS:"));
		  p.add(new Label("  1.- Seleccione 'Archivo', después 'Guardar Ruta', y en 'Archivo donde se guardará la Ruta',"));
		  p.add(new Label("  seleccione 'Guardar', aparecerá '¿Desea reemplazarlo?', seleccione 'Sí'."));
		  p.add(new Label("  2.- Seleccione 'Aceptar', 'Nuevo' o 'Abrir'"));
		  p.add(new Label("  "));
		  p.add(new Label("  "));
		  window.add(p, BorderLayout.CENTER); 
	  	  window.setBounds(180,40,550,100);
		  window.show();
            } else if("Acerca del SW".equals(arg)) {
		  window = new FrameGral("Ayuda, Objetivo");
		  Panel p = new Panel();
                  p.setLayout(new GridLayout(5, 0));
		  p.add(new Label("   -\"Sistema Editor de Interfaces de Aplicaciones de BD como Páginas Web\", Generador de Código."));
		  p.add(new Label("   -Ver. 1.0"));
		  p.add(new Label("   -Tesis de Maestría: \"Generador de Codigo de Interfaces Web para un Servidor de BD Distribuidas\"."));
		  p.add(new Label("   -Cenidet, Cuernavaca, Mor."));
		  p.add(new Label("   -Autor: I.S.C. Ismael Armando Zúñiga Félix."));
		  window.add(p, BorderLayout.CENTER); 
	  	  window.setBounds(180,40,600,130);
		  window.show();
            } 
        }
	}
	class EventosItem implements ItemListener {
        public void itemStateChanged(ItemEvent evt) {
        //    FVenProy.TodoComp = FVenProy.getComponents();
            boolean NuevoEdo = (evt.getStateChange() == ItemEvent.SELECTED);
            // Se habilitan todos los componentes.
            for (int i=0; i<FVenProy.TodoComp.length; i++) {
        //        FVenProy.TodoComp[i].setEnabled(NuevoEdo);
            }
        }
	}
	protected void guardarRuta() {
		String tmp;
		File arch1 = new File("proyectos");
               // oMArch.RutaPpal = arch1.getAbsolutePath() + arch1.separator;

		msaa.setEnabled(true);
		msab.setEnabled(true);
	}
    } //VentInicio.






    //----------------------------------------------------------------------------------------
    // Clase FrameVenProy, Para las Ventanas del Proyecto.
    //----------------------------------------------------------------------------------------
    class FrameVenProy extends FrameGralNivel0 implements ActionListener
     {
      MenuBar mbar = new MenuBar();
      Vector submenus = new Vector();
      Vector menus = new Vector();

      Component[] TodoComp;
      MenuBar mebar = new MenuBar();
      int cont = 0, contM = 0;
      Component arrastrar;
      Component estirar;
      Component c;
      Point desplazamiento, desplaza = new Point(0,0);

      public FrameVenProy(String title)
       {
        super(title);

        Menu m = new Menu("Op");

        m.add("Cerrar");
        mebar.add(m);
        setMenuBar(mebar);
        EventosMouse mouseListener = new EventosMouse();
               // Escuchando por eventos.
        addMouseListener(mouseListener);
        addMouseMotionListener(mouseListener);
               // Remueve el manejador de Layout, que existe por default.
        setLayout(null);
        setBounds(150,250,400,400);
      }

      public void windowClosing(WindowEvent e)
       {
        VentI.ContVentAbiertas--;
        if (VentI.ContVentAbiertas == 0)
         {
          VentI.mpc.setEnabled(false);         // Menú principal Adición.
          VentI.pruebaCB.setEnabled(false);    // Submenú principal Prueba Componente.  
          VentI.ElimUno.setEnabled(false);     // Submenú principal Eliminar Un Componente.
          VentI.mpbd.setEnabled(false);        // Submenú principal Ubicación y Dimención de Vent.
          VentI.mpcd.setEnabled(false);        // Submenú principal Barra de Menú.
          VentI.mpce.setEnabled(false);        // Submenú principal "Submenús".
        }
        FrameVenProy.this.setVisible(!isVisible());
      }

      public void actionPerformed(ActionEvent ev)
       {
        Object src = ev.getSource();
        String what = ev.getActionCommand();

        if (src instanceof MenuItem)
         {
          cont++;
          if (cont == 1)
           {
            //  FSubMenu.SeleccionSubmenu(what);
          }
        }
      }



      /*----------------------
        Class EventosMouse
      ---------------*/

      class EventosMouse extends MouseAdapter implements MouseMotionListener
       {


        public void mousePressed(MouseEvent evt)
         {
          int ElimCompV = 0;          //Indica si se eliminara un "Componente".
          String strTmp;              //Nombre del Componente.
          String strTmp2 = "lbt";     //Tipo de Componente.
          int x = evt.getX();
          int y = evt.getY();
          c = getComponentAt(x, y);
          strTmp = c.getName();


          System.out.println("mousePressed");

               //Eliminar componente, fisicamente de pantalla, por menu y raton.
          if(c != null && c != FrameVenProy.this && VentI.ElimUno.getState())
           {
            VentI.ElimUno.setState(false);
            remove(c);
            ElimCompV = 1;  
          }
          else if(c != null && c != FrameVenProy.this)
           {
                  //Eliminar componente, fisicamente de pantalla, por teclado y raton.
            if(evt.isShiftDown() && evt.isControlDown())
             {
              remove(c);
              ElimCompV = 1;
                     //Visualizar la ventana instanciada por un Boton, que se encuentra en una Vent. tipo menu. 
            }
            else if(evt.isShiftDown() && (strTmp.charAt(0) == strTmp2.charAt(1)))     //Se usa la combinacion shift y raton.
             {
              strTmp = c.getName();
              strTmp = strTmp.substring(6, strTmp.length());      //Obtiene identificador del Boton.
              FBoton.VerInstBV(java.lang.Integer.parseInt(strTmp));
               //Permite ver el "Atributo" de la BD. al cual se refiere un determinado Campo de Texto. 
            }
            else if(evt.isShiftDown() && (strTmp.charAt(0) == strTmp2.charAt(2)))   //Se usa la combinacion shift y raton.
             {
              strTmp = strTmp.substring(9, strTmp.length());  //Obtiene identificador del C. Texto.
              FCampoTexto.MenAtributo = new Mensajes("Nombre de Atributo...", FCampoTexto.AtributoCTexto(java.lang.Integer.parseInt(strTmp)));
              FCampoTexto.MenAtributo.setBounds(400,70,300,50);
              FCampoTexto.MenAtributo.show();
              // Para redimencionar un componente, exepto Etiquetas.
            }
            else if(evt.isAltDown())
             {
              strTmp = c.getName();
              if(strTmp.charAt(0) != strTmp2.charAt(0))
               {
                 estirar = c;
              }
            }
            else
             {
               desplazamiento = new Point(x-c.getLocation().x, y-c.getLocation().y);
               arrastrar = c;
            }
          }


          if(ElimCompV == 1)  //Eliminar un componente, de memoria, segun su tipo.
           {
            //Identifica el tipo de componente a eliminar.
            if (strTmp.charAt(0) == strTmp2.charAt(0))
             {
              strTmp = strTmp.substring(5, strTmp.length());  //Obtiene identificador de la Etiqueta.
              //FEtiqueta.EliminEtiq(java.lang.Integer.parseInt(strTmp));       //Elimina la etiqueta.
            }
            else if(strTmp.charAt(0) == strTmp2.charAt(1))
             {
              strTmp = strTmp.substring(6, strTmp.length());  //Obtiene identificador del Boton.
             // FBoton.EliminBoton(java.lang.Integer.parseInt(strTmp));
            }
            else if(strTmp.charAt(0) == strTmp2.charAt(2))
             {
              strTmp = strTmp.substring(9, strTmp.length());  //Obtiene identificador del C. Texto.
              //FCampoTexto.EliminCTexto(java.lang.Integer.parseInt(strTmp));   //Elimina Campo de Texto.
            }
          }
        }




        public void mouseReleased(MouseEvent evt)   //Liberar el ratón (boton izq.).
         {
          String strTmp;                  //Nombre del Componente.
          String strTmp2 = "lbt";         //Tipo de Componente.


          System.out.println("mouseReleased");


          if (arrastrar != null)
           {
                //Identifica el tipo de componente a reubicar.
            if(!(desplaza.x == 0 && desplaza.y == 0))
             {
              strTmp = c.getName();
              if(strTmp.charAt(0) == strTmp2.charAt(0))             //Etiqueta.
               {
                strTmp = strTmp.substring(5, strTmp.length());  //Obtiene identificador de la Etiqueta.
                //Guarda la nueva ubicacion de la Etiqueta. 
                //FEtiqueta.GuardarEtiq(java.lang.Integer.parseInt(strTmp), desplaza);
              }
              else if(strTmp.charAt(0) == strTmp2.charAt(1))      //Boton.
               {
                strTmp = strTmp.substring(6, strTmp.length());  //Obtiene identificador del Boton.
               // FBoton.GuardarBoton(java.lang.Integer.parseInt(strTmp), desplaza, 1);
              }
              else if(strTmp.charAt(0) == strTmp2.charAt(2))      //Campo de Texto.
               {

                System.out.println( "-----------" + strTmp );

                strTmp = strTmp.substring(9, strTmp.length());  //Obtiene identificador del Campo de Texto.

                System.out.println( "-----------" + strTmp );

                // Guarda la nueva ubicacion del Campo de Texto.
                // FCampoTexto.GuardarCTexto(java.lang.Integer.parseInt(strTmp), desplaza, 1);
              }
            }
          }
          else if(estirar != null)
           {
              //Identifica el tipo de componente a redimencionar.
            strTmp = c.getName();
            if(strTmp.charAt(0) == strTmp2.charAt(1))
             {
                      //Boton.
              strTmp = strTmp.substring(6, strTmp.length());  //Obtiene identificador del Boton.
              FBoton.GuardarBoton(java.lang.Integer.parseInt(strTmp), desplaza, 2);
            }
            else if(strTmp.charAt(0) == strTmp2.charAt(2))
             {
                 //Campo de Texto.
              strTmp = strTmp.substring(9, strTmp.length());  //Obtiene identificador del C. Texto.
              FCampoTexto.GuardarCTexto(java.lang.Integer.parseInt(strTmp), desplaza, 2);
            }
          }
          estirar = arrastrar = null;
        }



        public void mouseDragged(MouseEvent evt)
         {
            //Arrastrar el ratón.
          int x = evt.getX();
          int y = evt.getY();


          System.out.println("mouseDragged");


          if(arrastrar != null)
           {
            arrastrar.setLocation(x-desplazamiento.x, y-desplazamiento.y);
            desplaza = new Point(x-desplazamiento.x, y-desplazamiento.y);
          }
          else if(estirar != null)
           {
            estirar.setSize(x-estirar.getBounds().x, y-estirar.getBounds().y);
            desplaza = new Point(x-estirar.getBounds().x, y-estirar.getBounds().y);
          }
        }


        public void mouseMoved(MouseEvent evt)
         {
          int x = evt.getX();
          int y = evt.getY();
          c = getComponentAt(x, y);


          System.out.println("mouseMoved");


          if(c != null && c != FrameVenProy.this)
           {
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          }
          else
           {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
          }

          //Elimina la ventana instanciada, que se ha visualizado.
          (FBoton.FVP).setVisible(false);
          (FCampoTexto.MenAtributo).setVisible(false);
          contM++;

          if(!evt.isShiftDown())
           {
            //  (FSubMenu.FVP).setVisible(false);
          }
          else if(evt.isShiftDown() && contM >= 5)
           {
            //  (FSubMenu.FVP).setVisible(false);
          }
          cont = 0;
        }
      }



	public void AgregarActionListenerMBar()
         {
          int cont = mbar.getMenuCount();
          for (int y=0; y < cont ; y++)
           {
            ((Menu)mbar.getMenu(y)).addActionListener(this);
          }
	}

    }// FrameVenProy.



    //----------------------------------------------------------------------------------------- 
    // Clase FrameBoton, Para Botón.
    //-----------------------------------------------------------------------------------------
    class FrameBoton extends FrameGral {
	TextField tfa,tfb,tfc;
	Component comp = null;
	FrameVenProy FVP = new FrameVenProy(" ");

      public FrameBoton(String title) {
        super(title);
        MenuBar mb = new MenuBar();
        Menu m = new Menu("Opción");
        MenuItem mi;

        mi = new MenuItem("Mensaje");
        mi.setEnabled(false);   
        m.add(mi);
        m.add("-");
        m.add("Salir");
        mb.add(m);
        m.addActionListener(this);
        m = new Menu("Ayuda");	
        m.add("Objetivo");
        mb.add(m);

        m.addActionListener(this);
        // Coloca la barra de menú en la ventana (frame).
        setMenuBar(mb);

        setLayout(null);

	  Label la = new Label("Etiqueta :");
	  la.setBounds(50,50,100,20);
	  add(la);
	  tfa = new TextField("Aceptar");
	  tfa.setBounds(150,50,100,20);
	  add(tfa);

	  Label lb = new Label("Ancho :");
	  lb.setBounds(50,80,100,20);
	  add(lb);
	  tfb = new TextField("25");
	  tfb.setBounds(150,80,50,20);
	  add(tfb);

	  Label lc = new Label("Largo :");
	  lc.setBounds(50,110,100,20);
	  add(lc);
	  tfc = new TextField("150");
	  tfc.setBounds(150,110,50,20);
	  add(tfc);

	  Button ba = new Button("Aceptar");
	  ba.addActionListener(new AceptarCarac());
	  ba.addActionListener(this);
	  ba.setBounds(100,140,100,20);
	  add(ba);
      }

      public void windowClosing(WindowEvent e) {
        FrameBoton.this.setVisible(!isVisible());
      }

      // Manejo de acciones del menú.
      public void actionPerformed(ActionEvent evt)
       {
        String what = evt.getActionCommand();

        if("Mensaje".equals(what))
         {

        }
        else if("Salir".equals(what))
         {
	    FrameBoton.this.setVisible(!isVisible());
        }
        else if("Objetivo".equals(what))
         {
		Frame window = new FrameGral("Ayuda, Objetivo");
		Panel p = new Panel();
		p.setLayout(new GridLayout(6, 0));
		p.add(new Label("  -En esta ventana se especifican "));
		p.add(new Label("   las características de un Botón"));
		p.add(new Label("  -En Lo que respecta a las dimenciones,"));
		p.add(new Label("   estas se pueden modificar mediante"));
		p.add(new Label("   la combinación ALT+Ratón-Botón-Izq.,"));
		p.add(new Label("   una vez que el Botón se edite"));
		window.add(p, BorderLayout.CENTER); 
	  	window.setBounds(200,85,250,140);
		window.show();		    
        }
      }

      void MetAceptarCarac()
       {
        String strTmp;
        if (java.lang.Integer.parseInt(tfb.getText()) >= 15 && java.lang.Integer.parseInt(tfc.getText()) >= 15)
         {
          if ((int)VentI.NodoEdicion.tipo == 5)
           {
            //FArbolVentProy.CasoVentMenu(3);
          }
          else
           {
            Button ba = new Button();
            ba.setLabel(tfa.getText());
            FVenProy.show();
            FVenProy.add(comp = ba);
            comp.setBounds(20,50,java.lang.Integer.parseInt(tfc.getText()),
            java.lang.Integer.parseInt(tfb.getText()));
            comp.setEnabled(VentI.pruebaCB.getState());
            strTmp = comp.getName();
            strTmp = strTmp.substring(6, strTmp.length());
         //   AgregBoton(java.lang.Integer.parseInt(strTmp), tfa.getText(), java.lang.Integer.parseInt(tfc.getText()), java.lang.Integer.parseInt(tfb.getText()), new Point(20, 50), null);
          }
          FrameBoton.this.setVisible(!isVisible());
        }
        else
         {
          System.out.println("---ERROR: Incorrecto, valor para Dimensión...");
          //  ErrMen ErrorM = new ErrMen("ERROR...", "---ERROR: Incorrecto, valor para Dimensión...");
        }
         
      }

      //Accion del botón "Aceptar".
      class AceptarCarac extends Frame implements ActionListener
       {
         public void actionPerformed(ActionEvent evt)
          {
            FrameBoton.this.MetAceptarCarac();         
         }
      }

      public void InstancioBV(DefaultMutableTreeNode NodoRefer)
       {
        String strTmp;
        Button ba = new Button();
        ba.setLabel(tfa.getText());
        FVenProy.show();
        FVenProy.add(comp = ba);
        comp.setBounds(20,50,java.lang.Integer.parseInt(tfc.getText()),java.lang.Integer.parseInt(tfb.getText()));
        comp.setEnabled(VentI.pruebaCB.getState());
        strTmp = comp.getName();
        strTmp = strTmp.substring(6, strTmp.length());
      //  AgregBoton(java.lang.Integer.parseInt(strTmp), tfa.getText(), java.lang.Integer.parseInt(tfc.getText()), java.lang.Integer.parseInt(tfb.getText()), new Point(20, 50), NodoRefer);
      }


        

	public void VerInstBV(int IdentB) {
		DefaultMutableTreeNode NodoB, TNEtmp, VerifNodo = (DefaultMutableTreeNode)VentI.EstrucArbol;
		Nodo tmp = new Nodo(" ", 0, 0);
		Component comp1 = null;
		String strTmp;
		TNEtmp = VentI.TreeNodeEdicion;
		if (((Nodo)VentI.TreeNodeEdicion).Boton != null) {
			NodoB = ((Nodo)VentI.TreeNodeEdicion).Boton;
			for (;;) {
				if (IdentB == ((NodoBoton)NodoB).IdentB) {
					if (((NodoBoton)NodoB).NodoReferB != null) {
						for (;;) {
							VerifNodo = (DefaultMutableTreeNode)VerifNodo.getNextNode();
							if (((Nodo)(((NodoBoton)NodoB).NodoReferB)).ident == ((Nodo)VerifNodo).ident) {
								break;
							}
						}
//						tmp = (Nodo)(((NodoBoton)NodoB).NodoReferB);
						tmp = (Nodo)VerifNodo;
//						VentI.TreeNodeEdicion = ((NodoBoton)NodoB).NodoReferB;
						VentI.TreeNodeEdicion = VerifNodo;
						FVP = new FrameVenProy(tmp.msg);	//Abre Ventana.
                                                FVP.setBounds(20, 20, tmp.dimen.width, tmp.dimen.height);
						FVP.setBackground(((Nodo)VentI.TreeNodeEdicion).colorFondo);
						FVP.show();
                                               // FEtiqueta.MostrarEtiq(2);       //Agraga las etiquetas a la ventana. 
                                               // FCampoTexto.MostrarCTexto(2);   //Agrega los Campos de Texto a a la ventana.
						FBoton.MostrarBoton(2);	//Agrega los Botones a la ventana.
                                               // FBarraMenu.MostrarMenu(2);  //Agregar los Menu a la ventana.
                                               // FSubMenu.MostrarSubMenu(2);     //Agregar los Submenu a la ventana.
					}
					break;
				} else {
					NodoB = (DefaultMutableTreeNode)NodoB.getFirstChild();
				}
			}
   		}
		VentI.TreeNodeEdicion = TNEtmp;
	}

   

   

	public DefaultMutableTreeNode BuscaInstBV(DefaultMutableTreeNode VerifNodo, DefaultMutableTreeNode NodoInst, int InstCompIdent, boolean InstCompTipo) {
		DefaultMutableTreeNode NodoB, padreB;
		if (((Nodo)VerifNodo).Boton != null) {
			NodoB = ((Nodo)VerifNodo).Boton;
			for (;;) {
				if (NodoInst == ((NodoBoton)NodoB).NodoReferB) {
					if (VerifNodo == (DefaultMutableTreeNode)NodoInst.getParent()) {
						if (InstCompTipo) {
							if (InstCompIdent != ((NodoBoton)NodoB).IdentB) {
								return VerifNodo;	
							}
						} else {
							return VerifNodo;
						}
					} else {
						return VerifNodo;
					}
				} else {
					try {
						NodoB = (DefaultMutableTreeNode)NodoB.getFirstChild();
					} catch ( NoSuchElementException  e ) { break; }
				}
			}
   		}
		return null;
	}

    
               
    
	public DefaultMutableTreeNode VerificarOInst(DefaultMutableTreeNode NodoInst, int InstBotonIdent, boolean InstCompTipo) {
		DefaultMutableTreeNode VerifNodo = (DefaultMutableTreeNode)VentI.EstrucArbol;
		DefaultMutableTreeNode EncontroNodo = null;
		for (;;) {
			VerifNodo = (DefaultMutableTreeNode)VerifNodo.getNextNode();
			if (VerifNodo == null) {
				break;
			} else {
				EncontroNodo = BuscaInstBV(VerifNodo, NodoInst, InstBotonIdent, InstCompTipo);
				if (EncontroNodo != null) {
					break;
				}
			}
		}
		if (EncontroNodo == null) {
			VerifNodo = (DefaultMutableTreeNode)VentI.EstrucArbol;
			for (;;) {
				VerifNodo = (DefaultMutableTreeNode)VerifNodo.getNextNode();
				if (VerifNodo == null) {
					break;
				} else {
                                    //    EncontroNodo = FSubMenu.BuscaInstSMV(VerifNodo, NodoInst, 0, 0, InstCompTipo);
                                    //    if (EncontroNodo != null) {
                                    //            break;
                                    //    }
				}
			}
		}
		return EncontroNodo;
	}
    
    
    
	public void AgregBoton(int IdentB, String TextB, int largoB, int anchoB, Point ubicaB, DefaultMutableTreeNode NodoRefer)
         {
          DefaultMutableTreeNode NodoB2;
          NodoBoton NodoB = new NodoBoton();
          NodoB.IdentB = IdentB;
          NodoB.TextB = TextB;
          NodoB.largoB = largoB;
          NodoB.anchoB = anchoB;
          NodoB.ubicaB = ubicaB;
          NodoB.NodoReferB = NodoRefer;

          if(((Nodo)VentI.TreeNodeEdicion).Boton == null)
           {
            ((Nodo)VentI.TreeNodeEdicion).Boton = (DefaultMutableTreeNode)NodoB;
          }
          else
           {
            NodoB2 = ((Nodo)VentI.TreeNodeEdicion).Boton;
            for (;;)
             {
              if((int)NodoB2.getChildCount() == 0)
               {
                NodoB2.insert((DefaultMutableTreeNode)NodoB, 0);
                break;
              }
              else
               {
                NodoB2 = (DefaultMutableTreeNode)NodoB2.getFirstChild();
              }
            }
          }
	}

    

    

	public void EliminBoton(int IdentB)
         {
          DefaultMutableTreeNode NodoB, padreB, Instancia = null, tmpVI;

          if(((Nodo)VentI.TreeNodeEdicion).Boton != null)
           {
            NodoB = ((Nodo)VentI.TreeNodeEdicion).Boton;
            for(;;)
             {
              if(IdentB == ((NodoBoton)NodoB).IdentB)
               {
                             //Elimina Boton.
                padreB = (DefaultMutableTreeNode)NodoB.getParent();
                if((int)NodoB.getChildCount() == 0)
                 {
                  if(padreB != null)
                   {
                    padreB.remove(NodoB);
                  }
                  else
                   {
                    ((Nodo)VentI.TreeNodeEdicion).Boton = null;
                  }
                }
                else
                 {
                  if(padreB != null)
                   {
                     padreB.insert((DefaultMutableTreeNode)NodoB.getFirstChild(), 0);
                     padreB.remove(NodoB);
                  }
                  else
                   {
                     ((Nodo)VentI.TreeNodeEdicion).Boton = (DefaultMutableTreeNode)NodoB.getFirstChild();
                     NodoB.remove((DefaultMutableTreeNode)NodoB.getFirstChild());
                  }
                }
                if(((Nodo)VentI.TreeNodeEdicion).tipo == 5)
                 {
                  if(VentI.TreeNodeEdicion == (DefaultMutableTreeNode)(((NodoBoton)NodoB).NodoReferB).getParent())
                   {
                    tmpVI = VentI.TreeNodeEdicion;
                    Instancia = VerificarOInst(((NodoBoton)NodoB).NodoReferB, ((NodoBoton)NodoB).IdentB, true);
                    if(Instancia != tmpVI)
                     {
                      if(Instancia != null)
                       {
                        if(Instancia != VentI.TreeNodeEdicion)
                         {
                                      //alguin mas la Instancia y se debe mover al que la instancia, junto con sus hijos.
                          Instancia.add(((NodoBoton)NodoB).NodoReferB);
                        }
                      }
                      else
                       {
                                   //Nadien la instancia y debe moverse a la reiz "Estructura de ventanas", junto con sus hijos.
                        (VentI.EstrucArbol).add(((NodoBoton)NodoB).NodoReferB);
                      } 
                    }
                   // FArbolVentProy.setVisible(false);
                   // FArbolVentProy = new FrameArbolVentProy("Arbol de la estructura de Ventanas del Proyecto");
                   // FArbolVentProy.setBounds(80,70,700,400);
                   // FArbolVentProy.show();
                  }
                }
                break;
              }
              else
               {
                 NodoB = (DefaultMutableTreeNode)NodoB.getFirstChild();
              }
            } // end for(;;)
          }
	}

     

     

     public void MostrarBoton(int normal)
      {
       DefaultMutableTreeNode NodoB;
       Component comp1 = null;
       String strTmp;

       if (((Nodo)VentI.TreeNodeEdicion).Boton != null)
        {
         NodoB = ((Nodo)VentI.TreeNodeEdicion).Boton;
         for(;;)
          {
             // System.out.println("---B1: " + ((NodoBoton)NodoB).TextB + " - " + Integer.toString(normal));
           Button ba = new Button();
           ba.setLabel(((NodoBoton)NodoB).TextB);
           if(normal == 1)
            {
             FVenProy.show();
             FVenProy.add(comp1 = ba);
             // System.out.println("---B2: " + ((NodoBoton)NodoB).TextB + " - " + Integer.toString(normal));
           }
           else if(normal == 2)
            {
             FBoton.FVP.show();
             FBoton.FVP.add(comp1 = ba);
           }
           else if(normal == 3)
            {
            // FSubMenu.FVP.show();
            // FSubMenu.FVP.add(comp1 = ba);
           }
           comp1.setBounds((((NodoBoton)NodoB).ubicaB).x, (((NodoBoton)NodoB).ubicaB).y, ((NodoBoton)NodoB).largoB, ((NodoBoton)NodoB).anchoB);
            //System.out.println("---B2.5: " + Integer.toString((((NodoBoton)NodoB).ubicaB).x) + " - " + Integer.toString((((NodoBoton)NodoB).ubicaB).y) + " - " + Integer.toString(((NodoBoton)NodoB).largoB) + " - " + Integer.toString(((NodoBoton)NodoB).anchoB));
           comp1.setEnabled(VentI.pruebaCB.getState());
           strTmp = comp1.getName();

            //System.out.println("---B3: " + ((NodoBoton)NodoB).TextB + " - " + strTmp);
           strTmp = strTmp.substring(6, strTmp.length());
           ((NodoBoton)NodoB).IdentB = java.lang.Integer.parseInt(strTmp);

           if ((int)NodoB.getChildCount() == 0)
            {
             break;
           }
           else
            {
             NodoB = (DefaultMutableTreeNode)NodoB.getFirstChild();
           }
         }
       }
     }

     

     

      public void GuardarBoton(int IdentB, Point desplaza, int bandera)
       {
        DefaultMutableTreeNode NodoB, padreB;

        if (((Nodo)VentI.TreeNodeEdicion).Boton != null)
         {
          NodoB = ((Nodo)VentI.TreeNodeEdicion).Boton;
          for (;;)
           {
            if (IdentB == ((NodoBoton)NodoB).IdentB)
             {
              if (bandera == 1)
               {
                   //Se actualiza la ubicacion del Boton.
                ((NodoBoton)NodoB).ubicaB = desplaza;
              }
              else if(bandera == 2)
               {
                      //Se actualizan las dimenciones del Boton.
                ((NodoBoton)NodoB).largoB = desplaza.x;
                ((NodoBoton)NodoB).anchoB = desplaza.y;
              }
              break;
            }
            else
             {
              NodoB = (DefaultMutableTreeNode)NodoB.getFirstChild();
            }
          }
        } 
      }

    }// FrameBoton.




    //----------------------------------------------------------------------------------------- 
    // Clase FrameEtiqueta, para Etiqueta (Label).
    //-----------------------------------------------------------------------------------------
    class FrameEtiqueta extends FrameGral implements ItemListener {
      String[] NombreFuente = {"Dialog", "Serif", "SansSerif", "Monospaced", "DialogInput"};
      String[] NombreEstilo = {"plain", "italic", "bold", "bold-italic"};
      int[] ValorEstilo = {Font.PLAIN, Font.ITALIC, Font.BOLD, 
                           Font.ITALIC|Font.BOLD};
      Choice SelecFuente = new Choice();
      Choice SelecEstilo = new Choice();
      Choice TamanoLetra = new Choice();
      Font f;	
      FontMetrics fm;
      TextField tf = new TextField("Etiqueta");
	Component comp = null;

      public FrameEtiqueta(String title) {
        super(title);
        Panel p = new Panel();
        Panel p2 = new Panel();	

        MenuBar mb = new MenuBar();
        Menu m = new Menu("Opción");
        MenuItem mi;

        mi = new MenuItem("Mensaje");
        mi.setEnabled(false);
        m.add(mi);
        m.add("-");
        m.add("Salir");
        mb.add(m);
        m.addActionListener(this);
        m = new Menu("Ayuda");
        m.add("Objetivo");
        mb.add(m);
        m.addActionListener(this);
        // Coloca la barar de Menú en la ventana.
        setMenuBar(mb);

        for (int i=0; i<NombreFuente.length; i++) {
            SelecFuente.addItem(NombreFuente[i]);
        }
        // Inicializa el estilo de Fuente seleccionada.
        for (int i=0; i<NombreEstilo.length; i++){
            SelecEstilo.addItem(NombreEstilo[i]);
        }
        // Inicializa el Tamaño de Letra.
        for (int i=10; i<101; i++) {
            TamanoLetra.addItem(Integer.toString(i));
        }
	  p.setLayout(new GridLayout(3, 3, 5, 0));
	  p.add(new Label("     Tipo de letra :"));
	  p.add(new Label("     Estilo de letra :"));
	  p.add(new Label("     Tamaño de letra :"));
	  p.add(SelecFuente);
	  p.add(SelecEstilo);
	  p.add(TamanoLetra);
	  p.add(new Label(" "));
	  p.add(new Label("       _____Ejemplo :_____"));
	  p.add(new Label(" "));
        p2.setLayout(new GridLayout(2, 0));
	  p2.add(tf);
        Button ba = new Button("Aceptar");
	  ba.addActionListener(new AceptarCarac());
	  p2.add(ba);
        // Escuchando por los eventos en las selecciones.
        SelecFuente.addItemListener(this);
        SelecEstilo.addItemListener(this);
	  TamanoLetra.addItemListener(this);
        // Escuchando por los eventos en el Campo de Texto.
        tf.addActionListener(this);

        add(p, BorderLayout.NORTH); 
        add(p2, BorderLayout.SOUTH); 

        setVisible(false);
      }

      // Se rescribe el método de cierre de ventana.
      public void windowClosing(WindowEvent e) {
		FrameEtiqueta.this.setVisible(!isVisible());
      }

      // Acción del Menú principal y Campos de texto de la ventana.
      public void actionPerformed(ActionEvent evt) {
        repaint();  			       //Acciones del Campos de texto (enter).

        String what = evt.getActionCommand();  //Acciones del Menú.
        if ("Mensaje".equals(what)) {
        } else if ("Salir".equals(what)) {
		FrameEtiqueta.this.setVisible(!isVisible());
        } else if ("Objetivo".equals(what)) {
		Frame window = new FrameGral("Ayuda, Objetivo");
		Panel p = new Panel();
                p.setLayout(new GridLayout(2, 0));
		p.add(new Label("  -En esta ventana se especifican "));
		p.add(new Label("   las características de una Etiqueta"));
		window.add(p, BorderLayout.CENTER); 
	  	window.setBounds(200,85,250,80);
		window.show();		    
        }
      }

      public void paint(Graphics g) {
        Insets intercala = getInsets();
        int ancho = getSize().width-intercala.left-intercala.right-2;
        int alto = getSize().height-intercala.top-intercala.bottom-2;
        String str = tf.getText();
        f = new Font(SelecFuente.getSelectedItem(), ValorEstilo[SelecEstilo.getSelectedIndex()], java.lang.Integer.parseInt(TamanoLetra.getSelectedItem()));
        fm = g.getFontMetrics(f);
        g.clearRect(0, 0, ancho, alto);
	  g.setColor(Color.red);
        g.setFont(f);
        g.drawString(str, (ancho-fm.stringWidth(str))/2, (alto-fm.getHeight())/2+fm.getAscent()+50);
      }

      // Actualizando según las acciones de los componentes selecionados.
      public void itemStateChanged(ItemEvent e) {
		repaint();
      }

      void MetAceptarCarac() {
	   String strTmp;
	   Label la;
	   if (!tf.getText().equals("") && !tf.getText().equals(" ")) {
		if (java.lang.Integer.parseInt(TamanoLetra.getSelectedItem()) >= 10) {
			la = new Label(tf.getText());
			la.setFont(f);
			FVenProy.show();
			FVenProy.add(comp = la);
                      //  comp.setBounds(20,50,fm.stringWidth(tf.getText()), fm.getHeight());
                      //  comp.setEnabled(VentI.pruebaCB.getState());
			strTmp = comp.getName();
			strTmp = strTmp.substring(5, strTmp.length());
			FrameEtiqueta.this.setVisible(!isVisible());
                       // AgregEtiq(java.lang.Integer.parseInt(strTmp), tf.getText(), f, fm, new Point(20, 50));
		} else {
                        System.out.println("---ERROR: Incorrecto, valor para \"Tamaño de letra\"...");
                   //     ErrMen ErrorM = new ErrMen("ERROR...", "---ERROR: Incorrecto, valor para \"Tamaño de letra\"...");
		}
	   } else {
                System.out.println("---ERROR: Falta, texto para la Etiqueta...");
              //  ErrMen ErrorM = new ErrMen("ERROR...", "---ERROR: Falta, texto para la Etiqueta...");
	   }
      }

      //Accion del botón "Aceptar".
      class AceptarCarac extends Frame implements ActionListener {
          public void actionPerformed(ActionEvent evt) {
              FrameEtiqueta.this.MetAceptarCarac();		
          }
      }


   
      public void AgregEtiq(int IdentE, String TextE, Font fontE, FontMetrics fMetricE, Point ubicaE) {
		DefaultMutableTreeNode NodoE2;
		NodoEtiq NodoE = new NodoEtiq();
		NodoE.IdentE = IdentE;
		NodoE.TextE = TextE;
		NodoE.fontE = fontE;
		NodoE.fMetricE = fMetricE;
		NodoE.ubicaE = ubicaE;
		if (((Nodo)VentI.TreeNodeEdicion).Etiq == null) {
			((Nodo)VentI.TreeNodeEdicion).Etiq = (DefaultMutableTreeNode)NodoE;
		} else {
			NodoE2 = ((Nodo)VentI.TreeNodeEdicion).Etiq;
			for (;;) {
				if ((int)NodoE2.getChildCount() == 0) {
					NodoE2.insert((DefaultMutableTreeNode)NodoE, 0);
					break;
				} else {
					NodoE2 = (DefaultMutableTreeNode)NodoE2.getFirstChild();
				}
			}
   		}
	}

     

     /*

      public void EliminEtiq(int IdentE) {
		DefaultMutableTreeNode NodoE, padreE;
		if (((Nodo)VentI.TreeNodeEdicion).Etiq != null) {
			NodoE = ((Nodo)VentI.TreeNodeEdicion).Etiq;
			for (;;) {
				if (IdentE == ((NodoEtiq)NodoE).IdentE) {
					//Elimina la Etiqueta.
					padreE = (DefaultMutableTreeNode)NodoE.getParent();
					if ((int)NodoE.getChildCount() == 0) {
						if (padreE != null) {
							padreE.remove(NodoE);
						} else {
							((Nodo)VentI.TreeNodeEdicion).Etiq = null;
						}
					} else {
						if (padreE != null) {
							padreE.insert((DefaultMutableTreeNode)NodoE.getFirstChild(), 0);
							padreE.remove(NodoE);
						} else {
							((Nodo)VentI.TreeNodeEdicion).Etiq = (DefaultMutableTreeNode)NodoE.getFirstChild();
							NodoE.remove((DefaultMutableTreeNode)NodoE.getFirstChild());
						}
					}
					break;
				} else {
					NodoE = (DefaultMutableTreeNode)NodoE.getFirstChild();
				}
			}
   		} 
	}

     */

     

      public void MostrarEtiq(int normal) {
		DefaultMutableTreeNode NodoE;
		Component comp1 = null;
		String strTmp;
		if (((Nodo)VentI.TreeNodeEdicion).Etiq != null) {
			NodoE = ((Nodo)VentI.TreeNodeEdicion).Etiq;
			for (;;) {
//System.out.println("---E1: " + ((NodoEtiq)NodoE).TextE + " - " + Integer.toString(normal));
				Label la = new Label(((NodoEtiq)NodoE).TextE);
				la.setFont(((NodoEtiq)NodoE).fontE);
				if (normal == 1) {
					FVenProy.show();
					FVenProy.add(comp1 = la);
//System.out.println("---E2: " + ((NodoEtiq)NodoE).TextE + " - " + Integer.toString(normal));
				} else if (normal == 2) {
					FBoton.FVP.show();
					FBoton.FVP.add(comp1 = la);
				} else if (normal == 3){
                                      //  FSubMenu.FVP.show();
                                      //  FSubMenu.FVP.add(comp1 = la);
				}
				comp1.setBounds((((NodoEtiq)NodoE).ubicaE).x, (((NodoEtiq)NodoE).ubicaE).y, (((NodoEtiq)NodoE).fMetricE).stringWidth(((NodoEtiq)NodoE).TextE), (((NodoEtiq)NodoE).fMetricE).getHeight());
				comp1.setEnabled(VentI.pruebaCB.getState());
				strTmp = comp1.getName();
				strTmp = strTmp.substring(5, strTmp.length());
				((NodoEtiq)NodoE).IdentE = java.lang.Integer.parseInt(strTmp);
				if ((int)NodoE.getChildCount() == 0) {
					break;
				} else {
					NodoE = (DefaultMutableTreeNode)NodoE.getFirstChild();
				}
			}
   		}
	}

      

      
      public void GuardarEtiq(int IdentE, Point ubicaE) {
		DefaultMutableTreeNode NodoE, padreE;
		if (((Nodo)VentI.TreeNodeEdicion).Etiq != null) {
			NodoE = ((Nodo)VentI.TreeNodeEdicion).Etiq;
			for (;;) {
				if (IdentE == ((NodoEtiq)NodoE).IdentE) {
					((NodoEtiq)NodoE).ubicaE = ubicaE;
					break;
				} else {
					NodoE = (DefaultMutableTreeNode)NodoE.getFirstChild();
				}
			}
   		} 
	}

      

    }// FrameEtiqueta.



    //----------------------------------------------------------------------------------------- 
    // Clase FrameCampoTexto, Para Campo de Texto (TextField).
    //-----------------------------------------------------------------------------------------

    class FrameCampoTexto extends FrameGral implements ItemListener {
	TextField tfa, tfb, tfc, tfd;
	Label ld;

        Mensajes MenAtributo  = new Mensajes(" ", " ");

	boolean Consulta = false;
	Checkbox Llave = new Checkbox("Campo Llave", false);
      Choice Tipo = new Choice();
	Component comp = null;

	public FrameCampoTexto(String title) {
	  super(title);
	  MenuBar mb = new MenuBar();
	  Menu m = new Menu("Opción");
	  m.add("Salir");
	  mb.add(m);
	  m.addActionListener(this);
	  m = new Menu("Ayuda");	
	  m.add("Objetivo");
	  mb.add(m);
	  m.addActionListener(this);
	  // Colocando la barra de menú en la ventana.
	  setMenuBar(mb);
	  setLayout(null);

	  Tipo.addItem("Alfanumérico");
	  Tipo.addItem("Numérico");

	  Llave.setBounds(100,50,130,20);
	  Llave.addItemListener(this);
	  add(Llave);
	  ld = new Label("Atributo :");
	  ld.setBounds(20,80,45,20);
	  add(ld);
	  tfd = new TextField("");
	  tfd.setBounds(70,80,200,20);
	  add(tfd);
	  Label la = new Label("Ancho :");
	  la.setBounds(20,110,50,20);
	  add(la);
	  tfa = new TextField("20");
	  tfa.setBounds(80,110,50,20);
	  add(tfa);
	  Label lb = new Label("Largo :");
	  lb.setBounds(140,110,50,20);
	  add(lb);
	  tfb = new TextField("300");
	  tfb.setBounds(200,110,50,20);
	  add(tfb);
	  Tipo.addItemListener(this);
	  Tipo.setBounds(100,140,100,20);
	  add(Tipo);
	  Label lc = new Label("Texto :");
	  lc.setBounds(20,170,45,20);
	  add(lc);
	  tfc = new TextField("");
	  tfc.setBounds(70,170,200,20);
	  add(tfc);
	  Button ba = new Button("Aceptar");
	  ba.addActionListener(new AceptarCarac());
	  ba.addActionListener(this);
	  ba.setBounds(100,200,100,20);
	  add(ba);
      }

      public void windowClosing(WindowEvent e) {
		FrameCampoTexto.this.setVisible(!isVisible());
      }

	public void itemStateChanged(ItemEvent evt) {
		if (Llave.getState()) {
				tfc.setBackground(Color.yellow);
		} else {
			tfc.setBackground(Color.white);
		}
	}

      // Manejo de las acciones del menú.
      public void actionPerformed(ActionEvent evt) {
      	String what = evt.getActionCommand();
		if ("Salir".equals(what)) {
			FrameCampoTexto.this.setVisible(!isVisible());
		} else if ("Objetivo".equals(what)) {
			Frame window = new FrameGral("Ayuda, Objetivo");
			Panel p = new Panel();
      	      p.setLayout(new GridLayout(6, 0));
			p.add(new Label("  -En esta ventana se especifican "));
			p.add(new Label("   las características de un Campo de Texto"));
			p.add(new Label("  -En Lo que respecta a las dimenciones,"));
			p.add(new Label("   estas se pueden modificar mediante"));
			p.add(new Label("   la combinación ALT+Ratón-Botón-Izq.,"));
			p.add(new Label("   una vez que el Campo de Texto se edite"));
			window.add(p, BorderLayout.CENTER); 
	  		window.setBounds(200,85,250,140);
			window.show();		    
		}
      }

      void MetAceptarCarac() {
		String strTmp;
		TextField tf = new TextField(tfc.getText());
		boolean bandera = true;
		String Atributo = " ";
	   if ( Consulta ) {
		if (tfd.getText().equals("") || tfd.getText().equals(" ")) {
			bandera = false;
		}
	   }
	   if ( bandera && (!tfa.getText().equals("") && !tfa.getText().equals(" ")) && (!tfb.getText().equals("") && !tfb.getText().equals(" "))) {
		if (java.lang.Integer.parseInt(tfa.getText()) >= 15 && java.lang.Integer.parseInt(tfb.getText()) >= 30) {
			Atributo = tfd.getText();
			if (Llave.getState()) {
				tf.setBackground(Color.yellow);
			}
			FVenProy.show();
			FVenProy.add(comp = tf);
                        comp.setBounds(20,50,java.lang.Integer.parseInt(tfb.getText()), java.lang.Integer.parseInt(tfa.getText()));
                        comp.setEnabled(VentI.pruebaCB.getState());
			strTmp = comp.getName();
			strTmp = strTmp.substring(9, strTmp.length());
			FrameCampoTexto.this.setVisible(!isVisible());
                      //  AgregCTexto(java.lang.Integer.parseInt(strTmp), tfc.getText(), java.lang.Integer.parseInt(tfb.getText()), java.lang.Integer.parseInt(tfa.getText()), new Point(20, 50), Atributo, Llave.getState(), Tipo.getSelectedIndex());
		} else {
                      System.out.println("---ERROR: Incorrecto, valor para Dimensión...");
                   //     ErrMen ErrorM = new ErrMen("ERROR...", "---ERROR: Incorrecto, valor para Dimensión...");
		}
	   } else {
               System.out.println("---ERROR: Falta, Especifricar Dimensión o Atributo de la B.D.");
              //  ErrMen ErrorM = new ErrMen("ERROR...", "---ERROR: Falta, Especifricar Dimensión o Atributo de la B.D.");
	   }
      }

      //Accion del botón "Aceptar".
      class AceptarCarac extends Frame implements ActionListener {
          public void actionPerformed(ActionEvent evt) {
              FrameCampoTexto.this.MetAceptarCarac();		
          }
      }


    
      public void AgregCTexto(int IdentCT, String TextCT, int largoCT, int anchoCT, Point ubicaCT, String AtributoCT, boolean LlaveCT, int TipoCT) {
		DefaultMutableTreeNode NodoE2;
		NodoCTexto NodoCT = new NodoCTexto();
		NodoCT.IdentCT = IdentCT;
		NodoCT.TextCT = TextCT;
		NodoCT.largoCT = largoCT;
		NodoCT.anchoCT = anchoCT;
		NodoCT.ubicaCT = ubicaCT;
		NodoCT.AtributoCT = AtributoCT;
		NodoCT.LlaveCT = LlaveCT;
		if (TipoCT == 0) {
			NodoCT.TipoCT = true;	//Alfanumerico.
		} else if (TipoCT == 1) {
			NodoCT.TipoCT = false;	//Numerico.
		}
		if (((Nodo)VentI.TreeNodeEdicion).CTexto == null) {
			((Nodo)VentI.TreeNodeEdicion).CTexto = (DefaultMutableTreeNode)NodoCT;
		} else {
			NodoE2 = ((Nodo)VentI.TreeNodeEdicion).CTexto;
			for (;;) {
				if ((int)NodoE2.getChildCount() == 0) {
					NodoE2.insert((DefaultMutableTreeNode)NodoCT, 0);
					break;
				} else {
					NodoE2 = (DefaultMutableTreeNode)NodoE2.getFirstChild();
				}
			}
   		}
	}

      

      /*

      public void EliminCTexto(int IdentCT) {
		DefaultMutableTreeNode NodoCT, padreCT;
		if (((Nodo)VentI.TreeNodeEdicion).CTexto != null) {
			NodoCT = ((Nodo)VentI.TreeNodeEdicion).CTexto;
			for (;;) {
				if (IdentCT == ((NodoCTexto)NodoCT).IdentCT) {
					//Elimina la Etiqueta.
					padreCT = (DefaultMutableTreeNode)NodoCT.getParent();
					if ((int)NodoCT.getChildCount() == 0) {
						if (padreCT != null) {
							padreCT.remove(NodoCT);
						} else {
							((Nodo)VentI.TreeNodeEdicion).CTexto = null;
						}
					} else {
						if (padreCT != null) {
							padreCT.insert((DefaultMutableTreeNode)NodoCT.getFirstChild(), 0);
							padreCT.remove(NodoCT);
						} else {
							((Nodo)VentI.TreeNodeEdicion).CTexto = (DefaultMutableTreeNode)NodoCT.getFirstChild();
							NodoCT.remove((DefaultMutableTreeNode)NodoCT.getFirstChild());
						}
					}
					break;
				} else {
					NodoCT = (DefaultMutableTreeNode)NodoCT.getFirstChild();
				}
			}
   		} 
	}

      */

      

      public void MostrarCTexto(int normal) {
		DefaultMutableTreeNode NodoCT;
		Component comp1 = null;
		String strTmp;
		if (((Nodo)VentI.TreeNodeEdicion).CTexto != null) {
			NodoCT = ((Nodo)VentI.TreeNodeEdicion).CTexto;
			for (;;) {
				TextField tf = new TextField(((NodoCTexto)NodoCT).TextCT);
				if (((NodoCTexto)NodoCT).LlaveCT) {
					tf.setBackground(Color.yellow);
				}
				if (normal == 1) {
					FVenProy.show();
					FVenProy.add(comp1 = tf);
				} else if (normal == 2) {
					FBoton.FVP.show();
					FBoton.FVP.add(comp1 = tf);
				} else if (normal == 3) {
                                      //  FSubMenu.FVP.show();
                                      //  FSubMenu.FVP.add(comp1 = tf);
				}
				comp1.setBounds((((NodoCTexto)NodoCT).ubicaCT).x, (((NodoCTexto)NodoCT).ubicaCT).y, ((NodoCTexto)NodoCT).largoCT, ((NodoCTexto)NodoCT).anchoCT);
				comp1.setEnabled(VentI.pruebaCB.getState());
				strTmp = comp1.getName();
				strTmp = strTmp.substring(9, strTmp.length());
				((NodoCTexto)NodoCT).IdentCT = java.lang.Integer.parseInt(strTmp);
				if ((int)NodoCT.getChildCount() == 0) {
					break;
				} else {
					NodoCT = (DefaultMutableTreeNode)NodoCT.getFirstChild();
				}
			}
   		}
	}

      

      

      public void GuardarCTexto(int IdentCT, Point desplaza, int bandera)
       {
        DefaultMutableTreeNode NodoCT;

        if(((Nodo)VentI.TreeNodeEdicion).CTexto != null)
         {
          NodoCT = ((Nodo)VentI.TreeNodeEdicion).CTexto;

          System.out.println(NodoCT);

          for(;;)
           {
            if(IdentCT == ((NodoCTexto)NodoCT).IdentCT)
             {
              if (bandera == 1)
               {                   //Se actualiza la ubicacion del C. de T.
                ((NodoCTexto)NodoCT).ubicaCT = desplaza;
              }
              else if(bandera == 2)
               {                   //Se actualizan las dimenciones del C. de T.
                ((NodoCTexto)NodoCT).largoCT = desplaza.x;
                ((NodoCTexto)NodoCT).anchoCT = desplaza.y;
              }
              break;
            }
            else
             {
              NodoCT = (DefaultMutableTreeNode)NodoCT.getFirstChild();
            }
          }
        } 
      }

      

      

      public String AtributoCTexto(int IdentCT) {
      
		DefaultMutableTreeNode NodoCT;
		if (((Nodo)VentI.TreeNodeEdicion).CTexto != null) {
			NodoCT = ((Nodo)VentI.TreeNodeEdicion).CTexto;
			for (;;) {
				if (IdentCT == ((NodoCTexto)NodoCT).IdentCT) {
					return(((NodoCTexto)NodoCT).AtributoCT);
				} else {
					NodoCT = (DefaultMutableTreeNode)NodoCT.getFirstChild();
				}
			}
   		} 
		return(" ");
        
	}
      
      

    }// FrameCampoTexto.


}



//----------------------------------------------------------------------------------------- 
// Clase FrameGralNivel0, Clase general de NIVEL 0, padre de las "ventanas" utilizadas 
//  en la interfaz con el usuario.
//-----------------------------------------------------------------------------------------  
class FrameGralNivel0 extends Frame implements WindowListener {
      public FrameGralNivel0(String title) {
        super(title);
        addWindowListener(this);
      }
      public void windowOpened(WindowEvent e)     {      }
      public void windowClosing(WindowEvent e)    {      
		FrameGralNivel0.this.setVisible(!isVisible());
      }
      public void windowClosed(WindowEvent e)     {      }
      public void windowIconified(WindowEvent e)  {      }
      public void windowDeiconified(WindowEvent e){      }
      public void windowActivated(WindowEvent e)  {      }
      public void windowDeactivated(WindowEvent e){      }
}// FrameGralNivel0.


//----------------------------------------------------------------------------------------- 
// Clase FrameGral, Clase general padre de las "ventanas" utilizadas 
//  en la interfaz con el usuario.
//-----------------------------------------------------------------------------------------  
class FrameGral extends FrameGralNivel0 implements ActionListener {

      public FrameGral(String title) {
        super(title);
        MenuBar mb = new MenuBar();
        Menu m = new Menu("Opciones");
        m.add("Salir");
        mb.add(m);
        m.addActionListener(this);
        // Coloca la barra de menú en la ventana.
        setMenuBar(mb);
      }
      public void actionPerformed(ActionEvent evt) {
        String what = evt.getActionCommand();
	  if ("Salir".equals(what)) {
	    FrameGral.this.setVisible(!isVisible());
        }
      }

}// FrameGral.


//----------------------------------------------------------------------------------------- 
// Clase Nodo, Clase que representa las ventanas que componen el proyecto. 
//-----------------------------------------------------------------------------------------
/*public*/ class Nodo extends DefaultMutableTreeNode {
	int tipo;
	long ident;
	String msg;
	String bd;
	Color colorFondo = Color.white;
	Dimension dimen = new Dimension(500, 440);	//Dimensiones de la Ventana.
	Point ubica = new Point(150, 85);	//Localizacion o ubicacion de la ventana, esq. superior izq.
	DefaultMutableTreeNode Etiq = null;
	DefaultMutableTreeNode Boton = null;
	DefaultMutableTreeNode CTexto = null;
	DefaultMutableTreeNode Menu = null;

	public Nodo(String nombre, int tipo, long ident) {
	  super(nombre);
	  this.tipo = tipo;
	  this.msg = nombre;
	  this.ident = ident;	
	}
}// Nodo.

//----------------------------------------------------------------------------------------- 
// Clase NodoEtiq, Clase que representa las Etiquetas de las ventanas del proyecto. 
//-----------------------------------------------------------------------------------------
class NodoEtiq extends DefaultMutableTreeNode {
	int IdentE;
	String TextE;
	Font fontE;	
	FontMetrics fMetricE;
	Point ubicaE;

	public NodoEtiq() {
	}
}// NodoEtiq.

//----------------------------------------------------------------------------------------- 
// Clase NodoCTexto, Clase que representa las Campos de Texto de las ventanas del proyecto. 
//-----------------------------------------------------------------------------------------
class NodoCTexto extends DefaultMutableTreeNode {
	int IdentCT;
	String TextCT;
	int largoCT;
	int anchoCT;
	Point ubicaCT;
	String AtributoCT;
	boolean LlaveCT;
	boolean TipoCT;

	public NodoCTexto() {
	}
}// NodoCTexto.

//-----------------------------------------------------------------------------------------
// Clase NodoBoton, Clase que representa los Botones de las ventanas del proyecto. 
//-----------------------------------------------------------------------------------------
class NodoBoton extends DefaultMutableTreeNode {
	int IdentB;
	String TextB;
	int largoB;
	int anchoB;
	Point ubicaB;
	DefaultMutableTreeNode NodoReferB = null;

	public NodoBoton() {
	}
}// NodoBoton.




//----------------------------------------------------------------------------------------- 
// Clase Mensajes, Despliege de mensajes de tipo comentario, informacion u otro tipo.
//----------------------------------------------------------------------------------------- 
class Mensajes extends Frame {

  Mensajes(String title, String men) {
	super(title);

	setLayout(null);
	Label l1 = new Label(men);
	l1.setBounds(10,25,300,20);
	add(l1);
  }
}// Mensajes.



