home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 8.3 KB | 254 lines |
- /*
- *
- */
-
- package symantec.itools.db.awt;
-
- import java.applet.*;
- import symjava.sql.*;
- import symantec.itools.db.pro.*;
-
- public class Checkbox extends java.awt.Checkbox implements ProjLink {
-
- private ProjBinder m_ProjBinder;
-
- private String m_trueValue = new String("true");
- private String m_falseValue = new String("false");
- private int m_treatBlankAs = 0;
- private boolean m_DynamicUpdate = false;
- private boolean m_ignoreStateChange = true;
-
- /**
- * Constructs a Checkbox with the specified label, no Checkbox group, and
- * initialized to a false state.
- * @param label the label on the Checkbox
- */
- public Checkbox(String label) {
- super(label);
- }
-
- public Checkbox() {
- super();
- }
-
- public void init(ProjBinder binder) {
- m_ProjBinder = binder;
- setEditable(m_ProjBinder);
- }
-
- public void setTreatBlankAs(String blank)
- {
- if (new String(blank).toUpperCase().equals("DEFAULT"))
- {
- m_treatBlankAs = RelationView.SETBLANKTODEFAULT;
- }
- else if (new String(blank).toUpperCase().equals("NULL"))
- {
- m_treatBlankAs = RelationView.SETBLANKTONULL;
- }
- else if (new String(blank).toUpperCase().equals("BLANK"))
- {
- m_treatBlankAs = RelationView.SETBLANKTOEMPTY;
- }
- }
-
- public void setBinding(RelationView relView, String projection)
- {
- try
- {
- int projectionNumber = relView.findProjByName(projection);
- relView.bindProj(projectionNumber, this);
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from Checkbox.setBinding: "
- + Ex.getMessage());
- }
- }
-
- public void notifyDataChange(ProjBinder binder)
- {
- m_ignoreStateChange = true;
- try {
- if (m_trueValue.equals(binder.getStringValue()))
- {
- setState(true);
- }
- else
- {
- setState(false);
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from Checkbox.notifyDataChange: "
- + Ex.getMessage());
- }
- catch (java.io.IOException Ex)
- {
- raiseException(
- "IOException from Checkbox.notifyDataChange: "
- + Ex.getMessage());
- }
- }
-
- public boolean notifySetData(ProjBinder binder) throws SQLException
- {
- return ( notifyStateChange() );
- }
-
- boolean notifyStateChange()
- {
- if (!m_ignoreStateChange)
- {
- try
- {
- if (m_ProjBinder != null && m_ProjBinder.isWritable())
- {
- if (getState())
- {
- m_ProjBinder.setValueFromString(m_trueValue, 0, m_treatBlankAs);
- }
- else
- {
- m_ProjBinder.setValueFromString(m_falseValue, 0, m_treatBlankAs);
- }
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from Checkbox.notifyStateChange: "
- + Ex.getMessage());
- return false;
- }
- catch (java.io.IOException Ex)
- {
- raiseException(
- "IOException from Checkbox.notifyStateChange: "
- + Ex.getMessage());
- return false;
- }
- }
- return true;
- }
-
- /**
- * Handles the event. Returns true if the event is handled and
- * should not be passed to the parent of this component. The default
- * event handler calls some helper methods to make life easier
- * on the programmer.
- * @param evt the event
- * @see #mouseEnter
- * @see #mouseExit
- * @see #mouseMove
- * @see #mouseDown
- * @see #mouseDrag
- * @see #mouseUp
- * @see #keyDown
- * @see #action
- */
- public boolean handleEvent(java.awt.Event evt)
- {
- try
- {
- m_ignoreStateChange = false;
- notifySetData(m_ProjBinder);
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from Checkbox.handleEvent: "
- + Ex.getMessage());
- }
- return super.handleEvent(evt);
- }
-
- public void setTrueValue(String trueValue) {
- m_trueValue = new String(trueValue);
- notifyDataChange(m_ProjBinder);
- }
-
- public void setFalseValue(String falseValue) {
- m_falseValue = new String(falseValue);
- notifyDataChange(m_ProjBinder);
- }
-
- void setEditable(ProjBinder binder)
- {
- //Disable change of state if binder is not writeable
- disable();
- try
- {
- if (binder != null)
- {
- RelationView rv = binder.getRelationView();
- if (rv != null && (rv.getCurrentRecordState() != Record.RECSTATE_INVALID))
- {
- enable();
- }
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from Checkbox.setEditable: "
- + Ex.getMessage());
- }
- }
-
- // When the control gets focus, save a copy of the text.
- // When we lose focus, we use this copy to see if the data changed.
- /**
- * catch the got focus notification, save current data,
- * and pass along the event.
- *
- * @param evt the got focus event being caught
- * @param what the object that is getting focus
- */
- public boolean gotFocus(java.awt.Event evt, Object what)
- {
- return super.gotFocus(evt, what);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: raiseException //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- void raiseException(String text)
- {
- System.out.println(text);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setDynamicUpdate //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setDynamicUpdate(boolean update)
- {
- m_DynamicUpdate = update;
- }
- }
-