/*
 * @(#) MultiHistoCustomizer.java 1.0 2000/3/18
 * Copyright (c) 1997 Lawrence Rodrigues
 */
package vis.beans.plotter;

import java.io.*;
import java.beans.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import vis.util.*;
import java.lang.reflect.*;
import vis.beans.customizers.*;
import javax.swing.*;
 /** HistoCustomizer Class
   * @version 1.0  18 July 1997
   * @author Lawrence Rodrigues
   * 
   **/
  public class MultiHistoCustomizer extends CustomizerImpl{
     public MultiHistogram target;

     public MultiHistoCustomizer() {
       setTitle("Histogram Customizer");
     }

     protected void createGUI(){
        if(bean == null) return;
        target = (MultiHistogram)bean;
        pcs = new PropertyChangeSupport(target);
        JPanel pan = new JPanel();
        JPanel colorspan = createColorsPanel();
        JPanel labelspan = createLabelsPanel();
        JPanel tickspan = createTicksPanel();
        JPanel legendpan = createLegendPanel();
        JPanel origpan = createOriginPanel();
        GridBagLayout   gb = new GridBagLayout() ;
        GridBagConstraints c = new GridBagConstraints();
        pan.setLayout(gb);
        setBackground(Color.lightGray);
        setForeground(Color.black);
        c.fill = GridBagConstraints.BOTH;
        c.insets = new Insets(10,10,0,0);
        c.weighty = 0.0; c.weightx = 0.0;
        c.gridwidth = 1;
        gb.setConstraints(colorspan,c);
        pan.add(colorspan,c);
        c.gridwidth = GridBagConstraints.REMAINDER;
        gb.setConstraints(labelspan,c);
        pan.add(labelspan);
        c.gridwidth = GridBagConstraints.REMAINDER;
        gb.setConstraints(tickspan,c);
        pan.add(tickspan);
        c.gridwidth = 1;
        gb.setConstraints(legendpan,c);
        pan.add(legendpan);
        c.gridwidth = GridBagConstraints.REMAINDER;
        gb.setConstraints(origpan,c);
        pan.add(origpan);
        pan.setBorder(BorderFactory.createTitledBorder("Histogram Customizer"));
        add(pan);

        setSize(400,300);
     }

     public JPanel createColorsPanel(){
        JLabel bklab = new JLabel("Background color");
        JComboBox  bk = CustomizerUtil.createColorComboBox(target, pcs, "Background");
        JLabel fglab = new JLabel("Foreground color");
        JComboBox  fg = CustomizerUtil.createColorComboBox(target,pcs, "Foreground");
        JLabel gclab = new JLabel("Bar color");
        JComboBox  gc = CustomizerUtil.createColorComboBox(target, pcs,"GraphColor");
        Component comp[] = {bklab,bk,fglab,fg,gclab,gc};
        JPanel pan = CustomizerUtil.doGridbagLayout(comp, 2);
        pan.setBorder(BorderFactory.createTitledBorder("Colors"));
        return pan;
     }

     public JPanel createLabelsPanel(){
        JLabel tlab = new JLabel("Plot title");
        JTextField tl = CustomizerUtil.createJTextField(target, pcs,"TitleString", String.class);
        JLabel xlab = new JLabel("X label");
        JTextField xl = CustomizerUtil.createJTextField(target, pcs, "XLabelString", String.class);
        JLabel ylab = new JLabel("Y label");
        JTextField yl = CustomizerUtil.createJTextField(target, pcs, "YLabelString", String.class);
        Component comp[] = {tlab,tl,xlab,xl,ylab,yl};
        JPanel pan = CustomizerUtil.doGridbagLayout(comp,2);
        pan.setBorder(BorderFactory.createTitledBorder("Labels"));
        return pan;
     }

     public JPanel createTicksPanel(){
        JLabel xtick = new JLabel("Num of bars");
        JLabel ytick = new JLabel("Num of major Y ticks");
        JLabel sxtick = new JLabel("Num of minor X ticks");
        JLabel sytick = new JLabel("Num of minor Y ticks");
        JLabel xptlab = new JLabel("Num of bars/label");
        JLabel yptlab = new JLabel("Num of major Y ticks/label");
        JTextField xtf = CustomizerUtil.createJTextField(target,pcs,"NumBars", Integer.TYPE);
        JTextField ytf = CustomizerUtil.createJTextField(target,pcs,"NumYTicks", Integer.TYPE);
        JTextField sxtf = CustomizerUtil.createJTextField(target, pcs,"NumSmallXTicks",Integer.TYPE);
        JTextField sytf = CustomizerUtil.createJTextField(target, pcs,"NumSmallYTicks",Integer.TYPE);
        JTextField xlabpt = CustomizerUtil.createJTextField(target,pcs,"XLabelsPerTick", Integer.TYPE);
        JTextField ylabpt = CustomizerUtil.createJTextField(target,pcs,"YLabelsPerTick", Integer.TYPE);
        Component[] cmp = {xtick, xtf, ytick, ytf,
                            sxtick, sxtf, sytick, sytf,
                            xptlab, xlabpt, yptlab, ylabpt};
        JPanel pan = CustomizerUtil.doGridbagLayout(cmp,4);
        pan.setBorder(BorderFactory.createTitledBorder("Labels"));
        return pan;
     }
        protected JPanel createLegendPanel(){
        JPanel legpan = new JPanel();
        JPanel legpospan = CustomizerUtil.createXYIncrPanel(target,pcs, "LegendPosXIncr","LegendPosYIncr","Position");
        JPanel leggappan = CustomizerUtil.createIncrPanel(target, pcs, "LegendGapIncr", "Gap");
        legpan.add(leggappan);
        legpan.add(legpospan);

        legpan.setBorder(BorderFactory.createTitledBorder("Legend"));
        return legpan;
     }

     protected JPanel createOriginPanel(){
        JPanel origpan = new JPanel();
        JPanel origpospan = CustomizerUtil.createXYIncrPanel(target,pcs, "OriginXIncr","OriginYIncr","Position");
        origpan.add(origpospan);

        origpan.setBorder(BorderFactory.createTitledBorder("Plot Origin"));
        return origpan;
    }

  }
