Class sunsoft.jws.visual.rt.type.Converter
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sunsoft.jws.visual.rt.type.Converter

java.lang.Object
   |
   +----sunsoft.jws.visual.rt.type.Converter

public class Converter
extends Object
Base class for all converters. Converts a type of object to a string and back again.

Variable Index

 o converterType
The name of the type being edited.

Constructor Index

 o Converter()

Method Index

 o addConverter(String, String)
Adds a new type converter to the global table of converters.
 o addTypeEditor(String, String)
Registers a type editor for a type.
 o convertFromString(String)
Returns a new instance of the type this converter converts, as specified by the string given.
 o convertToCode(Object)
Converts an instance of the type converted into a line of code.
 o convertToCodeBlock(String, Attribute, int, StringBuffer)
Converts an instance of the type into a block of code.
 o convertToString(Object)
Returns the string representation for an instance of the type this converter converts.
 o convertToString(Object, StringBuffer)
Places a string representation of an instance of the type this converter converts into a string buffer.
 o decrIndent()
Decrements the indent level.
 o displayString(Object)
Returns the string that should be displayed in the attribute editor.
 o editableAsString()
Returns true if this type is simple enough to be edited as a string in an editor.
 o getConverter(String)
Returns an existing converter for the given type.
 o getConverterType()
Returns the type of object converted by this converter.
 o hasConverter(String)
Returns true if there is a converter for the given type.
 o hasTypeEditor()
Returns whether a converter instance has an associated type editor.
 o hasTypeEditor(String)
Returns true if there is an editor for the given type.
 o incrIndent()
Increments the indent level.
 o indent(StringBuffer)
Appends spaces to "buf" based on the current indent level.
 o indent(StringBuffer, int)
Appends spaces to "buf" based on the given indent level.
 o indentLevel()
Returns the current indent level.
 o newline()
Returns a string that can be used as a newline.
 o newline(StringBuffer)
Appends a newline to buf.
 o newTypeEditor()
Returns a new instance of the type editor associated with this converter.
 o newTypeEditor(String)
Returns a new instance of a type editor.
 o setConverterType(String)
An interface that can be overridden in sub-classes to whom the type converted is important.
 o shortClassName(String)
Returns the last token in a class name.
 o viewableAsString()
Returns true if this type should be displayed in an editor.

Variables

 o converterType
  protected String converterType
The name of the type being edited.

Constructors

 o Converter
  public Converter()

Methods

 o addConverter
  public static void addConverter(String typeName,
                                  String converterClassName)
Adds a new type converter to the global table of converters. A converter must be listed for this table in order for the search for a converter for that particular type to be successful.
Parameters:
typeName - the name of the type (what is returned by a call to getClass().getType() for an instance of that type)
converterClassName - the full name of the converter class
 o getConverter
  public static Converter getConverter(String typeName)
Returns an existing converter for the given type. Creates a new converter only if necessary (typically the first time one is asked for.)
 o hasConverter
  public static boolean hasConverter(String typeName)
Returns true if there is a converter for the given type.
 o addTypeEditor
  public static void addTypeEditor(String typeName,
                                   String editorClassName)
Registers a type editor for a type. At run-time (in generated applications) there will typically be no editors, but they are needed for the attribute editor in the designer. The designer will set up all the standard ones.
See Also:
TypeEditor
 o hasTypeEditor
  public static boolean hasTypeEditor(String typeName)
Returns true if there is an editor for the given type.
See Also:
TypeEditor
 o newTypeEditor
  public static TypeEditor newTypeEditor(String typeName)
Returns a new instance of a type editor. The caller (typically the Designer) gets a new one of these every time, one for each attribute being edited, even if they are the same type. Caching instances of these type editors is up to the caller.
 o hasTypeEditor
  public boolean hasTypeEditor()
Returns whether a converter instance has an associated type editor.
See Also:
TypeEditor
 o newTypeEditor
  public TypeEditor newTypeEditor()
Returns a new instance of the type editor associated with this converter.
 o setConverterType
  protected void setConverterType(String type)
An interface that can be overridden in sub-classes to whom the type converted is important.
See Also:
BaseEnumConverter
 o getConverterType
  public String getConverterType()
Returns the type of object converted by this converter.
 o convertToString
  public String convertToString(Object obj)
Returns the string representation for an instance of the type this converter converts. Must be declared in subclasses to convert an object of the type specific to that subclass of Converter.

One of the two "convertToString" methods must be overridden in the converter sub-class. The overridden "convertToString" method should NOT call "super.convertToString". It is preferrable to override the StringBuffer version (the other one) because this will result in better performance.

 o convertToString
  public void convertToString(Object obj,
                              StringBuffer buf)
Places a string representation of an instance of the type this converter converts into a string buffer.
 o convertFromString
  public abstract Object convertFromString(String s)
Returns a new instance of the type this converter converts, as specified by the string given. Must be declared in subclasses of Converter to convert a string representation into an object of the type converted by the subclass.
 o convertToCodeBlock
  public void convertToCodeBlock(String amName,
                                 Attribute a,
                                 int indent,
                                 StringBuffer buf)
Converts an instance of the type into a block of code.
 o convertToCode
  public String convertToCode(Object obj)
Converts an instance of the type converted into a line of code. This method provides a default way for any type to get a convertToCode method into it. It generates code that will feed the string representation of the object into the appropriate type converter. The performance isn't as good as customized convertToCode functions in subclasses since more classes have to be loaded at runtime.
 o displayString
  public String displayString(Object obj)
Returns the string that should be displayed in the attribute editor. Subclassers that want something displayed other than what is returned from convertToString should override this method to return that.
 o viewableAsString
  public boolean viewableAsString()
Returns true if this type should be displayed in an editor. For the attribute editor, a return value of false means that the the textfield will be hidden.
Returns:
true
 o editableAsString
  public boolean editableAsString()
Returns true if this type is simple enough to be edited as a string in an editor. Sub-classers that represent type too complex for this should override this function to return false. For the attribute editor, this means that the textfield will be read-only.
Returns:
same as viewableAsString
See Also:
viewableAsString
 o newline
  public static String newline()
Returns a string that can be used as a newline. This string includes a carriage return if we are running on Windows.
 o newline
  public static void newline(StringBuffer buf)
Appends a newline to buf. This also appends a carriage return if we are running on Windows.
 o indent
  protected static void indent(StringBuffer buf)
Appends spaces to "buf" based on the current indent level.
 o indent
  protected static void indent(StringBuffer buf,
                               int indentLevel)
Appends spaces to "buf" based on the given indent level.
 o incrIndent
  protected static void incrIndent()
Increments the indent level.
 o decrIndent
  protected static void decrIndent()
Decrements the indent level.
 o indentLevel
  protected static int indentLevel()
Returns the current indent level.
 o shortClassName
  public static String shortClassName(String className)
Returns the last token in a class name. i.e. the name that you can use for a class when you've imported the class already.

All Packages  Class Hierarchy  This Package  Previous  Next  Index