package jas2.hist;

import jas2.hist.normalization.Normalizer;
import jas2.util.CheckBoxBorderPanel;
import jas2.util.ColorChooser;
import jas2.util.DateChooser;
import jas2.util.JASTextField;
import jas2.util.JTextFieldBinding;
import jas2.util.PropertyBinding;
import jas2.util.PropertyDialog;
import jas2.util.PropertyPage;
import jas2.util.PropertySite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.Enumeration;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.UIManager;
import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import tablelayout.TableLayout;


public final class JASHistPropertyDialog extends PropertyDialog
{
   public JASHistPropertyDialog(Frame f,JASHist bean)
   {
      this(f, bean, DEFAULT);
   }
   public JASHistPropertyDialog(final Frame f, final JASHist bean, final byte axis)
   {
      super(f,"Histogram properties...",bean);
      
      addPage("General",new JASHistPropGeneral(), false);
      addPage("Y Axis" ,new JASHistPropYAxis(axis == Y_AXIS_RIGHT), axis == Y_AXIS_LEFT || axis == Y_AXIS_RIGHT);
      addPage("X Axis" ,new JASHistPropXAxis(), axis == X_AXIS);
      DataManager dm = bean.getDataManager();
      if (bean.numberOfDataSets() > 0) addPage("Data",new JASHistPropData(dm), false);
      if (dm instanceof SupportsFunctions)
         addPage("Functions",new JASHistPropFunctions(), false);
      pack();
   }
   final static byte DEFAULT = 0;
   final static byte Y_AXIS_LEFT = 1;
   final static byte Y_AXIS_RIGHT = 2;
   final static byte X_AXIS = 3;
}
final class JASHistPropGeneral extends PropertyPage
{
   public JASHistPropGeneral()
   {
      setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
      
      JPanel p1 = new FixedHeightPanel();
      p1.add(new JLabel("Title"));
      JASTextField title = new JASTextField(40);
      p1.add(title);
      add(p1);
      
      JPanel p4 = new FixedHeightPanel();
/*
                JCheckBox axis = new JCheckBox("Axis Bounding Box");
                axis.setMnemonic('B');
                p4.add(axis);
 */
      JComboBox legend = new JComboBox();
      legend.addItem("Hide Legend");
      legend.addItem("Automatic");
      legend.addItem("Show Legend");
      p4.add(legend);
      add(p4);
      
      JPanel p3 = new FixedHeightPanel();
      p3.setBorder(BorderFactory.createTitledBorder("Border"));
      JComboBox btype = new JComboBox();
      btype.addItem("None");
      btype.addItem("Bevel In");
      btype.addItem("Bevel Out");
      btype.addItem("Etched");
      btype.addItem("Line");
      btype.addItem("Shadow");
      p3.add(btype);
/*
                p3.add(new JLabel("Width"));
                SpinBox bwidth = new SpinBox(2,0,20);
                p3.add(bwidth);
 */
      add(p3);
      
      JPanel p2 = new FixedHeightPanel();
      p2.setBorder(BorderFactory.createTitledBorder("Color"));
      p2.add(new JLabel("Background"));
      ColorChooser back = new ColorChooser();
      p2.add(back);
      p2.add(new JLabel("Foreground"));
      ColorChooser fore = new ColorChooser();
      p2.add(fore);
      p2.add(new JLabel("Data Area"));
      ColorChooser data = new ColorChooser();
      p2.add(data);
      add(p2);
      add(Box.createVerticalGlue());
      
      addBinding(new PropertyBinding(title,"Title"));
      addBinding(new PropertyBinding(back,"Background"));
      addBinding(new PropertyBinding(fore,"Foreground"));
      addBinding(new PropertyBinding(data,"DataAreaColor"));
      addBinding(new PropertyBinding(btype,"DataAreaBorderType"));
/*
                addBinding(new PropertyBinding(bwidth,"DataAreaBorderWidth"));
                addBinding(new PropertyBinding(axis,"AxisBoundingBox"));
 */
      addBinding(new PropertyBinding(legend,"ShowLegend"));
   }
   public String getHelpTopic()
   {
      return "userInterface.propertiesDialog.generalTab";
   }
}
final class JASHistPropYAxis extends PropertyPage implements ListSelectionListener, PropertySite
{
   public JASHistPropYAxis(final boolean selectY2)
   {
      m_init = false;
      
      setLayout(new BorderLayout());
      
      m_listModel = new DefaultListModel();
      m_list = new JList(m_listModel);
      if (selectY2) m_list.setSelectedIndex(1);
      m_list.addListSelectionListener(this);
      JScrollPane scroll = new JScrollPane();
      scroll.setViewportView(m_list);
      scroll.setPreferredSize(new Dimension(100,120));
      add(scroll,BorderLayout.WEST);
      
      m_propAxis = new JASHistPropAxis();
      m_propAxis.setPropertySite(this);
      add(m_propAxis,BorderLayout.CENTER);
   }
   public String getHelpTopic()
   {
      return "userInterface.propertiesDialog.axesTabs";
   }
   public void activate()
   {
      m_init = false; // Recalculate list of axes each time page is activated
   }
   public void doDataExchange(boolean set,Object bean)
   {
      if (!m_init)
      {
         JASHist hist = (JASHist) bean;
         JASHistAxis[] axes = hist.getYAxes();
         
         m_listModel.removeAllElements();
         for (int i=0; i 

Ads help maintain this website.