home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 13.0 KB | 446 lines |
- /*
- * @(#FormattedTExtField.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
- package symantec.itools.db.awt;
-
- import java.util.*;
- import java.sql.*;
- import java.lang.*;
- import symantec.itools.db.awt.FormattedTextField;
- import symantec.itools.db.net.*;
- import symantec.itools.db.pro.*;
- import java.awt.event.*;
- import symantec.itools.db.beans.binding.Name;
-
- /**
- * a dbAware FormattedTextField component.
- * <p>
- * Creates a box in which the user can type text. Text formatting logic is
- * applied to the user input.
- * If the text box already contains text, the user can select the default text
- * and delete or edit it.
- * <p>
- * It may be bound to a projection in a database. This allows it to automatically
- * get and set the related database information.
- */
- public class FormattedTextField extends symantec.itools.awt.FormattedTextField implements ProjectionBean
- {
- private String m_Mask = "";
- private int m_ROD = 0;
- private boolean m_isMaskSet = false;
- private ProjectionBeanHelper m_Helper;
- /**
- * The value of the Triggering Event property.
- * 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 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;
-
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is FOCUS_LOST.
- */
- public static final int Focus_Event=0;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is KEY_PRESSED.
- */
- public static final int Key_Event=1;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is TEXT_VALUE_CHANGED.
- */
- public static final int Text_Event=2;
-
-
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public final static int Default = 0;
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public final static int Null = 1;
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public final static int Blank = 2;
-
- /**
- * Constructs a new FormattedTextField. It can have 256 columns.
- */
- public FormattedTextField()
- {
- this("", 256);
- }
-
- /**
- * Constructs a new FormattedTextField with the specified number of columns.
- * @param cols the number of character columns
- */
- public FormattedTextField(int cols)
- {
- this("", cols);
- }
-
- /**
- * Constructs a new FormattedTextField containing the specified text.
- * It can have 256 columns.
- *
- * @param text the field text
- */
- public FormattedTextField(String text)
- {
- this(text, 256);
- }
-
- /**
- * Constructs a new FormattedTextField containing the specified text and
- * able to have the specified number of columns.
- *
- * @param text the field text
- * @param cols the number of character columns
- */
- public FormattedTextField(String text, int cols)
- {
- super(text, cols);
- m_Helper = new ProjectionBeanHelper(this);
- (this).addFocusListener(m_Helper);
- setTriggeringEvent(Focus_Event);
- }
-
- /**
- * Ensure that the Edit Mask takes affect immediately after the
- * component is added.
- */
- public void addNotify()
- {
- super.addNotify();
-
- // The mask was not getting used on the first painting
- // unless we reset the mast AFTER the addNofify()
- if (m_isMaskSet == true)
- {
- setMask(getMask());
- }
- }
-
- /**
- * Sets the valid string format mask for this field.
- * @see symantec.itools.awt.FormattedTextField#getMask
- */
- public void setMask(String mask)
- {
- synchronized (this) {
- super.setMask(mask);
- m_Mask = new String(mask);
- m_ROD = getROD(m_Mask);
- m_isMaskSet = true;
- }
- }
-
- /**
- * Contitionally sets this field to be user-editable.
- *
- * @param value true to make this field editable, false otherwise
- */
- public void setEditable(boolean value)
- {
- m_Helper.setBinderDeterminesReadOnly(value);
- setReadOnly(!value);
- }
-
- int getROD(String mask)
- {
- int iROD = 0;
- String sROD = new String();
- int decimalCount = -1;
-
- if (!mask.equals(""))
- {
- StringTokenizer st = new StringTokenizer(mask);
- while (st.hasMoreElements())
- {
- decimalCount++;
- sROD = st.nextToken(".");
- }
- if (decimalCount == 1)
- {
- iROD = sROD.length();
- }
- }
- return iROD;
- }
-
- /**
- * 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(int value) {
- m_Helper.setTreatBlankAs(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==true){
- this.setTriggeringEvent(Key_Event);
- }
- if(value==false){
- this.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) {
- String text = value.toString();
- setText(text);
- }
-
- /**
- * Gets the value of this component.
- * @return the current component value
- * @see #setData
- */
- public Object getData() {
- String data;
- data = getText();
-
- return data;
- }
-
- /**
- * 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;
- }
-
- /**
- * 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() {
- int scale = ProjBinder.DEFAULTSCALE;
- synchronized (this) {
- if (m_isMaskSet) {
- scale = getROD(m_Mask);
- }
- }
- return scale;
- }
-
- /**
- * Registers the standard event listener(s) for this component.
- */
- public void registerListeners() {
- }
- /**
- * 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()
- {
- this.removeFocusListener(m_Helper);
- this.removeActionListener(m_Helper);
- this.removeTextListener(m_Helper);
- this.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, Key_Event, or Text_Event
- * @see #getTriggeringEvent
- * @see #Focus_Event
- * @see #Key_Event
- * @see #Text_Event
- */
- public void setTriggeringEvent(int Event)
- {
- TriggeringEvent=Event;
- this.removeAllListeners();
- switch(Event){
- case Text_Event:
- (this).addTextListener(m_Helper);
- break;
- case Key_Event:
- (this).addKeyListener(m_Helper);
- break;
- case Focus_Event:
- default:
- (this).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, Key_Event, or Text_Event
- * @see #setTriggeringEvent
- * @see #Focus_Event
- * @see #Key_Event
- * @see #Text_Event
- */
- public int getTriggeringEvent()
- {
- return 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();
- }
- }
-