home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 5.5 KB | 191 lines |
- /*
- * @(#)DataInput.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
- /**
- * <P> This is a basic Data Item to be used in the Info Bus
- */
-
- package symantec.itools.db.beans.binding;
- import java.awt.Dimension;
- import java.util.Vector;
- import symantec.itools.db.beans.binding.databus.*;
- public class DataInput implements DataItem, MutableImmediateAccess,DataItemAddition
- {
- //Members
- private String Name;
- private Object Value;//=new Object[1][1];
- private Dimension Size;
- private Vector DIChangedListeners =new Vector();
- private int StatusFlag=0;
-
- //Constructors
- /**
- * Constructor. An empty constructor
- */
- public DataInput(){
- }
-
- /**
- * Constructor. Constructs a data item from its name and its size
- * @param name. The name.
- * @param size. The size.
- */
- public DataInput(String name, Dimension size){
- setName(name);
-
- }
-
- /**
- * Sets the Name of the Data Input
- * Format: TableName@column1,column2%numberOfRow
- * @param name. The name of the Data Input.
- */
- public void setName(String name)
- {
- Name=name;
- }
-
-
- /**
- * Gets the Name of the Data Input
- * Format: TableName@column1,column2%numberOfRow
- * @return String. The name of the Data Input.
- */
- public String getName()
- {
- return(Name);
- }
-
-
- /**
- * Sets the value of the Data Input
- * @param newValue. An immediate access object necessary to change
- * the value of the data input.
- */
- public void setValue(ImmediateAccess newValue)
- {
-
- Object newvalue=newValue.getValueAsObject();
- if(Value!=null && newvalue!=null)
- {
- if((!newvalue.equals(Value)) && !((newvalue.toString()).equals(Value.toString())))
- {
- Value=newvalue;
- setStatusFlag(MODIFIED);
- notifyDataChanged();
-
- }
- }
- else if(newvalue==null && Value!=null && !Value.equals("") )
- {
- Value=newvalue;
- setStatusFlag(MODIFIED);
- notifyDataChanged();
- }
- else if(newvalue!=null && !newvalue.equals(Value))
- {
- Value=newvalue;
- setStatusFlag(MODIFIED);
- notifyDataChanged();
-
- }
-
- }
-
-
- //Event sources
- /**
- * Adds DataItemChangedListener to internal list so that they could be sent
- * DataItemChangedEvents when the data item is changed.
- *
- * @param dcl. An object implementing the DataItemChangedListener interface.
- *
- */
- public synchronized void addDataItemChangedListener(DataItemChangedListener dcl){
- DIChangedListeners.addElement(dcl);
- }
-
- /**
- * Removes DataItemChangedListeners from an internal list The object will no longer
- * be sent DataItemChangedEvents when a bound property changes.
- *
- * @param dcl. The DataItemChangedListener to remove.
- *
- */
- public synchronized void removeDataItemChangedListener(DataItemChangedListener dcl){
- DIChangedListeners.removeElement(dcl);
- }
- public void notifyDataChanged()
- {
-
- Vector l;
- try
- {
- DataItemChangedEvent dce=new DataItemChangedEvent(1,this);
- synchronized(this)
- {
- l=(Vector)DIChangedListeners.clone();
- }
- for(int i=0;i<l.size();i++)
- {
- ((DataItemChangedListener)l.elementAt(i)).notifyDataItemChanged(dce);
- }
- }
- catch(InvalidType e){System.out.println("invalidtype");}
- // cleanUp();
-
- }
-
- /**
- * Gets the value of the Data Input as a String
- * @return String. The value of the Data Input as a String.
- */
- public String getValueAsString(){
- return((String)Value.toString());
- }
-
- /**
- * Gets the value of the Data Input as a Object
- * @return Object. The value of the Data Input as a Object.
- */
- public Object getValueAsObject(){
- if(Value==null)return null;
- return((Object)Value);
- //return null;
- }
-
-
- public String getPresentationString(){
- return("String");
- }
-
-
- /**
- * Initializes the Data Input
- * @param d. The desired Dimension for a data input.
- */
-
- /* public void setUp(Dimension d){
- Size=d;
- Value=new Object[Size.height][Size.width];
-
- }*/
- public void setStatusFlag(int i)
- {
- StatusFlag=i;
- }
- public int getStatusFlag()
- {
- return StatusFlag;
- }
- public void cleanUp()
- {
- setStatusFlag(DataItemAddition.EXISTING);
- }
-
-
-
- }