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 / TextArea.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  13.2 KB  |  442 lines

  1. /*
  2.  * @(#TextArea.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8.  
  9. package symantec.itools.db.awt;
  10.  
  11. // import java.awt.*;
  12. import java.util.*;
  13. import java.sql.*;
  14. import java.lang.*;
  15. import symantec.itools.db.net.*;
  16. import symantec.itools.db.pro.*;
  17. import java.awt.event.*;
  18. import symantec.itools.db.beans.binding.Name;
  19.  
  20. /**
  21.  * A dbAWARE TextArea component.
  22.  * <p>
  23.  * This component is similar to the basic TextArea component, but can
  24.  * be "bound" to a projection within a relation view
  25.  * so that it automatically gets and sets the values in that relation.
  26.  * <p>
  27.  *
  28.  * @see java.awt.TextArea
  29.  */
  30. public class TextArea extends java.awt.TextArea implements ProjectionBean
  31. {
  32.     /**
  33.      * Constant value for the Triggering Event property.
  34.      * Indicates the triggering event is FOCUS_LOST.
  35.      */
  36.     public static final int Focus_Event = ProjectionBeanHelper.Focus_Event;
  37.     /**
  38.      * Constant value for the Triggering Event property.
  39.      * Indicates the triggering event is TEXT_VALUE_CHANGED.
  40.      */
  41.     public static final int Text_Event = ProjectionBeanHelper.Text_Event;
  42.     /**
  43.      * Constant value for the Triggering Event property.
  44.      * Indicates the triggering event is KEY_PRESSED.
  45.      */
  46.     public static final int Key_Event = ProjectionBeanHelper.Key_Event;
  47.  
  48.     /**
  49.      * A constant value indicating how an empty string will be saved in the database.
  50.      */
  51.     public static final String Default = ProjectionBeanHelper.DEFAULT;
  52.     /**
  53.      * A constant value indicating how an empty string will be saved in the database.
  54.      */
  55.     public static final String Blank = ProjectionBeanHelper.BLANK;
  56.     /**
  57.      * A constant value indicating how an empty string will be saved in the database.
  58.      */
  59.     public static final String Null = ProjectionBeanHelper.NULL;
  60.  
  61.     private ProjectionBeanHelper    m_Helper;
  62.     /**
  63.      * The type of event that triggers this component to commit its changes.
  64.      * @see #getTriggeringEvent
  65.      * @see #setTriggeringEvent
  66.      * @see #Focus_Event
  67.      * @see #Key_Event
  68.      * @see #Text_Event
  69.      */
  70.     protected int                   m_TriggeringEvent = Focus_Event;
  71.     /**
  72.      * Controls when the component commits its changes.
  73.      * If <code>true</code>, this component sets the triggering event to
  74.      * Key_Event, otherwise the triggering event is set to Focus_Event.
  75.      * @see #getDynamicUpdate
  76.      * @see #setDynamicUpdate
  77.      * @see #Focus_Event
  78.      * @see #Key_Event
  79.      */
  80.     protected boolean               m_DynamicUpdate = false;
  81.  
  82.  
  83.     /**
  84.      * Controls the behavior of the tab key.
  85.      * If <code>true</code>, pressing the tab key will move the input focus
  86.      * to the next component.
  87.      * Otherwise the focus will remain within this component.
  88.      * @see #getTabControl
  89.      * @see #setTabControl
  90.      */
  91.     private boolean tabControl=false;
  92.  
  93.     /**
  94.      * Constructs a default TextArea.
  95.      * <p>
  96.      * Call setBinding() to bind this component to a projection in a RelationView and
  97.      * auto-set the value.
  98.      *
  99.      * @see #setBinding
  100.      */
  101.     public TextArea()
  102.     {
  103.         this("");
  104.     }
  105.  
  106.     /**
  107.      * Constructs a TextArea with the specified number of rows and columns.
  108.      * <p>
  109.      * Call setBinding() to bind this component to a projection in a RelationView and
  110.      * auto-set the value.
  111.      *
  112.      * @param rows the number of rows
  113.      * @param cols the number of columns
  114.      *
  115.      * @see #setBinding
  116.      */
  117.     public TextArea(int rows, int cols)
  118.     {
  119.         this("", rows, cols);
  120.     }
  121.  
  122.     /**
  123.      * Constructs a TextArea with the specified initial value.
  124.      * <p>
  125.      * Call setBinding() to bind this component to a projection in a RelationView and
  126.      * auto-set the value.
  127.      *
  128.      * @param text the text to be displayed
  129.      *
  130.      * @see #setBinding
  131.      */
  132.     public TextArea(String text)
  133.     {
  134.         this(text, 0,0);
  135.     }
  136.  
  137.     /**
  138.      * Constructs a TextArea with the specified text and number of rows and columns.
  139.      * <p>
  140.      * Call setBinding() to bind this component to a projection in a RelationView and
  141.      * auto-set the value.
  142.      *
  143.      * @param text the text to be displayed
  144.      * @param rows the number of rows
  145.      * @param cols the number of columns
  146.      *
  147.      * @see #setBinding
  148.      */
  149.     public TextArea(String text, int rows, int cols)
  150.     {
  151.         super(text, rows, cols);
  152.         m_Helper = new ProjectionBeanHelper(this);
  153.         this.setTriggeringEvent(symantec.itools.db.awt.TextArea.Text_Event);
  154.     }
  155.  
  156.     /**
  157.      * Sets whether this component determines is user-editablity from the
  158.      * database it's bound with, or whether it will simple not be editable.
  159.      *
  160.      * @param value if true this component is editable if the database its bound
  161.      * with is writable, if false this component is not editable
  162.      */
  163.     public void setEditable(boolean value)
  164.     {
  165.         m_Helper.setBinderDeterminesReadOnly(value);
  166.         setReadOnly(!value);
  167.     }
  168.  
  169.     /**
  170.      * Binds this component to a given projection within the specified
  171.      * relation view.
  172.      *
  173.      * @param relView the relation view to bind with
  174.      * @param projection the projection in relView to bind with
  175.      */
  176.     public void setBinding(RelationView relView, String projection)
  177.     {
  178.         m_Helper.setBinding(relView, projection);
  179.     }
  180.  
  181.     /**
  182.      * Returns the projection in the RelationView that this component is bound with.
  183.      * @see #setBinding
  184.      * @see #setProjection
  185.      */
  186.     public String getProjection() {
  187.         return m_Helper.getProjection();
  188.     }
  189.  
  190.     /**
  191.      * Binds this component to the given projection within the RelationView
  192.      * the component is currently bound with.
  193.      * @see #setBinding
  194.      * @see #getProjection
  195.      * @see #getRelationView
  196.      */
  197.     public void setProjection(String projection) {
  198.         m_Helper.setProjection(projection);
  199.     }
  200.  
  201.     /**
  202.      * Gets the RelationView that this component is bound with.
  203.      * @return the RelationView currently bound with
  204.      * @see #setRelationView
  205.      * @see #setBinding
  206.      * @see #getProjection
  207.      */
  208.     public RelationView getRelationView() {
  209.         return m_Helper.getRelationView();
  210.     }
  211.  
  212.     /**
  213.      * Sets the RelationView that this component is bound with.
  214.      * @param rv the RelationView to bind with
  215.      * @see #getRelationView
  216.      * @see #setBinding
  217.      * @see #setProjection
  218.      */
  219.     public void setRelationView(RelationView rv) {
  220.         m_Helper.setRelationView(rv);
  221.     }
  222.  
  223.     /**
  224.      * Specifies how an empty string will be set when updating data on
  225.      * the dbANYWHERE server.
  226.      *
  227.      * @param blank one of "DEFAULT", "NULL", or "BLANK"
  228.      *
  229.      * @see symantec.itools.db.pro.ProjBinder#setValueFromString(java.lang.String, int, int)
  230.      */
  231.     public void setTreatBlankAs(String value) {
  232.         m_Helper.setTreatBlankAsString(value);
  233.     }
  234.  
  235.     /**
  236.      * Indicates when the component commits its changes.
  237.      * If <code>true</code>, this component has set the triggering event to
  238.      * Key_Event, otherwise the triggering event is set to Focus_Event.
  239.      * @see #setDynamicUpdate
  240.      * @see #Focus_Event
  241.      * @see #Key_Event
  242.      */
  243.      public boolean getDynamicUpdate() {
  244.        return m_DynamicUpdate;
  245.     }
  246.  
  247.     /**
  248.      * Sets when the component commits its changes.
  249.      * If <code>true</code>, this component sets the triggering event to
  250.      * Key_Event, otherwise the triggering event is set to Focus_Event.
  251.      * @param value the new dynamic update mode value
  252.      * @see #getDynamicUpdate
  253.      * @see #Focus_Event
  254.      * @see #Key_Event
  255.      */
  256.     public void setDynamicUpdate(boolean value)
  257.     {
  258.         if(value) {
  259.            setTriggeringEvent(Key_Event);
  260.         }
  261.         else {
  262.            setTriggeringEvent(Focus_Event);
  263.         }
  264.         m_DynamicUpdate = value;
  265.     }
  266.  
  267.     /**
  268.      * Sets whether the data value of this component may be modified.
  269.      * @param value <code>true</code> if the value may not be modified,
  270.      * <code>false</code>if the value may be modified
  271.      */
  272.     public void setReadOnly(boolean value) {
  273.         super.setEditable(!value);
  274.     }
  275.  
  276.     /**
  277.      * Sets the value of this component to the given value.
  278.      * @param value the new component value
  279.      * @see #getData
  280.      */
  281.     public void setData(Object value) {
  282.         setText(value.toString());
  283.     }
  284.  
  285.     /**
  286.      * Gets the value of this component.
  287.      * @return the current component value
  288.      * @see #setData
  289.      */
  290.     public Object getData() {
  291.         return getText();
  292.     }
  293.  
  294.     /**
  295.      * Gets whether this component saves its value as a text String.
  296.      * @return <code>true</code> if the value is saved as text,
  297.      * <code>false</code> otherwise
  298.      */
  299.     public boolean isTextBased() {
  300.         return true;
  301.     }
  302.  
  303.     /**
  304.      * Controls the behavior of the tab key.
  305.      * If <code>true</code>, pressing the tab key will move the input focus
  306.      * to the next component.
  307.      * Otherwise the focus will remain within this component.
  308.      * @param value the new tab control value
  309.      * @see #getTabControl
  310.      */
  311.     public void setTabControl(boolean value) {
  312.         tabControl = value;
  313.     }
  314.  
  315.     /**
  316.      * Gets the behavior of the tab key.
  317.      * If <code>true</code>, pressing the tab key will move the input focus
  318.      * to the next component.
  319.      * Otherwise the focus will remain within this component.
  320.      * @return the current tab control behavior
  321.      * @see #setTabControl
  322.      */
  323.     public boolean getTabControl() {
  324.         return tabControl;
  325.     }
  326.  
  327.     /**
  328.      * Gets the number of digits to the right of the decimal point for
  329.      * this component's value.
  330.      * @return the number of digits to the right of the decimal point
  331.      */
  332.     public int getScale() {
  333.         return ProjBinder.DEFAULTSCALE;
  334.     }
  335.  
  336.     /**
  337.      * Registers the standard event listener(s) for this component.
  338.      */
  339.     public void registerListeners() {
  340.         addKeyListener(m_Helper);
  341.     }
  342.     /**
  343.      * Sets the name of the data item to bind this component to.
  344.      * @param name the data item name, like "MyTable@MyColumn"
  345.      * @see #getDataBinding
  346.      */
  347.     public void setDataBinding(String name)
  348.     {
  349.         m_Helper.setDataBinding(new Name(name));
  350.     }
  351.  
  352.     /**
  353.      * Gets the name of the data item this component is bound to.
  354.      * @returns the data item name, like "MyTable@MyColumn"
  355.      * @see #setDataBinding
  356.      */
  357.     public String getDataBinding()
  358.     {
  359.         return  m_Helper.getDataBinding().getFullName();
  360.     }
  361.  
  362.     void removeAllListeners()
  363.     {
  364.         removeFocusListener(m_Helper);
  365.         removeTextListener(m_Helper);
  366.         removeKeyListener(m_Helper);
  367.     }
  368.  
  369.     /**
  370.      * Sets the value of the Triggering Event property.
  371.      * This determines the type of event that triggers the component to commit
  372.      * its changes to the database.
  373.      * @param event one of Focus_Event, Text_Event, or Key_Event
  374.      * @see #getTriggeringEvent
  375.      * @see #Focus_Event
  376.      * @see #Text_Event
  377.      * @see #Key_Event
  378.      */
  379.     public void setTriggeringEvent(int event)
  380.     {
  381.         m_TriggeringEvent = event;
  382.         removeAllListeners();
  383.  
  384.         switch(event){
  385.             case Focus_Event:
  386.                 addFocusListener(m_Helper);
  387.                 break;
  388.             case Text_Event:
  389.                 addTextListener(m_Helper);
  390.                 break;
  391.             case Key_Event:
  392.                 addKeyListener(m_Helper);
  393.                 break;
  394.             default:
  395.                 addFocusListener(m_Helper);
  396.         }
  397.     }
  398.  
  399.     /**
  400.      * Gets the current value of the Triggering Event property.
  401.      * This determines the type of event that triggers the component to commit
  402.      * its changes to the database.
  403.      * @return one of Focus_Event, Text_Event, or Key_Event
  404.      * @see #setTriggeringEvent
  405.      * @see #Focus_Event
  406.      * @see #Text_Event
  407.      * @see #Key_Event
  408.      */
  409.     public int getTriggeringEvent()
  410.     {
  411.         return m_TriggeringEvent;
  412.     }
  413.  
  414.      /**
  415.      * Sets the value of the Empty Means Null property.
  416.      * This determines how an empty string will be saved when updating data on
  417.      * the database server.
  418.      * A value of <code>true</code>indicates an empty string will be saved as a
  419.      * SQL NULL value. Otherwise it will be saved as a blank value.
  420.      * @param propertyValue <code>true</code> for NULL, <code>false</code> for BLANK
  421.      * @see #getEmptyMeansNull
  422.      */
  423.     public void setEmptyMeansNull(boolean propertyValue)
  424.     {
  425.         m_Helper.setEmptyMeansNull(propertyValue);
  426.     }
  427.  
  428.      /**
  429.      * Gets the value of the Empty Means Null property.
  430.      * This determines how an empty string will be saved when updating data on
  431.      * the database server.
  432.      * A value of <code>true</code>indicates an empty string will be saved as a
  433.      * SQL NULL value. Otherwise it will be saved as a blank value.
  434.      * @return <code>true</code> for NULL, <code>false</code> for BLANK
  435.      * @see #setEmptyMeansNull
  436.      */
  437.     public boolean getEmptyMeansNull()
  438.     {
  439.         return m_Helper.getEmptyMeansNull();
  440.     }
  441. }
  442.