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 / DefaultData.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  6.1 KB  |  195 lines

  1. /*
  2.  * Copyright (c) 1997 Krumel & Associates, Inc. All Rights Reserved.
  3.  *
  4.  * www.krumel.com - controls@krumel.com
  5.  *
  6.  * Permission is given to the buyer of this package for one software
  7.  * developer to use this software on one CPU (one workstation) and to make
  8.  * one backup copy.  You may uitilize and/or modify this class for use in your
  9.  * projects.  You may distribute or sell any executable which results from
  10.  * using this code in yur application, except a utility or class of similar
  11.  * nature to this product.  You may distribute this product in compiled
  12.  * form only, but soley to be used with your cmpiled executable product
  13.  * for the puposes of dynamic loading. You may NOT redistribute the source
  14.  * code in any form or make it accessible through a network or other
  15.  * distribution media to others. Please refer to the file "copyright.html"
  16.  * for further important copyright and licensing information.
  17.  *
  18.  * The source code is the confidential and proprietary information
  19.  * of Krumel & Associates, Inc. ("Confidential Information").  You shall
  20.  * not disclose such Confidential Information and shall use it only in
  21.  * accordance with the terms of the license agreement you entered into
  22.  * with Krumel & Associates, Inc..
  23.  
  24.  * KRUMEL & ASSOCIATES MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
  25.  * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
  26.  * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  27.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. KRUMEL & ASSOCIATES SHALL NOT
  28.  * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
  29.  * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  30.  */
  31.  
  32. package symantec.itools.db.awt;
  33.  
  34.  
  35. /**
  36.  * This class is designed to work with the DefaultDataSource, but with care should be
  37.  * usable by other DataSource classes.<p>
  38.  * CAUTION - CAUTION - CAUTION
  39.  * A TableCell should never hold onto this object (or any other Data object) for more
  40.  * than one invocation because a DataSource will usually reuse this object.
  41.  */
  42. public class DefaultData implements Data {
  43.     int         row;
  44.     int         col;
  45.     DataSource  dataSource;
  46.  
  47.     /**
  48.      * Constructs a DefaultData object that uses the specified data source.
  49.      * @param ds the data source to use
  50.      */
  51.     public DefaultData(DataSource ds) {
  52.         dataSource = ds;
  53.     }
  54.  
  55.     /**
  56.      * Sets the coordinates of this datum.
  57.      * @param the row index
  58.      * @param the column index
  59.      */
  60.     public void setRowAndCol(int r, int c) {
  61.         row = r;
  62.         col = c;
  63.     }
  64.  
  65.     /**
  66.      * Gets the value of the type flag to indicate the type of information
  67.      * held by the data object.
  68.      */
  69.     public int type() {
  70.         return dataSource.type(row, col);
  71.     }
  72.  
  73.     /**
  74.      * Gets whether the data can be modified.
  75.      */
  76.     public boolean isEditable(int row, int col) {
  77.         return dataSource.isDataEditable(row, col);
  78.     }
  79.  
  80.     /**
  81.      * Gets whether the data has been changed since last committed.
  82.      * <p>
  83.      * In this implementation, false is always returned.
  84.      */
  85.     public boolean changed() { return false; }
  86.  
  87.     /**
  88.      * Requests the value of the data be returned to the last save point.
  89.      * <p>
  90.      * In this implementation, no action is taken.
  91.      */
  92.     public void rollback() {}
  93.  
  94.     /**
  95.      * Commits the current data as the current value. This method is normally called
  96.      * by the data source when a commit request was issued.
  97.      * <p>
  98.      * In this implementation, no action is taken.
  99.      */
  100.     public void commit() {}
  101.  
  102.     /**
  103.      * Gets whether the data supports multiple predefined choice data.
  104.      */
  105.     public boolean supportsChoice() {
  106.         return dataSource.supportsChoice(row, col);
  107.     }
  108.  
  109.     /**
  110.      * Gets an array of Data objects that define the predefined values associated
  111.      * with a field.
  112.      * @exception TypeNotSupported if the data source does not support the type of
  113.      *          action requested or is not successful
  114.      */
  115.     public Data[] getChoices() throws TypeNotSupported {
  116.         return dataSource.getChoices(row, col);
  117.     }
  118.  
  119.     /**
  120.      * Sets the string value for the data.
  121.      */
  122.     public void setText(String t) {
  123.         dataSource.setText(row, col, t);
  124.     }
  125.  
  126.     //pos is space where to be inserted (0 = first char)
  127.     /**
  128.      * Inserts a character into the string data.
  129.      * @param pos the position in the string to insert the character. Follows the
  130.      *      same rules as the StringBuffer class.
  131.      * @param c The character to insert.
  132.      */
  133.     public void insertChar(int pos, char c) {
  134.         //this will most likely throw a STringIndexOUtOfBoundsException
  135.         dataSource.insertChar(row, col, pos, c);
  136.     }
  137.  
  138.     /**
  139.      * Sets the string value for the field using a character.
  140.      */
  141.     public void setText(char c) {
  142.         setText(String.valueOf(c));
  143.     }
  144.  
  145.     /**
  146.      * Appends a character to the end of the string data.
  147.      */
  148.     public void appendChar(char c) {
  149.         dataSource.appendChar(row, col, c);
  150.     }
  151.  
  152.     /**
  153.      * Sets the string value to the empty string.
  154.      */
  155.     public void clearText() {
  156.         dataSource.clearText(row, col);
  157.     }
  158.  
  159.     /**
  160.      * Removes a character from the string data for the field.
  161.      */
  162.     public void deleteChar(int pos) {
  163.         //this will most likely throw a STringIndexOUtOfBoundsException
  164.         dataSource.deleteChar(row, col, pos);
  165.     }
  166.  
  167.     /**
  168.      * Gets a substring from the string data for the field.
  169.      */
  170.     public String subString(int spos, int epos) {
  171.         return dataSource.subString(row, col, spos, epos);
  172.     }
  173.  
  174.     /**
  175.      * Sets a new image for the field.
  176.      */
  177.     public void setImage(java.awt.Image i) {
  178.         dataSource.setImage(row, col, i);
  179.     }
  180.  
  181.     /**
  182.      * Gets the current string value for the field.
  183.      */
  184.     public String toString() {
  185.         return dataSource.toString(row, col);
  186.     }
  187.  
  188.     /**
  189.      * Gets teh current image value for the field.
  190.      */
  191.     public java.awt.Image toImage() {
  192.         return dataSource.toImage(row, col);
  193.     }
  194. }
  195.