home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 7.5 KB | 245 lines |
- /*
- * Copyright (c) 1997 Krumel & Associates, Inc. All Rights Reserved.
- *
- * www.krumel.com - controls@krumel.com
- *
- * Permission is given to the buyer of this package for one software
- * developer to use this software on one CPU (one workstation) and to make
- * one backup copy. You may uitilize and/or modify this class for use in your
- * projects. You may distribute or sell any executable which results from
- * using this code in yur application, except a utility or class of similar
- * nature to this product. You may distribute this product in compiled
- * form only, but soley to be used with your cmpiled executable product
- * for the puposes of dynamic loading. You may NOT redistribute the source
- * code in any form or make it accessible through a network or other
- * distribution media to others. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * The source code is the confidential and proprietary information
- * of Krumel & Associates, Inc. ("Confidential Information"). You shall
- * not disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Krumel & Associates, Inc..
-
- * KRUMEL & ASSOCIATES MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
- * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
- * NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. KRUMEL & ASSOCIATES SHALL NOT
- * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
- * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- package symantec.itools.db.awt;
-
- import java.awt.Image;
-
- /**
- * This class serves as the workhorse for transferring data from a DataSource to a TableCell.
- * It provides support for transferring String and image information.
- */
- public class ImageStringData implements Data {
- StringBuffer text;
- Image im;
-
- String origText;
- boolean changed = false;
- DataSource dataSource;
-
- /**
- * Creates a Data element using the specified data source. The string data is set to
- * the emtpy string and the image is set to null.
- */
- public ImageStringData(DataSource ds) {
- this(ds, "", null);
- }
-
- /**
- * Creates a Data element using the specified data source. The string data is set to
- * the value passed as the parameter string and the image is set to null.
- */
- public ImageStringData(DataSource ds, String t) {
- this(ds, t, null);
- }
-
- /**
- * Creates a Data element using the specified data source. The string data is set to
- * the null and the image is set to specifeid paramter value.
- */
- public ImageStringData(DataSource ds, Image i) {
- this(ds, null, i);
- }
-
- /**
- * Creates a Data element using the specified data source. The string data and image
- * data are set to the specified values.
- */
- public ImageStringData(DataSource ds, String t, Image i) {
- dataSource = ds;
- text = new StringBuffer(t);
- origText = t;
- im = i;
- }
-
- /**
- * Gets the value of the type flag to indicate the type of information
- * held by the data object.
- * @return One of STRING, IMAGE, STRING_IMAGE as defined in the Data class.
- */
- public int type() {
- if (text != null && im != null) {
- return IMAGE_STRING;
- } else if (im == null) {
- return STRING;
- }
-
- return IMAGE;
- }
-
- /**
- * Gets whether the data can be modified.
- */
- public boolean isEditable(int row, int col) {
- return dataSource.isDataEditable(row, col);
- }
-
- /**
- * Gets whether the data has been changed since last committed.
- */
- public boolean changed() { return changed; }
-
- /**
- * Requests the value of the data be returned to the last save point.
- */
- public void rollback() {
- text.setLength(0);
- text.append(origText);
- changed = false;
- }
-
- /**
- * Commits the current data as the current value. This method is normally called
- * by the data source when a commit request was issued.
- * @exception TypeNotSupported if the data source does not support the type of
- * action requested or is not successful
- */
- public void commit() throws TypeNotSupported {
- if (changed) {
- origText = text.toString();
- changed = false;
- }
- }
-
- /**
- * Gets whether the data supports multiple predefined choice data.
- * @return Always return false.
- */
- public boolean supportsChoice() { return false; }
- /**
- * Gets an array of Data objects that define the predefined values associated
- * with a field. This method always throws a TypeNotSupported exception.
- * @exception TypeNotSupported since choices are not supported
- */
- public Data[] getChoices() throws TypeNotSupported {
- throw new TypeNotSupported("ImageStringData does not support choices");
- }
-
- /**
- * Sets a new image for the field.
- */
- public void setImage(Image i) {
- changed = true;
- im = i;
- }
-
- /**
- * Sets the string value for the data.
- */
- public void setText(String t) {
- text.setLength(0);
- text.append(t);
- // origText = t;
- changed = true;
- }
-
- /**
- * Sets the string value for the field using a character.
- */
- public void setText(char c) {
- text.setLength(0);
- text.append(c);
- changed = true;
- }
-
- /**
- * Inserts a character into the string data.
- * @param pos The position in the string to insert the character. Follows the
- * same rules as the StringBuffer class.
- * @param c The character to insert.
- */
- public void insertChar(int pos, char c) {
- text.insert(pos, c);
- changed = true;
- }
-
- /**
- * Appends a character to the end of the string data.
- */
- public void appendChar(char c) {
- text.append(c);
- changed = true;
- }
-
- /**
- * Gets a substring from the string data for the field.
- */
- public String subString(int spos, int epos) {
- return text.toString().substring(spos, epos);
- }
-
- //pos is space after char to delete
- /**
- * Removes a character from the string data for the field.
- */
- public void deleteChar(int pos) {
- //at beginning so do nothing
- if (pos <= 0)
- return;
-
- String t = text.toString();
- text.setLength(0);
- changed = true;
-
- if (pos >= t.length()) {
- //pos at end so take off last char
- text.append(t.substring(0, t.length()-1));
- } else {
- //take the char before the cursor
- text.append(t.substring(0, pos-1));
- text.append(t.substring(pos, t.length()));
- }
- }
-
- /**
- * Sets the string value to the empty string.
- */
- public void clearText() {
- text.setLength(0);
- changed = true;
- }
-
- /**
- * Gets the current string value for the field.
- */
- public String toString() {
- return text.toString();
- }
-
- /**
- * Gets teh current image value for the field.
- */
- public Image toImage() {
- return im;
- }
- }
-
-