overview-summary.html.svn-base
来自「j2me设计的界面包」· SVN-BASE 代码 · 共 415 行 · 第 1/2 页
SVN-BASE
415 行
</P>
<P>The rest of the code is left within the MIDlet for simplicity but
could be separated to any class whatsoever to allow full portability
to any future platform to which the LWUIT library would be ported.
</P>
<H3>Scope & Portability</H3>
<P>The LWUIT library is strictly a widget UI library and does not try
to abstract most of the underlying system services such as
networking, storage etc... It doesn't try to solve other UI issues
related to native graphics etc.
</P>
<P>To enable portability the LWUIT library implements its own thin
layer on top of the native system canvas and provides a widget
abstraction. This abstraction is achieved using several key classes
that hide the system specific equivalents to said classes, such as
<A HREF="com/sun/lwuit/Graphics.html" title="class in com.sun.lwuit"><CODE>Graphics</CODE></A>, <A HREF="com/sun/lwuit/Image.html" title="class in com.sun.lwuit"><CODE>Image</CODE></A> &
<A HREF="com/sun/lwuit/Font.html" title="class in com.sun.lwuit"><CODE>Font</CODE></A>.
</P>
<P>When working in the toolkit it is critical to use these classes
for everything, in fact there is no way to access the "real"
underlying instances of these classes (e.g.
javax.microedition.lwuit.Graphics) to avoid corruption.
</P>
<P>One of the main goals of the project is to enable great
functionality on small devices that might be incapable of
anti-aliasing in runtime or even choke under the weight of
translucency and many small images. To solve these problems the
toolkit ships with an optional build system tool that allows a
developer to unify images into a simple image file optionally with
Windows/Java SE fonts embedded or in a separate image file. This
solves cross device translucent image problems and is details in the
font and image unifier section bellow.
</P>
<H3>Theming & Customization</H3>
<P>The LWUIT library supports both theming and customization. Theming
consists of manipulating fonts, colors & images to produce a
highly custom UI. However, theming is limited by the existing shape
and structure of the components. To achieve a complete custom look
the toolkit supports a pluggable look that can allow components to
assume any shape and form. This look is implemented by <A HREF="com/sun/lwuit/plaf/LookAndFeel.html" title="class in com.sun.lwuit.plaf"><CODE>LookAndFeel</CODE></A> which internally performs most of the
drawing for the API.
</P>
<P>The key to theming is the <A HREF="com/sun/lwuit/plaf/UIManager.html" title="class in com.sun.lwuit.plaf"><CODE>UIManager</CODE></A> and
the <A HREF="com/sun/lwuit/plaf/Style.html" title="class in com.sun.lwuit.plaf"><CODE>Style</CODE></A> class. A style represents the
"look" of a specific element while the UIManager allows us
to associate it with a particular widget. We can express a theme
using a set of key/value pairs where the key represents the component
UI ID (usually equivalent to the class name) attached to the specific
attribute manipulated and the value represents a string
representation of a font, color or image.
</P>
<P>An example may help explain, a key can be one of the following:
Button.font, List.bgSelectionColor, Label.fgColor.<BR>A value can be
one of the following: System{FACE_SYSTEM;STYLE_PLAIN;SIZE_SMALL},
444444, /myImage.png
</P>
<P>Notice that you cannot set a value of a different type to a
different key value, so Button.font won't accept a number. There is
no validation code when parsing to keep the overhead low, the parsing
occurs once and stores the results in a <A HREF="com/sun/lwuit/plaf/Style.html" title="class in com.sun.lwuit.plaf"><CODE>Style</CODE></A> that allows the component to extract style
data efficiently. It is the responsibility of the look and feel code
to take the Style object into consideration when drawing the
component.
</P>
<P>The component id is determined by the <A HREF="com/sun/lwuit/Component.html#getUIID()"><CODE>Component.getUIID()</CODE></A> method of Component, this allows
subclasses of a component to still be identified as their parent or
alternatively override the style if so desired. By convention the
UIID is normally set to the name of the component class without the
package name.
</P>
<P>To set a look it is possible to programmatically invoke <A HREF="com/sun/lwuit/plaf/UIManager.html#setThemeProps(java.util.Hashtable)"><CODE>UIManager.setThemeProps(java.util.Hashtable)</CODE></A> which accepts a Hashtable
of key value pairs. This would save the cost of loading/parsing a
theme by coding themes into methods as such:
</P>
<PRE>public Hashtable createTheme() {
Hashtable h = new Hashtable();
h.put("Button.bgColor", "FF0000");//set red color by default to a Button
return h;
}
</PRE><P>
A theme can also be stored using a text file using an input stream to
load the theme on the fly. Themes can thus be stored anywhere and
downloaded on the fly through the network using the <A HREF="com/sun/lwuit/plaf/UIManager.html#loadTheme(java.io.InputStream)"><CODE>UIManager.loadTheme(java.io.InputStream)</CODE></A> API with a file similar to
this:
</P>
<PRE>Button.font=System{FACE_SYSTEM;STYLE_PLAIN;SIZE_SMALL}
Label.fgColor=333333
</PRE>
<H3>Resource Bundles</H3>
<P>Resource bundles allow us to package multiple resources in a more efficient
package for use in the application and for shipping separately. Resources allow
us to package themes, fonts, images, animations and localization information in
a portable manner.</P>
<P>
To build a resource file we can use Ant to generate the appropriate resource e.g.:
<pre>
<target name="pre-init">
<taskdef classpath="ResourceBuilder.jar" classname="com.sun.lwuit.resource.Builder" name="build" />
<build dest="src/output.res">
<animation file="animation.gif" />
<image file="image.png" pack="true" />
<font logicalName="Monospaced" size="10" />
<theme file="theme.conf" name="myTheme" />
</build>
</target>
</pre>
The code above demonstrates how to generate a simple resource containing an animation,
image, font and theme. All of these will be packaged in the resource and could be accessible
by their name.
</P>
<P>
Animations currently must be animated GIF's files and they are converted by the Ant task
to a portable internal structure. Standard images can be "packed" or not, when an image
is packed it will be stored as an 8 bit palette image and would be returned from the resources
as a <A HREF="com/sun/lwuit/IndexedImage.html" title="class in com.sun.lwuit"><CODE>IndexedImage</CODE></A>.
</P>
<P>
To use the resources above we can use the Resources class to extract information from
the file e.g.:
</P>
<PRE>
Resources r = Resources.open("/output.res");
Image i = r.getImage("animation.gif");
</PRE>
<P>Ant tasks support the following attributes:
</P>
<UL>
<LI>builder - dest (the output file path)</LI>
<LI>font - for full details see the <A HREF="com/sun/lwuit/Font.html" title="class in com.sun.lwuit"><CODE>Font</CODE></A> documentation</LI>
<LI>image - name (defaults to file name), file (required), pack (default false whether to use <A HREF="com/sun/lwuit/IndexedImage.html" title="class in com.sun.lwuit"><CODE>IndexedImage</CODE></A>)</LI>
<LI>theme - name (defaults to file name), file (required)</LI>
</UL>
<H3>Component List</H3>
<P>For more details about LWUIT widgets, please see the developer
guide for detail and screenshots.</P>
<H3>Events & Threading</H3>
<P>For increased compatibility, threading is handled and encapsulated
completely by this toolkit. The toolkit has a single main thread
referred to as the "EDT" (inspired by Swing/AWT's Event
Dispatch Thread), all events & paint calls are dispatched via
this thread. This guarantees that event and paint calls are
serialized and would not cause risk a threading issue it also enables
portability for profiles that might have minor threading model
inconsistencies. See <A HREF="com/sun/lwuit/Display.html" title="class in com.sun.lwuit"><CODE>Display</CODE></A> for further
details about integrating with the EDT and serializing calls on it.
</P>
<P>
<P>
<HR>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Overview</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Package</FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Class</FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <FONT CLASS="NavBarFont1">Use</FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
PREV
NEXT</FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="index.html?overview-summary.html" target="_top"><B>FRAMES</B></A>
<A HREF="overview-summary.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?