home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / ImageStringData.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  3.6 KB  |  150 lines

  1. /*
  2.  * ImageStringData.java   1.0   12 Jan 1997
  3.  *
  4.  * Copyright (c) 1996 Krumel & Associates, Inc.  All Rights Reserved.
  5.  *
  6.  * This software is provided as is.  Krumel & Associates shall not be liable
  7.  * for any damages suffered by licensee as a result of using, modifying or
  8.  * distributing this software or its derivatives.
  9.  */
  10.  
  11. package symantec.itools.db.awt;
  12.  
  13. import java.awt.Image;
  14.  
  15. public class ImageStringData implements Data {
  16.     StringBuffer        text;
  17.     Image               im;
  18.  
  19.     String              origText;
  20.     boolean             changed = false;
  21.     DataSource          dataSource;
  22.  
  23.     public ImageStringData(DataSource ds) {
  24.         this(ds, "", null);
  25.     }
  26.  
  27.     public ImageStringData(DataSource ds, String t) {
  28.         this(ds, t, null);
  29.     }
  30.  
  31.     public ImageStringData(DataSource ds, Image i) {
  32.         this(ds, null, i);
  33.     }
  34.  
  35.     public ImageStringData(DataSource ds, String t, Image i) {
  36.         dataSource = ds;
  37.         text = new StringBuffer(t);
  38.         origText = t;
  39.         im = i;
  40.     }
  41.  
  42.     public int type() {
  43.         if (text != null && im != null) {
  44.             return IMAGE_STRING;
  45.         } else if (im == null) {
  46.             return STRING;
  47.         }
  48.  
  49.         return IMAGE;
  50.     }
  51.  
  52.     public boolean isEditable(int row, int col) {
  53.         return dataSource.isDataEditable(row, col);
  54.     }
  55.  
  56.     public boolean changed() { return changed; }
  57.  
  58.     public void rollback() {
  59.         text.setLength(0);
  60.         text.append(origText);
  61.         changed = false;
  62.     }
  63.  
  64.     public void commit() throws TypeNotSupported {
  65.         if (changed) {
  66.             origText = text.toString();
  67.             changed = false;
  68.         }
  69.     }
  70.  
  71.     public boolean isMasked() {
  72.         return false;
  73.     }
  74.  
  75.     public String getMask() throws TypeNotSupported {
  76.         throw new TypeNotSupported("ImageStringData does not support choices");
  77.     }
  78.  
  79.     public boolean supportsChoice() { return false; }
  80.     public Data[] getChoices() throws TypeNotSupported {
  81.         throw new TypeNotSupported("ImageStringData does not support choices");
  82.     }
  83.  
  84.     public void setImage(Image i) {
  85.         changed = true;
  86.         im = i;
  87.     }
  88.  
  89.     public void setText(String t) {
  90.         text.setLength(0);
  91.         text.append(t);
  92. //        origText = t;
  93.         changed = true;
  94.     }
  95.  
  96.     public void setText(char c) {
  97.         text.setLength(0);
  98.         text.append(c);
  99.         changed = true;
  100.     }
  101.  
  102.     public void insertChar(int pos, char c) {
  103.         text.insert(pos, c);
  104.         changed = true;
  105.     }
  106.  
  107.     public void appendChar(char c) {
  108.         text.append(c);
  109.         changed = true;
  110.     }
  111.  
  112.     public String subString(int spos, int epos) {
  113.         return text.toString().substring(spos, epos);
  114.     }
  115.  
  116.     //pos is space after char to delete
  117.     public void deleteChar(int pos) {
  118.         //at beginning so do nothing
  119.         if (pos <= 0)
  120.             return;
  121.  
  122.         String t = text.toString();
  123.         text.setLength(0);
  124.         changed = true;
  125.  
  126.         if (pos >= t.length()) {
  127.             //pos at end so take off last char
  128.             text.append(t.substring(0, t.length()-1));
  129.         } else {
  130.             //take the char before the cursor
  131.             text.append(t.substring(0, pos-1));
  132.             text.append(t.substring(pos, t.length()));
  133.         }
  134.     }
  135.  
  136.     public void clearText() {
  137.         text.setLength(0);
  138.         changed = true;
  139.     }
  140.  
  141.     public String toString() {
  142.         return text.toString();
  143.     }
  144.  
  145.     public Image toImage() {
  146.         return im;
  147.     }
  148. }
  149.  
  150.