home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 3.6 KB | 150 lines |
- /*
- * ImageStringData.java 1.0 12 Jan 1997
- *
- * Copyright (c) 1996 Krumel & Associates, Inc. All Rights Reserved.
- *
- * This software is provided as is. 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;
-
- public class ImageStringData implements Data {
- StringBuffer text;
- Image im;
-
- String origText;
- boolean changed = false;
- DataSource dataSource;
-
- public ImageStringData(DataSource ds) {
- this(ds, "", null);
- }
-
- public ImageStringData(DataSource ds, String t) {
- this(ds, t, null);
- }
-
- public ImageStringData(DataSource ds, Image i) {
- this(ds, null, i);
- }
-
- public ImageStringData(DataSource ds, String t, Image i) {
- dataSource = ds;
- text = new StringBuffer(t);
- origText = t;
- im = i;
- }
-
- public int type() {
- if (text != null && im != null) {
- return IMAGE_STRING;
- } else if (im == null) {
- return STRING;
- }
-
- return IMAGE;
- }
-
- public boolean isEditable(int row, int col) {
- return dataSource.isDataEditable(row, col);
- }
-
- public boolean changed() { return changed; }
-
- public void rollback() {
- text.setLength(0);
- text.append(origText);
- changed = false;
- }
-
- public void commit() throws TypeNotSupported {
- if (changed) {
- origText = text.toString();
- changed = false;
- }
- }
-
- public boolean isMasked() {
- return false;
- }
-
- public String getMask() throws TypeNotSupported {
- throw new TypeNotSupported("ImageStringData does not support choices");
- }
-
- public boolean supportsChoice() { return false; }
- public Data[] getChoices() throws TypeNotSupported {
- throw new TypeNotSupported("ImageStringData does not support choices");
- }
-
- public void setImage(Image i) {
- changed = true;
- im = i;
- }
-
- public void setText(String t) {
- text.setLength(0);
- text.append(t);
- // origText = t;
- changed = true;
- }
-
- public void setText(char c) {
- text.setLength(0);
- text.append(c);
- changed = true;
- }
-
- public void insertChar(int pos, char c) {
- text.insert(pos, c);
- changed = true;
- }
-
- public void appendChar(char c) {
- text.append(c);
- changed = true;
- }
-
- public String subString(int spos, int epos) {
- return text.toString().substring(spos, epos);
- }
-
- //pos is space after char to delete
- 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()));
- }
- }
-
- public void clearText() {
- text.setLength(0);
- changed = true;
- }
-
- public String toString() {
- return text.toString();
- }
-
- public Image toImage() {
- return im;
- }
- }
-
-