blob: f09e8e863a5ae5c13716d1d8f966a1c206390cda [file] [log] [blame]
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List href="./Writing%20Your%20Own%20Widget_files/filelist.xml">
<link rel=OLE-Object-Data
href="./Writing%20Your%20Own%20Widget_files/oledata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>Writing Your Own Widget</title>
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Author>OTI EMPLOYEE</o:Author>
<o:LastAuthor>Dave Thomson</o:LastAuthor>
<o:Revision>12</o:Revision>
<o:TotalTime>2064</o:TotalTime>
<o:LastPrinted>2001-02-09T19:31:00Z</o:LastPrinted>
<o:Created>2001-06-04T02:12:00Z</o:Created>
<o:LastSaved>2001-06-04T18:05:00Z</o:LastSaved>
<o:Pages>30</o:Pages>
<o:Words>8616</o:Words>
<o:Characters>49116</o:Characters>
<o:Company>OBJECT TECHNOLOGY INTL</o:Company>
<o:Lines>409</o:Lines>
<o:Paragraphs>98</o:Paragraphs>
<o:CharactersWithSpaces>60317</o:CharactersWithSpaces>
<o:Version>9.2720</o:Version>
</o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:HideSpellingErrors/>
<w:DoNotHyphenateCaps/>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>0</w:DisplayVerticalDrawingGridEvery>
<w:UseMarginsForDrawingGridOrigin/>
<w:Compatibility>
<w:UsePrinterMetrics/>
<w:WW6BorderRules/>
<w:FootnoteLayoutLikeWW8/>
<w:ShapeLayoutLikeWW8/>
<w:AlignTablesRowByRow/>
<w:ForgetLastTabAlignment/>
<w:LayoutRawTableWidth/>
<w:LayoutTableRowsApart/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<link rel=Stylesheet type="text/css" media=all
href="Writing%20Your%20Own%20Widget_files/default_style.css">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
h1
{mso-style-next:Normal;
margin-top:12.0pt;
margin-right:0in;
margin-bottom:3.0pt;
margin-left:0in;
mso-pagination:widow-orphan;
page-break-after:avoid;
mso-outline-level:1;
font-size:21.0pt;
font-family:Arial;
color:windowtext;
mso-font-kerning:14.0pt;
font-weight:bold;}
h2
{mso-style-next:Normal;
margin-top:12.0pt;
margin-right:0in;
margin-bottom:6.0pt;
margin-left:0in;
mso-line-height-alt:10.5pt;
mso-pagination:widow-orphan;
page-break-after:avoid;
mso-outline-level:2;
font-size:18.0pt;
font-family:Arial;
color:windowtext;
font-weight:bold;}
h3
{mso-style-next:Normal;
margin-top:12.0pt;
margin-right:0in;
margin-bottom:3.0pt;
margin-left:0in;
mso-pagination:widow-orphan;
page-break-after:avoid;
mso-outline-level:3;
font-size:14.0pt;
font-family:Arial;
color:windowtext;
font-weight:bold;}
h4
{mso-style-next:Normal;
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
page-break-after:avoid;
mso-outline-level:4;
tab-stops:24.0pt 48.0pt 1.0in 96.0pt 120.0pt 2.0in 168.0pt 192.0pt 3.0in 240.0pt 264.0pt 4.0in 312.0pt 336.0pt 5.0in 384.0pt 408.0pt 6.0in 456.0pt 480.0pt 7.0in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt;
layout-grid-mode:char;
font-size:18.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
color:windowtext;
font-weight:normal;}
p.MsoToc1, li.MsoToc1, div.MsoToc1
{mso-style-next:Normal;
margin-top:.25in;
margin-right:0in;
margin-bottom:0in;
margin-left:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;
text-transform:uppercase;
font-weight:bold;
mso-bidi-font-weight:normal;}
p.MsoToc2, li.MsoToc2, div.MsoToc2
{mso-style-next:Normal;
margin-top:12.0pt;
margin-right:0in;
margin-bottom:0in;
margin-left:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;
font-weight:bold;
mso-bidi-font-weight:normal;}
p.MsoToc3, li.MsoToc3, div.MsoToc3
{mso-style-next:Normal;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:10.0pt;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoToc4, li.MsoToc4, div.MsoToc4
{mso-style-next:Normal;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:20.0pt;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoToc5, li.MsoToc5, div.MsoToc5
{mso-style-next:Normal;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:30.0pt;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoToc6, li.MsoToc6, div.MsoToc6
{mso-style-next:Normal;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:40.0pt;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoToc7, li.MsoToc7, div.MsoToc7
{mso-style-next:Normal;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:50.0pt;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoToc8, li.MsoToc8, div.MsoToc8
{mso-style-next:Normal;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:60.0pt;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoToc9, li.MsoToc9, div.MsoToc9
{mso-style-next:Normal;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:70.0pt;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoHeader, li.MsoHeader, div.MsoHeader
{margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:center 3.0in right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoFooter, li.MsoFooter, div.MsoFooter
{margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:center 3.0in right 6.0in;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:windowtext;}
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
{margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
color:red;}
p.MsoBodyText2, li.MsoBodyText2, div.MsoBodyText2
{margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in;
layout-grid-mode:char;
font-size:9.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Courier New";
mso-fareast-font-family:"Times New Roman";
mso-bidi-font-family:"Times New Roman";
color:black;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;
text-underline:single;}
strong
{mso-bidi-font-weight:normal;}
em
{mso-bidi-font-style:normal;}
p
{margin-top:5.0pt;
margin-right:0in;
margin-bottom:5.0pt;
margin-left:0in;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:Arial;
mso-fareast-font-family:"Times New Roman";
color:black;}
code
{mso-ansi-font-size:8.5pt;
mso-bidi-font-size:8.5pt;
mso-ascii-font-family:"Courier New";
mso-fareast-font-family:"Times New Roman";
mso-hansi-font-family:"Courier New";
mso-bidi-font-family:"Courier New";}
pre
{margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;
font-size:10.0pt;
font-family:"Courier New";
mso-fareast-font-family:"Courier New";
color:windowtext;}
p.Code, li.Code, div.Code
{mso-style-name:Code;
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in 2.25in 2.5in 2.75in 3.0in 3.25in 3.5in 3.75in 4.0in 4.25in 4.5in 4.75in 5.0in 5.25in 5.5in 5.75in;
layout-grid-mode:char;
font-size:9.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Courier New";
mso-fareast-font-family:"Times New Roman";
mso-bidi-font-family:"Times New Roman";
color:windowtext;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-title-page:yes;
mso-even-footer:url("./Writing%20Your%20Own%20Widget_files/header.htm") ef1;
mso-footer:url("./Writing%20Your%20Own%20Widget_files/header.htm") f1;
mso-paper-source:0;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:-2;
mso-list-type:simple;
mso-list-template-ids:-1;}
@list l0:level1
{mso-level-start-at:0;
mso-level-text:*;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:0in;
text-indent:0in;}
@list l1
{mso-list-id:174617761;
mso-list-type:simple;
mso-list-template-ids:67698689;}
@list l1:level1
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:.25in;
mso-level-number-position:left;
margin-left:.25in;
text-indent:-.25in;
font-family:Symbol;}
@list l2
{mso-list-id:1592273852;
mso-list-type:simple;
mso-list-template-ids:67698689;}
@list l2:level1
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:.25in;
mso-level-number-position:left;
margin-left:.25in;
text-indent:-.25in;
font-family:Symbol;}
@list l0:level1 lfo2
{mso-level-number-format:bullet;
mso-level-numbering:continue;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
mso-level-legacy:yes;
mso-level-legacy-indent:.25in;
mso-level-legacy-space:0in;
margin-left:.25in;
text-indent:-.25in;
font-family:Symbol;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1"/>
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple style='tab-interval:.5in'>
<div class=Section1>
<p class=MsoNormal align=right style='margin-top:14.2pt;margin-right:0in;
margin-bottom:0in;margin-left:25.5pt;margin-bottom:.0001pt;text-align:right'><a
name="_Toc496069418"></a><a name="_Toc506634621"><span style='mso-bookmark:
_Toc496069418'><span style='font-size:8.0pt;mso-bidi-font-size:10.0pt'>Copyright
© 2001 Object Technology International, Inc.<o:p></o:p></span></span></a></p>
<table border=0 cellspacing=0 cellpadding=0 width="100%" style='width:100.0%;
mso-cellspacing:0in;margin-left:25.5pt;mso-padding-alt:1.5pt 1.5pt 1.5pt 1.5pt'>
<tr>
<td valign=top style='background:#0080C0;padding:1.5pt 1.5pt 1.5pt 1.5pt'>
<p class=MsoNormal><span style='mso-bookmark:_Toc506634621'><span
style='mso-bookmark:_Toc496069418'><b><span style='font-family:Arial;
color:white'>&nbsp;Eclipse Corner Article</span></b></span></span><span
style='mso-bookmark:_Toc506634621'><span style='mso-bookmark:_Toc496069418'><span
style='mso-bidi-font-size:12.0pt'><o:p></o:p></span></span></span></p>
</td>
<span style='mso-bookmark:_Toc506634621'><span style='mso-bookmark:_Toc496069418'></span></span>
</tr>
</table>
<h1 style='margin-left:25.5pt'><span style='mso-bookmark:_Toc506634621'><span
style='mso-bookmark:_Toc496069418'><img width=120 height=86 id="_x0000_i1043"
src="Writing%20Your%20Own%20Widget_files/Idea.jpg" align=CENTER></span></span><span
style='mso-bookmark:_Toc506634621'><span style='mso-bookmark:_Toc496069418'><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt'><o:p></o:p></span></span></span></h1>
<h1 align=center style='margin-left:25.5pt;text-align:center'><span
style='mso-bookmark:_Toc506634621'><span style='mso-bookmark:_Toc496069418'>Creating
Your Own Widgets using SWT</span></span></h1>
<p class=MsoNormal style='margin-left:25.5pt;text-indent:.5in'><span
style='mso-bookmark:_Toc506634621'><span style='mso-bookmark:_Toc496069418'><b><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></span></span></p>
<p class=MsoNormal style='margin-top:0in;margin-right:.5in;margin-bottom:0in;
margin-left:61.5pt;margin-bottom:.0001pt'><span style='mso-bookmark:_Toc506634621'><span
style='mso-bookmark:_Toc496069418'><b>Summary</b> <br>
When writing applications, you typically use the standard widgets provided by
SWT. On occasion, you will need to create your own custom widgets. For example,
you might want to add a new type of widget not provided by the standard
widgets, or extend the functionality of an existing widget.<span
style="mso-spacerun: yes">  </span>This article explains the different SWT
extension strategies and shows you how to use them. </span></span></p>
<p class=MsoNormal style='margin-top:0in;margin-right:.5in;margin-bottom:0in;
margin-left:61.5pt;margin-bottom:.0001pt'><span style='mso-bookmark:_Toc506634621'><span
style='mso-bookmark:_Toc496069418'><b><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></span></span></p>
<p class=MsoNormal style='margin-top:0in;margin-right:.5in;margin-bottom:0in;
margin-left:61.5pt;margin-bottom:.0001pt'><span style='mso-bookmark:_Toc506634621'><span
style='mso-bookmark:_Toc496069418'><b>By Steve Northover &amp; Carolyn MacLeod,
OTI<br>
</b></span></span><span style='mso-bookmark:_Toc506634621'><span
style='mso-bookmark:_Toc496069418'><span style='font-size:10.0pt'>March 22,
2001</span><b><o:p></o:p></b></span></span></p>
<p class=MsoNormal style='margin-top:0in;margin-right:.5in;margin-bottom:0in;
margin-left:61.5pt;margin-bottom:.0001pt'><span style='mso-bookmark:_Toc506634621'><span
style='mso-bookmark:_Toc496069418'><b><span style='font-size:8.0pt;mso-bidi-font-size:
10.0pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></b></span></span></p>
<div class=MsoNormal align=center style='margin-left:25.5pt;text-align:center'><span
style='mso-bookmark:_Toc506634621'><span style='mso-bookmark:_Toc496069418'>
<hr size=2 width="100%" align=center>
</span></span></div>
<b><span style='font-size:21.0pt;font-family:Arial;mso-fareast-font-family:
"Times New Roman";mso-font-kerning:14.0pt;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA'><br clear=all style='page-break-before:always'>
</span></b>
<h1 style='margin-left:25.5pt'><span style='mso-bookmark:_Toc506634621'><span
style='mso-bookmark:_Toc496069418'>Creating Your Own Widgets</span></span></h1>
<h2 style='margin-left:25.5pt'><a name="_Toc496069419"></a><a
name="_Toc496069776"></a><a name="_Toc506634622"><span style='mso-bookmark:
_Toc496069776'><span style='mso-bookmark:_Toc496069419'>Overview</span></span></a></h2>
<p class=MsoNormal style='margin-left:25.5pt'>When writing applications, you
typically use the standard widgets provided by SWT. On occasion, you will need
to create your own custom widgets. There are several reasons that you might
want to do this:</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>To add a new type of widget not provided by the
standard widgets</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>To extend the functionality of an existing widget</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Custom widgets are
created by subclassing in the existing widget class hierarchy.</p>
<h2 style='margin-left:25.5pt'><a name="_Toc506634623">Portability Issues</a></h2>
<p class=MsoNormal style='margin-left:25.5pt'>It is very important to think
about portability before writing a custom widget. SWT can be extended in the
following ways:</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Write a new widget that is 100% Java&trade; portable</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Extend an existing widget in a 100% Java portable
manner</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Write a new widget that wraps an existing native widget
– not portable</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Extend an existing widget by calling natives – not
portable</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>In addition, a combination of
these can be used on different platforms:</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Write a new widget that wraps an existing native widget
on one platform, but is 100% Java portable on other platforms</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Extend an existing widget by calling natives on one
platform, but call 100% Java portable code on other platforms</p>
<p class=MsoNormal style='margin-left:25.5pt'>This of course involves
implementing the widget twice – using native calls on the one platform and
portable code on the others – while maintaining the same API for both.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>Each SWT platform is shipped with
both a shared library (for example, a DLL on Windows&reg;) and a jar (for the Java
class files). The shared library contains all of the native function required
for SWT, but it was not meant to be a complete set of the functions available
on the platform. Thus to expose native function or native widgets that were not
exposed by SWT, you need to write your own shared library. If you are using a
combination of native code on one platform and portable code on another, make
sure you call your shared library on the platform with the native widget, and
your jar on the platform with the portable widget.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>One final note: SWTÂ’s interface
to its shared libraries is internal SWT code. It was not meant to provide a framework
for applications to access all possible native function on all platforms – that
would be a daunting task. One of the purposes of this document is to show how
you can integrate C code with SWT, not model the operating system. As such, the
approach taken to writing natives in this document is different from the
approach taken by SWT.<br clear=all style='mso-special-character:line-break;
page-break-before:always'>
</p>
<h2 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc496069420"></a><a
name="_Toc496069777"></a><a name="_Toc506634624"><span style='mso-bookmark:
_Toc496069777'><span style='mso-bookmark:_Toc496069420'>Writing Portable
Widgets</span></span></a></h2>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>The SWT library
provides two widget classes that are typically used as the basis for a custom
100% Java portable widget:</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]><i style='mso-bidi-font-style:normal'>Canvas</i> - to
create basic widgets</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]><i style='mso-bidi-font-style:normal'>Composite</i> -
to create compound widgets</p>
<h3 style='margin-left:25.5pt'><a name="_Toc496069421"></a><a
name="_Toc496069778"></a><a name="_Toc506634625"><span style='mso-bookmark:
_Toc496069778'><span style='mso-bookmark:_Toc496069421'>Basic Widgets</span></span></a></h3>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Basic widgets do
not contain any other widgets, and are not built from any other widgets. Basic
widgets draw themselves. An example of a basic widget is <i style='mso-bidi-font-style:
normal'>Button</i>. Another example is <i style='mso-bidi-font-style:normal'>Text</i>.
To create a custom basic widget, subclass <i style='mso-bidi-font-style:normal'>Canvas</i>.</p>
<h3 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc496069422"></a><a
name="_Toc496069779"></a><a name="_Toc506634626"><span style='mso-bookmark:
_Toc496069779'><span style='mso-bookmark:_Toc496069422'>Compound Widgets</span></span></a></h3>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Compound widgets
contain other widgets, and/or are composed of other widgets. An example of a
compound widget is <i style='mso-bidi-font-style:normal'>Combo</i>. It contains
a <i style='mso-bidi-font-style:normal'>Text</i>, a <i style='mso-bidi-font-style:
normal'>Button</i> and a <i style='mso-bidi-font-style:normal'>List</i>.
Another example is <i style='mso-bidi-font-style:normal'>Group</i>. It can contain
any number of children. To create a custom compound widget, subclass <i
style='mso-bidi-font-style:normal'>Composite</i>.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>The astute reader may have
noticed that <i style='mso-bidi-font-style:normal'>Canvas</i> is actually a
subclass of <i style='mso-bidi-font-style:normal'>Composite</i>. This is an
artifact of the underlying implementation. We treat <i style='mso-bidi-font-style:
normal'>Canvas</i> as something you draw on and <i style='mso-bidi-font-style:
normal'>Composite</i> as something that has children. Therefore the rule for
deciding which class to subclass is this: If your widget has or will have
children, subclass <i style='mso-bidi-font-style:normal'>Composite</i>. If your
widget does not have and never will have children, subclass <i
style='mso-bidi-font-style:normal'>Canvas</i>.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>Note also that we do not
distinguish between a compound widget that is intended to contain and lay out
children, and one that is merely composed of other widgets. Both will be a
subclass of <i style='mso-bidi-font-style:normal'>Composite</i>, and as such we
are describing implementation, rather than type, inheritance. When writing 100%
Java portable widgets, we can think of <i style='mso-bidi-font-style:normal'>Composite
</i>as the portable entry point into the SWT class hierarchy for all compound
widgets, and <i style='mso-bidi-font-style:normal'>Canvas </i>as the portable
entry point into the SWT class hierarchy for all basic widgets, regardless of
widget type.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<b><span style='font-size:18.0pt;font-family:Arial;mso-fareast-font-family:
"Times New Roman";mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA'><br clear=all style='page-break-before:always'>
</span></b>
<h2 style='margin-left:25.5pt'><a name="_Toc496069423"></a><a
name="_Toc496069780"><span style='mso-bookmark:_Toc496069423'>Basic Widget
Example</span></a><span style='mso-bookmark:_Toc496069423'></span><span
style='mso-bookmark:_Toc496069780'></span><span style='font-size:12.0pt;
mso-bidi-font-size:18.0pt;font-family:"Times New Roman";font-weight:normal'><o:p></o:p></span></h2>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Imagine we are
building an application where we need a widget that displays an image with a
line of text to the right, something like this:</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><!--[if gte vml 1]><o:wrapblock><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_s1033" type="#_x0000_t75" style='position:absolute;
left:0;text-align:left;margin-left:154.8pt;margin-top:-14.25pt;width:51.75pt;
height:17.25pt;z-index:3;mso-position-horizontal-relative:text;
mso-position-vertical-relative:text' o:allowincell="f">
<v:imagedata src="./Writing%20Your%20Own%20Widget_files/image001.png"
o:title=""/>
<w:wrap type="topAndBottom" anchorx="page"/>
</v:shape><![if gte mso 9]><o:OLEObject Type="Embed" ProgID="PBrush"
ShapeID="_x0000_s1033" DrawAspect="Content" ObjectID="_1053168690">
</o:OLEObject>
<![endif]><![endif]--><![if !vml]><span style='mso-ignore:vglayout'>
<table cellpadding=0 cellspacing=0 align=left>
<tr>
<td width=206 height=0></td>
</tr>
<tr>
<td></td>
<td><img width=69 height=23
src="./Writing%20Your%20Own%20Widget_files/image002.jpg" v:shapes="_x0000_s1033"></td>
</tr>
</table>
</span><![endif]><!--[if gte vml 1]></o:wrapblock><![endif]--><br
style='mso-ignore:vglayout' clear=ALL>
<![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p><p></p>
<br style='mso-ignore:vglayout' clear=ALL>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Since we plan to
draw both the image and the text, we subclass <i style='mso-bidi-font-style:
normal'>Canvas</i>.</p>
<p style='margin-top:0in;margin-right:0in;margin-bottom:0in;margin-left:25.5pt;
margin-bottom:.0001pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> org.eclipse.swt.*;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
org.eclipse.swt.graphics.*;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> org.eclipse.swt.widgets.*;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> org.eclipse.swt.events.*;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>class</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> PictureLabel </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>extends</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Canvas {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Image image;<span style='mso-tab-count:1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>String text;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Our widget needs to
be created. To do this, we must write at least one constructor. Because widgets
in SWT cannot be created without a parent, the constructor must take at least
one argument that is the parent. The convention in SWT is to have a constructor
with two arguments, <b style='mso-bidi-font-weight:normal'>parent</b> and <b
style='mso-bidi-font-weight:normal'>style</b>. Style bits are used to control
the look of widgets. Neither the parent nor the style bits can be changed after
the widget is created. Your widget can use style bits too.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>PictureLabel(Composite parent, </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>int</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
style) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>super</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>(parent, style);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<span style='mso-tab-count:1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>The parent of any
widget must be a <i style='mso-bidi-font-style:normal'>Composite</i>. The style
is an integer, where some bits are already used by the system. For example, <b
style='mso-bidi-font-weight:normal'><span style='font-size:10.0pt'>SWT.BORDER</span></b>
will cause a <i style='mso-bidi-font-style:normal'>Canvas</i> to have a border.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Next we need to
initialize our widget. The convention in SWT is to do all initialization in the
constructor. Certainly, any initialization that requires the parent or the
style bits must be done here. We have decided that our <i style='mso-bidi-font-style:
normal'>PictureLabel</i> widget will default to a white background, so we need
to add a <i style='mso-bidi-font-style:normal'>Color</i> field, allocate a <i
style='mso-bidi-font-style:normal'>Color</i>, and initialize the background.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>class</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> PictureLabel </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>extends</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Canvas {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Image image;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>String text;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Color white;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>PictureLabel(Composite parent, </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>int</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
style) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>super</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>(parent, style);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>white = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Color(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 255, 255, 255);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>setBackground(white);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Colors are graphics
resources that must be disposed. How can we dispose of the white color that we
allocated? We add a dispose listener. Every widget provides notification when
it is destroyed. We add the dispose listener in the constructor.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>addDisposeListener(</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
DisposeListener() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
widgetDisposed(DisposeEvent e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
4'>                </span>white.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>});<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><b
style='mso-bidi-font-weight:normal'>Note:</b> Do not just override dispose() to
release the color. This only works in the case where dispose is actually sent
to the widget. When the shell is disposed this does not happen, so overriding
dispose will leak the color. To ensure that your widget is informed of an event
no matter how it was generated, add an event listener instead of overriding
methods that generate events. </p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Our widget is
created and initialized, and it can be destroyed without leaking graphics
resources. Now it needs some functionality. We need to draw the image and the
text, and this will require another listener: the paint listener. Implementing
a widget often requires adding many listeners. We could implement the listener
interfaces as part of our new widget class, but that would make the interface
methods public in our class. Instead, the SWT convention is to use anonymous inner
classes to forward the functionality to non-public methods of the same name.
For consistency, we will rewrite the dispose listener to follow this
convention, moving the color dispose code into the <b style='mso-bidi-font-weight:
normal'>widgetDisposed</b> method. We write the paint listener the same way.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>addDisposeListener(</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
DisposeListener() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
widgetDisposed(DisposeEvent e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
4'>            </span>PictureLabel.</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>this</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>.widgetDisposed(e);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>});<span style='mso-tab-count:1'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>addPaintListener(</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
PaintListener() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> paintControl(PaintEvent e)
{<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
4'>            </span>PictureLabel.</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>this</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>.paintControl(e);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>});<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>By choosing the
same names, we have the option of easily implementing the interfaces if we
decide to do so later. Here is the <b style='mso-bidi-font-weight:normal'>paintControl</b>
method to draw the widget.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> paintControl(PaintEvent e)
{<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>GC gc = e.gc;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> x = 1;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (image != </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>gc.drawImage(image, x, 1); <o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>x = image.getBounds().width + 5;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (text != </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>gc.drawString(text, x, 1);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<span style='mso-tab-count:1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p style='margin-top:0in;margin-right:0in;margin-bottom:0in;margin-left:25.5pt;
margin-bottom:.0001pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Now we can draw the
image and the text, but we need to let the user set them. So we write set and
get methods for each of them.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Image getImage() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> image;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> setImage(Image image) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>.image = image;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>redraw();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> String getText() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> text;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> setText(String text) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>.text = text;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>redraw();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>The get methods are
trivial. They simply answer the fields. The set methods set the fields and then
redraw the widget to show the change. The easiest way to do this is to damage
the widget by calling <b style='mso-bidi-font-weight:normal'>redraw()</b>,
which queues a paint event for the widget. This approach has the advantage that
setting both the image and the text will cause only one paint event because
multiple paints are collapsed in the event queue.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>We are not done
yet. Our widget does not know its preferred size. This information is needed in
order to lay out the widget. In our case, the best size is simply the size of
the text plus the size of the image, plus a little bit of space in between.
Also, we will add a 1 pixel margin all the way around.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>To return the
preferred size of the widget, we must implement the <b style='mso-bidi-font-weight:
normal'>computeSize</b> method. The <b style='mso-bidi-font-weight:normal'>computeSize</b>
method can be quite complicated. Its job is to calculate the preferred size of
the widget based on the current contents. The simplest implementation ignores
the arguments and just computes the size.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Point computeSize(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> wHint, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> hHint, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>boolean</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> changed) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> width = 0, height = 0;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (image != </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>Rectangle bounds = image.getBounds();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>width = bounds.width + 5;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>height = bounds.height;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (text != </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>GC gc = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
GC(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>Point extent = gc.stringExtent(text);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>gc.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>width += extent.x;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>height = Math.max(height, extent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Point(width + 2, height +
2);<span style='mso-tab-count:1'>     </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>What are <b
style='mso-bidi-font-weight:normal'>wHint</b>, <b style='mso-bidi-font-weight:
normal'>hHint</b>, and <b style='mso-bidi-font-weight:normal'>changed</b>? The
hint arguments allow you to ask a widget questions such as “Given a particular
width, how high does the widget need to be to show all of the contents”? For
example, a word-wrapping <i style='mso-bidi-font-style:normal'>Label</i> widget
might be asked this. To indicate that the client does not care about a
particular hint, the special value <b style='mso-bidi-font-weight:normal'><span
style='font-size:10.0pt'>SWT.DEFAULT</span></b> is used. The following example
asks a label for its preferred size given a width of 100 pixels: </p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Point extent = label.computeSize(100, </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>For our <i
style='mso-bidi-font-style:normal'>PictureLabel</i> widget, we could be fancy
and stack the image over the text when the width is too small, and/or wrap the text
in order to meet a width request, but for simplicity we have decided not to do
so. Still, we need to honour the hints. So, our widget will clip. The easiest
way to do this is to perform the calculation and then filter the results.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Point computeSize(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> wHint, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> hHint, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>boolean</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> changed) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> width = 0, height = 0;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (image != </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>Rectangle bounds = image.getBounds();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>width = bounds.width + 5;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>height = bounds.height;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (text != </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>GC gc = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
GC(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>Point extent = gc.stringExtent(text);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>gc.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>width += extent.x;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>height = Math.max(height, extent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (wHint != </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) width = wHint;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (hHint != </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) height = hHint;<span
style='mso-tab-count:2'>          </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Point(width + 2, height +
2);<span style='mso-tab-count:1'>     </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Notice that we do
not return the hint sizes exactly as specified. We have added the 1-pixel
border. Why do we do this? All widgets have a <i style='mso-bidi-font-style:
normal'>client area</i> and <i style='mso-bidi-font-style:normal'>trim</i>. The
hint parameters specify the desired size of the client area. We must set the
size of the widget so that the size of the client area is the same as the hint,
so the size we return from <b style='mso-bidi-font-weight:normal'>computeSize</b>
must include the trim.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>What about the <b
style='mso-bidi-font-weight:normal'>changed</b> flag? This is used in
conjunction with SWT layout managers and is ignored for basic widgets. This
will be discussed when we talk about compound widgets.</p>
<span style='font-size:18.0pt;font-family:Arial;mso-fareast-font-family:"Times New Roman";
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;
mso-bidi-font-weight:bold'><br clear=all style='page-break-before:always'>
</span>
<h2 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc496069424"></a><a
name="_Toc496069781"></a><a name="_Ref506190201"></a><a name="_Toc506634627"><span
style='mso-bookmark:_Ref506190201'><span style='mso-bookmark:_Toc496069781'><span
style='mso-bookmark:_Toc496069424'>Compound Widget Example</span></span></span></a></h2>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Now we will recode
the <i style='mso-bidi-font-style:normal'>PictureLabel</i> widget as a compound
widget. Note that this section assumes that you have read the basic widget
example section. This time the widget will be implemented using two <i
style='mso-bidi-font-style:normal'>Label</i> children: one to display the
image, and one to display the text. Since we are using other widgets to
implement our widget, we subclass <i style='mso-bidi-font-style:normal'>Composite</i>.</p>
<p class=Code style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>class</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> PictureLabel </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>extends</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Composite {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Label image, text;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Color white;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>PictureLabel(Composite parent, </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>int</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
style) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>super</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>(parent, style);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>white = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Color(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 255, 255, 255);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>image = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Label(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 0);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>text = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Label(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 0);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>setBackground(white);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>image.setBackground(white);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>text.setBackground(white);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>addDisposeListener(</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
DisposeListener() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
widgetDisposed(DisposeEvent e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
4'>            </span>PictureLabel.</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>this</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>.widgetDisposed(e);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>});<span style='mso-tab-count:1'> </span><o:p></o:p></span></p>
<p class=Code style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>As well as
initializing the graphics resources in the constructor, we need to create the child
widgets and set their background color. A common mistake is to create the child
widgets as children of the parent. This would make them peers of our widget.
Instead, make sure to create them as children of <b style='mso-bidi-font-weight:
normal'>this</b>. The dispose listener frees the color, as before.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Now that we have
handled creation and destruction, we need to lay out the children. There are
two possibilities:</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>position the children when the widget is resized</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>use a layout manager</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>We will implement
both here for comparison.</p>
<h3 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc496069425"></a><a
name="_Toc496069782"></a><a name="_Toc506634628"><span style='mso-bookmark:
_Toc496069782'><span style='mso-bookmark:_Toc496069425'>Positioning Children on
Resize</span></span></a></h3>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>First, we will
position the children when the widget is resized. We need to add a resize
listener.</p>
<p class=Code style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>addControlListener(</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
ControlAdapter() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
controlResized(ControlEvent e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
4'>            </span>PictureLabel.</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>this</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>.controlResized(e);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>});<span style='mso-tab-count:1'> </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman"'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
controlResized(ControlEvent e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Point iExtent = image.computeSize(</span><span style='font-size:
8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:black'>SWT.DEFAULT</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black'>, </span><span style='font-size:8.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Point tExtent = text.computeSize(</span><span style='font-size:
8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:black'>SWT.DEFAULT</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black'>, </span><span style='font-size:8.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>image.setBounds(1, 1, iExtent.x, iExtent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>text.setBounds(iExtent.x + 5, 1, tExtent.x, tExtent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=Code style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>When the widget is
resized, we compute the size of each of our children, and then use their
extents and our 5-pixel spacing and 1-pixel margin to position the children
using <b style='mso-bidi-font-weight:normal'>setBounds</b>.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Now we will write
the set and get methods. Because we are not drawing the image and text,
damaging the widget will not cause the correct behavior. The children must be
resized to show their new contents. To do this, we will take the code from the
resize listener and move it into a helper method called <b style='mso-bidi-font-weight:
normal'>resize</b>.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
controlResized(ControlEvent e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>resize();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> resize() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Point iExtent = image.computeSize(</span><span style='font-size:
8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:black'>SWT.DEFAULT</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black'>, </span><span style='font-size:8.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Point tExtent = text.computeSize(</span><span style='font-size:
8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:black'>SWT.DEFAULT</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black'>, </span><span style='font-size:8.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>image.setBounds(1, 1, iExtent.x, iExtent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>text.setBounds(iExtent.x + 5, 1, tExtent.x, tExtent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Here are the set
and get methods.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Image getImage() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> image.getImage();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> setImage(Image image) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>.image.setImage(image);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>resize();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> String getText() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> text.getText();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> setText(String text) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>.text.setText(text);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>resize();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p style='margin-top:0in;margin-right:0in;margin-bottom:0in;margin-left:25.5pt;
margin-bottom:.0001pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Now we have to
implement the <b style='mso-bidi-font-weight:normal'>computeSize</b> method. This
is a simple matter of asking the children for their preferred sizes.</p>
<p style='margin-top:0in;margin-right:0in;margin-bottom:0in;margin-left:25.5pt;
margin-bottom:.0001pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Point computeSize(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> wHint, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> hHint, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>boolean</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> changed) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Point iExtent = image.computeSize(</span><span style='font-size:
8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:black'>SWT.DEFAULT</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black'>, </span><span style='font-size:8.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Point tExtent = text.computeSize(</span><span style='font-size:
8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:black'>SWT.DEFAULT</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black'>, </span><span style='font-size:8.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> width = iExtent.x + 5 +
tExtent.x;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> height =
Math.max(iExtent.y, tExtent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (wHint != </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) width = wHint;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (hHint != </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) height = hHint;<span
style='mso-tab-count:2'>          </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Point(width + 2, height +
2);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<h3 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc496069426"></a><a
name="_Toc496069783"></a><a name="_Toc506634629"><span style='mso-bookmark:
_Toc496069783'><span style='mso-bookmark:_Toc496069426'>Positioning Children
With a Layout Manager</span></span></a></h3>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Now we will rewrite
our compound widget example using a layout manager to position our widgetÂ’s
children. We could just use an existing SWT layout manager - <i
style='mso-bidi-font-style:normal'>RowLayout</i> - to position the children,
but we promised to explain the <b style='mso-bidi-font-weight:normal'>changed</b>
parameter in the <b style='mso-bidi-font-weight:normal'>computeSize</b> method.
This also gives an example of how this might be done for more complicated
layout requirements. In the code that follows, the class <i style='mso-bidi-font-style:
normal'>PictureLabelLayout</i> extends <i style='mso-bidi-font-style:normal'>Layout</i>,
and the rewritten <i style='mso-bidi-font-style:normal'>PictureLabel</i> class
is listed in its entirety.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>The layout manager
is set into the widget with the following line of code in the widget
constructor:</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>setLayout(</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
PictureLabelLayout());<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>We will call the
layout manager in the widgetÂ’s two <b style='mso-bidi-font-weight:normal'>set</b>
methods, with the following line of code:</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>layout(</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>true</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>The parameter to
the <b style='mso-bidi-font-weight:normal'>layout</b> method is the <b
style='mso-bidi-font-weight:normal'>changed</b> flag. If <b style='mso-bidi-font-weight:
normal'>true</b>, it indicates that the widget contents have changed (as is the
case in the two <b style='mso-bidi-font-weight:normal'>set </b>methods),
therefore any caches that the layout manager may have been keeping need to be
flushed. When the widget is resized, the SWT system sends <b style='mso-bidi-font-weight:
normal'>layout(false)</b> to the layout manager, so caches do not need to be
flushed. This lets the layout manager perform any expensive calculations only
when necessary.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>In class <i
style='mso-bidi-font-style:normal'>PictureLabelLayout</i>, we know that <b
style='mso-bidi-font-weight:normal'>composite.getChildren()</b> will always
return exactly two children. In general, a layout manager will have to handle
any number of children, so if you are implementing a widget that can have an
arbitrary number of children you will need to loop through them to do your
calculations. Note that it is in this class that we check the value of the <b
style='mso-bidi-font-weight:normal'>changed</b> flag and optionally flush our
two “extent” caches.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Notice that the <i
style='mso-bidi-font-style:normal'>PictureLabel</i> class has been simplified
by using a layout manager. The code in <b style='mso-bidi-font-weight:normal'>computeSize</b>
and <b style='mso-bidi-font-weight:normal'>resize</b> has been moved to the <i
style='mso-bidi-font-style:normal'>PictureLabelLayout</i> class, and the resize
listener is no longer needed.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> org.eclipse.swt.*;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
org.eclipse.swt.graphics.*;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> org.eclipse.swt.widgets.*;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> org.eclipse.swt.events.*;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>class</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> PictureLabelLayout </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>extends</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Layout {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Point iExtent, tExtent; </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:maroon;layout-grid-mode:line'>// the cached sizes</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>protected</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Point
computeSize(Composite composite, </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>int</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
wHint, </span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> hHint,<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>boolean</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> changed) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Control [] children = composite.getChildren();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (changed || iExtent == </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> || tExtent == </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>iExtent = children[0].computeSize(</span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>tExtent = children[1].computeSize(</span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> width = iExtent.x + 5 +
tExtent.x;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> height = Math.max(iExtent.y,
tExtent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Point(width + 2, height +
2);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>protected</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> layout(Composite
composite, </span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>boolean</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> changed) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Control [] children = composite.getChildren();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (changed || iExtent == </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> || tExtent == </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>iExtent = children[0].computeSize(</span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>tExtent = children[1].computeSize(</span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:8.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>SWT.DEFAULT</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>false</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>children[0].setBounds(1, 1, iExtent.x, iExtent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>children[1].setBounds(iExtent.x + 5, 1, tExtent.x, tExtent.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>class</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> PictureLabel </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>extends</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Composite {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Label image, text;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>Color white;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>PictureLabel(Composite parent, </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>int</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
style) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>super</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>(parent, style);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>white = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Color(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 255, 255, 255);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>image = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Label(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 0);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>text = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Label(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 0);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>setBackground(white);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>text.setBackground(white);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>image.setBackground(white);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>addDisposeListener(</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
DisposeListener() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
widgetDisposed(DisposeEvent e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
4'>            </span>PictureLabel.</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>this</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>.widgetDisposed(e);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>});<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>setLayout(</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'> PictureLabelLayout());<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
widgetDisposed(DisposeEvent e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>white.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> Image getImage() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> image.getImage();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> setImage(Image image) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>.image.setImage(image);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>layout(</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>true</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> String getText() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>return</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> text.getText();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> setText(String text) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>.text.setText(text);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>layout(</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>true</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>}<o:p></o:p></span></p>
<span style='font-size:18.0pt;font-family:Arial;mso-fareast-font-family:"Times New Roman";
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;
mso-bidi-font-weight:bold'><br clear=all style='page-break-before:always'>
</span>
<h2 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc506634630">Events and
Listeners</a></h2>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Often, you will
want a new widget to support an event. For example, you may want your widget to
notify listeners when the user selects it. Or you may have an editable widget
that should notify listeners when its value has changed.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>The details to
implement an event called <i style='mso-bidi-font-style:normal'>AnEvent</i> are
<b style='mso-bidi-font-weight:normal'><i style='mso-bidi-font-style:normal'>exactly</i></b>
the same as implementing a Java Bean listener:</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>create a class called <i style='mso-bidi-font-style:
normal'>AnEvent </i>which extends <i style='mso-bidi-font-style:normal'>java.util.EventObject</i>
and may have additional fields related to the event. Usually you want to
provide get methods for event fields, but you do not always want to provide set
methods. Fields are typically set in the constructor.</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>create a class called <i style='mso-bidi-font-style:
normal'>AnEventListener </i>which implements the <i style='mso-bidi-font-style:
normal'>java.util.EventListener </i>interface and provides a method called,
say, <b style='mso-bidi-font-weight:normal'>anEventHappened(AnEvent event)</b></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>keep a <i style='mso-bidi-font-style:normal'>Vector</i>
(or some other collection) of <i style='mso-bidi-font-style:normal'>AnEventListener</i>Â’s
in your widget class</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>implement <b style='mso-bidi-font-weight:normal'>addAnEventListener</b>
which adds the specified listener to the <i style='mso-bidi-font-style:normal'>Vector</i></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>implement <b style='mso-bidi-font-weight:normal'>removeAnEventListener</b>
to remove the specified listener from the <i style='mso-bidi-font-style:normal'>Vector</i></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>determine when the event happens in your widget
(possibly by adding listeners to your widget) and when it does:</p>
<p class=MsoNormal style='margin-left:61.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>create an instance of <i style='mso-bidi-font-style:
normal'>AnEvent</i> called <b style='mso-bidi-font-weight:normal'>event</b>,
initialized as appropriate</p>
<p class=MsoNormal style='margin-left:61.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>send <b style='mso-bidi-font-weight:normal'>anEventHappened(event)</b>
to each of the <i style='mso-bidi-font-style:normal'>AnEventListener</i>Â’s in
the <i style='mso-bidi-font-style:normal'>Vector</i></p>
<p class=MsoNormal style='margin-left:25.5pt'><b style='mso-bidi-font-weight:
normal'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Say we want <i
style='mso-bidi-font-style:normal'>PictureLabel</i> widgets to notify listeners
when the user clicks the left mouse button in the image. We create class <i
style='mso-bidi-font-style:normal'>ImageClickedEvent</i> with <b
style='mso-bidi-font-weight:normal'>x</b> and <b style='mso-bidi-font-weight:
normal'>y</b> fields, and interface <i style='mso-bidi-font-style:normal'>ImageClickedListener</i>
with method <b style='mso-bidi-font-weight:normal'>imageClicked(ImageClickedEvent
event)</b>. </p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>class</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
ImageClickedEvent </span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy;
layout-grid-mode:line'>extends</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> java.util.EventObject {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>public</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> x, y;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>public</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> ImageClickedEvent(Object source, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> x, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>int</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> y) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>super</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'>(source);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>this</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'>.x = x;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>this</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'>.y = y;<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>interface</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
ImageClickedListener </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>extends</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> java.util.EventListener {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>public</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>void</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> imageClicked(ImageClickedEvent event);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>We add a <i
style='mso-bidi-font-style:normal'>Vector</i> to <i style='mso-bidi-font-style:
normal'>PictureLabel</i> to store the listeners:</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>Vector imageClickedListeners = </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Vector();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman"'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>public</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>void</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'>
addImageClickedListener(ImageClickedListener listener) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>imageClickedListeners.addElement(listener);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>public</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>void</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> removeImageClickedListener(ImageClickedListener
listener) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>imageClickedListeners.removeElement(listener);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Finally, in <i
style='mso-bidi-font-style:normal'>PictureLabel</i>Â’s constructor, we add a
mouse listener to the image <i style='mso-bidi-font-style:normal'>Label</i>
widget, which does the work of notifying the listeners when the left mouse
button is clicked over the image.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>…<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>addMouseListener(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
MouseAdapter() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>public</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>void</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> mouseDown(MouseEvent event) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>if</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (event.button == 1) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:5'>                </span>PictureLabel.</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>this</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>.mouseDown(event);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>});<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>public</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>void</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> mouseDown(MouseEvent event) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>ImageClickedEvent e = </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
ImageClickedEvent(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy;
layout-grid-mode:line'>this</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'>, event.x, event.y);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> size = imageClickedListeners.size();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>for</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> i = 0; i &lt; size; i++) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>ImageClickedListener listener =<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span>(ImageClickedListener) imageClickedListeners.elementAt(i);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>listener.imageClicked(e);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></p>
<span style='font-size:18.0pt;font-family:Arial;mso-fareast-font-family:"Times New Roman";
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;
mso-bidi-font-weight:bold'><br clear=all style='page-break-before:always'>
</span>
<h2 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc496069427"></a><a
name="_Toc496069784"></a><a name="_Toc506634631"><span style='mso-bookmark:
_Toc496069784'><span style='mso-bookmark:_Toc496069427'>Sample Application</span></span></a></h2>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Now we will use the
new widget in an example application. The application simply creates a shell
with a <i style='mso-bidi-font-style:normal'>PictureLabel</i> child. Then it
sets the <i style='mso-bidi-font-style:normal'>PictureLabel</i>Â’s image to a
little red square, and text to “Hi there!”. There is no <i style='mso-bidi-font-style:
normal'>Layout</i> manager for the shell, so we will set the <i
style='mso-bidi-font-style:normal'>PictureLabel</i>Â’s size. When the image is
clicked, we change the text to “Red!”.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Here is the
application code:</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> org.eclipse.swt.graphics.*;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:maroon'><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>import</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> org.eclipse.swt.widgets.*;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:maroon'><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>class</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> PictureLabelExample {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>static</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> main(String [] args) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Image image = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Image(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 20, 20);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Color red = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Color(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>null</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>, 255, 0, 0);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>GC gc = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
GC(image);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>gc.setBackground(red);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>gc.fillRectangle(image.getBounds());<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>gc.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>red.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Shell shell = </span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
Shell();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>PictureLabel label = </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy'>new</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black'>
PictureLabel(shell, 0);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>label.setImage(image);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>label.setText(</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:teal'>&quot;Hi there!&quot;</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>label.setSize(size);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>label.addImageClickedListener(new ImageClickedListener() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy;
layout-grid-mode:line'>public</span><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>void</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> imageClicked(ImageClickedEvent event) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span>((PictureLabel) event.getSource()).</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>setText(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal'>&quot;Red!&quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>);<span style='layout-grid-mode:
line'><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>});</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black'><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>shell.open();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>Display display = shell.getDisplay();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>while</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'> (!shell.isDisposed()) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
3'>         </span></span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:navy'>if</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>
(!display.readAndDispatch()) display.sleep();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
2'>     </span>image.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'><span style='mso-tab-count:
1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>And here is what
you see when you run it:</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<div style='mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:
auto;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:column;
mso-element-top:.05pt;mso-height-rule:exactly'>
<table cellspacing=0 cellpadding=0 hspace=0 vspace=0>
<tr>
<td valign=top align=left style='padding-top:0in;padding-right:9.0pt;
padding-bottom:0in;padding-left:9.0pt'>
<p class=MsoNormal align=center style='margin-left:25.5pt;text-align:center;
mso-list:skip;mso-element:frame;mso-element-frame-hspace:9.0pt;mso-element-wrap:
auto;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:
column;mso-element-top:.05pt;mso-height-rule:exactly'><span style='font-size:
10.0pt'><!--[if gte vml 1]><v:shape id="_x0000_i1046" type="#_x0000_t75"
style='width:99.75pt;height:82.5pt' fillcolor="window">
<v:imagedata src="./Writing%20Your%20Own%20Widget_files/image003.png"
o:title=""/>
</v:shape><![endif]--><![if !vml]><img width=133 height=110
src="./Writing%20Your%20Own%20Widget_files/image004.jpg" v:shapes="_x0000_i1046"><![endif]></span></p>
</td>
</tr>
</table>
</div>
<p class=MsoNormal align=center style='margin-left:25.5pt;text-align:center;
mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal align=center style='margin-left:25.5pt;text-align:center;
mso-list:skip'><b style='mso-bidi-font-weight:normal'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><b
style='mso-bidi-font-weight:normal'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></p>
<p class=MsoNormal align=center style='margin-left:25.5pt;text-align:center;
mso-list:skip'><b style='mso-bidi-font-weight:normal'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></p>
<p class=MsoNormal align=center style='margin-left:25.5pt;text-align:center;
mso-list:skip'><b style='mso-bidi-font-weight:normal'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></p>
<p class=MsoNormal align=center style='margin-left:25.5pt;text-align:center;
mso-list:skip'><b style='mso-bidi-font-weight:normal'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></p>
<p class=MsoNormal align=center style='margin-left:25.5pt;text-align:center;
mso-list:skip'><b style='mso-bidi-font-weight:normal'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></b></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><b
style='mso-bidi-font-weight:normal'>A PictureLabel in a Shell<o:p></o:p></b></p>
<h2 style='margin-left:25.5pt;mso-list:skip'><a name="_Ref498250831"></a><a
name="_Toc506634632"><span style='mso-bookmark:_Ref498250831'>Advanced Issues</span></a></h2>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>We have discussed
the basics of creating a custom widget: subclassing <i style='mso-bidi-font-style:
normal'>Canvas</i> or <i style='mso-bidi-font-style:normal'>Composite</i>,
creating and initializing, setting and getting the widgetÂ’s resources, drawing,
disposing graphics resources, size and layout, and providing events and listeners.
There are some advanced issues that you may need to deal with when you
implement a new widget.</p>
<h3 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc506634633">SWT Event
Mechanism</a></h3>
<p class=MsoNormal style='margin-left:25.5pt'>SWT provides a low-level listener
mechanism as well as the usual Java ‘typed’ listeners. Every SWT widget
understands <b style='mso-bidi-font-weight:normal'>addListener(int eventType,
Listener listener)</b> and <b style='mso-bidi-font-weight:normal'>notifyListeners(int
eventType, Event event)</b>. The <b style='mso-bidi-font-weight:normal'>eventType</b>
constants are defined in class <i style='mso-bidi-font-style:normal'>SWT</i>.
When an event occurs, the widget creates an SWT <i style='mso-bidi-font-style:
normal'>Event</i> object containing the appropriate type constant. The <b
style='mso-bidi-font-weight:normal'>notifyListeners </b>method<b
style='mso-bidi-font-weight:normal'> </b>calls <b style='mso-bidi-font-weight:
normal'>handleEvent(Event event)</b> for the <i style='mso-bidi-font-style:
normal'>Listener</i>. If you need to reuse an existing SWT event, you would
typically use this mechanism.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>For example, if your widget
implements a selection event, you could implement your ‘typed’ add and remove
methods as follows:</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
addSelectionListener(SelectionListener listener) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>addListener(SWT.Selection, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
TypedListener(listener));<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
removeSelectionListener(SelectionListener listener) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>removeListener(SWT.Selection, listener);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><br>
When the ‘selection event’ occurs in your widget (say, when <b
style='mso-bidi-font-weight:normal'>child1</b> is selected), you notify the
applicationÂ’s selection listeners using <b style='mso-bidi-font-weight:normal'>notifyListeners</b>.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>child1.addListener(SWT.Selection, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Listener() {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>public</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>void</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> handleEvent(Event e) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>notifyListeners(SWT.Selection, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Event());<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>});<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>Note that when we add the
listener we first wrap it in a <i style='mso-bidi-font-style:normal'>TypedListener</i>.
This is because<i style='mso-bidi-font-style:normal'> TypedListener</i>Â’s <b
style='mso-bidi-font-weight:normal'>handleEvent(Event event)</b> method creates
the appropriate <i style='mso-bidi-font-style:normal'>TypedEvent</i> subclass
based on the type in the <i style='mso-bidi-font-style:normal'>Event</i>, and
then calls the appropriate method for the typed event. In this way,
applications can add Java typed listeners to widgets, but widget
implementations can use the more efficient low-level listener mechanism. Make
sure that your widget implementation provides a typed listener API, however.
Applications should not be calling low-level listener methods. The typed
listener methods prevent accidental programming errors such as assuming that
all widgets can handle all types of event, or that all fields in the <i
style='mso-bidi-font-style:normal'>Event</i> class are valid for all events.</p>
<span style='font-size:14.0pt;font-family:Arial;mso-fareast-font-family:"Times New Roman";
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;
mso-bidi-font-weight:bold'><br clear=all style='page-break-before:always'>
</span>
<h3 style='margin-left:25.5pt;mso-list:skip'><a name="_Toc506634634"><span
style="mso-spacerun: yes"> </span>Wrapping an SWT Widget</a></h3>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Occasionally, you
may find that the best way to implement a new widget is by wrapping an existing
SWT widget. For example, to implement a <i style='mso-bidi-font-style:normal'>TableTree</i>,
you might want to use a <i style='mso-bidi-font-style:normal'>Table</i>. To do
this, create <i style='mso-bidi-font-style:normal'>TableTree</i> as a subclass
of <i style='mso-bidi-font-style:normal'>Composite</i>, and then in the <i
style='mso-bidi-font-style:normal'>TableTree</i> constructor create a <i
style='mso-bidi-font-style:normal'>Table</i> child. The resulting widget will
be 100% Java portable because you call the wrapped widgetÂ’s API.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>Here are some
guidelines for wrapping SWT widgets:</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Forward as few methods and events as possible. Do not
fall into the trap of automatically reimplementing the complete API of the
wrapped widget. This will cause lots of boilerplate code and leave you playing
catch up when new API is added to the wrapped widget. If you find that you are
automatically forwarding every method, then it <i style='mso-bidi-font-style:
normal'>might</i> make more sense to implement your code as an ‘adaptor’ (i.e.
as a set of listeners that are added to the unwrapped widget when the widget is
created).</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Typically the methods you forward will be <b
style='mso-bidi-font-weight:normal'>setFont</b>, <b style='mso-bidi-font-weight:
normal'>setForeground</b>, <b style='mso-bidi-font-weight:normal'>setBackground</b>,
<b style='mso-bidi-font-weight:normal'>setCursor</b>,<b style='mso-bidi-font-weight:
normal'> setEnabled</b>, <b style='mso-bidi-font-weight:normal'>setMenu</b>,
and<b style='mso-bidi-font-weight:normal'> setToolTipText</b>. A typical
forwarding method calls super to set the value for the parent, and then sets
the value for the wrapped widget. You do not usually need to reimplement the
corresponding get methods – these return the value from the parent.</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Do not reimplement <b style='mso-bidi-font-weight:normal'>setData</b>
or <b style='mso-bidi-font-weight:normal'>getData</b> – your widget users can
use the data field in the parent.</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Consider exposing the wrapped widget – it does not
necessarily need to be hidden.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>A complete example
of a <i style='mso-bidi-font-style:normal'>TableTree</i> widget that was
implemented by wrapping a <i style='mso-bidi-font-style:normal'>Table</i> is
provided in <a href="Writing%20Your%20Own%20Widget_files/AppendixA.htm">Appendix
A: TableTree and TableTreeItem</a>. This example also shows how <i
style='mso-bidi-font-style:normal'>TableTreeItem</i> was implemented by
subclassing <i style='mso-bidi-font-style:normal'>Item</i> and wrapping a <i
style='mso-bidi-font-style:normal'>TableItem</i>. Some of the design decisions
that were made are:</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>Wrap
a <i style='mso-bidi-font-style:normal'>Table</i> widget</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>Column
0 of the <i style='mso-bidi-font-style:normal'>Table</i> widget will contain
the ‘tree’ representation</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>The
image in column 0 will contain a [+] or [-] to show the expanded state of the
tree</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>Because
we are using a <i style='mso-bidi-font-style:normal'>Table</i>, we need to use <i
style='mso-bidi-font-style:normal'>TableColumn</i> and <i style='mso-bidi-font-style:
normal'>TableItem</i> classes</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>Use <i
style='mso-bidi-font-style:normal'>TableColumn</i> class directly – we do not
need to wrap it</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>Wrap <i
style='mso-bidi-font-style:normal'>TableItem</i> to store the expanded state
and to enforce the column 0 restrictions</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>Implement
some of the <i style='mso-bidi-font-style:normal'>Tree</i> and <i
style='mso-bidi-font-style:normal'>TreeItem</i> API methods that make sense for
<i style='mso-bidi-font-style:normal'>TableTree</i> and <i style='mso-bidi-font-style:
normal'>TableTreeItem</i></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>Expose
the fact that we are wrapping a <i style='mso-bidi-font-style:normal'>Table</i>
by providing a <b style='mso-bidi-font-weight:normal'>getTable()</b> method on <i
style='mso-bidi-font-style:normal'>TableTree</i>. This simplifies our
implementation significantly because the user can create columns and show
headers and grid lines by going directly to the <i style='mso-bidi-font-style:
normal'>Table</i>.</p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l2 level1 lfo4;
tab-stops:list .25in'><![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]>Reimplement
common API methods like <b style='mso-bidi-font-weight:normal'>setFont</b> for
convenience</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'>The following page
shows an example three-column <i style='mso-bidi-font-style:normal'>TableTree</i>,
and the application code that created it. The full source listing for <i
style='mso-bidi-font-style:normal'>TableTree</i> and <i style='mso-bidi-font-style:
normal'>TableTreeItem</i> is in <a
href="Writing%20Your%20Own%20Widget_files/AppendixA.htm">Appendix A: TableTree
and TableTreeItem</a>.</p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><!--[if gte vml 1]><o:wrapblock><v:shape
id="_x0000_s1027" type="#_x0000_t75" style='position:absolute;left:0;
text-align:left;margin-left:0;margin-top:0;width:246pt;height:170.25pt;
z-index:1;mso-position-horizontal-relative:text;
mso-position-vertical-relative:text' o:allowincell="f">
<v:imagedata src="./Writing%20Your%20Own%20Widget_files/image005.png"
o:title=""/>
<w:wrap type="topAndBottom" anchorx="page"/>
</v:shape><![endif]--><![if !vml]><img width=328 height=227
src="./Writing%20Your%20Own%20Widget_files/image006.jpg" v:shapes="_x0000_s1027"><![endif]><!--[if gte vml 1]></o:wrapblock><![endif]--><br
style='mso-ignore:vglayout' clear=ALL>
<![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<br style='mso-ignore:vglayout' clear=ALL>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><b
style='mso-bidi-font-weight:normal'>A TableTree in a Shell<o:p></o:p></b></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>public</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>static</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>void</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
main(String [] args) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>Shell shell = </span><span style='font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Shell();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>Image image = </span><span style='font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Image(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:
line'>null</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black;
layout-grid-mode:line'>, 20, 20);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>Color red = </span><span style='font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Color(</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:
line'>null</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;
font-family:"Courier New";mso-bidi-font-family:"Times New Roman";color:black;
layout-grid-mode:line'>, 255, 0, 0);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>GC gc = </span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>new</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> GC(image);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>gc.setBackground(red);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>gc.fillRectangle(image.getBounds());<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>gc.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>red.dispose();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>TableTree tableTree = </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
TableTree(shell, SWT.BORDER);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>tableTree.setSize(320, 200);</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:maroon;layout-grid-mode:line'><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>Table table = tableTree.getTable();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>table.setHeaderVisible(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>true</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>table.setLinesVisible(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>true</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>for</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> col = 0; col &lt; 3; col++) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>TableColumn column = </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> TableColumn(table,
SWT.NONE, col);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>column.setText(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;Column
&quot;</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:
line'> + col);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>column.setWidth(100);</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:maroon;layout-grid-mode:line'><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>for</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> iRoot = 0; iRoot &lt; 8; iRoot++) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>TableTreeItem root = </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
TableTreeItem(tableTree, SWT.NONE);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>root.setText(</span><span style='font-size:
9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:
"Times New Roman";color:teal;layout-grid-mode:line'>&quot;Root &quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> +
iRoot);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>for</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> iBranch = 0; iBranch &lt; 4; iBranch++) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>TableTreeItem branch = </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
TableTreeItem(root, SWT.NONE);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>branch.setText(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;Branch
&quot;</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:
line'> + iBranch);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>for</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> col = 1; col &lt; 3; col++) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span>branch.setImage(col, image);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span>branch.setText(col, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;R&quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>+iRoot+</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;B&quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>+iBranch+</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;C&quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>+col);</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'><o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>for</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> iLeaf = 0; iLeaf &lt; 4; iLeaf++) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span>TableTreeItem leaf = </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
TableTreeItem(branch, SWT.NONE);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span>leaf.setText(</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;Leaf
&quot;</span><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Courier New";mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:
line'> + iLeaf);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>for</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>int</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> col = 1; col &lt; 3; col++) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:5'>                </span>leaf.setImage(col, image);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:5'>                </span>leaf.setText(col, </span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;R&quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>+iRoot+</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;B&quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>+iBranch+</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>&quot;L&quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>+iLeaf+</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:teal;layout-grid-mode:line'>C&quot;</span><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>+col);<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:4'>            </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:3'>         </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>shell.pack(); shell.open();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>Display display = shell.getDisplay();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>while</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (!shell.isDisposed()) {<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:2'>     </span></span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>if</span><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'> (!display.readAndDispatch())
display.sleep();<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:.25in .5in .75in 1.0in 1.25in 1.5in 1.75in 2.0in'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>}<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<h3 style='margin-left:25.5pt'><a name="_Toc506634635"></a><a
name="_Toc496069428"></a><a name="_Toc496069785"><span style='mso-bookmark:
_Toc496069428'><span style='mso-bookmark:_Toc506634635'>Subclassing Widgets
Directly</span></span></a></h3>
<p class=MsoNormal style='margin-left:25.5pt;mso-list:skip'><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'>In extreme
circumstances, you may need to subclass a widget other than <i
style='mso-bidi-font-style:normal'>Canvas</i> or <i style='mso-bidi-font-style:
normal'>Composite</i>. We recommend against doing this unless all other avenues
have been explored and exhausted. Try to wrap the widget first, before
subclassing it. Here is why:</span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Subclasses may inherit a lot of API that makes no
sense, and must be overridden. In Java, you cannot override a method and change
the return type; therefore you cannot reimplement some methods.</span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Subclassing is typically not the safest way to extend a
class that you do not own. For a simplified list of the common arguments, see
the article by <strong><span style='font-weight:normal'>Bill Venners </span></strong>in
the Nov '98 issue of <i style='mso-bidi-font-style:normal'>Java World</i>
called <i style='mso-bidi-font-style:normal'>“Inheritance versus composition:
Which one should you choose?”</i> at: </span></span><a
href="http://www.javaworld.com/javaworld/jw-11-1998/jw-11-techniques.html"><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'>http://www.javaworld.com/javaworld/jw-11-1998/jw-11-techniques.html</span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'></span></span></a><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'></span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Widget subclasses are almost certainly guaranteed to be
platform-specific unless great care is taken to ensure that they work on all
platforms.</span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Subclassed widgets can be affected by changes in the
non-API implementation of the superclass.</span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Subclassing may cause bad system-level bugs, and runs
the risk of leaking resources. For example, if a subclass reimplements a method
without making certain that dispose code from the superclass method is still
called, then the new method will leak system resources.</span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>Binary incompatibility across releases becomes
possible. If a method signature or field name changes, or new methods or fields
are added, there may be a name conflict in the widget subclass. Only <i
style='mso-bidi-font-style:normal'>Canvas</i> and <i style='mso-bidi-font-style:
normal'>Composite </i>are guaranteed not to have name conflicts in future
releases.</span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l0 level1 lfo2'><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><![if !supportLists]><span
style='font-family:Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span><![endif]>See any paper by Leonid <span style='color:black'>Mikhajlov
on the <i style='mso-bidi-font-style:normal'>“Fragile Base Class Problem”</i>.
He has a summary of this problem on his web page at: </span></span></span><a
href="http://www.abo.fi/~lmikhajl/"><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>http://www.abo.fi/~lmikhajl/</span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'></span></span></a><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Consider the example of <i style='mso-bidi-font-style:
normal'>TableTree</i>. We chose to wrap <i style='mso-bidi-font-style:normal'>Table</i>
rather than subclass it. The best test is to ask whether a <i style='mso-bidi-font-style:
normal'>TableTree</i> ‘is-a’ <i style='mso-bidi-font-style:normal'>Table</i>.
The answer is definitely not – we have simply chosen to implement <i
style='mso-bidi-font-style:normal'>TableTree</i> using <i style='mso-bidi-font-style:
normal'>Table</i>. We cannot talk about the ‘rows’ of a <i style='mso-bidi-font-style:
normal'>TableTree</i>, or index into a <i style='mso-bidi-font-style:normal'>TableTree</i>;
and the first column of the <i style='mso-bidi-font-style:normal'>Table</i> is
reserved for the ‘tree’. Many of the operations for a <i style='mso-bidi-font-style:
normal'>Table</i> do not make sense for a <i style='mso-bidi-font-style:normal'>TableTree</i>,
for example <b style='mso-bidi-font-weight:normal'>getSelectionIndex()</b> and <b
style='mso-bidi-font-weight:normal'>getTopIndex()</b>.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Subclassing <i style='mso-bidi-font-style:
normal'>Canvas</i> or <i style='mso-bidi-font-style:normal'>Composite</i> is
the best way to ensure that your widget works on all SWT platforms. The ‘is-a’
test in this case tests whether your widget is-a basic or compound widget.
Subclassing anything else requires asking if the new widget<b style='mso-bidi-font-weight:
normal'> is-an SWT native widget of the type being subclassed</b>. For example,
a 100% Java portable <i style='mso-bidi-font-style:normal'>PictureLabel</i> is
not an SWT native <i style='mso-bidi-font-style:normal'>Label</i>.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>When subclassing anything other than <i
style='mso-bidi-font-style:normal'>Composite</i> or <i style='mso-bidi-font-style:
normal'>Canvas</i> you must override the method <b style='mso-bidi-font-weight:
normal'>protected void checkSubclass()</b> to do nothing. Make sure you read
the method comment before overriding it.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><b style='mso-bidi-font-weight:normal'><span
style='font-size:14.0pt;mso-bidi-font-size:10.0pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></b></span></span></p>
<h3 style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><a name="_Toc506634636">Wrapping a Native
Widget</a></span></span></h3>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Sometimes, an application requires a native
widget that is not provided by SWT. This may be a platform widget, or a third
party widget, or any other widget in a shared library. In this section, we will
describe how to interface to a native widget on the Windows and Motif
platforms. This section assumes that you have some understanding of the <i
style='mso-bidi-font-style:normal'>Java Native Interface</i>, or <b
style='mso-bidi-font-weight:normal'>JNI</b>. Two good books on JNI are:</span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l1 level1 lfo6;
tab-stops:list .25in'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportLists]><span style='font-family:
Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]><i
style='mso-bidi-font-style:normal'>“The Java Native Interface, Programmer’s
Guide and Specification”</i> by Sheng Liang</span></span></p>
<p class=MsoNormal style='margin-left:43.5pt;text-indent:-.25in;mso-list:l1 level1 lfo6;
tab-stops:list .25in'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportLists]><span style='font-family:
Symbol'>·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span><![endif]><i
style='mso-bidi-font-style:normal'>“Essential JNI, Java Native Interface”</i>
by Rob Gordon</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>This section also assumes that you have done
some platform programming before, and are proficient in C and in the use of
makefiles. You must have platform documentation available, such as the MSDN
Library on Windows, and Motif 2.1 documentation or ‘man pages’ for your Motif
Unix/Linux system. If you are programming to a third party widget, you will
need to know its API.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>In this section, we will create a shared
library and load it using:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>System.loadLibrary(<span
style='color:teal'>&quot;mywidget&quot;</span>);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>On Windows, this loads a Dynamic Link
Library or DLL file called “mywidget.dll”.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>On Motif, this loads a Shared Object Library
or SO file called “libmywidget.so”.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>For our example, we will be building a
widget we will call <i style='mso-bidi-font-style:normal'>Spinner</i>. On
Windows, the native widget we will use is called an <i style='mso-bidi-font-style:
normal'>UpDown</i> control, and on Motif we will be using an <i
style='mso-bidi-font-style:normal'>XmSimpleSpinBox</i>. They look like this:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><!--[if gte vml 1]><o:wrapblock><v:shape
id="_x0000_s1032" type="#_x0000_t75" style='position:absolute;left:0;
text-align:left;margin-left:59.55pt;margin-top:0;width:134.25pt;height:44.25pt;
z-index:2;mso-position-horizontal:absolute;
mso-position-horizontal-relative:text;mso-position-vertical:top;
mso-position-vertical-relative:text'>
<v:imagedata src="./Writing%20Your%20Own%20Widget_files/image007.png"
o:title=""/>
<w:wrap type="topAndBottom" anchorx="page"/>
</v:shape><![if gte mso 9]><o:OLEObject Type="Embed" ProgID="PBrush"
ShapeID="_x0000_s1032" DrawAspect="Content" ObjectID="_1053168692">
</o:OLEObject>
<![endif]><![endif]--><![if !vml]><span style='mso-ignore:vglayout'>
<table cellpadding=0 cellspacing=0 align=left>
<tr>
<td width=79 height=0></td>
</tr>
<tr>
<td></td>
<td><img width=179 height=59
src="./Writing%20Your%20Own%20Widget_files/image008.jpg" v:shapes="_x0000_s1032"></td>
</tr>
</table>
</span><![endif]><!--[if gte vml 1]></o:wrapblock><![endif]--><br
style='mso-ignore:vglayout' clear=ALL>
<span style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span><p></p>
<br style='mso-ignore:vglayout' clear=ALL>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Our <i style='mso-bidi-font-style:normal'>Spinner</i>
will be numeric, and we want to be able to set and get the maximum and minimum
value, as well as the current value (which we will call the ‘selection’, to
conform to SWT convention). We also want to be able to set the font. When the
user clicks on one of the arrows, we want to notify listeners that the
selection has changed, so we will need to implement a selection listener. The
test code for our widget looks something like this (the full source listing for
class <i style='mso-bidi-font-style:normal'>SpinnerTest</i> is in </span></span><a
href="Writing%20Your%20Own%20Widget_files/AppendixB.htm"><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'>Appendix
B: SpinnerTest and Spinner</span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'></span></span></a><span style='mso-bookmark:
_Toc496069785'><span style='mso-bookmark:_Toc496069428'>):</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:1'>  </span></span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>final</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Spinner spinner = </span></span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>new</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Spinner(shell, 0);<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:1'>  </span>spinner.setMaximum(999);<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:1'>  </span>spinner.setSelection(500);<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:1'>  </span>spinner.setMinimum(100);<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:1'>  </span>Font
font = </span></span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:navy;layout-grid-mode:line'>new</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
Font(display, </span></span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:teal;layout-grid-mode:line'>&quot;Courier&quot;</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>, 20,
SWT.NORMAL);<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:1'>  </span>spinner.setFont(font);<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:1'>  </span>spinner.addSelectionListener(</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>new</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
SelectionAdapter() {<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:2'>         </span></span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>public</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'> </span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:navy;layout-grid-mode:line'>void</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";color:black;layout-grid-mode:line'>
widgetSelected(SelectionEvent e) {<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:3'>                </span>System.out.println(spinner.getSelection());<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:2'>         </span>}<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><span style='mso-tab-count:1'>  </span>});<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The next step is to write the API in Java. Since
we know we will be writing the native interface file (weÂ’ll call it
“spinner.c”) twice – once on Windows and once on Motif – we try to write the
Java code only once so that it is easier to maintain. We start by creating a
subclass of <i style='mso-bidi-font-style:normal'>Composite</i>, and we load
the shared library in a static initializer:</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:1'>  </span></span>static<span style='color:black'> {<o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:2'>     </span>System.loadLibrary(</span><span
style='color:teal'>&quot;spinner&quot;</span><span style='color:black'>);<span
style='mso-tab-count:1'> </span><o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>This will load a file called “spinner.dll”
on Windows, and “libspinner.so” on Motif. Since we know that creating a widget
returns a ‘handle’ on both platforms, we define an instance variable to hold
the handle:</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>int</span> handleSpinner;</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:9.0pt;mso-bidi-font-size:
10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
color:black;layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Since we will be providing a listener, we
know that we will need to map this handle back to the Java <i style='mso-bidi-font-style:
normal'>Spinner</i> object when the platform calls in to Java to notify us of
the event. So we create a static <i style='mso-bidi-font-style:normal'>Hashtable</i>
that will contain <i style='mso-bidi-font-style:normal'>Spinner</i> handles as
keys and <i style='mso-bidi-font-style:normal'>Spinner</i> objects as values: </span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> Hashtable table = <span style='color:navy'>new</span>
Hashtable();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Now we write the constructor. We add the
handle to the table after the widget is created, and we remove it when the
widget is destroyed. Note that we donÂ’t create the widget in Java. We will
create it later, in the native <b style='mso-bidi-font-weight:normal'>createControl</b>
method. We also forward all <b style='mso-bidi-font-weight:normal'>controlResized</b>
and <b style='mso-bidi-font-weight:normal'>focusGained</b> events to the native
<b style='mso-bidi-font-weight:normal'>resizeControl</b> and <b
style='mso-bidi-font-weight:normal'>setFocus</b> methods, and set our font to
the default font using the native <b style='mso-bidi-font-weight:normal'>setFont</b>
method. There is one more thing to explain in the constructor. You may notice
that we are actually creating two widgets: a <i style='mso-bidi-font-style:
normal'>Composite</i> parent named <b style='mso-bidi-font-weight:normal'>handle</b>
in the call to super, and a <i style='mso-bidi-font-style:normal'>Spinner</i>
child named <b style='mso-bidi-font-weight:normal'>handleSpinner</b> in the
call to <b style='mso-bidi-font-weight:normal'>createControl</b>. This wraps
the native control in an SWT parent, allowing it to participate in the SWT
system.</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> Spinner(Composite parent, <span
style='color:navy'>int</span> style) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>super</span>(parent, style);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>int</span> handleParent = handle;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='mso-tab-count:1'>   </span>handleSpinner = createControl(handleParent);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>if</span> (handleSpinner == 0)
SWT.error(SWT.ERROR_NO_HANDLES);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>table.put(<span
style='color:navy'>new</span> Integer(handleSpinner), <span style='color:navy'>this</span>);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>addDisposeListener(<span
style='color:navy'>new</span> DisposeListener() {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
widgetDisposed(DisposeEvent e) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:4'>            </span>Spinner.<span
style='color:navy'>this</span>.widgetDisposed(e);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>});</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>addControlListener(<span
style='color:navy'>new</span> ControlAdapter() {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
controlResized(ControlEvent e) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:4'>            </span>Spinner.<span
style='color:navy'>this</span>.controlResized(e);<span style='mso-tab-count:
3'>          </span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>});</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>addFocusListener(<span
style='color:navy'>new</span> FocusAdapter() {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
focusGained(FocusEvent e) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:4'>            </span>Spinner.<span
style='color:navy'>this</span>.focusGained(e);<span style='mso-tab-count:3'>          </span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>});</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>Font
font = getFont();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>setFont(handleSpinner,
font.handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span><span style='color:black'> </span><span
style='color:navy'>void</span><span style='color:black'>
widgetDisposed(DisposeEvent e) {<o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:2'>     </span>table.remove(</span><span style='color:
navy'>new</span> Integer(handleSpinner)<span style='color:black'>);<o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:2'>     </span>handleSpinner = 0;<o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:1'>  </span><o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:1'>  </span></span><span style='color:navy'>public</span><span
style='color:black'> </span><span style='color:navy'>void</span><span
style='color:black'> controlResized(ControlEvent e) {<o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:2'>     </span>Rectangle rect = getClientArea();<o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:2'>     </span>resizeControl(handleSpinner, rect.x,
rect.y, rect.width, rect.height);<span style='mso-tab-count:2'>         </span><o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:black'><span
style='mso-tab-count:1'>  </span>}<o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
focusGained(FocusEvent e) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>setFocus(handleSpinner);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:navy'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='color:navy'><span
style='mso-tab-count:1'>  </span>static</span> <span style='color:navy'>final</span>
<span style='color:navy'>native</span> <span style='color:navy'>int</span> createControl(<span
style='color:navy'>int</span> handleParent);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
resizeControl(<span style='color:navy'>int</span> handle, <span
style='color:navy'>int</span> x, <span style='color:navy'>int</span> y, <span
style='color:navy'>int</span> width, <span style='color:navy'>int</span>
height);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span> setFocus(<span
style='color:navy'>int</span> handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>We write the <b style='mso-bidi-font-weight:
normal'>setFont</b> API method to call the native <b style='mso-bidi-font-weight:
normal'>setFont</b> method with the <i style='mso-bidi-font-style:normal'>Spinner</i>
handle and the font handle. Call <b style='mso-bidi-font-weight:normal'>super.setFont</b>
because some superclasses need to set fonts for things like titles – it will
not actually be needed in this case, but by convention widgets usually inform
their superclass of font and color changes.</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
setFont(Font font) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>super</span>.setFont(font);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>int</span> hFont = 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>if</span> (font != <span style='color:navy'>null</span>)
hFont = font.handle;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>setFont(handleSpinner,
hFont);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span> setFont(<span
style='color:navy'>int</span> handle, <span style='color:navy'>int</span>
hFont);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>In a similar manner, we write the remaining
set and get API methods and declare the corresponding native methods. The <b
style='mso-bidi-font-weight:normal'>checkWidget</b> method simply checks that
the widget is still valid.</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
setSelection(<span style='color:navy'>int</span> selection) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>checkWidget();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>setPosition(handleSpinner,
selection);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>int</span> getSelection()
{</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>checkWidget();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>return</span> getPosition(handleSpinner);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
setMaximum(<span style='color:navy'>int</span> maximum) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>checkWidget();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>setMaximum(handleSpinner,
maximum);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>int</span>
getMaximum() {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>checkWidget();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>return</span> getMaximum(handleSpinner);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
setMinimum(<span style='color:navy'>int</span> minimum) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>checkWidget();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>setMinimum(handleSpinner,
minimum);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>int</span>
getMinimum() {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>checkWidget();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>return</span> getMinimum(handleSpinner);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
setPosition(<span style='color:navy'>int</span> handle, <span style='color:
navy'>int</span> position);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>int</span>
getPosition(<span style='color:navy'>int</span> handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
setMaximum(<span style='color:navy'>int</span> handle, <span style='color:navy'>int</span>
max);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>int</span>
getMaximum(<span style='color:navy'>int</span> handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
setMinimum(<span style='color:navy'>int</span> handle, <span style='color:navy'>int</span>
min);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>int</span>
getMinimum(<span style='color:navy'>int</span> handle);</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>As with all widgets we implement, we need to
provide a <b style='mso-bidi-font-weight:normal'>computeSize</b> method to
compute the preferred size of the widget. This one also forwards to a native to
do the work. In this case, the native needs to return two integers (width and
height) so we use an int array of size 2 to hold the returned values:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> Point computeSize(<span style='color:navy'>int</span>
wHint, <span style='color:navy'>int</span> hHint, <span style='color:navy'>boolean</span>
changed) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>checkWidget();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>int</span> [] result = <span style='color:navy'>new</span> <span
style='color:navy'>int</span> [2];</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>computeSize(handleSpinner,
result);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>if</span> (wHint != SWT.DEFAULT) result [0] = wHint;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>if</span> (hHint != SWT.DEFAULT) result [1] = hHint;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>int</span> border = getBorderWidth();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>return</span> <span style='color:navy'>new</span>
Point(result [0] + border * 2, result [1] + border * 2);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
computeSize(<span style='color:navy'>int</span> handle, <span style='color:
navy'>int</span> [] result);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Finally, we need to define the listener
interface. The <b style='mso-bidi-font-weight:normal'>addSelectionListener</b>
method simply adds an <b style='mso-bidi-font-weight:normal'>SWT.Selection</b>
listener using the SWT low-level listener mechanism. The <b style='mso-bidi-font-weight:
normal'>widgetSelected</b> method is special. It is the entry point into Java
when the event occurs. In other words, we will be calling this method from C.
When the method is called, it determines the <i style='mso-bidi-font-style:
normal'>Spinner</i> for the event by looking in the table, and then forwards to
the SWT event mechanism by calling <b style='mso-bidi-font-weight:normal'>notifyListeners</b>.</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>public</span> <span style='color:navy'>void</span>
addSelectionListener(SelectionListener listener) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>if</span> (listener == <span style='color:navy'>null</span>)
<span style='color:navy'>throw</span> <span style='color:navy'>new</span>
SWTError(SWT.ERROR_NULL_ARGUMENT);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>addListener(SWT.Selection,
<span style='color:navy'>new</span> TypedListener(listener));</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>void</span>
widgetSelected(<span style='color:navy'>int</span> handle) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>Spinner
spinner = (Spinner) table.get(<span style='color:navy'>new</span>
Integer(handle));</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style='color:navy'>if</span> (spinner == <span style='color:navy'>null</span>) <span
style='color:navy'>return</span>;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>spinner.notifyListeners(SWT.Selection,
<span style='color:navy'>new</span> Event());</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Notice that the <i style='mso-bidi-font-style:
normal'>Event</i> object that we create for the <i style='mso-bidi-font-style:
normal'>Spinner</i> selection listener does not need to have any fields set. If
you need to return more information for your event, such as the x and y
coordinates of the event or the key that was pressed, then your call-in method
(<b style='mso-bidi-font-weight:normal'>widgetSelected</b>, in this case) will
have to have more parameters than just the handle.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>One more thing to note before we write the C
code. All of our native methods have been defined as static methods, and all of
them have the handle passed as the first parameter. This consistency makes it
easier to write the C native code.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The full source code listing for the Java <i
style='mso-bidi-font-style:normal'>Spinner</i> class is in in </span></span><a
href="Writing%20Your%20Own%20Widget_files/AppendixB.htm"><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'>Appendix
B: SpinnerTest and Spinner</span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'></span></span></a><span style='mso-bookmark:
_Toc496069785'><span style='mso-bookmark:_Toc496069428'>. Now we need to write
the native interface methods in C. First we will write the native interface for
Windows, and then we will write it for Motif.</span></span></p>
<h3 style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><a name="_Toc506634637">Windows Native Code</a></span></span></h3>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Now we really get into JNI and platform
programming. We will write a C file called “spinner.c”. It needs to implement
the following Java methods from class spinner.<i style='mso-bidi-font-style:
normal'>Spinner</i>:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>int</span>
createControl(<span style='color:navy'>int</span> handleParent);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
computeSize(<span style='color:navy'>int</span> handle, <span style='color:
navy'>int</span> [] result);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
resizeControl(<span style='color:navy'>int</span> handle, <span
style='color:navy'>int</span> x, <span style='color:navy'>int</span> y, <span
style='color:navy'>int</span> width, <span style='color:navy'>int</span>
height);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
setPosition(<span style='color:navy'>int</span> handle, <span style='color:
navy'>int</span> position);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>int</span>
getPosition(<span style='color:navy'>int</span> handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
setMaximum(<span style='color:navy'>int</span> handle, <span style='color:navy'>int</span>
max);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>int</span>
getMaximum(<span style='color:navy'>int</span> handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span>
setMinimum(<span style='color:navy'>int</span> handle, <span style='color:navy'>int</span>
min);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>int</span>
getMinimum(<span style='color:navy'>int</span> handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span> setFont(<span
style='color:navy'>int</span> handle, <span style='color:navy'>int</span>
hFont);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>final</span> <span
style='color:navy'>native</span> <span style='color:navy'>void</span> setFocus(<span
style='color:navy'>int</span> handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>It also needs to call in to the following
Java method when the selection changes:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style='color:navy'>static</span> <span style='color:navy'>void</span>
widgetSelected(<span style='color:navy'>int</span> handle);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The first thing we need to do is to include
at least these three files. Your control may require additional files.</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>#include &lt;jni.h&gt;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>#include &lt;windows.h&gt;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>#include &lt;commctrl.h&gt;</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>We will start with the <b style='mso-bidi-font-weight:
normal'>createControl</b> method. Recall that we decided to use a Windows <i
style='mso-bidi-font-style:normal'>UpDown</i> control. If we create an <i
style='mso-bidi-font-style:normal'>Edit</i> control first, and then create the <i
style='mso-bidi-font-style:normal'>UpDown</i> control with </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt;layout-grid-mode:line'>UDS_AUTOBUDDY
</span><span style='layout-grid-mode:line'>and</span></span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt;layout-grid-mode:line'>
UDS_SETBUDDYINT</span><span style='layout-grid-mode:line'> flags set, then the <i
style='mso-bidi-font-style:normal'>Edit</i> control will automatically be
associated with the <i style='mso-bidi-font-style:normal'>UpDown</i> controlÂ’s
arrows. We can retrieve the <i style='mso-bidi-font-style:normal'>Edit</i> control
by sending </span></span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:11.0pt;mso-bidi-font-size:
10.0pt;layout-grid-mode:line'>UDM_GETBUDDY</span><span style='layout-grid-mode:
line'> to the <i style='mso-bidi-font-style:normal'>UpDown </i>control. We will
show you the complete <b style='mso-bidi-font-weight:normal'>createControl</b>
method after we explain how to call in to Java.<o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><b style='mso-bidi-font-weight:normal'><span
style='layout-grid-mode:line'>Calling in to Java:<o:p></o:p></span></b></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The first time we ever call <b
style='mso-bidi-font-weight:normal'>createControl</b>, we initialize some
static variables:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>static DWORD tlsIndex = 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>static jobject javaClass;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>static jmethodID mid;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>static WNDPROC oldProc;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>We use one of them (<b style='mso-bidi-font-weight:
normal'>tlsIndex</b>) as a flag to make sure we initialize them only once. Here
is the initialization code from <b style='mso-bidi-font-weight:normal'>createControl</b>:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if
(tlsIndex == 0) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>tlsIndex
= TlsAlloc();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>if
(tlsIndex == -1) return (jint) 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>javaClass
= (*env)-&gt;NewGlobalRef(env, (jobject) that);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>mid
= (*env)-&gt;GetStaticMethodID(env, (jobject) that, &quot;widgetSelected&quot;,
&quot;(I)V&quot;);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>oldProc
= (WNDPROC) GetWindowLong((HWND) hwndParent, GWL_WNDPROC);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>TlsSetValue(tlsIndex,
(LPVOID) env);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>These variables are needed to implement
call-in. As this is important code, we will describe each variable that is
initialized:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>tlsIndex
= TlsAlloc();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>if
(tlsIndex == -1) return (jint) 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>…</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>TlsSetValue(tlsIndex,
(LPVOID) env);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Here, we allocate a Windows <i
style='mso-bidi-font-style:normal'>Thread Local Storage</i> (TLS) index, and
then (for each <i style='mso-bidi-font-style:normal'>Spinner</i>) we use the
TLS index to store a pointer called <b style='mso-bidi-font-weight:normal'>env</b>.
Notice that <b style='mso-bidi-font-weight:normal'>JNIEnv *env</b> is the first
parameter passed to every JNI method. It is a pointer to a function table, and
it is only valid in the thread associated with it. We know that we need to call
in to Java when the user changes the <i style='mso-bidi-font-style:normal'>Spinner</i>
value, and that we will be calling in from a Windows ‘window procedure’ or </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>WNDPROC</span>. The </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>WNDPROC</span> does not know
about the Java environment. When the </span></span><span style='mso-bookmark:
_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span style='font-size:
11.0pt;mso-bidi-font-size:10.0pt'>WNDPROC</span> is invoked, we will need
‘env’. So we have to save it on creation so that we have it when we need to
call in. We also need the class and method ID to call in to, and we can store
these in statics because they will be the same across all threads:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>javaClass
= (*env)-&gt;NewGlobalRef(env, (jobject) that);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>mid
= (*env)-&gt;GetStaticMethodID(env, (jobject) that, &quot;widgetSelected&quot;,
&quot;(I)V&quot;);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>When the user changes the <i
style='mso-bidi-font-style:normal'>Spinner</i> value, the <i style='mso-bidi-font-style:
normal'>UpDown</i> sends a </span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:11.0pt;mso-bidi-font-size:
10.0pt'>WM_VSCROLL</span> to its parent control.<span style="mso-spacerun:
yes">  </span>In order to see this message, it is necessary to “subclass the
window proc” of the parent.<span style="mso-spacerun: yes">  </span>In Windows,
this means replacing the window proc of the parent with our own window
proc.<span style="mso-spacerun: yes">  </span>The new </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>WNDPROC</span> will look for
</span></span><span style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:
_Toc496069428'><span style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>WM_VSCROLL</span>
(in order to notify the Java code that the <i style='mso-bidi-font-style:normal'>Spinner</i>
value has been changed) and then call the previous </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>WNDPROC</span> to handle
other messages that our control is not interested in.<span style="mso-spacerun:
yes">  </span>Note that it is important to call the previous </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>WNDPROC</span>, or the
parent window will not behave properly (i.e. it will not paint or resize, etc.)
We store the previous </span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:11.0pt;mso-bidi-font-size:
10.0pt'>WNDPROC</span> in oldProc:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>oldProc
= (WNDPROC) GetWindowLong((HWND) hwndParent, GWL_WNDPROC);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The last line in <b style='mso-bidi-font-weight:
normal'>createControl</b> before we return the new handle installs a </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>WNDPROC</span> called <b
style='mso-bidi-font-weight:normal'>WindowProc</b>:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>SetWindowLong((HWND)
hwndParent, GWL_WNDPROC, (long) WindowProc);</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Here is the code for our <b
style='mso-bidi-font-weight:normal'>WindowProc</b>. First we retrieve <b
style='mso-bidi-font-weight:normal'>env</b> from Thread Local Storage and check
if an exception has occurred. Then we see if this is an “<i style='mso-bidi-font-style:
normal'>UpDown</i> value changed” event (a </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>WM_VSCROLL<span
style='layout-grid-mode:line'> message with SB_THUMBPOSITION</span></span> in
the low order bits of <b style='mso-bidi-font-weight:normal'>wParam</b>). If it
is, we use <b style='mso-bidi-font-weight:normal'>env</b> to call in to the
Java static method called “widgetSelected”, passing <b style='mso-bidi-font-weight:
normal'>lParam</b> as the handle of the <i style='mso-bidi-font-style:normal'>UpDown</i>
control. Otherwise, we just forward to the parent controlÂ’s window procedure.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>LRESULT CALLBACK WindowProc(HWND hwnd, UINT
msg, WPARAM wParam, LPARAM lParam) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>JNIEnv
*env = TlsGetValue(tlsIndex);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if
(env != NULL) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>/*
If an exception has already occurred,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style="mso-spacerun: yes"> </span>* allow the stack to unwind so that the</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span><span
style="mso-spacerun: yes"> </span>* exception will be thrown in Java. */</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>if
((*env)-&gt;ExceptionOccurred(env)) return 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>switch
(msg) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span>case
WM_VSCROLL:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:4'>            </span>if
((wParam &amp; 0xFFFF) == SB_THUMBPOSITION) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:5'>                </span>return
(LRESULT) ((*env)-&gt;CallStaticIntMethod(env, javaClass, mid, lParam));</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:4'>            </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:4'>            </span>break;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>return
CallWindowProc(oldProc, hwnd, msg, wParam, lParam);<span style='mso-tab-count:
1'> </span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>And finally, here is the code for <b
style='mso-bidi-font-weight:normal'>createControl</b>:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>JNIEXPORT jint JNICALL
Java_spinner_Spinner_createControl</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style="mso-spacerun: yes"> 
</span>(JNIEnv *env, jclass that, jint hwndParent)</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>{</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>HWND
hwndText, hwndUpDown;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if
(tlsIndex == 0) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>tlsIndex
= TlsAlloc();</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>if
(tlsIndex == -1) return (jint) 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>javaClass
= (*env)-&gt;NewGlobalRef(env, (jobject) that);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>mid
= (*env)-&gt;GetStaticMethodID(env, (jobject) that, &quot;widgetSelected&quot;,
&quot;(I)V&quot;);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>oldProc
= (WNDPROC) GetWindowLong((HWND) hwndParent, GWL_WNDPROC);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>TlsSetValue(tlsIndex,
(LPVOID) env);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>hwndText
= CreateWindowEx(</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>WS_EX_CLIENTEDGE,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>&quot;EDIT&quot;,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>NULL,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>WS_CHILD
| WS_VISIBLE | WS_TABSTOP,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>0,
0, 0, 0,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>(HWND)
hwndParent,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>0,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>GetModuleHandle(NULL),</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>NULL);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if
(hwndText == 0) return (jint) 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>hwndUpDown
= CreateWindowEx(</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>0,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>UPDOWN_CLASS,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>NULL,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>WS_CHILD
| WS_VISIBLE | UDS_AUTOBUDDY | UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_ARROWKEYS
| UDS_NOTHOUSANDS,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>0,
0, 0, 0,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>(HWND)
hwndParent,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>0,</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>GetModuleHandle(NULL),</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>NULL);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if
(hwndUpDown == 0) return (jint) 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>SetWindowLong((HWND)
hwndParent, GWL_WNDPROC, (long) WindowProc);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>return
(jint) hwndUpDown;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>}</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The set and get methods we need to implement
are much simpler than the <b style='mso-bidi-font-weight:normal'>createControl</b>
and <b style='mso-bidi-font-weight:normal'>WindowProc</b> methods. Here are <b
style='mso-bidi-font-weight:normal'>setPosition</b> and <b style='mso-bidi-font-weight:
normal'>getPosition</b>. They simply send the </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>UDM_SETPOS</span> or </span></span><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><span
style='font-size:11.0pt;mso-bidi-font-size:10.0pt'>UDM_GETPOS</span> message to
the <i style='mso-bidi-font-style:normal'>UpDown</i> handle. The remaining set and
get methods are similar, and they are listed in </span></span><a
href="Writing%20Your%20Own%20Widget_files/AppendixC.htm"><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'>Appendix
C: Spinner for Windows</span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'></span></span></a><span style='mso-bookmark:
_Toc496069785'><span style='mso-bookmark:_Toc496069428'>. The only interesting
one is <b style='mso-bidi-font-weight:normal'>setFont</b>, which sets the font
of the <i style='mso-bidi-font-style:normal'>Edit</i> control, which it gets by
sending </span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='font-size:11.0pt;mso-bidi-font-size:
10.0pt'>UDM_GETBUDDY</span> to the <i style='mso-bidi-font-style:normal'>UpDown</i>
handle.</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>JNIEXPORT void JNICALL
Java_spinner_Spinner_setPosition</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style="mso-spacerun: yes"> 
</span>(JNIEnv *env, jclass that, jint hwnd, jint position)</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>{</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>SendMessage((HWND)
hwnd, UDM_SETPOS, 0, position);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>JNIEXPORT jint JNICALL Java_spinner_Spinner_getPosition</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style="mso-spacerun: yes"> 
</span>(JNIEnv *env, jclass that, jint hwnd)</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>{</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>return
(jint) SendMessage((HWND) hwnd, UDM_GETPOS, 0, 0) &amp; 0xFFFF;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The <b style='mso-bidi-font-weight:normal'>resizeControl</b>
method positions the <i style='mso-bidi-font-style:normal'>Edit</i> control
(the buddy) and the <i style='mso-bidi-font-style:normal'>UpDown</i> (the arrow
buttons) using the specified coordinates and size. For the width of the arrow
buttons, we use the width of a typical vertical scrollbar.</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>JNIEXPORT void JNICALL
Java_spinner_Spinner_resizeControl</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style="mso-spacerun: yes"> 
</span>(JNIEnv *env, jclass that, jint hwndUpDown, jint x, jint y, jint width,
jint height)</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>{</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>HWND
hwndText = (HWND) SendMessage((HWND) hwndUpDown, UDM_GETBUDDY, 0, 0);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>UINT
flags = SWP_NOZORDER | SWP_DRAWFRAME | SWP_NOACTIVATE;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>int
upDownWidth = GetSystemMetrics(SM_CXVSCROLL);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>SetWindowPos(hwndText,
(HWND) 0, x, y, width - upDownWidth + 2, height, flags);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>SetWindowPos((HWND)
hwndUpDown, (HWND) 0, x + width - upDownWidth, y, upDownWidth, height, flags);<span
style='mso-tab-count:3'>         </span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>}</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The final method we need to write is <b
style='mso-bidi-font-weight:normal'>computeSize</b>. This is typically a
complex method, and our <b style='mso-bidi-font-weight:normal'>computeSize</b>
is no exception. We construct a string of digits the same length as the maximum
value, and measure its height and width if drawn in the <i style='mso-bidi-font-style:
normal'>Edit</i> controlÂ’s font. We make sure our control is no shorter than a
combo box, and we add in text margins, and the width of the arrow buttons. In
order to return the computed height and width values in the <b
style='mso-bidi-font-weight:normal'>result</b> array, we need to lock down the
array using the JNI function <b style='mso-bidi-font-weight:normal'>GetIntArrayElements</b>
to protect it from moving as a result of garbage collection.</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>JNIEXPORT void JNICALL Java_spinner_Spinner_computeSize</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style="mso-spacerun: yes"> 
</span>(JNIEnv *env, jclass that, jint hwndUpDown, jintArray result) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>int
width, height;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>TEXTMETRIC
tm;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>RECT
rect;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>int
comboHeight;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>int
max, digits;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>UINT
flags;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>char
text[64];</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>HWND hwndText
= (HWND) SendMessage((HWND) hwndUpDown, UDM_GETBUDDY, 0, 0);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>HDC
hDC = GetDC(hwndText);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>HFONT
oldFont = 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>HFONT
newFont = (HFONT) SendMessage(hwndText, WM_GETFONT, 0, 0);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>jint
*result1 = NULL;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>result1
= (*env)-&gt;GetIntArrayElements(env, result, NULL);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if
(newFont != 0) oldFont = SelectObject(hDC, newFont);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>GetTextMetrics(hDC,
&amp;tm);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>comboHeight
= GetSystemMetrics(SM_CYVSCROLL);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>height
= (comboHeight &gt; tm.tmHeight) ? comboHeight : tm.tmHeight;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>max =
SendMessage((HWND) hwndUpDown, UDM_GETRANGE, 0, 0) &amp; 0xFFFF;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if
(max &gt; 0) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>digits
= 0;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>while
(max &gt; 0) {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span>text[digits]
= '0';</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span>max
/= 10;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:3'>         </span>digits++;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>flags
= DT_CALCRECT | DT_EDITCONTROL | DT_NOPREFIX;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>DrawText(hDC,
(LPCTSTR) text, digits, (LPRECT) &amp;rect, flags);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>width
= rect.right - rect.left + 3;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}
else {</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span><span
style="mso-spacerun: yes"> </span><span style='mso-tab-count:1'>  </span>width
= 10;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if
(newFont != 0) SelectObject(hDC, oldFont);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>ReleaseDC(hwndText,
hDC);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>width
+= GetSystemMetrics(SM_CXVSCROLL);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>SendMessage(hwndText,
EM_GETRECT, 0, (LPARAM) &amp;rect);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>if (rect.top
== 0) rect.top = 1; // windows bug fix</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>width
+= (rect.left + 1) * 2;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>height
+= (rect.top + 1) * 2;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>result1
[0] = width;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>result1
[1] = height;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>(*env)-&gt;ReleaseIntArrayElements(env,
result, result1, 0);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>}</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The full source listing for the Windows C
code and makefile are in </span></span><a
href="Writing%20Your%20Own%20Widget_files/AppendixC.htm"><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'>Appendix
C: Spinner for Windows</span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'></span></span></a><span style='mso-bookmark:
_Toc496069785'><span style='mso-bookmark:_Toc496069428'>. A batch file sets
environment variables and calls make to create the DLL. Options for your
compiler and linker may differ, but you will have to link in the win32 libs:
comctl32.lib, user32.lib, and gdi32.lib.</span></span></p>
<span style='font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA'><br clear=all style='mso-special-character:line-break;
page-break-before:always'>
</span>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'><o:p></o:p></span></span></p>
<h3 style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><a name="_Toc506634638">Motif Native Code</a></span></span></h3>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Now we need to write “spinner.c” for Motif.
In this section, we will only point out the differences between the Motif
“spinner.c” and the Windows one. The full source listing for the Motif C code
and makefile are in </span></span><a
href="Writing%20Your%20Own%20Widget_files/AppendixD.htm"><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'>Appendix
D: Spinner for Motif</span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'></span></span></a><span style='mso-bookmark:
_Toc496069785'><span style='mso-bookmark:_Toc496069428'>. A shell script sets
environment variables and calls make.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The Motif equivalent to Thread Local Storage
is called Thread-Specific Data (TSD), and its functions are defined in <b
style='mso-bidi-font-weight:normal'>pthread.h</b>. You will need to include at
least the following files:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>#include &lt;jni.h&gt;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>#include &lt;Xm/XmAll.h&gt;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>#include &lt;pthread.h&gt;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>In order to store the <b style='mso-bidi-font-weight:
normal'>env</b> pointer in Thread-Specific Data, you first create a key:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>static pthread_key_t envKey;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>…</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:2'>     </span>pthread_key_create(&amp;envKey,
NULL);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>and then you store into and retrieve from
TSD as follows:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>pthread_setspecific(envKey,
env);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>JNIEnv
*env = (JNIEnv *) pthread_getspecific(envKey);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>As you compare the Windows and Motif
“spinner.c” listings, you will notice that the JNI portions of the code are
identical: method templates, the use of JNI functions like <b style='mso-bidi-font-weight:
normal'>GetIntArrayElements</b> and <b style='mso-bidi-font-weight:normal'>ReleaseIntArrayElements</b>
for locking/releasing an array of integers, and <b style='mso-bidi-font-weight:
normal'>NewGlobalRef</b>, <b style='mso-bidi-font-weight:normal'>GetStaticMethodID</b>,
and <b style='mso-bidi-font-weight:normal'>CallStaticIntMethod</b> to call in
to Java.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The platform code, however, is completely
different. On Motif, we create the native control using <b style='mso-bidi-font-weight:
normal'>XmCreateSimpleSpinBox</b>. The <i style='mso-bidi-font-style:normal'>Text</i>
widget is created automatically and stored in the <b style='mso-bidi-font-weight:
normal'>XmNtextField</b> resource of the <i style='mso-bidi-font-style:normal'>SimpleSpinBox</i>.
You can retrieve the <i style='mso-bidi-font-style:normal'>Text</i> (for
setting the font or computing the preferred size) using:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>Arg
arg;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>Widget
handleText;</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>XtSetArg(arg,
XmNtextField, &amp;handleText);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>XtGetValues((Widget)
handle, &amp;arg, 1);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>After creating the <i style='mso-bidi-font-style:
normal'>SimpleSpinBox</i>, we have to ‘manage’ it, and then we add an <b
style='mso-bidi-font-weight:normal'>XtCallbackProc</b> for the <b
style='mso-bidi-font-weight:normal'>valueChanged</b> callback:</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>XtManageChild(handleSpinBox);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><span style='mso-tab-count:1'>  </span>XtAddCallback(handleSpinBox,
XmNvalueChangedCallback, (XtCallbackProc) Callback, NULL);</span></span></p>
<p class=Code style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>The <b style='mso-bidi-font-weight:normal'>computeSize</b>
method is about as complex as the one for Windows, with height and width based
on the maximum number of digits, with margins and shadows added in.
Unfortunately, we had to guess a nice width for the arrow buttons, as this value
could not be retrieved from a <i style='mso-bidi-font-style:normal'>SimpleSpinBox</i>.<br
clear=all style='mso-special-character:line-break;page-break-before:always'>
</span></span></p>
<h3 style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><a name="_Toc506634639">Mixing Native and
Java Widgets</a></span></span></h3>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Occasionally it is necessary to implement a
widget using a native widget on one platform, and emulating the widget behavior
with Java code on another platform. SWT does this for several widgets; for
example, <i style='mso-bidi-font-style:normal'>Tree</i> is native on Windows,
and emulated on Motif. All of the code to implement <i style='mso-bidi-font-style:
normal'>Tree</i> on Motif is shipped in the SWT jar for Motif. On Windows, the
API for <i style='mso-bidi-font-style:normal'>Tree</i> is shipped in the
Windows SWT jar and the interface to the native control is shipped in the
Windows SWT shared library (SWT.DLL).</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>When emulating a widget on one platform and
wrapping a native or third party widget on another, it is important to subclass
at the same point in the <i style='mso-bidi-font-style:normal'>Widget</i>
hierarchy on both platforms (i.e. <i style='mso-bidi-font-style:normal'>Composite</i>
or <i style='mso-bidi-font-style:normal'>Canvas</i>). It is also important to
make certain that the public API is identical for both widgets. This makes it
possible for applications to run on any platform without recompiling.</span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'>Looking at the <i style='mso-bidi-font-style:
normal'>Spinner</i> example in the previous section, suppose we now want to
have a <i style='mso-bidi-font-style:normal'>Spinner</i> on a third platform
that does not have a native <i style='mso-bidi-font-style:normal'>SpinBox</i>
or <i style='mso-bidi-font-style:normal'>UpDown</i> control. Since we
subclassed<i style='mso-bidi-font-style:normal'> Composite</i> on Windows and
Motif, we again subclass <i style='mso-bidi-font-style:normal'>Composite</i> on
the new platform. Then we create three children: a <i style='mso-bidi-font-style:
normal'>Text</i> and two arrow <i style='mso-bidi-font-style:normal'>Buttons</i>.
Then we fill in the API and write our widget as described earlier in the <span
style='mso-field-code:"REF _Ref506190201 \\h"'>Compound Widget Example<!--[if gte mso 9]><xml>
<w:data>08D0C9EA79F9BACE118C8200AA004BA90B02000000080000000E0000005F005200650066003500300036003100390030003200300031000000</w:data>
</xml><![endif]--></span> section. The full source code listing for this 100%
Java <i style='mso-bidi-font-style:normal'>Spinner</i> is in </span></span><a
href="Writing%20Your%20Own%20Widget_files/AppendixE.htm"><span
style='mso-bookmark:_Toc496069785'><span style='mso-bookmark:_Toc496069428'>Appendix
E: Spinner for Any Platform</span></span><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'></span></span></a><span style='mso-bookmark:
_Toc496069785'><span style='mso-bookmark:_Toc496069428'>.</span></span></p>
<b style='mso-bidi-font-weight:normal'><span style='font-size:14.0pt;
mso-bidi-font-size:10.0pt;font-family:"Times New Roman";mso-fareast-font-family:
"Times New Roman";mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA'><br clear=all style='page-break-before:always'>
</span></b>
<p class=MsoNormal style='margin-left:25.5pt'><span style='mso-bookmark:_Toc496069785'><span
style='mso-bookmark:_Toc496069428'><b style='mso-bidi-font-weight:normal'><span
style='font-size:18.0pt;mso-bidi-font-size:10.0pt'>Summary</span></b></span></span><b
style='mso-bidi-font-weight:normal'><span style='font-size:18.0pt;mso-bidi-font-size:
10.0pt'><o:p></o:p></span></b></p>
<p class=MsoNormal style='margin-left:25.5pt'>SWT provides several different
ways to implement new widgets. The simplest method, and the one you will
typically use, is to subclass <i style='mso-bidi-font-style:normal'>Canvas</i>
or <i style='mso-bidi-font-style:normal'>Composite</i> and add listeners and
methods to get the job done.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>In certain cases the
specification for your new widget will so closely resemble a single existing
SWT widget that you will want to use that widget in your implementation. The recommended
way to do this is to wrap the SWT widget in a subclass of <i style='mso-bidi-font-style:
normal'>Composite</i>, and implement a carefully determined subset of the
wrapped widgetÂ’s methods by forwarding to the wrapped widget.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>Occasionally, you may need to
wrap a platform or third party widget by writing a platform-specific shared
library that makes calls to this widget. You can then subclass <i
style='mso-bidi-font-style:normal'>Composite</i> and provide a Java native
interface to your library code.</p>
<p class=MsoNormal style='margin-left:25.5pt'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></p>
<p class=MsoNormal style='margin-left:25.5pt'>Finally, in very special and rare
circumstances, you can subclass an existing SWT widget, but this is not
recommended.</p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:24.0pt 48.0pt 1.0in 96.0pt 120.0pt 2.0in 168.0pt 192.0pt 3.0in 240.0pt 264.0pt 4.0in 312.0pt 336.0pt 5.0in 384.0pt 408.0pt 6.0in 456.0pt 480.0pt 7.0in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><span
style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:"Courier New";
mso-bidi-font-family:"Times New Roman";layout-grid-mode:line'><![if !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></span></p>
<h4 style='margin-left:25.5pt'><b>Example Code<o:p></o:p></b></h4>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:24.0pt 48.0pt 1.0in 96.0pt 120.0pt 2.0in 168.0pt 192.0pt 3.0in 240.0pt 264.0pt 4.0in 312.0pt 336.0pt 5.0in 384.0pt 408.0pt 6.0in 456.0pt 480.0pt 7.0in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><a
name="_Ref498278978"></a><a name="_Toc506634640"><span style='mso-bookmark:
_Ref498278978'></span></a><a
href="Writing%20Your%20Own%20Widget_files/AppendixA.htm"><span
style='mso-bookmark:_Toc506634640'><span style='mso-bookmark:_Ref498278978'>Appendix
A: TableTree and TableTreeItem</span></span><span style='mso-bookmark:_Ref498278978'></span><span
style='mso-bookmark:_Toc506634640'></span><span style='mso-bookmark:_Ref506196466'><span
style='mso-bookmark:_Ref506203309'><span style='mso-bookmark:_Toc506634643'></span></span></span><span
style='mso-bookmark:_Ref506196466'><span style='mso-bookmark:_Ref506203309'><span
style='mso-bookmark:_Toc506634643'></span></span></span></a><![if !supportNestedAnchors]><a
name="_Toc506634643"></a><a name="_Ref506203309"></a><a name="_Ref506196466"></a><![endif]><span
style='mso-bookmark:_Ref506196466'><span style='mso-bookmark:_Ref506203309'><span
style='mso-bookmark:_Toc506634643'></span></span></span></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:24.0pt 48.0pt 1.0in 96.0pt 120.0pt 2.0in 168.0pt 192.0pt 3.0in 240.0pt 264.0pt 4.0in 312.0pt 336.0pt 5.0in 384.0pt 408.0pt 6.0in 456.0pt 480.0pt 7.0in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><span
style='mso-bookmark:_Ref506196466'><span style='mso-bookmark:_Ref506203309'><span
style='mso-bookmark:_Toc506634643'></span></span></span><a
href="Writing%20Your%20Own%20Widget_files/AppendixB.htm"><span
style='mso-bookmark:_Ref506196466'><span style='mso-bookmark:_Ref506203309'><span
style='mso-bookmark:_Toc506634643'>Appendix B: Spinner</span></span></span><span
style='mso-bookmark:_Toc506634643'>Test and Spinner</span><span
style='mso-bookmark:_Toc506634643'></span></a></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:24.0pt 48.0pt 1.0in 96.0pt 120.0pt 2.0in 168.0pt 192.0pt 3.0in 240.0pt 264.0pt 4.0in 312.0pt 336.0pt 5.0in 384.0pt 408.0pt 6.0in 456.0pt 480.0pt 7.0in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><a
name="_Ref506009163"></a><a name="_Toc506634646"><span style='mso-bookmark:
_Ref506009163'></span></a><a
href="Writing%20Your%20Own%20Widget_files/AppendixC.htm"><span
style='mso-bookmark:_Toc506634646'><span style='mso-bookmark:_Ref506009163'>Appendix
C: Spinner for Windows</span></span><span style='mso-bookmark:_Ref506009163'></span><span
style='mso-bookmark:_Toc506634646'></span><span style='mso-bookmark:_Ref506009181'><span
style='mso-bookmark:_Toc506634650'></span></span><span style='mso-bookmark:
_Ref506009181'><span style='mso-bookmark:_Toc506634650'></span></span></a><![if !supportNestedAnchors]><a
name="_Toc506634650"></a><a name="_Ref506009181"></a><![endif]><span
style='mso-bookmark:_Ref506009181'><span style='mso-bookmark:_Toc506634650'></span></span></p>
<p class=MsoHeader style='margin-left:25.5pt;tab-stops:24.0pt 48.0pt 1.0in 96.0pt 120.0pt 2.0in 168.0pt 192.0pt 3.0in 240.0pt 264.0pt 4.0in 312.0pt 336.0pt 5.0in 384.0pt 408.0pt 6.0in 456.0pt 480.0pt 7.0in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><span
style='mso-bookmark:_Ref506009181'><span style='mso-bookmark:_Toc506634650'></span></span><a
href="Writing%20Your%20Own%20Widget_files/AppendixD.htm"><span
style='mso-bookmark:_Ref506009181'><span style='mso-bookmark:_Toc506634650'>Appendix
D: Spinner for Motif</span></span><span style='mso-bookmark:_Toc506634650'></span><span
style='mso-bookmark:_Ref506009181'></span></a></p>
<p class=MsoNormal style='margin-left:25.5pt;tab-stops:24.0pt 48.0pt 1.0in 96.0pt 120.0pt 2.0in 168.0pt 192.0pt 3.0in 240.0pt 264.0pt 4.0in 312.0pt 336.0pt 5.0in 384.0pt 408.0pt 6.0in 456.0pt 480.0pt 7.0in 528.0pt 552.0pt 8.0in 600.0pt 624.0pt 9.0in 672.0pt 696.0pt 10.0in 744.0pt 768.0pt'><a
name="_Ref506190577"></a><a name="_Toc506634654"><span style='mso-bookmark:
_Ref506190577'></span></a><a
href="Writing%20Your%20Own%20Widget_files/AppendixE.htm"><span
style='mso-bookmark:_Toc506634654'><span style='mso-bookmark:_Ref506190577'>Appendix
E: Spinner for Any Platform</span></span><span style='mso-bookmark:_Ref506190577'></span><span
style='mso-bookmark:_Toc506634654'></span></a><span style='font-size:9.0pt;
mso-bidi-font-size:10.0pt;font-family:"Courier New";mso-bidi-font-family:"Times New Roman";
layout-grid-mode:line'><o:p></o:p></span></p>
</div>
<p><small>Java and all Java-based trademarks and logos are trademarks or registered
trademarks of Sun Microsystems, Inc. in the United States, other countries, or
both.</small></p>
<p><small>Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both.</small></p>
</body>
</html>