|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttypes.WidgetDef
public abstract class WidgetDef
WidgetDef is the abstract class that all definitions in the library implement. Standardized Formats for our Libraries: String Concatenation: Use the StringBuilder class and the StringBuilder.append() method to concatenate strings. String Formatting: use the String.format(String, args) to format strings. Use Window.java class as an example.
| Nested Class Summary | |
|---|---|
static interface |
WidgetDef.Abstract
Annotation forbidding a widget type from being instantiated. |
static interface |
WidgetDef.Contained
Declare that a widget type cannot appear at the top level. |
static interface |
WidgetDef.Derived
Annotation specifying the base widget types of a widget. |
| Field Summary | |
|---|---|
String |
id
id of Widget object |
protected WidgetDef |
parent
Parent widget def |
protected Widget |
widget
Widget object that is passed as a parameter in the constructor. |
| Constructor Summary | |
|---|---|
protected |
WidgetDef(Widget widget,
WidgetDef parent)
|
protected |
WidgetDef(Widget widget,
WidgetDef parent,
LangDef langDef)
|
| Method Summary | |
|---|---|
abstract String |
addAttributes(GUIAttributes attrs)
The addAttributes code does two things; it creates the lib.java code necessary for the attributes and it type checks for all attributes. |
String |
addChild(String childType,
String childId,
GUIAttributes attrs)
Check to make sure the childType is legal for the widget, then add it. |
protected static String |
commentForm(String id,
String type)
Format a widget identifier for use in comments. |
static WidgetDef |
defineWidget(LangDef lang,
Widget widget)
Create a WidgetDef object for a given Widget and language. |
static WidgetDef |
defineWidget(LangDef lang,
Widget widget,
WidgetDef parent)
Create a WidgetDef object for a given Widget and language, with the given WidgetDef as the parent of the widget. |
boolean |
equals(Object other)
Compare this WidgetDef to another. |
List<WidgetDef> |
getAncestry()
Get all widget types from which this one derives, in method resolution order, including this type itself. |
List<Class<? extends WidgetDef>> |
getBaseWidgetDefClasses()
Retrieve the base widget types. |
List<Class<? extends WidgetDef>> |
getBaseWidgetDefClasses(Class<? extends WidgetDef> cls)
Retrieve the base widget types for a given WidgetDef class. |
static List<Class<? extends WidgetDef>> |
getBaseWidgetDefClasses(Class<? extends WidgetDef> cls,
LangDef langDef)
Retrieve the base widget types for a given WidgetDef class. |
List<WidgetDef> |
getBaseWidgetDefs()
Retrieve the base widget types. |
Map<String,List<String>> |
getChildDefaults()
Specifies the child attributes for the widget. |
List<String> |
getChildModifiers()
Analog of getModifiers() for child attributes. |
protected String |
getCommentName()
Format the widget identifier for use in comments. |
abstract Map<String,List<String>> |
getDefaults()
Every attribute in our language has to have a default setting. |
abstract Set<String> |
getImports()
getImports keeps a Set of import lines that are pertinent to the code generated in the other methods. |
Set<String> |
getInnerClasses()
getInnerClasses returns a set of strings corresponding to any inner classes utilized by the widget at runtime. |
abstract String |
getLanguage()
Accessor method for the Widget language. |
abstract List<String> |
getModifiers()
getModifiers returns a list of methods designed to modify various attributes of the widget type in question. |
Map<String,List<String>> |
getMultisynonymousAttributes()
Specifies multisynonymous attributes. |
Map<String,String> |
getSynonymousAttributes()
Specifies synonymous attributes. |
abstract List<String> |
getVariables()
Returns a chunk of code intended to declare variables which the backend code may need access to and therefore should be declared outside of the constructor code. |
int |
hashCode()
|
boolean |
isAbstract()
Test whether this widget definition is for an abstract widget type. |
static boolean |
isAbstract(Class<? extends WidgetDef> cls)
Test whether a class defines an abstract widget type. |
boolean |
isContained()
Test whether the represented widget is contained, and so cannot appear at the top level of a .gui file. |
boolean |
isContained(Class<? extends WidgetDef> cls)
Test whether a class defines the type of a widget that is contained, and so cannot appear at the top level of a .gui file. |
static boolean |
isContained(Class<? extends WidgetDef> cls,
LangDef langDef)
Test whether a class defines the type of a widget that is contained, and so cannot appear at the top level of a .gui file. |
boolean |
isDerivedFrom(Class<? extends WidgetDef> cls)
Test whether this widget definition derives from that specified by the given WidgetDef class. |
protected boolean |
isDerivedFrom(Class<? extends WidgetDef> deriv,
Class<? extends WidgetDef> maybeBase)
Determines whether one widget type is derived from or the same as another, directly or otherwise. |
protected static boolean |
isDerivedFrom(Class<? extends WidgetDef> deriv,
Class<? extends WidgetDef> maybeBase,
LangDef langDef)
Determines whether one widget type is derived from or the same as another, directly or otherwise. |
protected boolean |
isDerivedFrom(String derivName,
Class<? extends WidgetDef> maybeBase)
Determines whether one widget type is derived from or the same as another, directly or otherwise. |
protected static boolean |
isDerivedFrom(String derivName,
Class<? extends WidgetDef> maybeBase,
LangDef langDef)
Determines whether one widget type is derived from or the same as another, directly or otherwise. |
protected boolean |
isDerivedFrom(String derivName,
String maybeBaseName)
Determines whether one widget type is derived from or the same as another, directly or otherwise. |
protected static boolean |
isDerivedFrom(String derivName,
String maybeBaseName,
LangDef langDef)
Determines whether one widget type is derived from or the same as another, directly or otherwise. |
boolean |
isDerivedFrom(WidgetDef widgetDef)
Test whether this widget definition derives from the given one. |
String |
postamble()
Get the chunk of initialization code to be run after everything else is done. |
abstract String |
preamble()
Get the chunk of initialization code to be run first. |
GUIAttributes |
processAttributes()
Create a GUIAttributes object for a widget. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final Widget widget
public final String id
protected final WidgetDef parent
| Constructor Detail |
|---|
protected WidgetDef(Widget widget,
WidgetDef parent)
widget - The Widget object.parent - The WidgetDef for the parent widget, or null for a
top-level widget.
protected WidgetDef(Widget widget,
WidgetDef parent,
LangDef langDef)
widget - The Widget object.parent - The WidgetDef for the parent widget, or null for a
top-level widget.langDef - The language definition in use.| Method Detail |
|---|
protected String getCommentName()
id, if the widget is not anonymous; a placeholder
otherwise.
protected static String commentForm(String id,
String type)
id - The identifier of the widget.type - The type of the widget.
id, if the widget is not anonymous; a placeholder
otherwise.public abstract String getLanguage()
public abstract String preamble()
Note that, by its nature, a preamble should only be called once; therefore the preamble is not inherited.
public String postamble()
Note that the preamble() and postamble are not
inherited (much as Java constructors aren't).
public abstract List<String> getVariables()
public final GUIAttributes processAttributes()
throws BadAttributeException
BadAttributeException - If an unrecognized attribute is listed
for the widget.public abstract Map<String,List<String>> getDefaults()
public abstract String addAttributes(GUIAttributes attrs)
throws BadAttributeException
attrs - The attributes to set for the widget.
BadAttributeExceptionpublic Map<String,String> getSynonymousAttributes()
getDefaults()), and the value is the name of the real attribute
with which that attribute is synonymous (i.e. equivalent).
By default, returns the empty map; WidgetDef subclasses may override to specify synonymous attributes.
public Map<String,List<String>> getMultisynonymousAttributes()
public Map<String,List<String>> getChildDefaults()
getDefaults()
public String addChild(String childType,
String childId,
GUIAttributes attrs)
throws BadChildWidgetException,
BadAttributeException
childType - The widget type of the child.childId - The identifier of the child.attrs - The child's GUIAttributes map. Child attributes will be
read from this map.
BadChildWidgetException - If the child is of an inappropriate
type. For instance, a menu can only have certain widgets (items,
submenus, etc.) as children.
BadAttributeException - If one of the given attributes is
erroneous.public abstract List<String> getModifiers()
public List<String> getChildModifiers()
getModifiers() for child attributes.
public abstract Set<String> getImports()
public Set<String> getInnerClasses()
public static WidgetDef defineWidget(LangDef lang,
Widget widget,
WidgetDef parent)
throws BadWidgetTypeException
lang - The LangDef for the language to output.widget - The Widget, as given by the parser.parent - The WidgetDef for the parent widget.
BadWidgetTypeException - If the Widget specifies a widget type
in Widget.type that:
widget has no parent
public static WidgetDef defineWidget(LangDef lang,
Widget widget)
throws BadWidgetTypeException
lang - The LangDef for the language to output.widget - The Widget, as given by the parser.
BadWidgetTypeException - If the Widget specifies a widget type
in Widget.type that is either abstract or nonexistant.public final List<WidgetDef> getBaseWidgetDefs()
WidgetDef.Derivedpublic final List<Class<? extends WidgetDef>> getBaseWidgetDefClasses()
WidgetDef.Derivedpublic final List<Class<? extends WidgetDef>> getBaseWidgetDefClasses(Class<? extends WidgetDef> cls)
cls - The class in question.
WidgetDef.Derived
public static List<Class<? extends WidgetDef>> getBaseWidgetDefClasses(Class<? extends WidgetDef> cls,
LangDef langDef)
cls - The class in question.langDef - The language definition for the class.
WidgetDef.Derivedpublic final List<WidgetDef> getAncestry()
The method resolution order (MRO) used here is called C3; I'm borrowing the algorithm from Python 2.3 (which in turn borrowed it from a Lisp variant called Dylan). See this essay for a more thorough explanation and justification of the C3 algorithm.
public final boolean isDerivedFrom(WidgetDef widgetDef)
widgetDef - The potential ancestor of this widget definition.
true if this widget definition derives, directly or
indirectly, from widgetDef.public final boolean isDerivedFrom(Class<? extends WidgetDef> cls)
cls - The class of the potential ancestor of this widget
definition.
true if this widget definition derives, directly or
indirectly, from that specified by cls.
protected final boolean isDerivedFrom(Class<? extends WidgetDef> deriv,
Class<? extends WidgetDef> maybeBase)
deriv - The type in question.maybeBase - The type which may be the base widget type.
true if deriv equals or derives from
maybeBase.
protected static boolean isDerivedFrom(Class<? extends WidgetDef> deriv,
Class<? extends WidgetDef> maybeBase,
LangDef langDef)
deriv - The type in question.maybeBase - The type which may be the base widget type.langDef - The language definition in use.
true if deriv equals or derives from
maybeBase.
protected final boolean isDerivedFrom(String derivName,
Class<? extends WidgetDef> maybeBase)
derivName - The name of the type in question.maybeBase - The type which may be the base widget type.
true if deriv equals or derives from
maybeBase.
protected static boolean isDerivedFrom(String derivName,
Class<? extends WidgetDef> maybeBase,
LangDef langDef)
derivName - The name of the type in question.maybeBase - The type which may be the base widget type.langDef - The language definition in use.
true if deriv equals or derives from
maybeBase.
protected final boolean isDerivedFrom(String derivName,
String maybeBaseName)
derivName - The name of the type in question.maybeBaseName - The name of the type which may be the base widget
type.
true if deriv equals or derives from
maybeBase.
protected static boolean isDerivedFrom(String derivName,
String maybeBaseName,
LangDef langDef)
derivName - The name of the type in question.maybeBaseName - The name of the type which may be the base widget
type.langDef - The language definition in use.
true if deriv equals or derives from
maybeBase.public final boolean isAbstract()
true if this widget definition carries the
WidgetDef.Abstract annotation.WidgetDef.Abstractpublic static boolean isAbstract(Class<? extends WidgetDef> cls)
cls - A subclass of WidgetDef.
true if the class carries the WidgetDef.Abstract
annotation.WidgetDef.Abstractpublic final boolean isContained()
true if this widget definition (or any ancestor widget
type) carries the WidgetDef.Contained annotation.WidgetDef.Containedpublic final boolean isContained(Class<? extends WidgetDef> cls)
cls - A subclass of WidgetDef.
true if the class, or any ancestor widget type as
declared by the WidgetDef.Derived annotation, carries the
WidgetDef.Contained annotation.WidgetDef.Contained
public static boolean isContained(Class<? extends WidgetDef> cls,
LangDef langDef)
cls - A subclass of WidgetDef.langDef - The language definition in use.
true if the class, or any ancestor widget type as
declared by the WidgetDef.Derived annotation, carries the
WidgetDef.Contained annotation.WidgetDef.Containedpublic final boolean equals(Object other)
equals in class Objectother - The WidgetDef to compare to.
true if this WidgetDef is of the same class as the
given one and was given the same Widget at construction.public int hashCode()
hashCode in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||