home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / ActiveX / JChart / JChartFormatCustomizer.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  7.1 KB  |  214 lines

  1. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. //  JChartFormatCustomizer.java
  3. //
  4. //  This provides editors for modifying the format of the chart
  5. //
  6. //  (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  7. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8.  
  9. import com.ms.ui.*;
  10. import com.ms.ui.event.*;
  11. import java.beans.*;
  12. import com.ms.fx.*;
  13.  
  14. public class JChartFormatCustomizer extends UIPanel implements Customizer, IUIItemListener
  15. {
  16.     private JChart bean;                                     // the bean which is to be customized
  17.     private PropertyChangeSupport helper;                   // to listen to property change listeners
  18.     private UIGroup chartType;                              // what type of a chart is it
  19.     private UIRadioButton pieButton;                        // pie chart button
  20.     private UIRadioButton barButton;                        // bar chart radio button
  21.     private UIRadioButton lineButton;                       // a line graph button
  22.     private UIRadioButton columnButton;                     // a column graph
  23.     private UIGroup rowsOrColumns;                          // group data by rows or columns
  24.     private UIRadioButton compareColumns;                   // compare columns in a row
  25.     private UIRadioButton compareRows;                      // compare the rows in a columns
  26.  
  27.     public JChartFormatCustomizer()
  28.     {
  29.         // setup the property change listener support
  30.         helper = new PropertyChangeSupport(this);
  31.  
  32.         //set the layout manager
  33.         setLayout( new UIRowLayout(2) );
  34.  
  35.         // set the back ground
  36.         setBackground(FxColor.lightGray);
  37.  
  38.         // create a group for the chart type
  39.         chartType = new UIGroup("Chart Type");
  40.         pieButton = new UIRadioButton("Pie chart", UIButton.TOGGLE);
  41.         pieButton.addItemListener(this);
  42.         barButton = new UIRadioButton("Bar chart", UIButton.TOGGLE);
  43.         barButton.addItemListener(this);
  44.         lineButton = new UIRadioButton("Line graph", UIButton.TOGGLE);
  45.         lineButton.addItemListener(this);
  46.         columnButton = new UIRadioButton("Column chart", UIButton.TOGGLE);
  47.         columnButton.addItemListener(this);
  48.  
  49.  
  50.         chartType.add(pieButton);
  51.         chartType.add(barButton);
  52.         chartType.add(lineButton);
  53.         chartType.add(columnButton);
  54.  
  55.         add(chartType);
  56.  
  57.         // create a group for the rows vs columns
  58.         rowsOrColumns = new UIGroup("Rows or columns");
  59.         compareRows = new UIRadioButton("Compare rows", UIButton.TOGGLE);
  60.         compareRows.addItemListener(this);
  61.         compareColumns = new UIRadioButton("Compare columns", UIButton.TOGGLE);
  62.         compareColumns.addItemListener(this);
  63.  
  64.         rowsOrColumns.add(compareRows);
  65.         rowsOrColumns.add(compareColumns);
  66.  
  67.         add(rowsOrColumns);
  68.     }
  69.  
  70.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  71.     // Interface Customizer requires the following methods to be defined
  72.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  73.  
  74.     /**
  75.      * Set the bean object which is to be customized
  76.      */
  77.     public void setObject(Object beanToCustomize)
  78.     {
  79.         this.bean = (JChart) beanToCustomize;
  80.  
  81.         switch(bean.getChartType())
  82.         {
  83.         case JChart.BAR_CHART:
  84.             barButton.setChecked(true);
  85.             break;
  86.  
  87.         case JChart.PIE_CHART:
  88.             pieButton.setChecked(true);
  89.             break;
  90.  
  91.         case JChart.LINE_GRAPH:
  92.             lineButton.setChecked(true);
  93.             break;
  94.  
  95.         case JChart.COLUMN_CHART:
  96.             columnButton.setChecked(true);
  97.             break;
  98.  
  99.         default:
  100.             // do nothing I don't know this chart type
  101.             break;
  102.         }
  103.  
  104.  
  105.         if(bean.getCompareColumns() )
  106.         {
  107.             compareColumns.setChecked(true);
  108.         }
  109.  
  110.         else
  111.         {
  112.             compareRows.setChecked(true);
  113.         }
  114.  
  115.     }
  116.  
  117.     /**
  118.      * Add a listener for changes to the bean
  119.      * @param   PropertyChangeListener  The object which should be informed of a change
  120.      */
  121.     public void addPropertyChangeListener(PropertyChangeListener listener)
  122.     {
  123.         helper.addPropertyChangeListener(listener);
  124.     }
  125.     /**
  126.      * Remove a listener of bean property changes
  127.      * @param   PropertyChangeListener  The object who no longer wants to listen to changes
  128.      */
  129.     public void removePropertyChangeListener(PropertyChangeListener listener) 
  130.     {
  131.         helper.removePropertyChangeListener(listener);
  132.     }
  133.  
  134.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  135.     // Interface IUIActionListener requires the following methods.
  136.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  137.     
  138.     public void itemStateChanged(UIItemEvent evt)
  139.     {
  140.         UIRadioButton source = (UIRadioButton) evt.getSource();
  141.  
  142.         // if this button is de- selected then do nothing
  143.         if( !source.isChecked() )
  144.         {
  145.             source.setChecked(true);
  146.             return;
  147.         }
  148.  
  149.         if(source == compareRows)
  150.         {
  151.             compareColumns.setChecked(false);
  152.             bean.setCompareColumns(false);
  153.             helper.firePropertyChange("compareColumns", new Boolean(true), new Boolean(false) );
  154.         }
  155.         else if(source == compareColumns)
  156.         {
  157.             compareRows.setChecked(false);
  158.             bean.setCompareColumns(true);
  159.             helper.firePropertyChange("compareColumns", new Boolean(false), new Boolean(true) );            
  160.         }
  161.  
  162.         else 
  163.         {
  164.             // the click has to be one of the chart types
  165.  
  166.             // de-select all
  167.             pieButton.setChecked(false);
  168.             barButton.setChecked(false);
  169.             lineButton.setChecked(false);
  170.             columnButton.setChecked(false);
  171.  
  172.             // now select the one which was clicked
  173.             source.setChecked(true);
  174.  
  175.             try
  176.             {
  177.                 // now update the bean property
  178.                 if( source == pieButton)
  179.                 {
  180.                     bean.setChartType(JChart.PIE_CHART);
  181.                 }
  182.  
  183.                 else if(source == lineButton)
  184.                 {
  185.                     bean.setChartType(JChart.LINE_GRAPH);
  186.                 }
  187.  
  188.                 else if(source == barButton)
  189.                 {
  190.                     bean.setChartType(JChart.BAR_CHART);
  191.                 }
  192.  
  193.                 else if(source == columnButton)
  194.                 {
  195.                     bean.setChartType(JChart.COLUMN_CHART);
  196.                 }
  197.  
  198.                 else // I don't know how I got this Event
  199.                 {
  200.                     System.err.println("Unexpected Adjustment Event received");
  201.                 }
  202.             
  203.                 helper.firePropertyChange(null, null, null);
  204.             }
  205.             catch( PropertyVetoException e)
  206.             {
  207.                 System.err.println("Unexpected Property Veto Exception: "+e.toString() );
  208.                 e.printStackTrace();
  209.             }
  210.         }
  211.         
  212.     }
  213. }
  214.