home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / prosrc.bin / DataInput.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  5.5 KB  |  191 lines

  1. /*
  2.  * @(#)DataInput.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  /**
  8.  * <P> This is a basic Data Item to be used in the Info Bus
  9.  */
  10.  
  11. package symantec.itools.db.beans.binding;
  12. import java.awt.Dimension;
  13. import java.util.Vector;
  14. import symantec.itools.db.beans.binding.databus.*;
  15. public class DataInput implements DataItem, MutableImmediateAccess,DataItemAddition
  16. {
  17.         //Members
  18.         private String Name;
  19.         private Object Value;//=new Object[1][1];
  20.         private Dimension Size;
  21.         private Vector DIChangedListeners =new Vector();
  22.         private int StatusFlag=0;
  23.       
  24.         //Constructors
  25.         /**
  26.         * Constructor. An empty constructor
  27.         */
  28.         public DataInput(){
  29.         }
  30.  
  31.         /**
  32.         * Constructor. Constructs a data item from its name and its size
  33.         * @param       name.           The name.
  34.         * @param       size.            The size.
  35.         */
  36.         public DataInput(String name, Dimension size){
  37.             setName(name);
  38.            
  39.         }
  40.  
  41.          /**
  42.          * Sets the Name of the Data Input
  43.          * Format: TableName@column1,column2%numberOfRow
  44.          * @param name.     The name of the Data Input.
  45.          */
  46.         public void setName(String name)
  47.         {
  48.             Name=name;
  49.         }
  50.  
  51.  
  52.          /**
  53.          * Gets the Name of the Data Input
  54.          * Format: TableName@column1,column2%numberOfRow
  55.          * @return String.     The name of the Data Input.
  56.          */
  57.         public String getName()
  58.         {
  59.             return(Name);
  60.         }
  61.  
  62.  
  63.         /**
  64.          * Sets the value of the Data Input
  65.          * @param newValue.     An immediate access object necessary to change
  66.          * the value of the data input.
  67.          */
  68.         public void setValue(ImmediateAccess newValue)
  69.         {
  70.            
  71.            Object newvalue=newValue.getValueAsObject();
  72.            if(Value!=null && newvalue!=null)
  73.             {
  74.                 if((!newvalue.equals(Value)) && !((newvalue.toString()).equals(Value.toString())))
  75.                 {
  76.                             Value=newvalue;
  77.                              setStatusFlag(MODIFIED);
  78.                             notifyDataChanged();
  79.                              
  80.                 }
  81.             }
  82.             else if(newvalue==null && Value!=null && !Value.equals("") )
  83.             {
  84.                 Value=newvalue;
  85.                 setStatusFlag(MODIFIED);
  86.                 notifyDataChanged();  
  87.             }
  88.             else if(newvalue!=null && !newvalue.equals(Value))
  89.             {
  90.                     Value=newvalue;
  91.                      setStatusFlag(MODIFIED);
  92.                     notifyDataChanged();      
  93.                      
  94.             }
  95.             
  96.             }
  97.  
  98.  
  99.         //Event sources
  100.         /**
  101.          * Adds DataItemChangedListener to internal list so that they could be sent
  102.          * DataItemChangedEvents when the data item is changed.
  103.          *
  104.          * @param       dcl. An object implementing the DataItemChangedListener interface.
  105.          *
  106.          */
  107.         public synchronized void addDataItemChangedListener(DataItemChangedListener dcl){
  108.         DIChangedListeners.addElement(dcl);
  109.         }
  110.  
  111.         /**
  112.          * Removes DataItemChangedListeners from an internal list The object will no longer
  113.          * be sent DataItemChangedEvents when a bound property changes.
  114.          *
  115.          * @param       dcl. The DataItemChangedListener to remove.
  116.          *
  117.          */
  118.         public synchronized void removeDataItemChangedListener(DataItemChangedListener dcl){
  119.         DIChangedListeners.removeElement(dcl);
  120.         }
  121.         public void notifyDataChanged()
  122.         {
  123.            
  124.             Vector l;
  125.             try
  126.             {
  127.             DataItemChangedEvent dce=new DataItemChangedEvent(1,this);
  128.             synchronized(this)
  129.             {
  130.                 l=(Vector)DIChangedListeners.clone();
  131.             }
  132.             for(int i=0;i<l.size();i++)
  133.             {
  134.                ((DataItemChangedListener)l.elementAt(i)).notifyDataItemChanged(dce);
  135.             }
  136.             }
  137.             catch(InvalidType e){System.out.println("invalidtype");}
  138.            // cleanUp();
  139.            
  140.         }
  141.         
  142.          /**
  143.          * Gets the value of the Data Input as a String
  144.          * @return String.     The value of the Data Input as a String.
  145.          */
  146.         public String getValueAsString(){
  147.             return((String)Value.toString());
  148.         }
  149.  
  150.          /**
  151.          * Gets the value of the Data Input as a Object
  152.          * @return Object.     The value of the Data Input as a Object.
  153.          */
  154.         public Object getValueAsObject(){
  155.             if(Value==null)return null;
  156.             return((Object)Value);
  157.             //return null;
  158.         }
  159.  
  160.  
  161.         public String getPresentationString(){
  162.             return("String");
  163.         }
  164.  
  165.  
  166.         /**
  167.          * Initializes the Data Input
  168.          * @param d.     The desired Dimension for a data input.
  169.          */
  170.  
  171.        /* public void setUp(Dimension d){
  172.           Size=d;
  173.             Value=new Object[Size.height][Size.width];
  174.  
  175.         }*/
  176.         public void setStatusFlag(int i)
  177.         {
  178.             StatusFlag=i;
  179.         }
  180.         public int getStatusFlag()
  181.         {
  182.             return StatusFlag;
  183.         }
  184.         public void cleanUp()
  185.         {
  186.             setStatusFlag(DataItemAddition.EXISTING);
  187.         }
  188.         
  189.         
  190.     
  191.     }