<?xml version="1.0" encoding="GB2312"?>
<rss version="2.0">
<channel>
<title>RF机器人博客</title>
<link>http://www.roboticfan.com/blog/</link>
<description>1</description>
<generator>4.60 Final</generator>
<webMaster>roboticfan@gmail.com</webMaster>
<item>
<title><![CDATA[Arduino语言注解]]></title>
<link>http://www.roboticfan.com/blog/user_2005/1229/archives/2008/20081123185958.shtml</link>
<author>wxxmickey</author>
<pubDate>2008-11-23 18:59:00</pubDate>
<description><![CDATA[<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Arduino语言是建立在C/C++基础上的，其实也就是基础的C语言，Arduino语言只不过把AVR单片机（微控制器）相关的一些参数设置都函数化，不用我们去了解他的底层，让我们不了解AVR单片机（微控制器）的朋友也能轻松上手。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在与Arduino DIYER接触的这段时间里，发现有些朋友对Arduino语言还是比较难入手，那么这里我就简单的注释一下Arduino语言（本人也是半罐子水，有错的地方还请各位指正）。</P>
<P>/*************基础C语言*************/</P>
<H4>关键字：</H4>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/If"><FONT color=#111111>if</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Else"><FONT color=#111111>if...else</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/For"><FONT color=#111111>for</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/SwitchCase"><FONT color=#111111>switch case</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/While"><FONT color=#111111>while</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/DoWhile"><FONT color=#111111>do... while</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Break"><FONT color=#111111>break</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Continue"><FONT color=#111111>continue</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Return"><FONT color=#111111>return</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Goto"><FONT color=#111111>goto</FONT></A> </LI></UL>
<P class=vspace></P>
<H4>语法符号：</H4>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/SemiColon"><FONT color=#111111>;</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Braces"><FONT color=#111111>{}</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Comments"><FONT color=#111111>//</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Comments"><FONT color=#111111>/* */</FONT></A> </LI></UL>
<P class=vspace></P>
<H4>运算符：</H4>
<UL>
<LI><FONT color=#111111>= </FONT>
<LI><FONT color=#111111>+ </FONT>
<LI><FONT color=#111111>- </FONT>
<LI><FONT color=#111111>* </FONT>
<LI><FONT color=#111111>/ </FONT>
<LI><FONT color=#111111>% </FONT></LI>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/If"><FONT color=#111111>==</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/If"><FONT color=#111111>!=</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/If"><FONT color=#111111>&lt;</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/If"><FONT color=#111111>&gt;</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/If"><FONT color=#111111>&lt;=</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/If"><FONT color=#111111>&gt;=</FONT></A> </LI>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Boolean"><FONT color=#111111>&amp;&amp;</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Boolean"><FONT color=#111111>||</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Boolean"><FONT color=#111111>!</FONT></A> </LI>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Increment"><FONT color=#111111>++</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Increment"><FONT color=#111111>--</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/IncrementCompound"><FONT color=#111111>+=</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/IncrementCompound"><FONT color=#111111>-=</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/IncrementCompound"><FONT color=#111111>*=</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/IncrementCompound"><FONT color=#111111>/=</FONT></A> </LI></UL>
<H4>数据类型：</H4>
<P class=vspace></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/BooleanVariables"><FONT color=#111111>boolean</FONT></A>&nbsp; 布尔类型 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Char"><FONT color=#111111>char</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Byte"><FONT color=#111111>byte</FONT></A>&nbsp; 字节类型 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Int"><FONT color=#111111>int</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/UnsignedInt"><FONT color=#111111>unsigned int</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Long"><FONT color=#111111>long</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/UnsignedLong"><FONT color=#111111>unsigned long</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Float"><FONT color=#111111>float</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Double"><FONT color=#111111>double</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/String"><FONT color=#111111>string</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Array"><FONT color=#111111>array</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Void"><FONT color=#111111>void</FONT></A> </LI></UL>
<H4>数据类型转换：</H4>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/CharCast"><FONT color=#111111>char()</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/ByteCast"><FONT color=#111111>byte()</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/IntCast"><FONT color=#111111>int()</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/LongCast"><FONT color=#111111>long()</FONT></A> 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/FloatCast"><FONT color=#111111>float()</FONT></A> </LI></UL>
<H4>常量：</H4>
<P class=vspace></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>HIGH</FONT></A> | <A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>LOW</FONT></A>&nbsp;&nbsp;&nbsp;&nbsp; 表示数字IO口的电平，<A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>HIGH</FONT></A> 表示高电平（1），<A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>LOW</FONT></A>&nbsp;表示低电平（0）。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>INPUT</FONT></A> | <A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>OUTPUT</FONT></A>&nbsp; &nbsp;表示数字IO口的方向，<A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>INPUT</FONT></A> 表示输入（高阻态），<A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>OUTPUT</FONT></A>&nbsp;&nbsp;表示输出（AVR能提供5V电压 40mA电流）。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>true</FONT></A> | <A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>false</FONT></A>&nbsp;&nbsp; &nbsp;<A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>true</FONT></A> 表示真（1），<A class=wikilink href="http://arduino.cc/en/Reference/Constants"><FONT color=#111111>false</FONT></A>表示假（0）。</LI></UL>
<P>/******************************************/</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 以上为基础c语言的关键字和符号，有c语言基础的都应该了解其含义，这里也不作过多的解释。</P>
<P>/*************Arduino 语言*************/</P>
<H2>结构</H2>
<UL>
<LI>void <A class=wikilink href="http://arduino.cc/en/Reference/Setup"><FONT color=#111111>setup</FONT></A>()&nbsp;&nbsp; <FONT size=2>初始化变量，管脚模式，调用库函数等</FONT> 
<LI>void <A class=wikilink href="http://arduino.cc/en/Reference/Loop"><FONT color=#111111>loop</FONT></A>()&nbsp; 连续执行函数内的语句</LI></UL>
<H2>功能</H2>
<P><STRONG>数字&nbsp;I/O</STRONG> </P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/PinMode"><FONT color=#111111>pinMode</FONT></A>(pin, mode)&nbsp;&nbsp;&nbsp; 数字IO口输入输出模式定义函数，pin表示为0～13， mode表示为INPUT或OUTPUT。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/DigitalWrite"><FONT color=#111111>digitalWrite</FONT></A>(pin, value)&nbsp;&nbsp; &nbsp;数字IO口输出电平定义函数，pin表示为0～13，value表示为HIGH或LOW。比如定义HIGH可以驱动LED。 
<LI>int <A class=wikilink href="http://arduino.cc/en/Reference/DigitalRead"><FONT color=#111111>digitalRead</FONT></A>(pin)&nbsp;&nbsp;&nbsp; 数字IO口读输入电平函数，pin表示为0～13，value表示为HIGH或LOW。比如可以读数字传感器。</LI></UL>
<P class=vspace></P>
<P><STRONG>模拟&nbsp;I/O</STRONG> </P>
<UL>
<LI>int <A class=wikilink href="http://arduino.cc/en/Reference/AnalogRead"><FONT color=#111111>analogRead</FONT></A>(pin)&nbsp;&nbsp;&nbsp; 模拟IO口读函数，pin表示为0～5（Arduino Diecimila为0～5，Arduino nano为0～7）。比如可以读模拟传感器（10位AD，0～5V表示为0～1023）。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/AnalogWrite"><FONT color=#111111>analogWrite</FONT></A>(pin, value) - <EM>PWM</EM>&nbsp;&nbsp;&nbsp;&nbsp; 数字IO口PWM输出函数，Arduino数字IO口标注了PWM的IO口可使用该函数，pin表示3, 5, 6, 9, 10, 11，value表示为0～255。比如可用于电机PWM调速或音乐播放。</LI></UL>
<P class=vspace></P>
<P><STRONG>扩展&nbsp;I/O</STRONG> </P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/ShiftOut"><FONT color=#111111>shiftOut</FONT></A>(dataPin, clockPin, bitOrder, value)&nbsp;&nbsp;&nbsp; SPI外部IO扩展函数，通常使用带SPI接口的74HC595做8个IO扩展，dataPin为数据口，clockPin为时钟口，bitOrder为数据传输方向（<STRONG>MSBFIRST</STRONG>高位在前，<STRONG>LSBFIRST</STRONG>低位在前），value表示所要传送的数据（0～255），另外还需要一个IO口做74HC595的使能控制。 
<LI>unsigned long <A class=wikilink href="http://arduino.cc/en/Reference/PulseIn"><FONT color=#111111>pulseIn</FONT></A>(pin, value)&nbsp;&nbsp;&nbsp; 脉冲长度记录函数，返回时间参数（us），pin表示为0～13，value为HIGH或LOW。比如value为HIGH，那么当pin输入为高电平时，开始计时，当pin输入为低电平时，停止计时，然后返回该时间。</LI></UL>
<P class=vspace></P>
<P><STRONG>时间函数</STRONG></P>
<UL>
<LI>unsigned long <A class=wikilink href="http://arduino.cc/en/Reference/Millis"><FONT color=#111111>millis</FONT></A>()&nbsp;&nbsp; 返回时间函数（单位ms），该函数是指，当程序运行就开始计时并返回记录的参数，该参数溢出大概需要50天时间。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Delay"><FONT color=#111111>delay</FONT></A>(ms)&nbsp;&nbsp;&nbsp; 延时函数（单位ms）。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/DelayMicroseconds"><FONT color=#111111>delayMicroseconds</FONT></A>(us)&nbsp;&nbsp;&nbsp; 延时函数（单位us）。<BR></LI></UL>
<P class=vspace></P>
<P><STRONG>数学函数</STRONG></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Min"><FONT color=#111111>min</FONT></A>(x, y)&nbsp; 求最小值 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Max"><FONT color=#111111>max</FONT></A>(x, y)&nbsp; 求最大值 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Abs"><FONT color=#111111>abs</FONT></A>(x)&nbsp;&nbsp; 计算绝对值 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Constrain"><FONT color=#111111>constrain</FONT></A>(x, a, b)&nbsp; 约束函数，下限a，上限b，x必须在ab之间才能返回。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Map"><FONT color=#111111>map</FONT></A>(value, fromLow, fromHigh, toLow, toHigh)&nbsp;&nbsp;&nbsp; 约束函数，value必须在fromLow与toLow之间和fromHigh与toHigh之间。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Pow"><FONT color=#111111>pow</FONT></A>(base, exponent)&nbsp; 开方函数，base的exponent次方。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Sq"><FONT color=#111111>sq</FONT></A>(x)&nbsp;&nbsp;&nbsp;&nbsp; 平方 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Sqrt"><FONT color=#111111>sqrt</FONT></A>(x)&nbsp;&nbsp; 开根号</LI></UL>
<P class=vspace></P>
<P><STRONG>三角函数</STRONG></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Sin"><FONT color=#111111>sin</FONT></A>(rad) 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Cos"><FONT color=#111111>cos</FONT></A>(rad) 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Tan"><FONT color=#111111>tan</FONT></A>(rad) </LI></UL>
<P class=vspace></P>
<P><STRONG>随机数函数</STRONG></P>
<P class=vspace></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/RandomSeed"><FONT color=#111111>randomSeed</FONT></A>(seed)&nbsp;&nbsp; 随机数端口定义函数，seed表示读模拟口analogRead(pin)函数 。 
<LI>long <A class=wikilink href="http://arduino.cc/en/Reference/Random"><FONT color=#111111>random</FONT></A>(max)&nbsp;&nbsp; 随机数函数，返回数据大于等于0，小于max。 
<LI>long <A class=wikilink href="http://arduino.cc/en/Reference/Random"><FONT color=#111111>random</FONT></A>(min, max)&nbsp;&nbsp; 随机数函数，返回数据大于等于min，小于max。</LI></UL>
<P><STRONG>外部中断函数</STRONG></P>
<P class=vspace></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/AttachInterrupt"><FONT color=#111111>attachInterrupt</FONT></A>(interrupt, , mode)&nbsp;&nbsp;&nbsp;&nbsp; 外部中断只能用到数字IO口2和3，interrupt表示中断口初始0或1，表示一个功能函数，mode：<STRONG>LOW</STRONG>低电平中断，<STRONG>CHANGE</STRONG>有变化就中断，<STRONG>RISING</STRONG>上升沿中断，<STRONG>FALLING</STRONG> 下降沿中断。 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/DetachInterrupt"><FONT color=#111111>detachInterrupt</FONT></A>(interrupt)&nbsp;&nbsp;&nbsp; 中断开关，interrupt=1 开，interrupt=0 关。</LI></UL>
<P class=vspace></P>
<P><STRONG>中断使能函数</STRONG></P>
<P class=vspace></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Interrupts"><FONT color=#111111>interrupts</FONT></A>()&nbsp; 使能中断 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/NoInterrupts"><FONT color=#111111>noInterrupts</FONT></A>()&nbsp; 禁止中断</LI></UL>
<P class=vspace></P>
<P><STRONG>串口收发函数</STRONG></P>
<P class=vspace></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Serial/Begin"><FONT color=#111111>Serial.begin</FONT></A>(speed)&nbsp; 串口定义波特率函数，speed表示波特率，如9600，19200等。 
<LI>int <A class=wikilink href="http://arduino.cc/en/Serial/Available"><FONT color=#111111>Serial.available</FONT></A>()&nbsp; 判断缓冲器状态。 
<LI>int <A class=wikilink href="http://arduino.cc/en/Serial/Read"><FONT color=#111111>Serial.read</FONT></A>()&nbsp;&nbsp; 读串口并返回收到参数。 
<LI><A class=wikilink href="http://arduino.cc/en/Serial/Flush"><FONT color=#111111>Serial.flush</FONT></A>()&nbsp;&nbsp;&nbsp; 清空缓冲器。 
<LI><A class=wikilink href="http://arduino.cc/en/Serial/Print"><FONT color=#111111>Serial.print</FONT></A>(data)&nbsp; 串口输出数据。 
<LI><A class=wikilink href="http://arduino.cc/en/Serial/Println"><FONT color=#111111>Serial.println</FONT></A>(data)&nbsp;&nbsp; 串口输出数据并带回车符。</LI></UL>
<P>/**********************************/</P>
<P>/************Arduino语言库文件*************/</P>
<H3>官方库文件</H3>
<P class=vspace></P>
<UL>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/EEPROM"><FONT color=#111111>EEPROM</FONT></A> - EEPROM读写程序库 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Ethernet"><FONT color=#111111>Ethernet</FONT></A> - 以太网控制器程序库 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/LiquidCrystal"><FONT color=#111111>LiquidCrystal</FONT></A> - <SPAN class=wikiword>LCD控制程序库 </SPAN>
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Servo"><FONT color=#111111>Servo</FONT></A> - 舵机控制程序库 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/SoftwareSerial"><FONT color=#111111>SoftwareSerial</FONT></A> - 任何数字IO口模拟串口程序库 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Stepper"><FONT color=#111111>Stepper</FONT></A> - 步进电机控制程序库 
<LI><A class=wikilink href="http://arduino.cc/en/Reference/Wire"><FONT color=#111111>Wire</FONT></A> - <SPAN class=wikiword>TWI/I2C总线程序库</SPAN> </LI>
<LI><A class=urllink href="http://wiring.org.co/reference/libraries/Matrix/index.html" rel=nofollow><FONT color=#111111>Matrix</FONT></A> - LED矩阵控制程序库
<LI><A class=urllink href="http://wiring.org.co/reference/libraries/Sprite/index.html" rel=nofollow><FONT color=#111111>Sprite</FONT></A> - LED矩阵图象处理控制程序库</LI></UL>
<H3>非官方库文件</H3>
<P class=vspace></P>
<UL>
<LI><A class=urllink href="http://www.arduino.cc/playground/Code/DateTime" rel=nofollow><FONT color=#111111>DateTime</FONT></A> - a library for keeping track of the current date and time in software. 
<LI><A class=urllink href="http://www.arduino.cc/playground/Code/Debounce" rel=nofollow><FONT color=#111111>Debounce</FONT></A> - for reading noisy digital inputs (e.g. from buttons) 
<LI><A class=urllink href="http://www.arduino.cc/playground/ComponentLib/Firmata" rel=nofollow><FONT color=#111111>Firmata</FONT></A> - for communicating with applications on the computer using a standard serial protocol. 
<LI><A class=urllink href="http://www.arduino.cc/playground/Code/GLCDks0108" rel=nofollow><FONT color=#111111>GLCD</FONT></A> - graphics routines for LCD based on the <SPAN class=wikiword>KS0108</SPAN> or equivalent chipset. 
<LI><A class=urllink href="http://www.arduino.cc/en/Tutorial/LCDLibrary" rel=nofollow><FONT color=#111111>LCD</FONT></A> - control <SPAN class=wikiword>LCDs</SPAN> (using 8 data lines) 
<LI><A class=urllink href="http://www.arduino.cc/playground/Code/LCD4BitLibrary" rel=nofollow><FONT color=#111111>LCD 4 Bit</FONT></A> - control <SPAN class=wikiword>LCDs</SPAN> (using 4 data lines) 
<LI><A class=urllink href="http://www.arduino.cc/playground/Main/LedControl" rel=nofollow><FONT color=#111111>LedControl</FONT></A> - for controlling LED matrices or seven-segment displays with a <SPAN class=wikiword>MAX7221</SPAN> or <SPAN class=wikiword>MAX7219</SPAN>. 
<LI><A class=urllink href="http://www.wayoda.org/arduino/ledcontrol/index.html" rel=nofollow><FONT color=#111111>LedControl</FONT></A> - an alternative to the Matrix library for driving multiple <SPAN class=wikiword>LEDs</SPAN> with Maxim chips. 
<LI><A class=urllink href="http://www.arduino.cc/playground/Code/Messenger" rel=nofollow><FONT color=#111111>Messenger</FONT></A> - for processing text-based messages from the computer 
<LI><A class=urllink href="http://www.arduino.cc/playground/Code/Metro" rel=nofollow><FONT color=#111111>Metro</FONT></A> - help you time actions at regular intervals 
<LI><A class=urllink href="http://www.arduino.cc/playground/Main/MsTimer2" rel=nofollow><FONT color=#111111>MsTimer2</FONT></A> - uses the timer 2 interrupt to trigger an action every N milliseconds. 
<LI><A class=urllink href="http://www.arduino.cc/playground/Learning/OneWire" rel=nofollow><FONT color=#111111>OneWire</FONT></A> - control devices (from Dallas Semiconductor) that use the One Wire protocol. 
<LI><A class=urllink href="http://www.arduino.cc/playground/Main/PS2Keyboard" rel=nofollow><FONT color=#111111>PS2Keyboard</FONT></A> - read characters from a <SPAN class=wikiword>PS2</SPAN> keyboard. 
<LI><A class=urllink href="http://www.arduino.cc/playground/ComponentLib/Servo" rel=nofollow><FONT color=#111111>Servo</FONT></A> - provides software support for Servo motors on any pins. 
<LI><A class=urllink href="http://www.arduino.cc/playground/ComponentLib/Servotimer1" rel=nofollow><FONT color=#111111>Servotimer1</FONT></A> - provides hardware support for Servo motors on pins 9 and 10 
<LI><A class=urllink href="http://www.arduino.cc/playground/Code/SimpleMessageSystem" rel=nofollow><FONT color=#111111>Simple Message System</FONT></A> - send messages between Arduino and the computer 
<LI><A class=urllink href="http://code.google.com/p/sserial2mobile/" rel=nofollow><FONT color=#111111>SSerial2Mobile</FONT></A> - send text messages or emails using a cell phone (via AT commands over software serial) 
<LI><A class=wikilink href="http://arduino.cc/en/Tutorial/TextString"><FONT color=#111111>TextString</FONT></A> - handle strings 
<LI><A class=urllink href="http://www.arduino.cc/playground/Learning/TLC5940" rel=nofollow><FONT color=#111111>TLC5940</FONT></A> - 16 channel 12 bit PWM controller. 
<LI><A class=wikilink href="http://arduino.cc/en/Tutorial/X10"><FONT color=#111111>X10</FONT></A> - Sending X10 signals over AC power lines </LI></UL>
<P>/****************************************/</P>
<P>以上库文件都需要下载到编译环境（如下目录：arduino-0011\hardware\libraries）中才能使用。</P>]]></description>
</item><item>
<title><![CDATA[脑电图的形成机理]]></title>
<link>http://www.roboticfan.com/blog/user_2005/2171/archives/2008/2008112222322.shtml</link>
<author>chenghw</author>
<pubDate>2008-11-22 22:03:00</pubDate>
<description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">记忆柱之间兴奋能力的增加，从而使主注意对象所对应的原始记忆柱群能更快的下一原始记忆柱群，从而更快的发生主注意对象的转移，由于最强的兴奋是主注意对象产生，我认为它是脑电产生的主要组成部分，因而波形会增快。同时由于不需要达到最强就能产生兴奋转移，因而随兴奋能力的增加，波形会加快，同时波幅会减小。（当然正如我在其它文章中的一样，大家可将我的记忆柱或原始记忆柱群换成神经元簇、神经通路或其它的来论述，会机理是一样的）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这样对于人类的早期是</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">θ</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">波，随成熟变成其它更快的波就好理解了。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore">1、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></SPAN></SPAN><SPAN lang=EN-US>α</SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">波的梭状兴奋与海马的延迟兴奋有何关系。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">2、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">记忆柱的被兴奋能力决定了波形。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">3、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">主注意对象或一个皮质局部区域的被兴奋能力应决定波形。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">4、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">小孩</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">θ</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">波与海马</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">θ</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">波关系。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">5、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">小孩</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">θ</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">波与记忆柱被兴奋能力之间的关系。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman">6、<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">增眼及新刺激给予皮质更大的易化，从而使记忆柱的被兴奋能力增加了。</SPAN></P>]]></description>
</item><item>
<title><![CDATA[如何消除因疲劳产生的皱纹]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/20081121135354.shtml</link>
<author>流子</author>
<pubDate>2008-11-21 13:53:00</pubDate>
<description><![CDATA[<P>真的皱纹是随着的时间年龄的增长而逐渐形成的.假性皱纹是皮肤营养的丢失所形成的.皱纹一般分为表情纹,鱼尾纹,干纹,细纹等.</CN> </P>
<P>假纹由于不注重休息保养而形成，可以去掉 真的皱纹属于正常生理现象，这个没办法去除 <BR><BR>顺便告诉你解决假纹的窍门： 用橄榄油 热水汽混一起涂在假纹上 可以去除假纹：）</CN> </P>
<P>皱纹是美容的大敌，可是并不是所有皱纹都是不可修复的；要认识到有的是假性皱纹，有的是真性皱纹： <BR>假性皱纹 <BR>属于短暂出现的皱纹，多因皮肤失去水分或皮下脂肪减少而产生，是一些小细纹，只要立即补救，即会消失。 <BR>真性皱纹 <BR>若假性皱纹得不到护理，日子久了，皮肤的营养得不到补充，皮肤纤维就会渐渐失去弹性并断裂，而形成真性皱纹，也就是永久性皱纹，用护肤品很难去除。 <BR><BR>影响皱纹的六大不良习惯 <BR>脸部皱纹影响健美。皱纹的产生，有些是由於个人生活习惯及不表情引起的。请注意改正以下不好的习惯： <BR>（1）眯眼睛：在耀眼的阳光下，有的人习惯眯起眼精看东西；有的人患近视眼不愿戴眼镜，而把眼精眯起来看东西，久而久之，眼围便布满了小皱纹。 <BR>（2）皮笑肉不笑：有些人笑力只动嘴角，嘴角，嘴象上也就有了很多的皱纹。 <BR>（3）单侧咀嚼食物：单侧嚼食，会使另一侧的牙齿失去正常的咬合关系，颔骨、颔咀嚼肌、表情允等缺少生理性功能刺激，久而久之会使颔骨骨质畸形，肌肉萎缩，脸部左右不对称。 <BR>（4）浓妆过夜：浓妆过夜是美容之大忌。化妆品留在脸上过夜，阻塞毛孔，渗入及肤后，会造成皮肤损害。擦粉过度，会使皮肤变粗糙或生出斑点。 <BR>（5）蒙头睡觉：会使脸部皮肤乾燥，唇部皮肤容易乾裂脱皮。 <BR>（6）吸烟：吸烟成者，其眼外久皱纹会过早地呈现出来。因为香中的尼古丁等有物质对皮肤满细血管有破坏作用，能影响皮肤的盛液环，造成营养障碍。加上香烟中的一氧化碳与血红蛋白结合，降低了盛红蛋白的带满功能，造成皮肤缺氧。 <BR><BR>减少皱纹有妙法 <BR>无论如何，面部出现皱纹总是一件令人烦心的事情。那么，脸上已经出现了皱纹，又该怎么办呢？看一看下面的内容，你也许会得到一些启发。 <BR>米饭团去皱——煮熟的米饭，挑比较软的，趁热揉成团，放在脸部揉搓，直到将饭团揉搓成污黑状，然后用清水洗净脸部，可以使皮肤呼吸畅通，减少皱纹。 <BR>母猪蹄去皱——用老母猪蹄数只，洗净后煮成膏，晚上睡觉时搽脸，次日早晨洗去连续搽半个月后，有明显的去皱效果。 <BR>啤酒去皱——啤酒含有大量维生素、糖和蛋白质。适量饮用啤酒，可以增强体质，减少脸部皱纹。 <BR>咀嚼去皱——每咀嚼口香糖15~20分钟，连续咀嚼几周后，可以使脸部皱纹减少，面庞红润。因为，咀嚼能运动脸部肌肉，改善脸部血液循环，增强脸部肌肉细胞的代谢功能。 <BR>只要坚持一段时间，你一定可以找到青春的影子。 <BR><BR>如何保养脸部肌肤？ <BR><BR>1、口香糖除皱纹 <BR>咀嚼口香糖能收缩肌肉，调整脸部肌肤，逐渐减少皱纹沟形成的深度，甚至可以消除一些细小的皱纹。至于快要形成皱纹的部分，更因肌肉收缩、增强弹性，从而防止皱纹的产生。例如双下巴，可减少下垂的赘肉。 <BR><BR>2、眼皮肿胀的迅速消除 <BR>早晨睡醒，发觉眼皮肿肿的，很不好看，用化妆品也掩盖不住。这时用纱布裹冰块敷在眼皮上或用冰牛奶冷敷，可消除肿胀。另外用收敛水冷敷也一样会奏效。 <BR><BR>3、年轻20岁的妙方 <BR>如果希望脸上几乎没有皱纹，或者可以使肌肤看上去比实际年龄年轻15到20岁，就必须按照下列的预防措施进行操作。 <BR>（1）每天晚上在洗脸以前，先用毛巾热敷全脸3分钟。水蒸气可以打开毛孔，把所有油脂和灰尘带到肌肤表面上； <BR>（2）使用洁面乳，不要用肥皂； <BR>（3）在上床前使用晚霜、营养霜或精华液、润肤水； <BR>（4）在夜间，卧房里最好放1台空气润湿机； <BR>（5）眼部卸妆的时候，由外眼角向鼻子方向擦拭，但脸部卸妆时，必须由下向上擦； <BR>（6）每天至少喝6杯水，身体需要足够水分，水分足够可以使肌肤保持滋润； <BR>（7）睡觉的姿势应该为脸朝上仰卧，不要用枕头； <BR>（8）不要抽烟、喝酒。 <BR><BR>4、适当的进行简易的脸部按摩 <BR>（1） 额头按摩：用中指和无名指以打圆圈方式按摩到太阳穴； <BR>（2） 眼睛四周按摩：从太阳穴开始，顺着眼睑而下，围绕眼眶作5、6圈的按摩； <BR>（3） 鼻部按摩：先由上至下，再用力按摩鼻子两边； <BR>（4） 面颊按摩：分3处由下巴至耳下、嘴角至耳上及鼻旁到太阳穴，都以打圆圈方式仔细按摩。 <BR><BR>5、损害脸部线条的14种动作 <BR>脸部表情是由24条随意肌构成，一些不正确的动作会加深脸部皱纹，加速肌肤老化。以下是14种对脸部有害的动作：抽烟、用手拖腮、抓搔搓抚脸、挖鼻孔或刷牙缝、咬手指、拉耳垂或头发、咬笔杆、经常张着嘴、咬嘴唇、上扬单边眉毛、吹口哨、用吸管喝饮料、蹙眉或噘嘴、睡姿侧卧或俯卧。 <BR>此外，一些日常的生活习惯也会影响脸部的线条，例如不干净的头发；在大太阳底下眯着眼睛，但是却不戴眼镜等。 <BR><BR>6、清洁脸部选用弱碱肥皂 <BR>彻底清洁脸部是美容养颜第一步，而清洁品则是洗脸不可或缺的东西。但市面上五花八门的洗面皂、洗面奶常常让人不知如何选择。平常清洁脸部用弱碱性肥皂即可，它可将脸上的弱酸中和，发挥最好的清洁力，清洁完毕再擦点乳液，即可防止紧绷达到润滑效果。此外应避免使用含特殊成分的肥皂，否则容易弄巧成拙。 <BR><BR>7、简易速效敷脸法 <BR>敷脸能帮助去除污物、收缩毛孔，同时还能保持肌肤柔软，防止皱纹产生。以下两种敷脸方法，适合在家里做，不但简单，功效也佳。 <BR>（1） 茶叶敷脸法：因为茶叶中的单宁酸具有治疗和提神效果，将两包茶袋放入盛有开水的碗内，让它冷却，然后用茶袋轻拍脸部，5分钟后重复1遍，再用清水洗净脸部。 <BR>（2） 牛奶敷脸法：此法对中性和干性肌肤均具有滋养作用，将棉花浸入牛奶中，再敷在脸上，大约5分钟后用清水洗净。 <BR><BR>8、自制玫瑰露 <BR>玫瑰鲜艳的花瓣是最有效的肌肤保养品之一，自古以来，玫瑰露一直是女士们所深爱的神奇美容水。它对肌肤快速的恢复清爽嫩滑，具有相当独特的效果。玫瑰露的做法是，收集大约2磅的新鲜玫瑰花瓣，洗净，将3杯的花瓣放入防热的炖锅中，加入刚好盖住花瓣的清水，用小火慢慢地煮45分钟；然后将花瓣捞出留下汁液，再放入3杯鲜花瓣继续煮，这一次不用加水。如此反复地做，直到2磅花瓣都煮完，然后以粗棉布把花渣过滤，玫瑰露冷冻。使用时，以脱脂棉蘸取玫瑰露，在面部轻轻拍动，一方面收缩毛孔，一方面给肌肤补充一定的水分，使肌肤清新、舒服。 <BR><BR>9、指压法美丽你的眼睛 <BR>指压眼睛周围的肌肤，不但可消除鱼尾纹，又可增加眼睛的魅力。 <BR>（1） 消除鱼尾纹的指压方法：用两手无名指、中指、食指3个指头，压在眼角处，每次压3至5秒，重复3次。 <BR>（2） 使眼睛更灵活迷人的指压方法：先从左眼上部开始，用食指往眼角方向依次按压，每点按压2至4秒，重复做3次，再换右眼。最后，以左右手的三指一起按压左右眼角，约10秒左右。 <BR><BR>10、喝啤酒可使肌肤健美 <BR>啤酒是美容食品之一，适量的啤酒，可以促进血液循环，使女性肤色健美鲜明。同时，啤酒又是一种利尿剂，喝了它，能加速排泄系统的作用，促进新陈代谢、吸收营养，间接可使容光焕发。</CN> </P>
<P><SPAN style="COLOR: #ff0000">人瘦才是产生皱纹的主要原因，不要熬夜11点睡，多洗脸，一个月去死皮一次，多吃口香糖，每天多喝水</SPAN></P><SPAN style="COLOR: #ff0000">
<DIV class=operatorfont style="MARGIN-LEFT: 5px">
<DIV>你皱纹的产生与你的作息时间有关系</DIV></DIV>
<P><SPAN class=clientnamefont style="COLOR: #008000">您 11-21 12:17:21</SPAN></P>
<DIV class=clientfont style="MARGIN-LEFT: 5px"><SPAN style="FONT-FAMILY: Tahoma">是的，就是熬夜引起的</SPAN></DIV>
<P><SPAN class=operatornamefont style="COLOR: #0000ff">整形专家05&nbsp;11-21 12:17:35</SPAN></P>
<DIV class=operatorfont style="MARGIN-LEFT: 5px">
<DIV>你现在还年轻，调整好作息后会有相应的改善</DIV></DIV>
<P><SPAN class=clientnamefont style="COLOR: #008000">您 11-21 12:18:09</SPAN></P>
<DIV class=clientfont style="MARGIN-LEFT: 5px"><SPAN style="FONT-FAMILY: Tahoma">不知作息时间调整后，哪些产生的皱纹会不会消失，太恐怖了现在，呵呵</SPAN></DIV>
<P><SPAN class=operatornamefont style="COLOR: #0000ff">整形专家05&nbsp;11-21 12:18:29</SPAN></P>
<DIV class=operatorfont style="MARGIN-LEFT: 5px">
<DIV>皱纹大体有两种，真性的和假性的 </DIV></DIV>
<P><SPAN class=clientnamefont style="COLOR: #008000">您 11-21 12:18:40</SPAN></P>
<DIV class=clientfont style="MARGIN-LEFT: 5px">
<DIV><SPAN style="FONT-FAMILY: Tahoma">如何识别？</SPAN></DIV></DIV>
<P><SPAN class=operatornamefont style="COLOR: #0000ff">整形专家05&nbsp;11-21 12:19:22</SPAN></P>
<DIV class=operatorfont style="MARGIN-LEFT: 5px">
<DIV>假性的在表情肌肉静止的情况下就基本没有了 </DIV></DIV>
<P><SPAN class=operatornamefont style="COLOR: #0000ff">整形专家05&nbsp;11-21 12:19:35</SPAN></P>
<DIV class=operatorfont style="MARGIN-LEFT: 5px">
<DIV>真性的，是已经产生了，有纹理了</DIV></DIV></SPAN>]]></description>
</item><item>
<title><![CDATA[土人知道了空调功能模式]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/20081120233135.shtml</link>
<author>流子</author>
<pubDate>2008-11-20 23:31:00</pubDate>
<description><![CDATA[“模式”选项中有个“水滴”豆是“除湿”模式。曾经有人说以为“太阳”是“夏天”模式（制冷），“雪花”是“冬天”模式（制热）。]]></description>
</item><item>
<title><![CDATA[网络身份证]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/20081119121410.shtml</link>
<author>流子</author>
<pubDate>2008-11-19 12:14:00</pubDate>
<description><![CDATA[<P><A href="http://pic.91cool.net/id/">http://pic.91cool.net/id/</A></P>]]></description>
</item><item>
<title><![CDATA[[原创]模仿魔兽争霸UI实现不规则控件的界面]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/20081117181235.shtml</link>
<author>流子</author>
<pubDate>2008-11-17 18:12:00</pubDate>
<description><![CDATA[<A href="http://www.roboticfan.com/blog/attachment.asp?FileID=3199">不规则控件.rar</A><BR>]]></description>
</item><item>
<title><![CDATA[SWT实现不规则窗体/控件]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/20081117161523.shtml</link>
<author>流子</author>
<pubDate>2008-11-17 16:15:00</pubDate>
<description><![CDATA[窗口标题。<BR>SWT窗口Shell有public void setText(String string)，public void setImage(Image image) 方法用来设置标题和图标。但是现在窗口的样式已经是SWT.NO_TRIM，不再有标题栏了，因此标题只能自己“画”。在paintControl方法中添加如下代码：<BR>else if (e.getSource() == northPanel) {<BR>&nbsp;&nbsp;&nbsp;String text = getText();<BR>&nbsp;&nbsp;&nbsp;if (text != null) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;gc.setForeground(titleColor);<BR>&nbsp;&nbsp;&nbsp;&nbsp;gc.drawText(text, e.width / 2 - gc.stringExtent(text).x / 2,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.height / 2 - gc.stringExtent(text).y / 2, true);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;Image image = getImage();<BR>&nbsp;&nbsp;&nbsp;if (text == null) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;text = "";<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;if (image != null) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;gc.drawImage(image, e.width / 2 - gc.stringExtent(text).x / 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- image.getBounds().width - 10, e.height / 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- image.getBounds().height / 2);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>标题文字居中显示，图标居标题文字10像素。代码中“e.width”获取绘图环境上下文的长度，“gc.stringExtent(text).x”获得标题文字的长度，“true”表示绘制的文字不需要背景，如果是false，会看到有明显的灰色矩形作背景。绘制图标不难理解。当然通常的标题栏是九宫格的“上部”面板，所以要为northPanel添加绘制监听器。northPanel.addPaintListener(this);
<P>二、边缘圆角<BR>如果你不熟悉SWT的Region使用，请先研读<A title=http://www.eclipse.org/swt/snippets/ href="http://www.eclipse.org/swt/snippets/" href_cetemp="http://www.eclipse.org/swt/snippets/">http://www.eclipse.org/swt/snippets/</A>中的“create a non-rectangular shell from a transparent image”程序。<BR>该程序通过分析Image各个像素点的alpha值，来获取Region的填充。你可以通过本地图片实例化一个Image对象，支持透明的图片格式有PNG和GIF两种，美工都会知道这一点，本程序中用到的southwest.png、southeast.png、northeast.png、northwest.png均符合，以图片透明度来实现不规则窗体是常用的方法，这样做的好处是只要更换图片就可达到改变窗体形状。但是有些应用自身规定一种颜色为透明颜色，例如QQ，规定紫色为透明颜色，所以在它的实现中通过对图片逐个像素点分析，发现RGB是紫色就认为是透明。好，原理大致如此。下面来定义一个函数来完成次功能：<BR>private Region getImageTransparenceRegion(Image image, int offsetX,<BR>&nbsp;&nbsp;&nbsp;int offsetY) {<BR>&nbsp;&nbsp;Region region = new Region();<BR>&nbsp;&nbsp;final ImageData imageData = image.getImageData();<BR>&nbsp;&nbsp;if (imageData.alphaData != null) {<BR>&nbsp;&nbsp;&nbsp;Rectangle pixel = new Rectangle(0, 0, 1, 1);<BR>&nbsp;&nbsp;&nbsp;for (int y = 0; y &lt; imageData.height; y++) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;for (int x = 0; x &lt; imageData.width; x++) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (imageData.getAlpha(x, y) != 255) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pixel.x = imageData.x + x + offsetX;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pixel.y = imageData.y + y + offsetY;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;region.add(pixel);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;return region;<BR>&nbsp;}<BR>该方法参考了Snippet21（<A title=http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet219.java?view=co href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet219.java?view=co" href_cetemp="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet219.java?view=co">http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet219.java?view=co</A>），方法返回给定图片透明部分构造的Region。然后在controlResized末尾添加如下代码：<BR>Region ldRegion = getRegion();<BR>&nbsp;&nbsp;if (oldRegion != null &amp;&amp; !oldRegion.isDisposed()) {<BR>&nbsp;&nbsp;&nbsp;oldRegion.dispose();<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;Region newRegion = new Region();<BR>&nbsp;&nbsp;newRegion.add(0, 0, getSize().x, getSize().y);<BR>&nbsp;&nbsp;newRegion.subtract(getImageTransparenceRegion(northwestImage, 0, 0));<BR>&nbsp;&nbsp;newRegion.subtract(getImageTransparenceRegion(northeastImage,<BR>&nbsp;&nbsp;&nbsp;&nbsp;getSize().x - northeastImage.getBounds().width, 0));<BR>&nbsp;&nbsp;newRegion.subtract(getImageTransparenceRegion(southwestImage, 0,<BR>&nbsp;&nbsp;&nbsp;&nbsp;getSize().y - southwestImage.getBounds().y));<BR>&nbsp;&nbsp;newRegion.subtract(getImageTransparenceRegion(southeastImage,<BR>&nbsp;&nbsp;&nbsp;&nbsp;getSize().x - southeastImage.getBounds().width, getSize().y<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- southeastImage.getBounds().height));<BR>&nbsp;&nbsp;setRegion(newRegion);</P>
<P>Shell实例通过setRegion(Region region)设置区域来实现不规则巨型窗体，但是前提是把样式设置成SWT.NO_TRIM。<BR>由于窗体尺寸的变更相应的区域也要跟着调整，所以要把逻辑写在controlResized方法中，而且每次改变过后要释放Region资源并重新设置新的区域。上述在初始化Region对象后，“newRegion.add(0, 0, getSize().x, getSize().y);”方法将覆盖窗口整个区域，随后的subtract挖掉四个角落的透明部分。</P>
<P>三、功能按钮<BR>出于时间比较紧，只添加关闭按钮，其他按钮如最小化、最大化原理相同。<BR>通常按钮有四种状态，分别是：正常态、鼠标在上方、鼠标按下、被禁用。这4态对应4个图标。由于时间关系，只对需要注意的地方简单介绍。具体见完整代码。<BR>无疑，4种状态切换要添加鼠标事件监听器。关闭按钮通过声明private Composite closeButton;来实现。具体位置本程序实现是右端与northeastPanel相邻，左边与northPanel相邻。在鼠标抬起时，要检查抬起点是否在该按钮上，如果是才执行关闭操作。见如下代码<BR>if (e.x &gt; 0 &amp;&amp; e.x &lt; closeButton.getSize().x &amp;&amp; e.y &gt; 0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&amp; e.y &lt; closeButton.getSize().y){<BR>// 执行关闭操作，否则鼠标在关闭按钮上方按下，但是不在其上松开，表明用户放弃关闭行为。<BR>}<BR>重写dispose方法如下：<BR>@Override<BR>&nbsp;public void dispose() {<BR>&nbsp;&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;northwestImage.dispose();<BR>&nbsp;&nbsp;&nbsp;northeastImage.dispose();<BR>&nbsp;&nbsp;&nbsp;northImage.dispose();<BR>&nbsp;&nbsp;&nbsp;southwestImage.dispose();<BR>&nbsp;&nbsp;&nbsp;southeastImage.dispose();<BR>&nbsp;&nbsp;&nbsp;southImage.dispose();<BR>&nbsp;&nbsp;&nbsp;westImage.dispose();<BR>&nbsp;&nbsp;&nbsp;eastImage.dispose();<BR>&nbsp;&nbsp;&nbsp;closeImage.dispose();<BR>&nbsp;&nbsp;&nbsp;closeOverImage.dispose();<BR>&nbsp;&nbsp;&nbsp;color1.dispose();<BR>&nbsp;&nbsp;&nbsp;color2.dispose();<BR>&nbsp;&nbsp;&nbsp;titleColor.dispose();<BR>&nbsp;&nbsp;} finally {<BR>&nbsp;&nbsp;&nbsp;super.dispose();<BR>&nbsp;&nbsp;}<BR>&nbsp;}<BR>首先是释放所有SWT本地资源，然后是super.dispose();释放窗口资源。<BR><BR>运行程序，界面效果如下<BR><IMG title=点击图片可在新窗口打开 style="CURSOR: pointer" height=343 alt="" src="http://www.blogjava.net/images/blogjava_net/javagui/swt_demo/swt-shell.jpg" width=423 border=0 src_cetemp="http://www.roboticfan.com/blog//images/blogjava_net/javagui/swt_demo/swt-shell.jpg"><BR><BR>至此，打造专业外观-窗口部分的讲述就结束了，在这3篇幅中，主要讲述了九宫格的概念，九宫格法俗话说就是“贴图”，这个手法最常用也是最基础的，你会发现界面美观与否与图片有很大关系，同时桌面编程人员需要频繁与美工交互才能达到理想效果，如果没有合格的美工，但凭技术很难实现漂亮的外观，不过确实也存在只用多边形与曲线绘制组件的高手，swing的L&amp;F就是这么实现的，但是贴图的好处是只要图片替换，外观也跟着替换，不用更改代码。<BR><BR>本程序只作为您设计的参考，欠缺还很多，并且没有对代码的健壮性、异常情况过多考虑，由于swt资源必须手工释放，如dispose方法中那样，其实那是最基本的，在实际环境下这么做还很有限，而且nullPoint异常也没有过多考虑。这都需要你自己去实现。<BR><BR>最终的完整程序<A title=这里 href="http://www.blogjava.net/Files/javagui/Demo-final.rar" href_cetemp="http://www.blogjava.net/Files/javagui/Demo-final.rar">这里</A>下载</P>]]></description>
</item><item>
<title><![CDATA[习惯性兴奋回忆]]></title>
<link>http://www.roboticfan.com/blog/user_2005/2171/archives/2008/20081116171511.shtml</link>
<author>chenghw</author>
<pubDate>2008-11-16 17:15:00</pubDate>
<description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">习惯性兴奋回忆不管对人还是未来的智能机器人都是至关重要的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">习惯性回忆也可以类似于状态性回忆。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行习惯性回忆，再习惯性由</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">进行习惯性回忆。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">习惯性易化兴奋与之有记忆联系的记忆柱。</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也是，但只有即与</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">A</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">又与</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">B</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有记忆联系的记忆柱得到最强的易化兴奋。（这与状态性回忆相似）</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">被习惯性兴奋的记忆柱主要是：</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">1</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、是由刺激直接引起。</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">2</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、是由主注意对象引起。是与它们有记忆联系的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">记忆柱联系不强的记忆柱必被抑制。（对人来说可能通过扩布性抑制获得，但智能软件来说可通过直接设置）</SPAN></P>]]></description>
</item><item>
<title><![CDATA[具有编辑功能的Treeviewer / TableTreeviewer实例]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/20081116155420.shtml</link>
<author>流子</author>
<pubDate>2008-11-16 15:54:00</pubDate>
<description><![CDATA[<P>周末在家里做了个research</P>
<P><IMG src="http://www.roboticfan.com/blog/UploadFiles/2008-11/16160960995.png"><BR></P>源码：<A href="http://www.roboticfan.com/blog/attachment.asp?FileID=3197">TableTree.rar</A><BR>]]></description>
</item><item>
<title><![CDATA[关于arduino]]></title>
<link>http://www.roboticfan.com/blog/u2007/16448/archives/2008/20081116154927.shtml</link>
<author>ceasimo</author>
<pubDate>2008-11-16 15:49:00</pubDate>
<description><![CDATA[<P>要懂它。</P>
<P>以后会很有用的。</P>
<P>CEASIMO</P>]]></description>
</item><item>
<title><![CDATA[钻研仿生RT的理论]]></title>
<link>http://www.roboticfan.com/blog/u2007/16448/archives/2008/20081116154534.shtml</link>
<author>ceasimo</author>
<pubDate>2008-11-16 15:45:00</pubDate>
<description><![CDATA[<P>旭日固然为一日之始的象征，苏醒的大地沐浴在它温暖的光照之下。使人感到无限的温暖。然而早晨上午，中午，午后乃至夕照之时。它仍撒下大量光热.....太阳在一日中始终都在无私地放射着自己的能量，犹如人生的全程任何阶段都潜伏着巨大的创造性。征程一生绝非仅有绝对唯一的“起点”。而是随时是振奋可为的踏荒之始。 </P>
<P>从明天开始了对它的征程。加油/。</P>
<P>仿生的理论。</P>
<P>CEASIMO</P>]]></description>
</item><item>
<title><![CDATA[刚刚注册了这个blog]]></title>
<link>http://www.roboticfan.com/blog/u2007/16521/archives/2008/200811161155.shtml</link>
<author>tangjianqiu</author>
<pubDate>2008-11-16 1:01:00</pubDate>
<description><![CDATA[<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 明天休息,在网上找找ABB,就注册了这个blog,有时间来这里玩玩吧!大家一起来研究研究啊!</P>]]></description>
</item><item>
<title><![CDATA[笑话几则]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/20081115205555.shtml</link>
<author>流子</author>
<pubDate>2008-11-15 20:55:00</pubDate>
<description><![CDATA[<P>1、 毕业后七年，总算接了个大工程，造一根三十米烟囱，工期两个月，造价三十万，不过要垫资。总算在去年年底搞完了。今天人家去验收，被人骂得要死，还没有钱拿。妈的!图纸看反了，人家是要挖一口井！</P>
<P>2、医生问病人是怎么骨折的。病人说，我觉得鞋里有沙子，就扶着电线杆抖鞋。TMD有个混蛋经过那里，以为我触电了，便抄起木棍给了我两棍子!</P>
<P>3、 乌龟受伤.让蜗牛去买药。过了2个小时.蜗牛还没回来。乌龟急了骂道:他妈的再不回来老子就死了!这时门外传来了蜗牛的声音:你他妈再说老子不去了!</P>
<P>4、一醉汉不慎从三楼掉下,引来路人围观,一警察过来:发生什么事？醉汉：不清楚,我也是刚到 </P>]]></description>
</item><item>
<title><![CDATA[兴奋能力的变化]]></title>
<link>http://www.roboticfan.com/blog/user_2005/2171/archives/2008/20081115161257.shtml</link>
<author>chenghw</author>
<pubDate>2008-11-15 16:12:00</pubDate>
<description><![CDATA[<P>在智能软件（或人）的早期，由于记忆柱之间的相互兴奋能力不强，原始记忆柱群这间的兴奋需要主注意对象中枢的强烈参与才能兴奋，不存在习惯性问题，更多的是选择性兴奋。但随学习记忆的发展，原始记忆柱之间的兴奋能力不但增加，在智能软件成熟（人的思维发展一定水平）后，更多的是习惯性兴奋，而且这种习惯性兴奋能力会越来越强，思维的速度也越来越快（兴奋速度）。</P>
<P>讨论以上的问题会有什么意义呢？这有助于我们对一些心理问题及脑电形成机理的讨论。今后我将讨论之。</P>]]></description>
</item><item>
<title><![CDATA[QQ游戏网络架构研究]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/20081114165328.shtml</link>
<author>流子</author>
<pubDate>2008-11-14 16:53:00</pubDate>
<description><![CDATA[<P><IMG src="http://www.roboticfan.com/blog/UploadFiles/2008-11/141653871951.png"><BR>1.从中得到的启发：聊天系统改成UDP方式，</P>
<P>2.对于房间列表，如果点击一次节点后30秒内无动作，则断开连接，不是一点击获得后马上断开</P>]]></description>
</item><item>
<title><![CDATA[【Eclipse插件开发】打开编辑器]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/2008111318721.shtml</link>
<author>流子</author>
<pubDate>2008-11-13 18:07:00</pubDate>
<description><![CDATA[今天终于可以闲一天，想来想去就乱写点东西吧，说不定对有些新人有点帮助呢～_～<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用Eclipse API的方式来打开编辑器，可能对任何一个插件开发者都不是很陌生的操作了。但是，还是建议你忍着看一下，全当是复习吧～_～。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="FONT-SIZE: 18pt; COLOR: red">【打开editor的接口讨论】</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 先来看一下workbench吧，workbench从静态划分应该大致如下：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=353 alt="" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_02.JPG" width=517 border=0><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从结构图我们大致就可以猜测出来，workbench page作为一个IWorkbenchPart（无论是eidtor part还是view part）的容器，肯定会接受workbench page的管理。看了一下，IWorkbenchPage接口定义中确实提供给了如下打开编辑器的操作：<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="http://www.roboticfan.com/blog/COLOR: red">【IWokbenchPage提供的接口】</SPAN> 
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">1</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">interface</SPAN><SPAN style="COLOR: #000000">&nbsp;IWorkbenchPage&nbsp;</SPAN><SPAN style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000">&nbsp;IPartService,&nbsp;ISelectionService,ICompatibleWorkbenchPage&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorPart&nbsp;openEdito(IEditorInput&nbsp;input,&nbsp;String&nbsp;editorId)</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;PartInitException;<BR></SPAN><SPAN style="COLOR: #008080">4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorPart&nbsp;openEdito(IEditorInput&nbsp;input,&nbsp;String&nbsp;editorId,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;activate)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;PartInitException;<BR></SPAN><SPAN style="COLOR: #008080">6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorPart&nbsp;openEditor(</SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorInput&nbsp;input,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000">&nbsp;String&nbsp;editorId,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;activate,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">final</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;matchFlags)</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;PartInitException;<BR></SPAN><SPAN style="COLOR: #008080">8</SPAN>&nbsp;<SPAN style="COLOR: #000000">}</SPAN></DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;那到这边，可能很多人已经知道了怎么调用这些接口了：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<STRONG> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(...)</STRONG><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;（说明：PlatformUI可以看作是整个eclipse ui框架的门面类，当然最核心的作用就是让用户获取到workbench。Eclipse中存在的其他一些门面类如：ResourcesPlugin、Platform、JavaCore、JavaUI等）<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;我们再仔细看一下IWorkbenchPage对应的实现类（org.eclipse.ui.internal.WorkbenchPage）中的以上接口的实现代码，真正在管理Editor的是一个叫做EditorManager的东东（同理，view part对应的管理器角色类是叫做ViewFactory的东东）。<STRONG>这里的EditorManager和View Factory是workbench实现中非常精华的部分，看一下里面的实现就会很大程度上理解workbench所谓懒加载、懒初始化是如何实现的了，如何实现part 复用的...等等</STRONG>。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=297 alt="" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_03.JPG" width=532 border=0><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 上图就用来说明workbench是如何来管理各种part的，其中deor角色的核心作用是延迟加载扩展（延迟加载用户通过editors或者views提供的扩展），reference角色的核心作用是用来延迟初时化具体的part（例如避免过早的创建对应的control等等）。再说下去有点偏离主题了，这部分，以后有时间再写<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="http://www.roboticfan.com/blog/COLOR: red">【IDE工具类提供的接口】<BR></SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;上面IWorkbenchPage提供接口都需要用户准备两样东西：一是创建IEditorInput实例，二是指定editor id。有些用户可能不想干这两件事情，所以在工具类org.eclipse.ui.ide.IDE中提供了其他的接口：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorPart&nbsp;openEditor(IWorkbenchPage&nbsp;page,&nbsp;IFile&nbsp;input)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;PartInitException&nbsp;{&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorPart&nbsp;openEditor(IWorkbenchPage&nbsp;page,&nbsp;IFile&nbsp;input,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;activate)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;PartInitException&nbsp;{&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorPart&nbsp;openEditor(IWorkbenchPage&nbsp;page,&nbsp;IFile&nbsp;input,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;activate,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;determineContentType)&nbsp;{&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorPart&nbsp;openEditor(IWorkbenchPage&nbsp;page,&nbsp;IFile&nbsp;input,&nbsp;String&nbsp;editorId)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;PartInitException&nbsp;{&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorPart&nbsp;openEditor(IWorkbenchPage&nbsp;page,&nbsp;IFile&nbsp;input,&nbsp;String&nbsp;editorId,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;activate)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;PartInitException&nbsp;{&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;</DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;上面5个接口操作中，&nbsp;对于上面的三个操作，Eclipse会自动为你准备IEditorInput实例，并动态绑定合适的编辑器类型。对于下面的两个操作，Eclipse会为你自动准备IEditorInput实例，但是需要用户自己指定editor id。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;接下来我们看两个问题，一是如何创建IEditorInput实例的；而是如何动态计算对应的editor id的。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【有关FileEditorInput】<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在IDE工具类中提供的5个接受IFile对象的openEditor接口中，在对应的实现中都是默认构造了一个FileEditorInput（org.eclipse.ui.part.FileEditorInput）实例，这个实例也是org.eclipse.ui.IFileEditorInput接口的默认实现类（注意：Eclipse中很多地方都使用这种Interface/Default Impl的方式，Interface会暴露，Default Impl则根据情况选择是否暴露，一般是如果Interface希望用户来扩展继承，则会暴露对应的Default Impl，如果Interface不希望用户来扩展继承，例如IResource系列接口，则一般会将Default Impl丢如对应的internal包中）。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;我们看一下org.eclipse.ui.part.FileEditorInput中是如何实现IEditorInput.exists()接口的：<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">1</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;FileEditorInput&nbsp;</SPAN><SPAN style="COLOR: #0000ff">implements</SPAN><SPAN style="COLOR: #000000">&nbsp;IFileEditorInput,IPathEditorInput,IPersistableElement&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;IFile&nbsp;file;<BR></SPAN><SPAN style="COLOR: #008080">3</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;exists()&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;file.exists();<BR></SPAN><SPAN style="COLOR: #008080">6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">7</SPAN>&nbsp;<SPAN style="COLOR: #000000">}</SPAN></DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我们看到内部的实现是持有了IFile句柄，如果IFile代表的资源没有存在于工作区之内，那么就会返回false。（疑问：如果我们打开工作区外部的文件呢？？？显然，FileEditorInput并不合适，稍后看...）<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【动态计算editor id】<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下面，我们再来看一下IDE类是如何计算所谓的默认eidtor id的。追踪实现，我们看到了IDE.getDefaultEditor<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;IEditorDeor&nbsp;getDefaultEditor(IFile&nbsp;file,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">boolean</SPAN><SPAN style="COLOR: #000000">&nbsp;determineContentType)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Try&nbsp;file&nbsp;specific&nbsp;editor.</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IEditorRegistry&nbsp;editorReg&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PlatformUI.getWorkbench()<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.getEditorRegistry();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;editorID&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;file.getPersistentProperty(EDITOR_KEY);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(editorID&nbsp;</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IEditorDeor&nbsp;desc&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;editorReg.findEditor(editorID);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(desc&nbsp;</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;desc;<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(CoreException&nbsp;e)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;do&nbsp;nothing</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">15</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IContentType&nbsp;contentType&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(determineContentType)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contentType&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;getContentType(file);<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Try&nbsp;lookup&nbsp;with&nbsp;filename</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">22</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;editorReg.getDefaultEditor(file.getName(),&nbsp;contentType);<BR></SPAN><SPAN style="COLOR: #008080">23</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;上面的代码大致赶了如下两件事情：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1、如果对应的资源设定了一个特定的持久化属性EDITOR_KEY，则会使用EDITOR_KEY属性值所代表的编辑器（说明：有关Eclipse资源的属性支持，请参阅其他文档）。那如果一个资源不在工作区之内，又如何设定EDITOR_KEY属性呢？？？&nbsp; （～_～确实没法设定）<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2、查找对应的content type，用户通过org.eclipse.core.runtime.contentTypes扩展点来注册自定义的内容类型，在内容类型中会指定对应的文件扩展名和默认编码，例如JDT中注册了如下内容类型（摘自org.eclipse.jdt.core/plugin.xml）：<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">&nbsp;===================================================================================&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">&nbsp;Extension:&nbsp;Java&nbsp;Content&nbsp;Types&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">&nbsp;===================================================================================&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">extension&nbsp;</SPAN><SPAN style="COLOR: #ff0000">point</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.core.runtime.contentTypes"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">&nbsp;declares&nbsp;a&nbsp;content&nbsp;type&nbsp;for&nbsp;Java&nbsp;Properties&nbsp;files&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">content-type&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="javaProperties"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="%javaPropertiesName"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;base-type</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.core.runtime.text"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;priority</SPAN><SPAN style="COLOR: #0000ff">="high"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file-extensions</SPAN><SPAN style="COLOR: #0000ff">="properties"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default-charset</SPAN><SPAN style="COLOR: #0000ff">="ISO-8859-1"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">&nbsp;Associates&nbsp;.classpath&nbsp;to&nbsp;the&nbsp;XML&nbsp;content&nbsp;type&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">file-association&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">content-type</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.core.runtime.xml"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file-names</SPAN><SPAN style="COLOR: #0000ff">=".classpath"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">&nbsp;declares&nbsp;a&nbsp;content&nbsp;type&nbsp;for&nbsp;Java&nbsp;Source&nbsp;files&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">content-type&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="javaSource"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="%javaSourceName"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;base-type</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.core.runtime.text"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;priority</SPAN><SPAN style="COLOR: #0000ff">="high"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file-extensions</SPAN><SPAN style="COLOR: #0000ff">="java"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">&nbsp;declares&nbsp;a&nbsp;content&nbsp;type&nbsp;for&nbsp;Java&nbsp;class&nbsp;files&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">content-type&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="javaClass"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="%javaClassName"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;priority</SPAN><SPAN style="COLOR: #0000ff">="high"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file-extensions</SPAN><SPAN style="COLOR: #0000ff">="class"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">describer<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">class</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.core.runtime.content.BinarySignatureDescriber"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">parameter&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="signature"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;value</SPAN><SPAN style="COLOR: #0000ff">="CA,&nbsp;FE,&nbsp;BA,&nbsp;BE"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">describer</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">content-type</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">&lt;!--</SPAN><SPAN style="COLOR: #008000">&nbsp;declares&nbsp;a&nbsp;content&nbsp;type&nbsp;for&nbsp;JAR&nbsp;manifest&nbsp;files&nbsp;</SPAN><SPAN style="COLOR: #008000">--&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">content-type&nbsp;</SPAN><SPAN style="COLOR: #ff0000">id</SPAN><SPAN style="COLOR: #0000ff">="JARManifest"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;name</SPAN><SPAN style="COLOR: #0000ff">="%jarManifestName"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;base-type</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.core.runtime.text"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;priority</SPAN><SPAN style="COLOR: #0000ff">="high"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file-names</SPAN><SPAN style="COLOR: #0000ff">="MANIFEST.MF"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default-charset</SPAN><SPAN style="COLOR: #0000ff">="UTF-8"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">extension</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 那如果我们在注册编辑器的时候和对应的content type绑定，这不就联系起来了吗～_～。那我们看一下java源码编辑器扩展描述（摘自org.eclipse.jdt.ui/plugin.xml）：<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">editor<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">name</SPAN><SPAN style="COLOR: #0000ff">="%JavaEditor.label"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default</SPAN><SPAN style="COLOR: #0000ff">="true"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;icon</SPAN><SPAN style="COLOR: #0000ff">="$nl$/icons/full/obj16/jcu_obj.gif"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;contributorClass</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditorActionContributor"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;symbolicFontName</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.jdt.ui.editors.textfont"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.jdt.ui.CompilationUnitEditor"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">contentTypeBinding<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #ff0000">contentTypeId</SPAN><SPAN style="COLOR: #0000ff">="org.eclipse.jdt.core.javaSource"</SPAN><SPAN style="COLOR: #ff0000"><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">editor</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我们看到上面的xml中有contentTypeBinding元素，里面指定了绑定java源码content type。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<STRONG>那如果我们在注册编辑器的时候，没有绑定对应的content type呢</STRONG>？Eclipse允许你配置，往下看：<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=526 alt="" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_04.JPG" width=718 border=0><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=526 alt="http://www.roboticfan.com/blog/" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_05.JPG" width=718 border=0></P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;我想看到这边对eclipse如何动态计算一个文件对应的editor应该是明白了吧，再回顾一下吧：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1、查看资源本身是否有EIDTOR_ID持久属性（注意：一、只有工作区中存在的资源才允许设置持久属性；二、资源属性知识针对特定资源，不会影响同类型资源，即你对工作区中特定的.java文件设定了EIDTOR_ID持久属性，并不会影响工作区中其他.java文件资源的编辑器绑定操作）<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2、查找对应的content type，然后查找对应的editor扩展或者查找Eclipse中的Content Types和File Associations配置<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3、如果都找不到，则直接给一个默认的编辑器。例如，我们经常碰到是"org.eclipse.ui.DefaultTextEditor"<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="http://www.roboticfan.com/blog/COLOR: red">【IDE工具类提供的接口 VS&nbsp; IWorkbenchPage提供的接口】<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: #000000">看一下以上提到的各个角色之间的调用关系图吧：<BR></SPAN></SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=341 alt="" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_06.JPG" width=528 border=0><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="http://www.roboticfan.com/blog/FONT-SIZE: 18pt; COLOR: red">【使用Eclipse提供的打开editor的接口】<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="FONT-SIZE: 12pt; COLOR: #000000">还是那句话，需求决定一切。我们看一下打开编辑器的需求：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1、打开工作区中工程内的文件资源<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2、打开工作区.data目录中的文件资源<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3、打开工作区外部的文件资源<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【说明】Eclipse工作区实际上是有数据区和元数据区两个区域组成的，示意如下：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=306 alt="" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_07.JPG" width=536 border=0><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=148 alt="http://www.roboticfan.com/blog/" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_09.JPG" width=736 border=0><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;对于Eclipse来说，.data目录下存放的是插件运行时的关键状态数据，不建议用户再工作区实例运行期间做相应修改，为此eclipse干了两件事情：1、运行期间会自动在.data目录下产生一个进程锁定的.lock文件；2、Eclipse不允许用户通过IResource系列接口直接访问或修改.meatadata目录下的资源<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【打开工作区工程内的资源】<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN></SPAN> 假设工作区中有测试工程TestProject，工程下有文本文件java_file.txt。对应创建代码如下：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">创建工程</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IProject&nbsp;project&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ResourcesPlugin.getWorkspace().getRoot().getProject(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">TestProject</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #000000">project.exists())<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;project.create(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #000000">project.isOpen())<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;project.open(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">创建文件</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IFile&nbsp;java_file&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;project.getFile(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Path(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/java_file.txt</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;inputStreamJava&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ByteArrayInputStream(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">class&nbsp;MyType{}</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.getBytes());<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #000000">java_file.exists())<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java_file.create(inputStreamJava,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(CoreException&nbsp;e)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IStatus&nbsp;status&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Status(IStatus.ERROR,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">myplugin</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">101</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">创建资源失败</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;e);<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Activator.getDefault().getLog().log(status);<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></DIV><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=320 alt="" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_10.JPG" width=263 border=0><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;打开方式一：Eclipse默认计算对应的editor id，会用default text&nbsp;editor打开&nbsp; 
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IWorkbenchPage&nbsp;page&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IProject&nbsp;project&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ResourcesPlugin.getWorkspace().getRoot().getProject(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">TestProject</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IFile&nbsp;java_file&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;project.getFile(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Path(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/java_file.txt</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IDE.openEditor(page,&nbsp;java_file);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(CoreException&nbsp;e)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IStatus&nbsp;status&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Status(IStatus.ERROR,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">myplugin</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">102</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">打开工作区内文件出错</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;e);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Activator.getDefault().getLog().log(status);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></DIV><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;打开方式二：指定java源码编辑器打开，会用java源码编辑器打开<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IWorkbenchPage&nbsp;page&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IProject&nbsp;project&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ResourcesPlugin.getWorkspace().getRoot().getProject(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">TestProject</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IFile&nbsp;java_file&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;project.getFile(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Path(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/java_file.txt</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IDE.openEditor(page,&nbsp;java_file,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">org.eclipse.jdt.ui.CompilationUnitEditor</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(CoreException&nbsp;e)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IStatus&nbsp;status&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Status(IStatus.ERROR,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">myplugin</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">102</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">打开工作区内文件出错</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;e);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Activator.getDefault().getLog().log(status);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></DIV><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打开方式三：设定editor id属性，该文件以后默认都用此editor id打开<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IWorkbenchPage&nbsp;page&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IProject&nbsp;project&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;ResourcesPlugin.getWorkspace().getRoot().getProject(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">TestProject</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IFile&nbsp;java_file&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;project.getFile(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Path(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">/java_file.txt</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;java_file.setPersistentProperty(IDE.EDITOR_KEY,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">org.eclipse.jdt.ui.CompilationUnitEditor</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IDE.openEditor(page,&nbsp;java_file);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(CoreException&nbsp;e)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IStatus&nbsp;status&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Status(IStatus.ERROR,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">myplugin</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">102</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">打开工作区内文件出错</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;e);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Activator.getDefault().getLog().log(status);<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></DIV><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;说明：对于工作区工程内的资源，可以有两种方式：一是local的，那就是物理存在与工程之内；二是link进入的。打开编辑器的时候，不需要做区分。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【打开工作区外部的资源】<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;说明：既存在于工作区外部，同时又没有被link进工程。<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在Eclipse中有个功能，就是File-&gt;Open File，可以打开一个外部文件。那我们看一下它是怎么实现的。我们只需要打开对应的对话框，然后挂起主线程，就可以找到对应的action了（挂起线程可以帮我们很方便的调试很多类型的问题，以后细说~_~）：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=283 alt="" src="http://www.blogjava.net/images/blogjava_net/zhuxing/open_editor_11.JPG" width=838 border=0><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 分析一下OpenExternalFileAction的实现，我们发现它自己构建了一个editor input<BR><BR><BR>
<P style="COLOR: red">本博客中的所有文章、随笔除了标题中含有引用或者转载字样的，其他均为原创。转载请注明出处，谢谢！</P>
<P style="COLOR: red">org.eclipse.jdt.ui;bundle-version="3.4.0",<BR>&nbsp;org.eclipse.jface.text;bundle-version="3.4.0",<BR>&nbsp;org.eclipse.jdt.core;bundle-version="3.4.0",<BR>&nbsp;org.eclipse.core.resources;bundle-version="3.4.0",<BR>&nbsp;org.eclipse.ui.ide;bundle-version="3.4.0",<BR>&nbsp;org.eclipse.ui.editors;bundle-version="3.4.0"</P>
<P><A href="http://www.roboticfan.com/blog/attachment.asp?FileID=3188">javaEditor.rar</A></P>
<P>出自：<A href="http://www.blogjava.net/zhuxing/category/33273.html">http://www.blogjava.net/zhuxing/category/33273.html</A><BR></P>]]></description>
</item><item>
<title><![CDATA[[转]Editor中嵌入Editor]]></title>
<link>http://www.roboticfan.com/blog/user_2005/104/archives/2008/2008111310376.shtml</link>
<author>流子</author>
<pubDate>2008-11-13 10:37:00</pubDate>
<description><![CDATA[<P>原文出处：<A href="http://liugang594.javaeye.com/blog/208495">http://liugang594.javaeye.com/blog/208495</A></P>
<P><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-FAMILY: Times New Roman">---Eclipse</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">系列（刘刚）</SPAN></SPAN></P>
<H2 style="MARGIN: 6pt 0in"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial"><EM><SPAN style="FONT-SIZE: 14pt">一、背景</SPAN></EM></SPAN></H2>
<P class=MsoNormal style="MARGIN: 6pt 0in; TEXT-INDENT: 29.25pt; LINE-HEIGHT: 150%"><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">有时按照功能的需要，我们希望能在自己的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">Editor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">中嵌入其他已经存在的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">Editor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">，比如</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">JavaEditor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">，比如</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">XMLEditor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">，以方便的使用这些</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">Editor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">已经有的一些方便特性。</SPAN></SPAN></P>
<H2 style="MARGIN: 6pt 0in"><EM><SPAN style="FONT-SIZE: large"><SPAN style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">二、思路</SPAN></SPAN></EM></H2>
<P class=MsoNormal style="MARGIN: 6pt 0in; LINE-HEIGHT: 150%"><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-FAMILY: 'Courier New'; mso-hansi-font-family: 'Times New Roman'"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">粗看来，好像无计可施，实际不然。如果你曾经实现过自己的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">MultiEditor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">，并且在其他的某一页中是直接引用的其他的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">Editor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">，那么你肯定记得：在</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">MultiEditor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">addPage()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Courier New'">系列方法中，有一个方法是：</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; TEXT-ALIGN: center" align=center><SPAN style="FONT-SIZE: 10pt"><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">public</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> </SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">int</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> addPage(IEditorPart editor, IEditorInput input)</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">；</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 6pt 0in; LINE-HEIGHT: 150%"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">这个方法表明，可以直接把一个</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">Editor</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">做为一个</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">page</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">加到</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">MultiEditor</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">中去。所以我们的实现可以参考</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">MultiEditor</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">。</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">我们可以找到</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">MultiEditor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">中，</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">addPage(editor,input)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">部分的源码：</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-FAMILY: 'Courier New'"><SPAN style="FONT-SIZE: 10pt"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">public</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> </SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">void</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> addPage(</SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">int</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> index, IEditorPart editor, IEditorInput input)</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">throws</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> PartInitException {</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: small"><SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>IEditorSite site = createSite(editor);</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">// call init first so that if an exception is thrown, we have created no</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">// new widgets</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: small"><SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>editor.init(site, input);</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Composite parent2 = </SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> Composite(getContainer(),</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: small"><SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>getOrientation(editor));</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>parent2.setLayout(</SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> FillLayout());</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: small"><SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>editor.createPartControl(parent2);</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">……</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-SIZE: small"><SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-FAMILY: 'Courier New'"><SPAN style="FONT-SIZE: 10pt"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">看上部分代码，我们可以知道：要把一个</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">editor A</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">作为某个</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">editor B</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的一部分加进去，我们首先需要有一个</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">A</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的对象，然后这个</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">A</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象要调用</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">init(site,input)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">方法，最后要创建一个面板，调用</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">A</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">createPartControl(parent)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">方法，以在这个面板上画出</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">A</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的界面。</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 6pt 0in"><SPAN style="FONT-FAMILY: 'Courier New'"><SPAN style="FONT-SIZE: 10pt"></SPAN></SPAN>&nbsp;</P>
<H2 style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial"><EM><SPAN style="FONT-SIZE: 14pt">三、实现</SPAN></EM></SPAN></H2>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">有了以上思路，下面我们就可以在自己的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">editor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">中嵌入其他的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">editor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">了。首先我们要定义一个自己的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">editor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">，这里省略过程。然后我定义了一个名为</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">ComboEditor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">Editor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">。我要在这其中嵌入</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">JavaEditor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">TextEditor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">。</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-SIZE: 10pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">我一开始设想代码如下（在</SPAN><SPAN style="FONT-FAMILY: 'Courier New'">createPartControl()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">方法里）：</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%"><SPAN style="FONT-FAMILY: 'Courier New'"><SPAN style="FONT-SIZE: 10pt"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">public</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> </SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">void</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> createPartControl(Composite parent) {</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">try</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> {</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>parent.setLayout(</SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> GridLayout());</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN><SPAN style="COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'">// </SPAN><STRONG><SPAN style="COLOR: #7f9fbf; FONT-FAMILY: 'Courier New'">TODO</SPAN></STRONG><SPAN style="COLOR: #3f7f5f; FONT-FAMILY: 'Courier New'"> Auto-generated method stub</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>TextEditor textEditor = </SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> TextEditor();</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>textEditor.init(</SPAN><SPAN style="COLOR: #0000c0; FONT-FAMILY: 'Courier New'">site</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">, </SPAN><SPAN style="COLOR: #0000c0; FONT-FAMILY: 'Courier New'">input</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">);</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Composite parent2 = </SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> Composite(parent,</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: small"><SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>textEditor.getOrientation());</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>parent2.setLayout(</SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> FillLayout());</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>parent2.setLayoutData(</SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> GridData(GridData.</SPAN><EM><SPAN style="COLOR: #0000c0; FONT-FAMILY: 'Courier New'">FILL_BOTH</SPAN></EM><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">));</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: small"><SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>textEditor.createPartControl(parent2);</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-FAMILY: 'Courier New'"><SPAN style="FONT-SIZE: 10pt"></SPAN></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>CompilationUnitEditor javaEditor = </SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> CompilationUnitEditor();</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>javaEditor.init(</SPAN><SPAN style="COLOR: #0000c0; FONT-FAMILY: 'Courier New'">site</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">, </SPAN><SPAN style="COLOR: #0000c0; FONT-FAMILY: 'Courier New'">input</SPAN><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'">);</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: 10pt"><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Composite <SPAN style="BACKGROUND: silver; mso-highlight: silver">parent3</SPAN> = </SPAN><STRONG><SPAN style="COLOR: #7f0055; FONT-FAMILY: 'Courier New'">new</SPAN></STRONG><SPAN style="COLOR: #000000; FONT-FAMILY: 'Courier New'"> Composite(parent,</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid-align: none"><SPAN style="FONT-SIZE: small"><SPAN style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: 'Courier New'"><SPAN style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>javaEditor.getOrientation());</SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: 150%; mso-layout-grid