public class IlvPrototypeBeanGenerator extends Object
This class generates Java Beans that encapsulate prototypes. It allows you to turn the prototypes that you have designed into standard Java Beans that you can load and edit in any Java IDE.
The class IlvPrototypeBeanGenerator
handles all the "low-level"
work of generating beans. You will probably prefer to use the "Bean Wizard",
which is the GUI front-end provided in Composer, the Rogue Wave JViews
editor.
Each generated bean is a subclass of java.awt.Component
. The
bean draws the graphic elements of the prototype and dispatches mouse and
keyboard events to them.
The bean's properties are the public properties of the prototype.
If the prototype has output properties, the corresponding bean properties are bound: the bean has methods for registering property change listeners for these properties and fires property change events when the property is output.
Most of the generated bean's implementation is delegated to an
IlvPrototypeBeanSupport
object. The bean subclass itself simply
defines the properties and events specific to the bean.
You can choose the type of component you generate by specifying the
superclass of the bean. By default, a subclass of
java.awt.Component
is generated, which means that the bean will
be a lightweight (that is, "windowless") AWT component. With this default
choice, the bean is "transparent". The other components that overlap it will
"show through" the areas where no graphic elements are drawn. The other
possible choices include:
java.awt.Panel
- This will generate a heavyweight AWT
component, which can be useful if you want your beans to be opaque (that is,
to hide all other components that overlap its bounding box).
javax.swing.JComponent
- This will generate a Swing 1.1
component. In principle, if you generate your beans as subclasses of
Component
(default case), they can be added as children of Swing
containers, because they are lightweight. However, some IDEs may refuse to
let you add non-Swing components to Swing containers. In this case, you have
to generate Swing components.
com.sun.java.swing.JComponent
- This will generate a Swing
1.0 component. This is useful if your IDE only supports Swing 1.0.
In addition to generating the Java source code for your beans, the
IlvPrototypeBeanGenerator
class can
A number of generation options are available. The usual scheme for generating beans is:
IlvPrototypeBeanGenerator
.
generateBean
or generateBeans
.
generateBeanIcons
, compile
,
copyDataFiles
and makeJar
.
If you use the same instance of IlvPrototypeBeanGenerator
to
generate several different JAR files, you must call reset
to
clear the list of generated beans.
IlvPrototype
,
IlvPrototypeBeanSupport
Constructor and Description |
---|
IlvPrototypeBeanGenerator()
Creates a new prototype bean generator.
|
Modifier and Type | Method and Description |
---|---|
String |
compile()
Compiles the source files of the generated Java Beans.
|
void |
copyDataFiles()
Copies the data files used by the generated beans into the package
directory.
|
void |
generateBean(IlvPrototype prototype,
String beanName)
Generate the source code of a Java Bean from a prototype.
|
void |
generateBeanIcons()
Creates the icons for the beans that have been generated by this generator.
|
void |
generateBeans(IlvPrototypeLibrary library)
Generate Java Beans from all the prototypes in a library.
|
String |
getBaseClass()
Returns the base class of the generated beans.
|
int |
getBeanCount()
Returns the number of beans generated.
|
String |
getClassPath()
Returns the class path used to compile bean classes.
|
String |
getDefaultIcon()
Returns the default icon file.
|
String |
getDirectory()
Returns the directory where this bean generator will save source files.
|
Image |
getIcon(IlvPrototype prototype,
int iconSize,
Color background)
Creates an icon for the current bean.
|
String |
getIconFile(String beanName)
Returns the user-specified icon file for a given bean.
|
int |
getIconHints()
Returns the algorithm used to scale icons.
|
int |
getIconMargin()
Returns the margin left around the icons.
|
int |
getIconShadowThickness()
Returns the thickness of the shadow drawn around icons.
|
String |
getJarCommand()
Returns the jar command used to pack bean classes.
|
String |
getJavaCompiler()
Returns the java compiler command used to compile bean classes.
|
String |
getPackageName()
Returns the package name of the generated bean classes.
|
String |
getPrototypeName()
Returns the name of the prototype or prototype library for which beans will
be generated.
|
boolean |
isGeneratingIcons()
Returns the flag which indicates that the generator should generate icons
for the beans.
|
boolean |
isMakingJar()
Returns the flag which indicates that the generator should compile the Java
source files for the beans and build the final JAR file.
|
boolean |
isUsingAutoIcons()
Returns the flag which indicates that the generator should generate bean
icons automatically.
|
String |
makeJar()
Make the final JAR file containing all the Java Beans generated so far with
this generator.
|
void |
readOptions()
Reads the generation options from the generation directory.
|
void |
reset()
Resets this bean generator.
|
void |
setBaseClass(String baseClass)
Changes the base class of the generated beans.
|
void |
setClassPath(String classPath)
Changes the class path used to compile bean classes.
|
void |
setDefaultIcon(String defaultIcon)
Changes the default icon file.
|
void |
setDirectory(String directory)
Changes the directory where this bean generator will save source files.
|
void |
setGeneratingIcons(boolean generatingIcons)
Sets the flag which indicates that the generator should generate icons for
the beans.
|
void |
setIconFile(String beanName,
String iconFile)
Sets the icon file to use for a given bean.
|
void |
setIconHints(int iconHints)
Changes the algorithm used to scale icons.
|
void |
setIconMargin(int iconMargin)
Sets the margin left around the icons.
|
void |
setIconShadowThickness(int iconShadowThickness)
Sets the thickness of the shadow drawn around icons.
|
void |
setJarCommand(String jarCommand)
Changes the jar command used to pack bean classes.
|
void |
setJavaCompiler(String javaCompiler)
Changes the java compiler command used to compile bean classes.
|
void |
setMakingJar(boolean makingJar)
Sets the flag which indicates that the generator should compile the Java
source files for the beans and build the final JAR file.
|
void |
setPackageName(String packageName)
Changes the package name of the generated bean classes.
|
void |
setPrototypeName(String prototypeName)
Changes the name of the prototype or prototype library for which beans will
be generated.
|
void |
setUsingAutoIcons(boolean autoIcons)
Sets the flag which indicates that the generator should generate bean icons
automatically.
|
void |
stop()
Stops the current process launched by this generator, for example the Java
compiler run by the
compile method. |
void |
writeOptions()
Writes the generation options in the generation directory.
|
public IlvPrototypeBeanGenerator()
public void reset()
public void setDirectory(String directory)
public String getDirectory()
public void setPrototypeName(String prototypeName)
public String getPrototypeName()
public void setPackageName(String packageName)
public String getPackageName()
public void setBaseClass(String baseClass)
"java.awt.Component"
. The base class must be a subclass of
java.awt.Component
.public String getBaseClass()
public void setJavaCompiler(String javaCompiler)
"javac"
.public String getJavaCompiler()
public void setClassPath(String classPath)
public String getClassPath()
public void setJarCommand(String jarCommand)
"jar"
.public String getJarCommand()
public void setIconFile(String beanName, String iconFile)
public String getIconFile(String beanName)
public void setUsingAutoIcons(boolean autoIcons)
public boolean isUsingAutoIcons()
public void setGeneratingIcons(boolean generatingIcons)
public boolean isGeneratingIcons()
public void setMakingJar(boolean makingJar)
public boolean isMakingJar()
public void setDefaultIcon(String defaultIcon)
public String getDefaultIcon()
public void setIconHints(int iconHints)
iconHints
- the constant that identifies the scaling algorithm. The possible
values are: Image.SCALE_AREA_AVERAGING
,
Image.SCALE_DEFAULT
, Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
.public int getIconHints()
public void setIconMargin(int iconMargin)
public int getIconMargin()
public void setIconShadowThickness(int iconShadowThickness)
public int getIconShadowThickness()
public void writeOptions()
public void readOptions()
public int getBeanCount()
public void generateBean(IlvPrototype prototype, String beanName) throws IOException
makeJar
to compile the Java files and to pack them into a JAR
file.prototype
- the prototype.beanName
- the name of the bean class. If the name is null, the prototype's
name is used.IOException
- if an I/O error occurs.public void generateBeans(IlvPrototypeLibrary library) throws IOException
makeJar
to compile the Java files and to pack them into a JAR
file.library
- the prototype library.IOException
- if an I/O error occurs.public void copyDataFiles() throws IOException
IOException
- if an I/O error occurs.public String compile() throws IOException
The Java compiler specified by setJavaCompiler
is executed in
a separate process.
IOException
- if the Java compiler could not be found, or if an I/O error
occurs.public String makeJar() throws IOException
This method executes the jar
command in a separate process to
build the JAR file.
IOException
- if the jar command could not be found, or if an I/O error
occurs.public void stop()
compile
method.public void generateBeanIcons() throws IOException
For each bean, if an icon file was specified explicitly using
setIconFile
, this icon file is used. If a file named
beanNameIcon.gif
is found in the bean generation
directory, this file is used. Otherwise, an icon is created automatically
by taking a snapshot of the prototype.
A 16x16 icon and a 32x32 icon is generated for each bean. Such generated icons are saved as PNG files.
IOException
- if an I/O error occurs.public Image getIcon(IlvPrototype prototype, int iconSize, Color background)
This method can be used to preview a bean's icons in the GUI front-end for the bean generator.
prototype
- the bean's prototype.iconSize
- the icon size (usually 16 or 32).background
- the background color.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.