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 / OutputEditor.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  3.0 KB  |  106 lines

  1. /*
  2.  * @(#OutputEditor.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8.  
  9. package symantec.itools.db.beans.binding;
  10.  
  11. /*
  12.     A basic extension of the java.awt.Dialog class
  13.  */
  14.  
  15. import java.awt.*;
  16. import java.beans.*;
  17. import java.util.*;
  18.  
  19. public class OutputEditor extends PropertyEditorSupport
  20. {
  21.  
  22.     public OutputEditor() {
  23.     }
  24.  
  25.     /**
  26.      * Set (or change) the object that is to be edited.
  27.      * @param value The new target object to be edited.  Note that this
  28.      *     object should not be modified by the PropertyEditor, rather
  29.      *     the PropertyEditor should create a new object to hold any
  30.      *     modified value.
  31.      */
  32.     public void setValue(Object value) {
  33.         name = "null";
  34.         if (value == null) {
  35.             name = "null";
  36.         }
  37.         else if (value instanceof String) {
  38.             name = (String)value;
  39.         }
  40.         else if (value instanceof Component) {
  41.             name = ((Component)value).getName();
  42.             object = value;
  43.         }
  44.         else if (value instanceof QueryNavigator) {
  45.             name = ((QueryNavigator)value).getName();
  46.             object = value;
  47.         }
  48.         firePropertyChange();
  49.     }
  50.  
  51.     /**
  52.      * @return The value of the property.
  53.      */
  54.  
  55.     public Object getValue() {
  56.         if (name.equals("null")) {
  57.             return null;
  58.         }
  59.         return object;
  60.     }
  61.  
  62.     //----------------------------------------------------------------------
  63.  
  64.     /**
  65.      * This method is intended for use when generating Java code to set
  66.      * the value of the property.  It should return a fragment of Java code
  67.      * that can be used to initialize a variable with the current property
  68.      * value.
  69.      * <p>
  70.      * Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
  71.      *
  72.      * @return A fragment of Java code representing an initializer for the
  73.      *       current value.
  74.      */
  75.     public String getJavaInitializationString() {
  76.         return name;
  77.     }
  78.  
  79.     //----------------------------------------------------------------------
  80.  
  81.     /**
  82.      * @return The property value as a string suitable for presentation
  83.      *       to a human to edit.
  84.      * <p>   Returns "null" is the value can't be expressed as a string.
  85.      * <p>   If a non-null value is returned, then the PropertyEditor should
  86.      *         be prepared to parse that string back in setAsText().
  87.      */
  88.     public String getAsText() {
  89.         return name;
  90.     }
  91.  
  92.     /**
  93.      * Set the property value by parsing a given String.  May raise
  94.      * java.lang.IllegalArgumentException if either the String is
  95.      * badly formatted or if this kind of property can't be expressed
  96.      * as text.
  97.      * @param text  The string to be parsed.
  98.      */
  99.     public void setAsText(String text) throws java.lang.IllegalArgumentException {
  100.         name = text;
  101.     }
  102.  
  103.     private String name = "null";
  104.     private Object object = null;
  105.  
  106. }