The Goal
Keep walking……
posts - 23,  comments - 1,  trackbacks - 0

是JFace的类,继承自ContributionManager,凡是继承了IAction或IContribution接口的对象都可被加至ToolBarManager.你只要花时间为ToolBarManager添加Action,Toolbar和ToolItem实例会自动产生。

你可通过调用ApplicationWindow的createToolBarManager()来为你的应用程序添加一个toolbar。与MenuManager不同的是,createToolBarManager()需要一个style参数,这个参数用来设定ToolBar所用的按钮的风格:flat或normal。

  • ControlContribution

除了MenuManager所用的ContributionItems之外,还有一个新的ContributionItem,只能被ToolBarManager使用——ControlContribution。这个类可将任何能被用于toolbar的Control打包进去。

要使用ControlContribution类,必须要实现抽象方法createControl().

toolBarManager.add(new ControlContribution("Custom") {
protected Control createControl(Composite parent) {
SashForm sf = new SashForm(parent, SWT.NONE);
Button b1 = new Button(sf, SWT.PUSH);
b1.setText("Hello");
Button b2 = new Button(sf, SWT.PUSH);
b2.setText("World");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.out.println("Selected:" + e);
}
});
return sf;
}
});

如果你希望有任何的事件发生,必须在你的controls上实现SelectionListeners

  • Creating toolbars by hand

如果你不想ToolBarManager来创建toolbar的话,可以手动创建,需要用到ToolBar和ToolItem类.

Toolbar
是一个composite control,包含多个ToolItems.Toolbar由多个小图标按钮组成,一般是16-by-16bitmap图片。每个按钮都对应一个ToolItem。Toolbar可以是水平的也可以是垂直的,默认为水平

ToolItem
每一个ToolItem都有一个图片,如果没有,默认为红色方块。When the user selects a ToolItem from the menu, it broadcasts the event to any registered SelectionListeners.Your application should register a listener with each ToolItem and use that listener to perform whatever logic corresponds to the menu item.

posted @ 2006-04-07 16:32 JOO 阅读(658) | 评论 (0)编辑 收藏

三种类型的Combo control:
1.Simple:默认类型,一个可编辑的text field和一个供选择的list
2.Drop-down:下拉列表,文本框可编辑
3.Read-only:文本框不可编辑的下拉列表,可用select( 0 )来将其默认选中列表中的首项。

以上三种类型可在构造函数中通过STYLE.*来设置。

posted @ 2006-04-07 16:30 JOO 阅读(265) | 评论 (0)编辑 收藏

先要将org.eclipse.text_x.y.z和org.eclipse.jface.text_x.y.z加到classpath

  • TextViewer and Document

两个重要的接口:IDocument和ITextViewer。JFace为其提供了默认的实现。

一个IDocument的实例持有被编辑的真实的文本信息。它的主要实现是Document类。AbstractDocument提供了部分实现,你可通过继承它来添加自己的实现。IDocument允许通过IDocumentListener接口来获取内容编辑的通知。

IDocument还提供了以下功能
Positions
可以给每一个text区域分配一个记号来作为它的Position。当被指定给某个ducument时一个Position对象有an offset and a length of text。如果document的text被更新的话,Position也会同步更新,所以他永远都是指向同一段文字。Position类本身提供了一些基本的功能,可通过继承他来完善更多有用的功能。

Partition content types
每个document由一个或多个partitions组成,通过ITypedRegion接口来表现。每一个partition可以有各自的内容类型,如plain text, rich text, or HTML。要使用它,你要创建一个IDocumentPartitioner然后assign给你的document,然后document的partitioner就会负责响应对指定位置内容类型的查询,它必须通过实现computePartitioning()来返回包含此document中所有ITypedRegions的一个数组。不需要实现你自己的document partitioner。如果没有创建,整个document就是一个区域,类型为IDocument.DEFAULT_CONTENT_TYPE。

Searching
IDocument通过search()提供了搜索的功能。不支持regular expressions or other patterns,但提供了search start location,direction, and case sensitivity and whether to match whole words only.

ITextViewer将一个标准的text widget转换成一个基于document的text widget

ITextViewer的默认实现是TextViewer,它使用StyledText来显示数据。ITextViewer支持text modifications的listener,也支持visual events(如改变viewport,即text的当前可视区域)的监听器。

虽然作为ITextViewer的默认应用,如果你想要修改显示,TextViewer允许你直接accessStyledText,但建议你使用TextPresentation,因为它可以收集该文档中带有的各个不同的StyleRanges。

ITextViewer还支持很多不同类型的插件,可用来修改widget的行为。可以被customized的功能有:
1.通过IUndoManager来支持undo
2.通过ITextDoubleClickStrategy来支持对鼠标双击的处理
3.通过IAutoIndentStrategy来支持文本的自动缩进
4.通过ITextHover来实现,当鼠标停留在document的一个section上时,显示text.
要使用上述插件,你需要分配一个适当的接口实例给text viewer,然后调用activatePlugins().

如下列出了org.eclipse.jface.text的子包及其作用

posted @ 2006-04-04 15:02 JOO 阅读(412) | 评论 (0)编辑 收藏

用于文本编辑的control有2个:Text和StyledText.后者可以为文本和control本身设定颜色,格式等。这两个control之间毫无关联,除了都是Composite的子类之外。

  • The basic Text widget

package com.swtjface.Ch5;

import org.eclipse.swt.SWT;

import org.eclipse.swt.events.VerifyEvent;

import org.eclipse.swt.events.VerifyListener;

import org.eclipse.swt.layout.FillLayout;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Text;

public class Ch5Capitalizer extends Composite {

public Ch5Capitalizer(Composite parent) {

super(parent, SWT.NONE);

buildControls();

}

private void buildControls() {

this.setLayout(new FillLayout());

Text text = new Text(this, SWT.MULTI | SWT.V_SCROLL);

text.addVerifyListener(new VerifyListener() { //每当text被改变,任何以注册的VerifyListeners便会被调用。此处每按一次键盘,此方法就被调用。如果是同时输入多个字符,也调用一次

public void verifyText(VerifyEvent e) {

if( e.text.startsWith("1") ) {

e.doit = false;

} //如果文本以1开头,即不允许编辑

else {

e.text = e.text.toUpperCase();

}

}

});

}

}

Text的重要方法,见下图

insert()--doesn’t allow you to insert text into the existing content.

  • The StyledText widget

StyledText包含了一系列的应用到该小部件的预定义的动作,这些是常规的东西如:剪切、粘贴、移动至下一个词、移动至文末。代表这些动作的常量在org.eclipse.swt.custom程序包中的ST类中有定义。这些常量在两种情况下发挥功效:首先,你可以使用它们程序性地使用invokeAction()方法调用任一的这些方法;其次,你也可以使用setKeyBinding()方法来将它们绑定于键击行为。setKeyBinding()选定一个键(可以通过诸如Shift或是Ctrl之类的编辑键来修改SWT常量之一)绑定于指定的动作。如下的例子中组合键Ctrl-Q绑定于粘贴动作。引起注意的是这并不意味着会将默认键的绑定清除,该两个绑定都会生效。

相对于Text而言,还添加了drawing line backgrounds and line styles的事件,可以通过此事件来改变整行的style或背景颜色。注意:如果使用了LineStyleListener,就不能在StyledText实例上调用get/setStyleRange(), 如果使用了LineBackgroundListener,那你就不能调用getLineBackground() or setLineBackground().

可以通过使用一个StyledText的StyleRanges来改变显示的风格

StyleRange
StyledText通过使用StyleRange类来管理当前所显示的不同styles。其所有的栏位都是public的可随意修改,但是要一直到当此StyledText实例的setStyleRange()被调用之后才会生效。

StyleRanges通过开始偏移量和长度来设定text的区域范围。
StyleRange可设定背景和前景色,默认为null,还可设定字体,SWT.NORMAL 或者SWT.BOLD.

similarTo()可用来判断两个StyleRange实例是否有同样的前景、背景和字体。

当我们保存text之后,可通过styledText.getStyleRanges()来获取style信息,此函数会返回an array of StyleRange


toggleBold()--将已输入的文本在bold和normal之间切换,是被一个KeyListener调用的,此KeyListener会监听F1是否被按下

A StyledText example
复制、粘贴功能不需要通过代码便可使用,是和platform的标准键盘快捷方式相关联的

ExtendedModifyListener和ModifyListener不同,前者提供了关于what was done的event细节,而后者只是当编辑懂作产生时notify,不会去准确的辨别到底何种修改发生了。

package com.swtjface.Ch5;

import java.util.LinkedList;

import java.util.List;

import org.eclipse.swt.SWT;

import org.eclipse.swt.custom.*;

import org.eclipse.swt.events.KeyAdapter;

import org.eclipse.swt.events.KeyEvent;

import org.eclipse.swt.layout.FillLayout;

import org.eclipse.swt.widgets.Composite;

public class Ch5Undoable extends Composite {

private static final int MAX_STACK_SIZE = 25;

private List undoStack;

private List redoStack;

private StyledText styledText;

public Ch5Undoable(Composite parent) {

super(parent, SWT.NONE);

undoStack = new LinkedList();

redoStack = new LinkedList();

buildControls();

}

private void buildControls() {

this.setLayout(new FillLayout());

styledText = new StyledText(this, SWT.MULTI | SWT.V_SCROLL);

styledText.addExtendedModifyListener(

new ExtendedModifyListener() { //每次text被编辑的时候,都会调用此listener

public void modifyText(ExtendedModifyEvent event) {

String currText = styledText.getText();

String newText = currText.substring(event.start,

event.start + event.length); //获得新插入的文本

if( newText != null && newText.length() > 0 ) {

if( undoStack.size() == MAX_STACK_SIZE ) {

undoStack.remove( undoStack.size() - 1 );

}

undoStack.add(0, newText);//将新插入的文本保存到undoStack中

}

}

}); //关键部分

styledText.addKeyListener(new KeyAdapter() {

public void keyPressed(KeyEvent e) {

switch(e.keyCode) {

case SWT.F1:

undo(); break;

case SWT.F2:

redo(); break;

default: //ignore everything else

}

}

});

}

private void undo() {

if( undoStack.size() > 0 ) {

String lastEdit = (String)undoStack.remove(0);//得到要undo的字符

int editLength = lastEdit.length();

String currText = styledText.getText();

int startReplaceIndex = currText.length() - editLength;

styledText.replaceTextRange(startReplaceIndex, editLength, ""); //将最后输入的字符替换成空

redoStack.add(0, lastEdit);//把最后的这个undo的字符加到redoStack中

}

}

private void redo() {

if( redoStack.size() > 0 ) {

String text = (String)redoStack.remove(0);//得到要恢复的字符

moveCursorToEnd();

styledText.append(text);//将要恢复的字符加至文本的最后

moveCursorToEnd();

}

}

private void moveCursorToEnd() {

styledText.setCaretOffset(styledText.getText().length());

}

}

posted @ 2006-03-29 17:42 JOO 阅读(992) | 评论 (0)编辑 收藏

ActionContributionItem--combines the function of a GUI widget and its attached listener class.
Action--处理事件
与SWT的listener/event模式很类似,但是其class更抽象,更易于使用,scope更窄。

  • actions and contributions

Action--可以简单的理解成一个命令,可以关联到菜单,工具条,以及按钮
Contribution--在JFace里面,一个Action可以对应多个GUI对象,这些对象就是所谓的Contribution Item. 有两个主要的Contribution类:ContributionItem和ContributionManager,它们都是抽象类,靠其子类来实现事件的处理。继承关系见下图
ContributionItem--引发事件的单独GUI组件
ContributionManager--产生包含ContributionItems的对象

ActionContributionItem--最重要,在ApplicationWindow中创建和实施,来将一个action连接至此GUI,它虽没有设定好的外观,但是依赖于你使用的fill()方法,却可以帮助一个按钮、菜单栏和工具栏的成形

另一个与Contribution协作的方法是通过ContributionManager,它的子类类似于ContributionItem的container。其中MenuManager将ContributionItems组合在窗口最高层菜单, ToolBarManager则将这些对象放在仅在菜单之下的toolbar中。

  • 创建Action类

Action是抽象类。

package com.swtjface.Ch4;
import org.eclipse.jface.action.*;
import org.eclipse.jface.resource.*;
public class Ch4_StatusAction extends Action
{
StatusLineManager statman;
short triggercount = 0;
public Ch4_StatusAction(StatusLineManager sm)
{
super("&Trigger@Ctrl+T",
AS_PUSH_BUTTON);//在T字母之前的&符号意味着这个字母将作为该动作的快捷键。而在TEXT领域内的“Ctrl+T”确保了当用户在同时按下Ctrl键和T键时该动作就会被激发。
statman = sm;
setToolTipText("Trigger the Action");
setImageDescriptor(ImageDescriptor.createFromFile
(this.getClass(),"eclipse.gif"));
}
public void run() //每次当Ch4_StatusAction被生成,run()方法就被调用
{
triggercount++;
statman.setMessage("The status action has fired. Count: " +
triggercount);
}

  • Implementing contributions in an ApplicationWindow

package com.swtjface.Ch4;

import org.eclipse.swt.*;

import org.eclipse.swt.widgets.*;

import org.eclipse.jface.window.*;

import org.eclipse.jface.action.*;

public class Ch4_Contributions extends ApplicationWindow {

StatusLineManager slm = new StatusLineManager();

Ch4_StatusAction status_action = new Ch4_StatusAction(slm); //StatusLineManager的对象作参数,创建了一个Ch4_StatusAction的实例

ActionContributionItem aci = new ActionContributionItem(status_action); //用Ch4_StatusAction的对象作参数,创建了ActionContributionItem对象

public Ch4_Contributions() {

super(null); // 创建了 ApplicationWindow对象

addStatusLine();

addMenuBar();

addToolBar(SWT.FLAT | SWT.WRAP); //在窗口上添加了status line, menu, toolbar

}

protected Control createContents(Composite parent) {

getShell().setText("Action/Contribution Example");

parent.setSize(290,150); //设置了窗口的title和size

aci.fill(parent); // 将ActionContributionItem放在GUI中。因为这里的参数是Composite对象,所以根据Action的STYLE属性来确定。此处是Button,因为Ch4_StatusAction 的STYLE属性是AS_PUSH_BUTTON;

return parent;

}

public static void main(String[] args) {

Ch4_Contributions swin = new Ch4_Contributions();

swin.setBlockOnOpen(true);

swin.open();

Display.getCurrent().dispose();

}

protected MenuManager createMenuManager() {

MenuManager main_menu = new MenuManager(null);

MenuManager action_menu = new MenuManager("Menu");

main_menu.add(action_menu);

action_menu.add(status_action); //关联status_action.created and added to the menu in the form of a menu item

return main_menu;

}

protected ToolBarManager createToolBarManager(int style) {

ToolBarManager tool_bar_manager = new ToolBarManager(style);

tool_bar_manager.add(status_action); //关联status_action。created and added to the toolbar as a toolbar item.

return tool_bar_manager;

}

protected StatusLineManager createStatusLineManager() {

return slm;

}

}

  • Interfacing with contributions

两个途径来将ActionContributionItem添加到GUI:
1. 通过ContributionManager子类的add()方法。
(1)可接受Action对象的参数,从而间接的将ContributionItem和ContributionManager关联。可多次执行
(2)可直接接受ActionContributionItem对象的参数。只可执行一次
2.通过ActionContributionItem类的fill()方法。根据其参数的不同,所先是的组件也不同,具体见下表:

  • Exploring the Action class

Important methods of the Action class


Property methods for the Action class

DESCRIPTION--written to a status line to provide additional help.

Style methods for the Action class

如果ENABLED是FALSE,则变灰。CHECKED主要用于radio和checkbox

Accelerator key / keyboard methods for the Action class

Accelerator keys--鼠标点击的键盘块捷方式


Listener methods for the Action class

虽然JFace使用action代替了SWT的listener/event机制,但是Actiono类仍然可以和listener协作来处理特定需求的事件。
IPropertyChangeListener接口关注客户自定义的PropertyChangeEvents,当所给的对象按照你所给的方式变成另一个对象时,此事件被触发。

Miscellaneous methods of the Action class

posted @ 2006-03-24 17:02 JOO 阅读(784) | 评论 (1)编辑 收藏
  • The SWT event-processing cycle


1. Once an SWT application begins running, its Display class sorts through this queue using its readAndDispatch() method and msg field, which acts as a handle to the underlying OS message queue.
2. If it finds anything relevant, it sends the event to its top-level Shell object, which determines which widget should receive the event.
3. The Shell then sends the event to the widget that the user acted on, which transfers this information to an associated interface called a listener.
4. One of the listener’s methods performs the necessary processing or invokes another method to handle the user’s action, called an event handler.


所在包:org.eclipse.swt.events   

  • typed listeners and events

typed listeners--只对某一类的用户事件起作用,继承TypedListener类
typed events--与此类特定动作相关的事件,继承TypedEvent类

可通过add...Listener()method with the typed listener as the argument来将listener附加到widget。

完整的typed events和listeners列表,如下:
 

TypedEvent类包含了一些member field,他们提供与事件发生相关的一些信息,这些信息可以在event handler中使用来获得与环境相关的信息。下图为继承自TypedEvent及EventObject类的fields:

除此之外,很多的event类还有其他用来提供更多用户动作信息的fields,如MouseEvent类的button field

要将listener加入到code中,有两个主要的方法:
第一个是在component的add...Listener()中创建一个匿名接口,这样可以使listener的作用域仅限于此component,示例代码如下:
Button button = new Button(shell, SWT.PUSH | SWT.CENTER);//创建了一个button,并将其加入到shell中
button.addMouseListener(new MouseListener() //创建了一个匿名MouseListener接口,并将其与button关联
{
public void mouseDown(MouseEvent e)
{
clkdwnEventHandler();
}
public void mouseUp(MouseEvent e)
{
clkupEventHandler();
}
public void mouseDoubleClick(MouseEvent e)
{
dblclkEventHandler(); //此接口中必须被实现的三个方法。一旦鼠标按下,放开或双击,就会有一个MouseEvent被发送到这三个方法中的一个,然后,此方法再调用相关联的event-handling方法(即下文中的三个)。
}
});
static void dblclkEventHandler()
{
System.out.println("Double click.");
}
static void clkdwnEventHandler()
{
System.out.println("Click - down.");
}
static void clkupEventHandler()
{
System.out.println("Click - up.");//event-handlers通过发送message到console来完成事件处理
}

上一类方法的缺点是此listener仅限于此component内,而第二种方法便可解决这种问题--独立的声明一个继承MouseListener的接口,示例代码如下:
Button button = new Button(shell, SWT.PUSH | SWT.CENTER);
button.addMouseListener(ExampleMouseListener);
MouseListener ExampleMouseListener = new MouseListener()
{
public void mouseDoubleClick(MouseEvent e)
{
System.out.println("Double click.");
}
public void mouseDown(MouseEvent e)
{
System.out.println("Click - down.");
}
public void mouseUp(MouseEvent e)
{
System.out.println("Click - up.");
}
};

使用MouseListener的缺点就是哪怕你只关心鼠标双击事件,却仍要声明其接口中所包含的所有方法。
 

  • Adapter

Adapter是继承了Listener接口并提供了所有required方法的实现的abstract类。也就是说如果你使用adapter而不是listener的话,你只需要写你感兴趣的方法

只有那些listener有多个成员方法的event才有adapter,其完整列表见下图:

adapter同样是通过add...Listener()方法来创建的,与listener类似,同样也可通过匿名类和本地类两种方法,下例为匿名类方法:
button.addMouseListener(new MouseAdapter()
{
public void mouseDoubleClick(MouseEvent e)
{
dblclkEventHandler();
}
)};
static void dblclkEventHandler()
{
System.out.println("Double click.");
}

  • Keyboard events

任何时候只要key被按下,就会创建KeyEvent,它有两个子类:TraverseEvent 和VerifyEvent.
TraverseEvent--当按下arrow key或tab key来focus on text widget时
VerifyEvent--fires when the user enters text that the program needs to check before taking further action.

除了继承自TypedEvent和EventObject的field,KeyEvent还包括三个member field来提供那些与触发事件的key相关的信息,具体如下:
character--代表被按下key的char
stateMask--Returns an integer representing the state of the keyboard modifier keys.By examining this integer, a program can determine whether any of the Alt, Ctrl, Shift, and Command keys are currently pressed.
keyCode--Provides the SWT public constant corresponding to the typed key. KeyCode列表,见下图:


TraverseEvent中有两个fields:
1. doit--返回布尔值,若为真则允许在各个component间切换focus,若为假则不允许切换focus
2. detail--It’s an integer that represents the identity of the key that caused the event. For example, if the user presses the Tab key to switch to a new component, the detail field will contain the SWT constant TRAVERSE_TAB_NEXT.

每个类型的Control对于所给的traversal key都有不同的默认behavior,如果设doit为true,则override了其默认的设置。

VerifyEvent的field:
1.start和end--设定了输入的范围
2.text--contains the input String under examination.
3.doit--Having looked at the user’s text, you set the boolean doit field to allow (TRUE) or disallow (FALSE) the action.

  • untyped events

更灵活,但不安全,不推荐使用。
当一个代表着非类型化监听器的监听器类和GUI的某一组件相联系时,它就能接受该组件所能发送的任一类事件。因此,你需要操控这由Event类代表的捕获的全部事件,决定用户执行的那个动作。然后,正确的事件处理方法就被调用。

不是被包含在org.eclipse.swt.events包中,而是被包含在org.eclipse.swt.widgets包中。

代码示例如下:
Listener listener = new Listener ()
{
public void handleEvent (Event event)
{
switch (event.type)
{
case SWT.KeyDown:
if (event.character == 'b')
System.out.println("Key"+event.character);
break;
case SWT.MouseDown:
if (event.button == 3)
System.out.println("Right click");
break;
case SWT.MouseDoubleClick:
System.out.println("Double click");
break;
}
}
};
Button button = new Button(shell, SWT.CENTER);
button.addListener(SWT.KeyDown, listener);
button.addListener(SWT.MouseDown, listener);
button.addListener(SWT.MouseDoubleClick, listener);


Event类包含了所有typed event中的所有field,此外还有一个type field,其所有的值列表如下:

posted @ 2006-03-23 16:32 JOO 阅读(804) | 评论 (0)编辑 收藏
  • Composite类

getChildren()
lists the children of a Composite as an array of Control objects.
getLayout()、setLayout(Layout)
处理layout对象
getTabList()、setTabList(Control[])
指定widgets在Composite中的Tab顺序(按键盘tab键的切换顺序)

Composite类是Scrollable类的直接子类,这就是说SWT/JFace中的所有Composite对象都有Scrollbars.所有的Scrollable对象都可使用如下方法:
getClientArea()、 computeTrim(int, int,int, int)
trim--Composite的不可编辑区域,如title bars, scrollbars, 或status bars等.
client area--那些可编辑,使用的区域
getClientArea()--Returns the available display area of a Scrollable object
computeTrim(int,int,int,int)--Returns the necessary dimensions of the Composite for the desired client area
getHorizontalBar()、getVerticalBar()
Returns the horizontal/vertical ScrollBar object

Control, Scrollable, and Composite的关系,如下图
  

  • Groups

Composite子类中最简单的一个,自身不执行任何动作,仅仅是将一组子widgets用矩形边框起来,此边框类似于之前提到的分隔符,同样也提供SWT.SHADOW_IN, SWT.SHADOW_OUT, SWT.SHADOW_NONE风格,还可以通过选择SWT.SHADOW_ETCHED_IN or SWT.SHADOW_ETCHED_OUT来客制化阴影效果。

可以通过setText()方法来设定它的label

与许多Widgets子类一样,Group类不可被继承。

  • SashForms

可以在子widgets之间创建可移动的分界,此分界称为Sash.Sash类可以在org.eclipse.swt.widgets包中找到,而SashForms却存在于org.eclipse.swt.custom包中。

SWT.HORIZONTAL和SWT.VERTICAL--用来设定Sash的方向
setOrientation()--用来设定Sash的方向
getMaximizedControl()--returns the Control object that has been expanded the most.
getWeights()--returns an int array containing the weight of each of the SashForm’s children.uses an int array to specify weights for each of the widgets in the Composite.

  • TabFolders

creating and populating a TabFolder的四个步骤:
1. 创建一个TabFolder实例
2. 为每个页面构建一个TabItem对象
3. 用setText()方法来设定tab的label
4. setControl()--关联一个control,当它的tab被选中时,显示此control

TabFolder类提供了一些用来获得TabItems信息的方法,如下:
getItemCount()
返回此TabFolder所包含的TabItems数
getItems()
返回TabItems对象的数组
getSelection()
确定user选择了哪个TabItem
setSelection()
Makes this decision from within the application

posted @ 2006-03-22 17:55 JOO 阅读(333) | 评论 (0)编辑 收藏
  • SWT.PUSH

Button类的默认风格。
SWT.FLAT

  • SWT.ARROW

与SWT.UP, SWT.DOWN, SWT.LEFT, and SWT.RIGHT组合,也可使用SWT.FLAT

  • SWT.TOGGLE

类似于SWT.PUSH,但是按下后会保持按下状态。可通过setSelection(boolean)方法来改变其状态。接下去介绍的check按钮和radio按钮也share这个功能

  • SWT.CHECK

建议用数组来实现,如下:
Button[] checks = new Button[2];
checks[0] = new Button(shell, SWT.CHECK);
checks[0].setText("Choice 1");
checks[0].setLocation(10,5);
checks[0].pack();
checks[1] = new Button(shell, SWT.CHECK);
checks[1].setText("Choice 2");
checks[1].setLocation(10,30);
checks[1].pack();

  • SWT.RADIO

建议用数组来实现,如下:
Button[] radios = new Button[3];
radios[0] = new Button(shell, SWT.RADIO);
radios[0].setSelected(true);
radios[0].setText("Choice 1");
radios[0].setLocation(10,5);
radios[0].pack();
radios[1] = new Button(shell, SWT.RADIO);
radios[1].setText("Choice 2");
radios[1].setLocation(10,30);
radios[1].pack();
radios[2] = new Button(shell, SWT.RADIO);
radios[2].setText("Choice 3");
radios[2].setLocation(10,55);
radios[2].pack();
for (int i=0; i<radios.length; i++)
if (radios[i].getSelected())
System.out.println(i);


通过RadioGroupFieldEditors将radio buttons组合在一起:

RadioGroupFieldEditor rgfe = new RadioGroupFieldEditor(
"UserChoice", "Choose an option:", 1,
new String[][] {{"Choice1", "ch1"},
{"Choice2", "ch2"},
{"Choice3", "ch3"}},
shell, true);

其中的各个参数含义如下——1.name for the type of value returned by the editor.2.group label.3.列数。4.creates a set of option names with their associated values.In this manner, the RadioGroupFieldEditor can display a series of radio buttons without allocating Button objects.5.将editor加至Shell对象。6.specifies whether the radio buttons should be incorporated in a Group object.

在SWT/JFace中,container widgets是由Composite类来提供的。

posted @ 2006-03-21 17:03 JOO 阅读(272) | 评论 (0)编辑 收藏

用于在GUI中显示静态的信息:String或Image

  • 风格和分隔符

对齐方式:SWT.CENTER,SWT.LEFT, and SWT.RIGHT.
分隔符:SWT.SEPARATOR;SWT.VERTICAL, SWT.HORIZONTAL;SWT.SHADOW_IN, SWT.SHADOW_OUT, and SWT.SHADOW_NONE.

  • Label的方法

posted @ 2006-03-21 16:32 JOO 阅读(193) | 评论 (0)编辑 收藏
  • Widget类

是所有widget的父类。为抽象类,而且Eclipse.org也强烈反对去继承它,因此你既不能继承他,也不能直接使用它
Widget类中的重要方法,如下:

  • Control objects

Control类中的对象在OS中有一个直接的副本,你可以通过类的handle field来直接access.然而SWT还提供了一些在Control类之外的widgets,如下所示:
 

Control类的两类方法:


posted @ 2006-03-21 15:11 JOO 阅读(227) | 评论 (0)编辑 收藏
仅列出标题
共3页: 上一页 1 2 3 下一页 
Hit the target!

<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(2)

随笔分类(23)

随笔档案(22)

文章档案(1)

相册

Neighbor

搜索

  •  

最新评论

阅读排行榜

评论排行榜