home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 13.2 KB | 442 lines |
- /*
- * @(#TextArea.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
-
- package symantec.itools.db.awt;
-
- // import java.awt.*;
- import java.util.*;
- import java.sql.*;
- import java.lang.*;
- import symantec.itools.db.net.*;
- import symantec.itools.db.pro.*;
- import java.awt.event.*;
- import symantec.itools.db.beans.binding.Name;
-
- /**
- * A dbAWARE TextArea component.
- * <p>
- * This component is similar to the basic TextArea component, but can
- * be "bound" to a projection within a relation view
- * so that it automatically gets and sets the values in that relation.
- * <p>
- *
- * @see java.awt.TextArea
- */
- public class TextArea extends java.awt.TextArea implements ProjectionBean
- {
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is FOCUS_LOST.
- */
- public static final int Focus_Event = ProjectionBeanHelper.Focus_Event;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is TEXT_VALUE_CHANGED.
- */
- public static final int Text_Event = ProjectionBeanHelper.Text_Event;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is KEY_PRESSED.
- */
- public static final int Key_Event = ProjectionBeanHelper.Key_Event;
-
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public static final String Default = ProjectionBeanHelper.DEFAULT;
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public static final String Blank = ProjectionBeanHelper.BLANK;
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public static final String Null = ProjectionBeanHelper.NULL;
-
- private ProjectionBeanHelper m_Helper;
- /**
- * The type of event that triggers this component to commit its changes.
- * @see #getTriggeringEvent
- * @see #setTriggeringEvent
- * @see #Focus_Event
- * @see #Key_Event
- * @see #Text_Event
- */
- protected int m_TriggeringEvent = Focus_Event;
- /**
- * Controls when the component commits its changes.
- * If <code>true</code>, this component sets the triggering event to
- * Key_Event, otherwise the triggering event is set to Focus_Event.
- * @see #getDynamicUpdate
- * @see #setDynamicUpdate
- * @see #Focus_Event
- * @see #Key_Event
- */
- protected boolean m_DynamicUpdate = false;
-
-
- /**
- * Controls the behavior of the tab key.
- * If <code>true</code>, pressing the tab key will move the input focus
- * to the next component.
- * Otherwise the focus will remain within this component.
- * @see #getTabControl
- * @see #setTabControl
- */
- private boolean tabControl=false;
-
- /**
- * Constructs a default TextArea.
- * <p>
- * Call setBinding() to bind this component to a projection in a RelationView and
- * auto-set the value.
- *
- * @see #setBinding
- */
- public TextArea()
- {
- this("");
- }
-
- /**
- * Constructs a TextArea with the specified number of rows and columns.
- * <p>
- * Call setBinding() to bind this component to a projection in a RelationView and
- * auto-set the value.
- *
- * @param rows the number of rows
- * @param cols the number of columns
- *
- * @see #setBinding
- */
- public TextArea(int rows, int cols)
- {
- this("", rows, cols);
- }
-
- /**
- * Constructs a TextArea with the specified initial value.
- * <p>
- * Call setBinding() to bind this component to a projection in a RelationView and
- * auto-set the value.
- *
- * @param text the text to be displayed
- *
- * @see #setBinding
- */
- public TextArea(String text)
- {
- this(text, 0,0);
- }
-
- /**
- * Constructs a TextArea with the specified text and number of rows and columns.
- * <p>
- * Call setBinding() to bind this component to a projection in a RelationView and
- * auto-set the value.
- *
- * @param text the text to be displayed
- * @param rows the number of rows
- * @param cols the number of columns
- *
- * @see #setBinding
- */
- public TextArea(String text, int rows, int cols)
- {
- super(text, rows, cols);
- m_Helper = new ProjectionBeanHelper(this);
- this.setTriggeringEvent(symantec.itools.db.awt.TextArea.Text_Event);
- }
-
- /**
- * Sets whether this component determines is user-editablity from the
- * database it's bound with, or whether it will simple not be editable.
- *
- * @param value if true this component is editable if the database its bound
- * with is writable, if false this component is not editable
- */
- public void setEditable(boolean value)
- {
- m_Helper.setBinderDeterminesReadOnly(value);
- setReadOnly(!value);
- }
-
- /**
- * Binds this component to a given projection within the specified
- * relation view.
- *
- * @param relView the relation view to bind with
- * @param projection the projection in relView to bind with
- */
- public void setBinding(RelationView relView, String projection)
- {
- m_Helper.setBinding(relView, projection);
- }
-
- /**
- * Returns the projection in the RelationView that this component is bound with.
- * @see #setBinding
- * @see #setProjection
- */
- public String getProjection() {
- return m_Helper.getProjection();
- }
-
- /**
- * Binds this component to the given projection within the RelationView
- * the component is currently bound with.
- * @see #setBinding
- * @see #getProjection
- * @see #getRelationView
- */
- public void setProjection(String projection) {
- m_Helper.setProjection(projection);
- }
-
- /**
- * Gets the RelationView that this component is bound with.
- * @return the RelationView currently bound with
- * @see #setRelationView
- * @see #setBinding
- * @see #getProjection
- */
- public RelationView getRelationView() {
- return m_Helper.getRelationView();
- }
-
- /**
- * Sets the RelationView that this component is bound with.
- * @param rv the RelationView to bind with
- * @see #getRelationView
- * @see #setBinding
- * @see #setProjection
- */
- public void setRelationView(RelationView rv) {
- m_Helper.setRelationView(rv);
- }
-
- /**
- * Specifies how an empty string will be set when updating data on
- * the dbANYWHERE server.
- *
- * @param blank one of "DEFAULT", "NULL", or "BLANK"
- *
- * @see symantec.itools.db.pro.ProjBinder#setValueFromString(java.lang.String, int, int)
- */
- public void setTreatBlankAs(String value) {
- m_Helper.setTreatBlankAsString(value);
- }
-
- /**
- * Indicates when the component commits its changes.
- * If <code>true</code>, this component has set the triggering event to
- * Key_Event, otherwise the triggering event is set to Focus_Event.
- * @see #setDynamicUpdate
- * @see #Focus_Event
- * @see #Key_Event
- */
- public boolean getDynamicUpdate() {
- return m_DynamicUpdate;
- }
-
- /**
- * Sets when the component commits its changes.
- * If <code>true</code>, this component sets the triggering event to
- * Key_Event, otherwise the triggering event is set to Focus_Event.
- * @param value the new dynamic update mode value
- * @see #getDynamicUpdate
- * @see #Focus_Event
- * @see #Key_Event
- */
- public void setDynamicUpdate(boolean value)
- {
- if(value) {
- setTriggeringEvent(Key_Event);
- }
- else {
- setTriggeringEvent(Focus_Event);
- }
- m_DynamicUpdate = value;
- }
-
- /**
- * Sets whether the data value of this component may be modified.
- * @param value <code>true</code> if the value may not be modified,
- * <code>false</code>if the value may be modified
- */
- public void setReadOnly(boolean value) {
- super.setEditable(!value);
- }
-
- /**
- * Sets the value of this component to the given value.
- * @param value the new component value
- * @see #getData
- */
- public void setData(Object value) {
- setText(value.toString());
- }
-
- /**
- * Gets the value of this component.
- * @return the current component value
- * @see #setData
- */
- public Object getData() {
- return getText();
- }
-
- /**
- * Gets whether this component saves its value as a text String.
- * @return <code>true</code> if the value is saved as text,
- * <code>false</code> otherwise
- */
- public boolean isTextBased() {
- return true;
- }
-
- /**
- * Controls the behavior of the tab key.
- * If <code>true</code>, pressing the tab key will move the input focus
- * to the next component.
- * Otherwise the focus will remain within this component.
- * @param value the new tab control value
- * @see #getTabControl
- */
- public void setTabControl(boolean value) {
- tabControl = value;
- }
-
- /**
- * Gets the behavior of the tab key.
- * If <code>true</code>, pressing the tab key will move the input focus
- * to the next component.
- * Otherwise the focus will remain within this component.
- * @return the current tab control behavior
- * @see #setTabControl
- */
- public boolean getTabControl() {
- return tabControl;
- }
-
- /**
- * Gets the number of digits to the right of the decimal point for
- * this component's value.
- * @return the number of digits to the right of the decimal point
- */
- public int getScale() {
- return ProjBinder.DEFAULTSCALE;
- }
-
- /**
- * Registers the standard event listener(s) for this component.
- */
- public void registerListeners() {
- addKeyListener(m_Helper);
- }
- /**
- * Sets the name of the data item to bind this component to.
- * @param name the data item name, like "MyTable@MyColumn"
- * @see #getDataBinding
- */
- public void setDataBinding(String name)
- {
- m_Helper.setDataBinding(new Name(name));
- }
-
- /**
- * Gets the name of the data item this component is bound to.
- * @returns the data item name, like "MyTable@MyColumn"
- * @see #setDataBinding
- */
- public String getDataBinding()
- {
- return m_Helper.getDataBinding().getFullName();
- }
-
- void removeAllListeners()
- {
- removeFocusListener(m_Helper);
- removeTextListener(m_Helper);
- removeKeyListener(m_Helper);
- }
-
- /**
- * Sets the value of the Triggering Event property.
- * This determines the type of event that triggers the component to commit
- * its changes to the database.
- * @param event one of Focus_Event, Text_Event, or Key_Event
- * @see #getTriggeringEvent
- * @see #Focus_Event
- * @see #Text_Event
- * @see #Key_Event
- */
- public void setTriggeringEvent(int event)
- {
- m_TriggeringEvent = event;
- removeAllListeners();
-
- switch(event){
- case Focus_Event:
- addFocusListener(m_Helper);
- break;
- case Text_Event:
- addTextListener(m_Helper);
- break;
- case Key_Event:
- addKeyListener(m_Helper);
- break;
- default:
- addFocusListener(m_Helper);
- }
- }
-
- /**
- * Gets the current value of the Triggering Event property.
- * This determines the type of event that triggers the component to commit
- * its changes to the database.
- * @return one of Focus_Event, Text_Event, or Key_Event
- * @see #setTriggeringEvent
- * @see #Focus_Event
- * @see #Text_Event
- * @see #Key_Event
- */
- public int getTriggeringEvent()
- {
- return m_TriggeringEvent;
- }
-
- /**
- * Sets the value of the Empty Means Null property.
- * This determines how an empty string will be saved when updating data on
- * the database server.
- * A value of <code>true</code>indicates an empty string will be saved as a
- * SQL NULL value. Otherwise it will be saved as a blank value.
- * @param propertyValue <code>true</code> for NULL, <code>false</code> for BLANK
- * @see #getEmptyMeansNull
- */
- public void setEmptyMeansNull(boolean propertyValue)
- {
- m_Helper.setEmptyMeansNull(propertyValue);
- }
-
- /**
- * Gets the value of the Empty Means Null property.
- * This determines how an empty string will be saved when updating data on
- * the database server.
- * A value of <code>true</code>indicates an empty string will be saved as a
- * SQL NULL value. Otherwise it will be saved as a blank value.
- * @return <code>true</code> for NULL, <code>false</code> for BLANK
- * @see #setEmptyMeansNull
- */
- public boolean getEmptyMeansNull()
- {
- return m_Helper.getEmptyMeansNull();
- }
- }
-