home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 15.3 KB | 493 lines |
- /*
- * @(#Checkbox.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
- package symantec.itools.db.awt;
-
- import java.applet.*;
- import java.awt.event.*;
- import symantec.itools.db.pro.*;
- import symantec.itools.db.beans.binding.Name;
- import symantec.itools.db.beans.binding.Mediator;
-
- /**
- * A dbAWARE Checkbox.
- * <p>
- * This component can be "bound" to a projection within a relation view
- * so that it automatically gets and sets the values in that relation.
- *
- */
- public class Checkbox extends java.awt.Checkbox implements ProjectionBean
- {
- private String m_trueValue = new String("");
- private String m_falseValue = new String("");
- 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 #Item_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
- * Item_Event, otherwise the triggering event is set to Focus_Event.
- * @see #getDynamicUpdate
- * @see #setDynamicUpdate
- * @see #Focus_Event
- * @see #Item_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 = ProjectionBeanHelper.Focus_Event;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is KEY_PRESSED.
- */
- public static final int Key_Event = ProjectionBeanHelper.Key_Event;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is ITEM_STATE_CHANGED.
- */
- public static final int Item_Event = ProjectionBeanHelper.Item_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;
-
- /**
- * The value of the Foreground color property.
- * @see java.awt.Component#getForeground
- * @see #setForeground
- */
- public java.awt.Color foreg=java.awt.Color.black;
- /**
- * Indicates whether the value of this component is of type Boolean.
- * @see #getData
- * @see #setData
- *
- public boolean hasReceivedABoolean=false;*/
- /**
- * <code>True</code> if the Checkbox value is neither true nor false.
- * This happens when <code>setData</code> is called with a value other
- * than those chosen to represent true or false.
- * @see #setData
- * @see #getData
- * @see #getTrueValue
- * @see #setTrueValue
- * @see #getFalseValue
- * @see #setFalseValue
- */
- protected boolean isNotDefined=false;
- /**
- * The current value of this component as a String.
- * @see #getData
- * @see #setData
- */
- public Object Text;
- /**
- * Constructs a Checkbox with the specified label.
- * It will have no Checkbox group, and be initialized to a false state.
- * @param label the label on the Checkbox
- */
- public Checkbox(String label) {
- super(label);
- m_Helper = new ProjectionBeanHelper(this);
- addFocusListener(m_Helper);
- setTriggeringEvent(Item_Event);
- }
-
- /**
- * Constructs a default Checkbox.
- * It will have no label, no Checkbox group, and be initialized to a false state.
- */
- public Checkbox() {
- this("");
- }
-
- /**
- * Sets the string sent to the database server to indicate that this
- * checkbox is checked.
- * @param trueValue the string used to indicate checked
- * @see #getTrueValue
- */
- public void setTrueValue(String trueValue) {
- m_trueValue = new String(trueValue);
- m_Helper.notifyDataChange();
- //m_Helper.m_Mediator.setBooleanTrueValue(m_trueValue);
- }
-
- /**
- * Gets the string sent to the database server to indicate that this
- * checkbox is checked.
- * @return the string used to indicate checked
- * @see #setTrueValue
- */
- public String getTrueValue() {
- return m_trueValue;
- }
-
- /**
- * Sets the string sent to the database server to indicate that this
- * checkbox is unchecked.
- * @param falseValue the string used to indicate unchecked
- * @see #getFalseValue
- */
- public void setFalseValue(String falseValue) {
- m_falseValue = new String(falseValue);
- m_Helper.notifyDataChange();
- // m_Helper.m_Mediator.setBooleanFalseValue(m_falseValue);
- }
-
- /**
- * Gets the string sent to the database server to indicate that this
- * checkbox is unchecked.
- * @return the string used to indicate unchecked
- * @see #setFalseValue
- */
- public String getFalseValue() {
- return m_falseValue;
- }
-
- /**
- * Binds this component to a given projection within the specified
- * RelationView.
- *
- * @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 value the RelationView to bind with
- * @see #getRelationView
- * @see #setBinding
- * @see #setProjection
- */
- public void setRelationView(RelationView value) {
- m_Helper.setRelationView(value);
- }
-
- /**
- * Specifies how an empty string will be set when updating data on
- * the database server.
- *
- * @param value 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
- * Item_Event, otherwise the triggering event is set to Focus_Event.
- * @see #setDynamicUpdate
- * @see #Focus_Event
- * @see #Item_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
- * Item_Event, otherwise the triggering event is set to Focus_Event.
- * @param value the new dynamic update mode value
- * @see #getDynamicUpdate
- * @see #Focus_Event
- * @see #Item_Event
- */
- public void setDynamicUpdate(boolean value)
- {
- if(value){
- setTriggeringEvent(Item_Event);
- }
- else {
- setTriggeringEvent(Focus_Event);
- }
- m_DynamicUpdate = value;
- }
- /**
- * Sets the value of the Foreground color property.
- * @see java.awt.Component#getForeground
- */
- public void setForeground(java.awt.Color c)
- {
- foreg=c;
- if(!isNotDefined)super.setForeground(c);
- }
-
- /**
- * 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) {
- }
-
- /**
- * Sets the value of this component to the given state.
- * @param b <code>true</code> if the Checkbox is checked
- * @see #setData
- */
- public void setState(boolean b)
- {
- if(b)Text=m_trueValue;
- else Text=m_falseValue;
- super.setState(b);
- }
-
- /**
- * Sets the value of this component to the given value.
- * If the value parameter is of class Boolean, its value is used to
- * set this component's value directly. Otherwise the parameter's
- * <code>toString</code> method is called and this component's value
- * is set according to whether the string matches that of the
- * True Value, or False Value property.
- *
- * @param value the new component value
- * @see #getData
- * @see #setState
- * @see #setTrueValue
- * @see #setFalseValue
- */
- public void setData(Object value) {
- if(value != null && value instanceof Boolean)
- {
- setState(((Boolean)value).booleanValue());
- return;
- }
- else if(value != null)
- {
- if (value != null) {
- Text = value.toString();
- }
- else {
- Text = null;
- setState(false);
- super.setForeground(java.awt.Color.gray);
- return;
- }
-
- if(Text.equals(m_trueValue)||(!Text.equals(m_falseValue)&&m_trueValue.equals(""))){
- Text=m_trueValue;
- super.setForeground(foreg);
- setState(true);}
-
- else if(Text.equals(m_falseValue)||m_falseValue.equals("")){
- Text=m_falseValue;
- super.setForeground(foreg);
- setState(false);
- }
- else {
- setState(false);
- isNotDefined=true;
- super.setForeground(java.awt.Color.gray);
- }
- }
- }
-
- /**
- * Gets the value of this component.
- * If this component's value was set with a Boolean, this method
- * returns a Boolean. Otherwise it returns the current value
- * as a String.
- * @return the current component value
- * @see #setData
- * @see #getTrueValue
- * @see #getFalseValue
- */
- public Object getData() {
- if(m_trueValue.equals("") && m_falseValue.equals(""))
- {
- return new Boolean(getState());
- }
- super.setForeground(foreg);
- return Text;
- }
-
- /**
- * 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() {
- return ProjBinder.DEFAULTSCALE;
- }
-
- /**
- * Registers the standard event listener(s) for this component.
- */
- public void registerListeners() {
- addItemListener(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);
- removeKeyListener(m_Helper);
- removeItemListener(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 Item_Event
- * @see #getTriggeringEvent
- * @see #Focus_Event
- * @see #Key_Event
- * @see #Item_Event
- */
- public void setTriggeringEvent(int event)
- {
- m_TriggeringEvent = event;
-
- removeAllListeners();
- switch(event) {
- case Focus_Event:
- addFocusListener(m_Helper);
- break;
- case Item_Event:
- addItemListener(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, Key_Event, or Item_Event
- * @see #setTriggeringEvent
- * @see #Focus_Event
- * @see #Key_Event
- * @see #Item_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();
- }
- }
-