??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品色图,精品欧美一区二区在线观看,国产一区二区无遮挡http://www.aygfsteel.com/joeyjong/Keep walking…?/description>zh-cnSat, 05 Jul 2025 14:41:36 GMTSat, 05 Jul 2025 14:41:36 GMT607.1 graphic contexthttp://www.aygfsteel.com/joeyjong/archive/2006/04/14/41042.htmlJOOJOOFri, 14 Apr 2006 03:26:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/14/41042.htmlhttp://www.aygfsteel.com/joeyjong/comments/41042.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/14/41042.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/41042.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/41042.htmlgraphic contextpControl最层的画板,它可以你向GUI components加入客制化的囑ŞQ图片,及不同字体的文本。同样也提供事g处理

graphic context是在GCcM的,GC对象是附着于现存的Controls?br />
要创Z个graphically oriented的应用程序,首先要创建graphic contextQƈ其与一个component相关联,q两步都可通过GC的constructor来实现。共?个构造函敎ͼ见下Q?br />1. GC(Drawable)--Creates a GC and configures it for the Drawable object
2. GC(Drawable, int)--Creates and configures a GC and sets the text-display styleQ第二个参数可以是RIGHT_TO_LEFT或LEFT_TO_RIGHTQ默认|;
W一个参数需要实现Drawable接口的对象, 此接口包含了与graphic context.内部相联pȝҎ。SWT提供了三个实现Drawable接口的类QImage, Device, ?Control.


Control子类虽然都能包含囑ŞQ但只有一个类是特别适合GC对象的:Canvas。它不仅提供了一个Composite的containment propertyQ还可以用一pd的风格来定义囑Ş在此区域内如何显C?br />
CZQ?/u>

package com.swtjface.Ch7;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class DrawExample
{
public static void main (String [] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Drawing Example");
Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.setSize(150, 150);
canvas.setLocation(20, 20);//在shell中创建canvas
shell.open ();
shell.setSize(200,220);
GC gc = new GC(canvas);//在canvas中创?/font>graphic context
gc.drawRectangle(10, 10, 40, 45);
gc.drawOval(65, 10, 30, 35);
gc.drawLine(130, 10, 90, 80);
gc.drawPolygon(new int[] {20, 70, 45, 90, 70, 70});
gc.drawPolyline(new int[] {10,120,70,100,100,130,130,75});
gc.dispose();//释放Color对象
while (!shell.isDisposed())
{
 if (!display.readAndDispatch())
 display.sleep();
 }
 display.dispose();
 }
 }
有两炚w要注意:1.在调用shell.open()之前构徏Canvas对象Q然后在调用shell.open()之后创徏和用GC对象
                     2.在用完之后一定要立即释放GC object
如上例所CGC提供了一pd在Drawable对象上画囑Ş的方法,如下Q?br />

但是上例中有个问题:当shell被变灰过或者最化q之后,囑Ş׃被擦厅R所以我们需要解决的事,无论window怎么变化Q图形都保持可见。因此SWT在一?/span>Drawable对象被刷新后让你自行控制。这个更新的q程pUCؓpainting?/span>


Painting and PaintEvents

当一个GCҎ在一个Drawabel对象上画Z个图案,它仅执行q个paintingq程一ơ。如果用h变对象尺寸或是用另一个窗口去覆盖它,则图形会被消除。因此,应用E序能否在外界事件媄响下l持其外观这一点相当重要?br />
q些外部事g被称为PaintEventsQ接收它们的E序接口是PaintListener。一个Control在Q何时候当其外观被应用E序或是外界zd改变都会触发一个PaintEvent。这些类对于事g和监听器的用方式都和我们在W四章内提到的类伹{由于PaintListener只有一个事件处理方法,所以不需要用adapterc?br />
Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.setSize(150, 150);
canvas.setLocation(20, 20);
canvas.addPaintListener(new PaintListener()
{
public void paintControl(PaintEvent pe)
{
GC gc = pe.gc;//每一个PaintEvent对象都包含有其自qGC
gc.drawPolyline(new int[] {10,120,70,100,100,130,130,75});
}
});
shell.open();

每一个PaintEvent对象都包含有其自qGCQ主要有2个原因:1.因ؓq个GC instance是由事g产生的,所以PaintEvent会负责释放他?.应用E序可以在shell open之前创徏GC,q样可以使图形在一个独立的cM被创建?/font>

SWT?/span>PaintListener接口内优?/span>paintingq程,SWT的开发者强烈徏?/span>Control?/span>painting仅对PaintEvent作出反应。如果一个应用程序因为其他原因必L新其囑ŞQ则他们推荐使用control?/span>redraw()ҎQ这会在队列中加入一?/span>painth。之后,你可以调?/span>update()Ҏ来处理所有的l定于该对象?/span>painth?br />
需要牢记的是,虽然对于Control对象推荐在一个PaintListener内paintingQ但是由于Device和Image对象q不能在该接口内使用。如果你需要在一个image或device内生成图形,你必d独地生成一个GC对象q在使用l束后将光毁?/span>



JOO 2006-04-14 11:26 发表评论
]]>
6.5 Custom layoutshttp://www.aygfsteel.com/joeyjong/archive/2006/04/12/40691.htmlJOOJOOWed, 12 Apr 2006 09:19:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/12/40691.htmlhttp://www.aygfsteel.com/joeyjong/comments/40691.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/12/40691.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40691.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40691.html 要客制化layoutQ需要承抽象类LayoutQ需要写2个方法——computeSize() 和layout().

computeSize()

protected Point computeSize(Composite composite,
int wHint, int hHint,
boolean flushCache)
{
Point maxDimensions =
calculateMaxDimensions(composite.getChildren());
int stepsPerHemisphere =
stepsPerHemisphere(composite.getChildren().length);
int maxWidth = maxDimensions.x;
int maxHeight = maxDimensions.y;
int dimensionMultiplier = (stepsPerHemisphere + 1);
int controlWidth = maxWidth * dimensionMultiplier;
int controlHeight = maxHeight * dimensionMultiplier;
int diameter = Math.max(controlWidth, controlHeight);
Point preferredSize = new Point(diameter,
diameter);
... // code to handle case when our calculations
// are too large
return preferredSize;
}

参数Q?br />1.composite--The object we’re going to populate. At the time this method is called, it has children, but neither the composite nor the children have been sized or positioned on the screen.

2.wHint and hHint--layout所需的最大长宽。若带有参数SWT.DEFAULT,表示此layout可以随意使用use whatever sizes it decides it needs.

3.flushCache--作ؓflagQto tell the layout whether it’s safe to use any cached values that it may be maintaining.

computeSize()的目的主要在于计我们要layout的composite有多?br />layout()
…?br />



JOO 2006-04-12 17:19 发表评论
]]>
6.4 The form layouthttp://www.aygfsteel.com/joeyjong/archive/2006/04/12/40607.htmlJOOJOOWed, 12 Apr 2006 04:22:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/12/40607.htmlhttp://www.aygfsteel.com/joeyjong/comments/40607.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/12/40607.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40607.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40607.html 与之前所q的layout不同Qform layout不是Z行和列的Q它是基于与其他control之间的相对位|的?br />
FormLayout十分单,你只要:1.讑֮边距(高,宽)属性?2.讑֮spacing属性,x有control间的距离(in pixels)

同样可以使用FormData来配|单个的control?br />
FormData
如果一个control没有一个FormData实例来描q它的话Q就会默认放在composite的右上角
width和height属性指定了control的尺寸,in pixels.
top, bottom, right, 和left属性,每一个都有一个FormAttachment实例Q这些attachments描述了control与其他control之间的关pR?br />
FormAttachment
?个用途径Q?br />1.通过使用percentage of the parent composite.


2.通过讑֮一个control和另一个control之间的相对位|?br />《图?br />
package com.swtjface.Ch6;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class Ch6FormLayoutComposite extends Composite {
public Ch6FormLayoutComposite(Composite parent) {
super(parent, SWT.NONE);
FormLayout layout = new FormLayout();
setLayout(layout);
Text t = new Text(this, SWT.MULTI);
FormData data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100);
data.bottom = new FormAttachment(75);//定text的位|,因ؓ左上角是坐标原点Q所以right的百分数?00?br />
t.setLayoutData(data);
Button ok = new Button(this, SWT.NONE);
ok.setText("Ok");
Button cancel = new Button(this, SWT.NONE);
cancel.setText("Cancel");
data = new FormData();
data.top = new FormAttachment(t);
data.right = new FormAttachment(cancel);//ok按钮在text下面Qcancel左边
ok.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(t);
data.right = new FormAttachment(100);//cancel按钮在text下面Q在最双
cancel.setLayoutData(data);
}
}



JOO 2006-04-12 12:22 发表评论
]]>
6.3 The grid layouthttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40484.htmlJOOJOOTue, 11 Apr 2006 08:16:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40484.htmlhttp://www.aygfsteel.com/joeyjong/comments/40484.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40484.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40484.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40484.html 最常用的一Ulayout.以row layout为基?br />
package com.swtjface.Ch6;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class Ch6GridLayoutComposite extends Composite {
public Ch6GridLayoutComposite(Composite parent) {
super(parent, SWT.NONE);
GridLayout layout = new GridLayout(4,false);//每一行有4个controlQ后一个参数是a
boolean to indicate whether the columns should take up an even amount of
space. By passing false, you tell the layout to only use the minimum amount of
space needed for each column.

setLayout(layout);
for (int i = 0; i < 16; ++i) {
Button button = new Button(this, SWT.NONE);
button.setText("Cell " + i);
}
}
}

Using GridData styles
十分cM于RowData对象。可通过其构造函数来讑֮STYLEQ这些STYLE可分?c:FILL, HORIZONTAL_ALIGN, and VERTICAL_ALIGN.
1.FILL:此cell是否fill所有的availabe的空间。可用的D包括FILL_HORIZONTALQ水qx张),FILL_VERTICALQ垂直扩张),FILL_BOTH?br />2.ALIGNQ用来指定control在cell中的什么位|。值包括BEGINNING, END, CENTER和FILL?br />具体参见下表

Using GridData size attributes
与RowData不同QGridDataq有很多的public属性。其中有些是布尔值类型的Q一般会Ҏ所讄的不同styles而自动管理,所以无需对其直接操作。还有一些是integer|用来定单个cells的大。具体g下表Q?br />



JOO 2006-04-11 16:16 发表评论
]]>
6.2 The row layouthttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40479.htmlJOOJOOTue, 11 Apr 2006 07:58:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40479.htmlhttp://www.aygfsteel.com/joeyjong/comments/40479.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40479.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40479.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40479.html可以多行/列显C?br />
package com.swtjface.Ch6;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class Ch6RowLayoutComposite extends Composite {
public Ch6RowLayoutComposite(Composite parent) {
super(parent, SWT.NONE);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
setLayout(layout);
for (int i = 0; i < 16; ++i) {
Button button = new Button(this, SWT.NONE);
button.setText("Sample Text");
}
}
}

wrap——默认ؓtrue,若设为false,所有的controls都在同一行?br />pack——默认ؓtrue.使所有的child controls都大一栗?br />justify——默认ؓfalse. 若ؓtrue,每一行的control都会以间隔相同的方式排列?br />
RowData
可以通过setLayoutData()来设定每个control的大,如:button.setLayoutData(new RowData(200 + 5 * i, 20 + i));


JOO 2006-04-11 15:58 发表评论
]]>
6.1 The fill layouthttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40472.htmlJOOJOOTue, 11 Apr 2006 07:23:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40472.htmlhttp://www.aygfsteel.com/joeyjong/comments/40472.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/11/40472.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40472.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40472.html 默认Z左到x攄Q根据每个control实际所需的大来分配I间Q此composite中多于出来的I间Q再qx到每个control上。随着composite的大调_control的大也会跟着调整?br />
package com.swtjface.Ch6;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class Ch6FillLayoutComposite extends Composite {
public Ch6FillLayoutComposite(Composite parent) {
super(parent, SWT.NONE);
FillLayout layout = new FillLayout( SWT.VERTICAL); //默认是SWT.HORIZONTAL
setLayout(layout);//为此Composite讑֮一个layout.如果漏了此语句,会显CZ出child control?br />for (int i = 0; i < 8; ++i) {
Button button = new Button(this, SWT.NONE);
button.setText("Sample Text");
}
}
}



JOO 2006-04-11 15:23 发表评论
]]>
5.8 ProgressIndicatorhttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40291.htmlJOOJOOMon, 10 Apr 2006 10:07:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40291.htmlhttp://www.aygfsteel.com/joeyjong/comments/40291.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40291.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40291.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40291.html同ProgressIndicator一P它支持工作的虚拟单位Qyou need only initialize the ProgressIndicator with the total amount of work you expect to do and notify it as work is completed:

ProgressIndicator indicator = new ProgressIndicator(parent);
...
indicator.beginTask(10);
...
Display.getCurrent()display.asyncExec(new Runnable() {
public void run() {
//Inform the indicator that some amount of work has been done
indicator.worked(1);
}
});

正如上例所C,使用ProgressIndicator需?步:
1.让indicator知道d有多工作,通过使用beginTask().只有q个Ҏ被调用了之后Q这个control才会在屏q上昄?br />2.每当有一部分工作被完成了Q就调用worked()。ؓ了防止非ui的线E来update widgetsQ所以用asyncExec()来解册个问题?br />
ProgressIndicator也提供animated模式Q即d作量不知道的情况。在q种模式下,the bar continually fills and empties
until done() is called. 要用这个模式,p用beginAnimatedTask()代替beginTask();q且不需要worked()Ҏ?/font>

JOO 2006-04-10 18:07 发表评论
]]>
5.7 ProgressBarhttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40287.htmlJOOJOOMon, 10 Apr 2006 09:56:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40287.htmlhttp://www.aygfsteel.com/joeyjong/comments/40287.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40287.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40287.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40287.htmlProgressBarQ进度条Q是ProgressIndicator的简化版本。大多数情况下推荐用ProgressIndicator。如果你军_直接使用ProgressBarQ需要手动改变此bar的外观。如?br />
//Style can be SMOOTH, HORIZONTAL, or VERTICAL
ProgressBar bar = new ProgressBar(parent, SWT.SMOOTH);
bar.setBounds(10, 10, 200, 32);
bar.setMaximum(100);
...
for(int i = 0; i < 10; i++) {
//Take care to only update the display from its
//own thread
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
//Update how much of the bar should be filled in
bar.setSelection((int)(bar.getMaximum() * (i+1) / 10));
}
});
}

setSelection()causes the widget to be updated every time.This behavior is unlike that of ProgressIndicator or ProgressMonitorDialog,which will update the display only if it has changed by an amount that will be visible to the end user.


JOO 2006-04-10 17:56 发表评论
]]>5.6 Sliderhttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40286.htmlJOOJOOMon, 10 Apr 2006 09:45:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40286.htmlhttp://www.aygfsteel.com/joeyjong/comments/40286.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40286.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40286.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40286.htmlcM于scrollbars。scrollbars仅限于用在可滑动的item上,如text?br />
可通过setMinimum()和setMaximum()来设定它的范围。可通过setThumb()来设定滑块的倹{在有些OS上,thumb的大是常数。每按一下箭_所Ud的值称为increment.可通过setIncrement()来设定,按滑块和头间的I间所滑动的gؓpage incrementQ可通过PageIncrement()来设定。以上这些数据可以通过void setValues( int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement)来一ơ性设定,其中selection是thumb的出发点?br />
Slider有个属性用来设定其是水q是垂直的Q默认ؓ水^?br />
package com.swtjface.Ch5;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Slider;
public class Ch5Slider extends Composite {
public Ch5Slider(Composite parent) {
super(parent, SWT.NONE);
setLayout(new FillLayout());
Slider slider = new Slider(this, SWT.HORIZONTAL);
slider.setValues(1000, 400, 1600, 200, 10, 100);
}
}


JOO 2006-04-10 17:45 发表评论
]]>
5.5 CoolBarhttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40279.htmlJOOJOOMon, 10 Apr 2006 09:28:00 GMThttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40279.htmlhttp://www.aygfsteel.com/joeyjong/comments/40279.htmlhttp://www.aygfsteel.com/joeyjong/archive/2006/04/10/40279.html#Feedback0http://www.aygfsteel.com/joeyjong/comments/commentRss/40279.htmlhttp://www.aygfsteel.com/joeyjong/services/trackbacks/40279.htmlcM于ToolBar的升U。他们的区别在于CoolBar上的item可以被重新配|,重新定大。CoolBar的一般用途就是包含toolbars或按钮?br />
String[] coolItemTypes = {"File", "Formatting", "Search"};
CoolBar coolBar = new CoolBar(parent, SWT.NONE);
for(int i = 0; i < coolItemTypes.length; i++)
{
CoolItem item = new CoolItem(coolBar, SWT.NONE);
ToolBar tb = new ToolBar(coolBar, SWT.FLAT);
for(int j = 0; j < 3; j++)
{
ToolItem ti = new ToolItem(tb, SWT.NONE);
ti.setText(coolItemTypes[i] + " Item #" + j);
}
}

JOO 2006-04-10 17:28 发表评论
]]>
վ֩ģ壺 | | Ȩ| Ϣ| | | | żҿ| ɽ| | | ѧ| ǰ| â| | ϼ| Һ| | Ͷ| Ͻ| | | 㶫ʡ| »Ȱ| | ˮ| | ǭ| | | ػ| | | | | Դ| Ȫ| | п| ¬| |