/**@(#) ParamsSelectionPanel.java 1.0 99/07/24 Larry Rodrigues\
  * Copyright (c) 1998 Lawrence Rodrigues
  **/
package com.vistech.graphics;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.beans.*;
import javax.swing.event.*;
import javax.swing.border.*;
/** Creates a GUI panel for selecting graphics attributes.
  * @version 1.0  24  July 1999
  * @author Larry Rodrigues
  * **/
public class ParamsSelectionPanel extends JPanel {
   protected GraphicsDisplay target;
   public ParamsSelectionPanel(GraphicsDisplay gd){
      target = gd;
      createUI();
   }

   private void createUI(){
      JTabbedPane tab = new JTabbedPane();
      JPanel shpan = createShapesPanel();
      JPanel textpan = createTextPanel();
      tab.add(shpan, "Shapes");
      tab.add(textpan, "Text");
      tab.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(),
                    "Parameter Selection Panel"));
      add(tab);
   }

   public void setTarget(GraphicsDisplay tar){
       target = tar;
   }
   protected JPanel createTextPanel(){
      String fonttags[] =
         GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
      int[] fontvalues = new int[fonttags.length];
      for(int i=0;i<fonttags.length;i++) {
          fontvalues[i] = i;
      }
      JComboBox fontnames = AttributeSetterUtil.createChoice(target,"FontType",
                                         fonttags,fontvalues);
      int minFontSize = 4;
      int maxFontSize = 48;
      int numOfSizes = (maxFontSize - minFontSize)/2;
             String fontsizetags[] = new String[numOfSizes];
      int fontsizevalues[] = new int[numOfSizes];
      for(int i=0; i<numOfSizes; i++) {
          fontsizetags[i] = (new Integer(2*i+minFontSize)).toString();
          fontsizevalues[i] = (2*i)+minFontSize;
      }
      JComboBox fontsizes = AttributeSetterUtil.createChoice(target, "FontSize",
                                         fontsizetags, fontsizevalues);

      String fontstyletags[] = {"PLAIN", "BOLD", "ITALIC"};
      int fontstylevalues[] ={Font.PLAIN, Font.BOLD, Font.ITALIC};
      JComboBox fontstyles = AttributeSetterUtil.createChoice(target, "FontStyle",
                                          fontstyletags, fontstylevalues);

      JComboBox txtcolor = AttributeSetterUtil.createColorChoice(target, "TextColor");
      Component com[] = {new JLabel("Text Color"),new JLabel("Fonts"),
                         new JLabel("Font Size"), new JLabel("Font Style"),
                         txtcolor,fontnames, fontsizes, fontstyles};
      JPanel fontpan = AttributeSetterUtil.doGridbagLayout(com, 4);
      return fontpan;
  }


  protected JPanel createShapesPanel() {
     JLabel drawcolorlab = new JLabel("Drawing Color");
     JComboBox drawcolor = AttributeSetterUtil.createColorChoice(target, "DrawingColor");

     JLabel fillcolorlab = new JLabel("Fiiling Color");
     JComboBox fillcolor = AttributeSetterUtil.createColorChoice(target, "FillColor");

     JPanel paramspan = new JPanel();
     Component comp[] = {drawcolorlab,drawcolor, fillcolorlab,fillcolor};
     JPanel pan1 = AttributeSetterUtil.doGridbagLayout(comp,4);

     JLabel strokelab = new JLabel("Basic Stroke");
     String widthtags[] = {"0.5", "1.0", "1.5", "2.0", "2.5",
                           "3.0", "3.5", "4.0", "4.5", "5.0",
                           "5.5", "6.0", "6.5", "7.0", "7.5"};
     int[] widthvalues = new int[widthtags.length];
     for(int i=0;i<widthtags.length;i++) {
         widthvalues[i] = i;
     }
     JComboBox strokewidth = AttributeSetterUtil.createChoice(target,"StrokeWidth",
                                          widthtags,widthvalues);
     String captags[] = {"CAP_BUTT", "CAP_ROUND","CAP_SQUARE"};

     int[] capvalues = {BasicStroke.CAP_BUTT,
                        BasicStroke.CAP_ROUND,
                        BasicStroke.CAP_SQUARE};
     JComboBox  capstyle = AttributeSetterUtil.createChoice(target,"CapStyle",
                                        captags,capvalues);
     String jointags[] = {"JOIN_MITER", "JOIN_ROUND","JOIN_BEVEL"};
     int[] joinvalues = {BasicStroke.JOIN_MITER,
                         BasicStroke.JOIN_ROUND,
                         BasicStroke.JOIN_BEVEL};
     JComboBox joinstyle = AttributeSetterUtil.createChoice(target,"JoinStyle",
                                        jointags, joinvalues);

     Component comp1[] = {new JLabel("Stroke Width"),
                         new JLabel("Cap Style"),
                         new JLabel("Join Style"),
                         strokewidth, capstyle, joinstyle};

     JPanel pan2 = AttributeSetterUtil.doGridbagLayout(comp1, 3);
     GridBagLayout gb = new GridBagLayout() ;
     GridBagConstraints c = new GridBagConstraints();
     paramspan.setLayout(gb);
     c.weighty = 1.0; c.weightx = 1.0;
     c.fill = GridBagConstraints.NONE;
     c.insets = new Insets(0,1, 0,10);
     c.fill = GridBagConstraints.HORIZONTAL;
     c.gridwidth = GridBagConstraints.REMAINDER;
     gb.setConstraints(pan1, c);
     paramspan.add(pan1);
     c.weighty = 1.0; c.weightx = 1.0;
     gb.setConstraints(pan2, c);
     paramspan.add(pan2);
     return paramspan;
  }
}