//-----------begin ConstraintsDialog.java--------------
import java.awt.*;
import java.io.*;
/**
A dialog with controls arranged by absolute positioning.
The control positions were generated an early version of the
Screen Designer application.
@author Art Sulger, asulger@ibm.net
*/
public class ConstraintsDialog
   {
   private GridBagConstraints gc;
   public ConstraintsDialog
   (Container c, Component[] comp,
   Component component, int TOOL, int x, int y, int LAYOUT)
      {
      if (LAYOUT == Screen.GRIDBAG)
         gc = ((GridBagLayout)
         component.getParent().getLayout()).
         getConstraints(component);
      c.setLayout(null);
      // inset north
      comp[0] = new Choice();
      c.add(comp[0]);
      comp[0].reshape(144, 50, 48, 20);
      Choice choice0 = (Choice)comp[0];
      buildList(choice0, 0, 20, 1);
      choice0.addItem(String.valueOf(gc.insets.top));
      choice0.select(String.valueOf(gc.insets.top));
      // inset west
      comp[1] = new Choice();
      c.add(comp[1]);
      comp[1].reshape(120, 80, 48, 20);
      Choice choice1 = (Choice)comp[1];
      buildList(choice1, 0, 20, 1);
      choice1.addItem(String.valueOf(gc.insets.left));
      choice1.select(String.valueOf(gc.insets.left));
      // inset east
      comp[2] = new Choice();
      c.add(comp[2]);
      comp[2].reshape(184, 80, 48, 20);
      Choice choice2 = (Choice)comp[2];
      buildList(choice2, 0, 20, 1);
      choice2.addItem(String.valueOf(gc.insets.right));
      choice2.select(String.valueOf(gc.insets.right));
      // inset south
      comp[3] = new Choice();
      c.add(comp[3]);
      comp[3].reshape(144, 110, 48, 20);
      Choice choice3 = (Choice)comp[3];
      buildList(choice3, 0, 20, 1);
      choice3.addItem(String.valueOf(gc.insets.bottom));
      choice3.select(String.valueOf(gc.insets.bottom));

      comp[4] = new Label();
      c.add(comp[4]);
      comp[4].reshape(10, 86, 95, 20);
      Label label4 = (Label)comp[4];
      label4.setText("Insets:");
      label4.setAlignment(0);

      comp[5] = new Label();
      c.add(comp[5]);
      comp[5].reshape(10, 140, 80, 20);
      Label label5 = (Label)comp[5];
      label5.setText("Anchor:");
      label5.setAlignment(0);
      // anchor:
      comp[6] = new Choice();
      c.add(comp[6]);
      comp[6].reshape(120, 140, 95, 20);
      Choice choice6 = (Choice)comp[6];
      choice6.addItem("CENTER");
      choice6.addItem("EAST");
      choice6.addItem("NORTH");
      choice6.addItem("NORTHEAST");
      choice6.addItem("NORTHWEST");
      choice6.addItem("SOUTH");
      choice6.addItem("SOUTHEAST");
      choice6.addItem("SOUTHWEST");
      choice6.addItem("WEST");
      switch (gc.anchor)
         {
         case GridBagConstraints.CENTER:
            choice6.select("CENTER"); break;
         case GridBagConstraints.EAST:
            choice6.select("EAST"); break;
         case GridBagConstraints.NORTH:
            choice6.select("NORTH"); break;
         case GridBagConstraints.NORTHEAST:
            choice6.select("NORTHEAST"); break;
         case GridBagConstraints.NORTHWEST:
            choice6.select("NORTHWEST"); break;
         case GridBagConstraints.SOUTH:
            choice6.select("SOUTH"); break;
         case GridBagConstraints.SOUTHEAST:
            choice6.select("SOUTHEAST"); break;
         case GridBagConstraints.SOUTHWEST:
            choice6.select("SOUTHWEST"); break;
         case GridBagConstraints.WEST:
            choice6.select("WEST"); break;
         default:break;
         }

      comp[7] = new Label();
      c.add(comp[7]);
      comp[7].reshape(10, 170, 95, 20);
      Label label7 = (Label)comp[7];
      label7.setText("Fill:");
      label7.setAlignment(0);
      // fill
      comp[8] = new Choice();
      c.add(comp[8]);
      comp[8].reshape(120, 170, 95, 20);
      Choice choice8 = (Choice)comp[8];
      choice8.addItem("HORIZONTAL");
      choice8.addItem("VERTICAL");
      choice8.addItem("BOTH");
      choice8.addItem("NONE");
      switch (gc.fill)
         {
         case GridBagConstraints.HORIZONTAL:
            choice8.select("HORIZONTAL"); break;
         case GridBagConstraints.VERTICAL:
            choice8.select("VERTICAL"); break;
         case GridBagConstraints.BOTH:
            choice8.select("BOTH"); break;
         case GridBagConstraints.NONE:
            choice8.select("NONE"); break;
         default:break;
         }

      comp[9] = new Label();
      c.add(comp[9]);
      comp[9].reshape(10, 200, 99, 20);
      Label label9 = (Label)comp[9];
      label9.setText("Width & Height:");
      label9.setAlignment(0);
      // width
      comp[10] = new Choice();
      c.add(comp[10]);
      comp[10].reshape(120, 200, 95, 20);
      Choice choice10 = (Choice)comp[10];
      try{
         if (LAYOUT == Screen.GRIDBAG)
            {
            buildList(choice10, 0, 20, 1);
            choice10.addItem("REMAINDER");
            choice10.addItem(String.valueOf(gc.gridwidth));
            if (gc.gridwidth == GridBagConstraints.REMAINDER)
               choice10.select("REMAINDER");
            else
               choice10.select(String.valueOf(gc.gridwidth));
            }
         else
            {
            buildList(choice10, 0, 200, 5);
            choice10.addItem
            (String.valueOf(component.size().width));
            choice10.select
            (String.valueOf(component.size().width));
            }
         }
      catch(Exception e){;}
      // height
      comp[12] = new Choice();
      c.add(comp[12]);
      comp[12].reshape(240, 200, 95, 20);
      Choice choice12 = (Choice)comp[12];
      try{
         if (LAYOUT == Screen.GRIDBAG)
            {
            buildList(choice12, 0, 20, 1);
            choice12.addItem("REMAINDER");
            choice12.addItem(String.valueOf(gc.gridheight));
            if (gc.gridheight == GridBagConstraints.REMAINDER)
               choice12.select("REMAINDER");
            else
               choice12.select(String.valueOf(gc.gridwidth));
            }
         else
            {
            choice12.addItem
            (String.valueOf(component.size().height));
            choice12.select
            (String.valueOf(component.size().height));
            }
         }
      catch(Exception e){System.out.println(e.getMessage());}

      comp[13] = new Label();
      c.add(comp[13]);
      comp[13].reshape(10, 230, 95, 20);
      Label label13 = (Label)comp[13];
      label13.setText("x & y:");
      label13.setAlignment(0);
      // x position:
      comp[19] = new Choice();
      c.add(comp[19]);
      comp[19].reshape(120, 230, 95, 20);
      Choice choice19 = (Choice)comp[19];
      try{
         if (LAYOUT == Screen.GRIDBAG)
            {
            buildList(choice19, 0, 20, 1);
            choice19.addItem("RELATIVE");
            choice19.addItem(String.valueOf(gc.gridx));
            if (gc.gridx == GridBagConstraints.RELATIVE)
               choice19.select("RELATIVE");
            else
               choice19.select(String.valueOf(gc.gridx));
            }
         else
            {
            buildList(choice19, 0, 200, 5);
            choice19.addItem
            (String.valueOf(x));
            choice19.select
            (String.valueOf(x));
            }
         }
      catch(Exception e){System.out.println(e.getMessage());}
      // y position:
      comp[20] = new Choice();
      c.add(comp[20]);
      comp[20].reshape(240, 230, 95, 20);
      Choice choice20 = (Choice)comp[20];
      try{
         if (LAYOUT == Screen.GRIDBAG)
            {
            buildList(choice20, 0, 20, 1);
            choice20.addItem("RELATIVE");
            choice20.addItem(String.valueOf(gc.gridy));
            if (gc.gridy == GridBagConstraints.RELATIVE)
               choice20.select("RELATIVE");
            else
               choice20.select(String.valueOf(gc.gridy));
            }
         else
            {
            buildList(choice20, 0, 200, 5);
            choice20.addItem
            (String.valueOf(y));
            choice20.select
            (String.valueOf(y));
            }
         }
      catch(Exception e){System.out.println(e.getMessage());}

      comp[15] = new Label();
      c.add(comp[15]);
      comp[15].reshape(10, 260, 95, 20);
      Label label15 = (Label)comp[15];
      label15.setText("x & y pad:");
      label15.setAlignment(0);
      // x pad:
      comp[21] = new Choice();
      c.add(comp[21]);
      comp[21].reshape(120, 260, 48, 20);
      Choice choice21 = (Choice)comp[21];
      buildList(choice21, 0, 20, 1);
      choice21.addItem(String.valueOf(gc.ipadx));
      choice21.select(String.valueOf(gc.ipadx));

      // y pad:
      comp[22] = new Choice();
      c.add(comp[22]);
      comp[22].reshape(180, 260, 48, 20);
      Choice choice22 = (Choice)comp[22];
      buildList(choice22, 0, 20, 1);
      choice22.addItem(String.valueOf(gc.ipady));
      choice22.select(String.valueOf(gc.ipady));

      comp[17] = new Label();
      c.add(comp[17]);
      comp[17].reshape(10, 290, 95, 20);
      Label label17 = (Label)comp[17];
      label17.setText("x & y weight:");
      label17.setAlignment(0);
      // x weight:
      comp[23] = new Choice();
      c.add(comp[23]);
      comp[23].reshape(120, 290, 48, 20);
      Choice choice23 = (Choice)comp[23];
      buildListByDoubles(choice23, 0.0, 2.0, 0.1);
      choice23.addItem(String.valueOf(gc.weightx));
      choice23.select(String.valueOf(gc.weightx));
      // y weight:
      comp[24] = new Choice();
      c.add(comp[24]);
      comp[24].reshape(180, 290, 48, 20);
      Choice choice24 = (Choice)comp[24];
      buildListByDoubles(choice24, 0.0, 2.0, 0.1);
      choice24.addItem(String.valueOf(gc.weighty));
      choice24.select(String.valueOf(gc.weighty));

      comp[25] = new Label();
      c.add(comp[25]);
      comp[25].reshape(10, 320, 95, 20);
      Label label25 = (Label)comp[25];
      label25.setText("Name or Label:");
      label25.setAlignment(0);
      // name:
      comp[26] = new TextField();
      c.add(comp[26]);
      comp[26].reshape(120, 320, 120, 30);
      if (component instanceof Button)
         {
         Button b = (Button)component;
         TextField t = (TextField)comp[26];
         t.setText(b.getLabel());
         }
      comp[28] = new Button();
      c.add(comp[28]);
      comp[28].reshape(130, 360, 60, 20);
      Button button28 = (Button)comp[28];
      button28.setLabel("Apply");

      comp[29] = new Button();
      c.add(comp[29]);
      comp[29].reshape(200, 360, 60, 20);
      Button button29 = (Button)comp[29];
      button29.setLabel("Done");

      c.resize(430, 400);
      }
   private void buildList
      (Choice c, int start, int end, int inc)
      {
      for (int i = start; i <= end; i += inc)
         c.addItem(new Integer(i).toString());
      }
   private void buildListByDoubles
      (Choice c, double start, double end, double inc)
      {
      for (double i = start; i <= end; i += inc)
         c.addItem(Double.toString(i));
      }
   }
