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

  1. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. //  JChartTitlesCustomizer.java
  3. //
  4. //  This provides editors for modifying the various titles displayed in the
  5. //  chart.
  6. //
  7. //  (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  8. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9.  
  10. import com.ms.ui.*;
  11. import com.ms.ui.event.*;
  12. import java.beans.*;
  13. import java.awt.*;
  14.  
  15. public class JChartTitlesCustomizer extends UIPanel implements Customizer, IUIKeyListener
  16. {
  17.     UIEdit captionEdit;                     // The editor for changing the caption of the chart
  18.     UIEdit titleEdit;                       // The editor for the title
  19.     UIEdit xTitleEdit;                      // The editor for x-axis title
  20.     UIEdit yTitleEdit;                      // The editor for the y-axis title
  21.     JChart bean;                             // the bean we are customizing
  22.     PropertyChangeSupport helper;           // to help fire property change events.
  23.  
  24.     /**
  25.      * Constructor for the Titles Customizer. It sets up the various
  26.      * controls to be displayed in the customizer and then displays
  27.      * them.
  28.      * @param   JChartCustomizer The customizer which created this guy.
  29.      */
  30.     public JChartTitlesCustomizer()
  31.     {
  32.         // setup the property change listener support
  33.         helper = new PropertyChangeSupport(this);
  34.  
  35.         setLayout( new UIGridLayout(4,2, 10, 10) );
  36.  
  37.         add( new UIDrawText("Caption") );
  38.         add( new UIDrawText("Title") );
  39.  
  40.         captionEdit = new UIEdit("<blank>");
  41.         captionEdit.setMaxBufferSize(20);
  42.         captionEdit.setBackground(Color.white);
  43.         captionEdit.addKeyListener(this);
  44.         add( captionEdit );
  45.  
  46.         titleEdit = new UIEdit("<blank>");
  47.         titleEdit.setMaxBufferSize(20);
  48.         titleEdit.setBackground(Color.white);
  49.         titleEdit.addKeyListener(this);
  50.         add( titleEdit );
  51.  
  52.         add( new UIDrawText("X - Axis Title") );
  53.         add( new UIDrawText("Y - Axis Title") );
  54.  
  55.         xTitleEdit= new UIEdit("<blank>");
  56.         xTitleEdit.setBackground(Color.white);
  57.         xTitleEdit.addKeyListener(this);
  58.         add( xTitleEdit );
  59.  
  60.         yTitleEdit= new UIEdit("<blank>");
  61.         yTitleEdit.setBackground(Color.white);
  62.         yTitleEdit.addKeyListener(this);
  63.         add( yTitleEdit );
  64.     }
  65.  
  66.     /**
  67.      * This function is called internally whenever some user input is given
  68.      * to a UI and the new properties have to be calculated  based on this
  69.      * input.
  70.      * @param   Object  The UI object which received input
  71.      */
  72.     private void updateProperties(Object source)
  73.     {
  74.         if(source == titleEdit)
  75.         {
  76.             bean.setChartTitle( titleEdit.getValueText() );
  77.         }
  78.  
  79.         else if(source == captionEdit)
  80.         {
  81.             bean.setCaption(captionEdit.getValueText() );
  82.         }
  83.  
  84.         else if(source == xTitleEdit)
  85.         {
  86.             bean.setXAxisTitle(xTitleEdit.getValueText());
  87.         }
  88.  
  89.         else if(source == yTitleEdit)
  90.         {
  91.             bean.setYAxisTitle(yTitleEdit.getValueText());
  92.         }
  93.  
  94.         else
  95.         {
  96.             return;
  97.         }
  98.  
  99.         helper.firePropertyChange(null, null, null);
  100.     }
  101.  
  102.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  103.     // Interface customizer requires the following procedures to be defined
  104.     //
  105.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  106.  
  107.     /**
  108.      * This function passes a reference to the chart bean we are customizing
  109.      * @param   JChart   The chart bean to be customized
  110.      */
  111.     public void setObject(Object beanToCustomize)
  112.     {
  113.         bean = (JChart) beanToCustomize;
  114.  
  115.         captionEdit.setValueText( bean.getCaption() );
  116.         
  117.         titleEdit.setValueText( bean.getChartTitle() );
  118.  
  119.         yTitleEdit.setValueText( bean.getYAxisTitle() );
  120.  
  121.         xTitleEdit.setValueText( bean.getXAxisTitle() );
  122.     }
  123.  
  124.     /**
  125.      * Add a listener for changes to the bean
  126.      * @param   PropertyChangeListener  The object which should be informed of a change
  127.      */
  128.     public void addPropertyChangeListener(PropertyChangeListener listener)
  129.     {
  130.         helper.addPropertyChangeListener(listener);
  131.     }
  132.  
  133.     /**
  134.      * Remove a listener of bean property changes
  135.      * @param   PropertyChangeListener  The object who no longer wants to listen to changes
  136.      */
  137.     public void removePropertyChangeListener(PropertyChangeListener listener) 
  138.     {
  139.         helper.removePropertyChangeListener(listener);
  140.     }
  141.  
  142.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  143.     // Interface UIKeyListener requires the following methods.
  144.     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  145.     
  146.     public void keyPressed(UIKeyEvent event)
  147.     {        
  148.         Object source = event.getSource();
  149.  
  150.         // now fugure out which property has to change
  151.         updateProperties(source);
  152.     }
  153.  
  154.     public void keyReleased(UIKeyEvent event)
  155.     {
  156.         Object source = event.getSource();
  157.  
  158.         // now fugure out which property has to change
  159.         updateProperties(source);
  160.     }
  161.  
  162.     public void keyTyped(UIKeyEvent event) 
  163.     {
  164.         Object source = event.getSource();
  165.  
  166.         // now fugure out which property has to change
  167.         updateProperties(source);
  168.     }
  169.  
  170.  
  171. }
  172.  
  173.