blog211210. JFace之Window

JFace的Window是对Shell的封装,提供了默认异常处理、字体监听、初始位置和大小设置等功能。常用方法包括configureShell()、createContents()、getLayout()等。ApplicationWindow作为Window的子类,增加了对menuBar、statusLine、toolBar和coolBar的支持,并提供相应的Manager管理。了解Window的创建步骤和相关类可以帮助更好地理解和使用JFace中的窗口操作。
摘要由CSDN通过智能技术生成

Window

JFace的Window是对Shell的封装, 便利使用. 封装的内容包括,

  • shell. 可以用getShell()得到.
  • default exception handler
  • font change listener
  • 初始定位和大小的设置. 默认的定位是屏幕居中, 尺寸是缺省值.
  • layout的设置, 默认是gridLayout
  • 可选的event loop
  • return code的设置和读取
  • close过程
  • 支持关联windowManager

Window的创建分做3步,

  1. new Window instance
  2. 调用create(), 创建shell和content. 此步若省略, 则在open()中会默认自动调用.
  3. 调用open(), 封装有shell.open(), 至此窗口shell才真正显示出来.

若想window.open()直接进入event loop, window close后方才退出, 则可以在open()调用前调用setBlockOnOpen

	windowObj.setBlockOnOpen(true);
	int retCode = windowObj.open();

Window继承的methods常用的有,

  • configureShell(), 完成shell显示前的设定工作. 例如再次调用setShellStyle().
  • createContents(), 在此创建window的具体内容
  • getLayout(), 返回shell要使用的layout.
  • getInitialLocation()和getInitialSize(), 设置shell显示是的位置和尺寸.
  • canHandleShellCloseEvent(), 判断是否继续/放弃close过程.
  • close(), 执行shell的close.

ApplicationWindow

ApplicationWindow是Window的子类, 增强的功能包括,

  • 使用定制的ApplicationWindowLayout布局内容, 支持摆放menuBar, statusLine, toolBar和coolBar.
  • 支持menuManager, toolBarManager, statusLineManager, coolBarManager管理和设置.

一个例子

public class Snippet002ApplicationWindow extends ApplicationWindow {
   

	public static ApplicationWindow app;

	Action newAction;
	Action openAction;
	Action saveAction;
	Action saveAsAction;
	Action exitAction;
	Action copyAction;
	Action cutAction;
	Action pasteAction;
	Action helpAction;
	Text content;
	
	class MyAction extends Action{
   
		public MyAction(String text, String tooltip, int keycode, String img)
		{
   
			super(text);
			
			setToolTipText(tooltip);
			
			if(keycode != 0)
				setAccelerator(keycode);

			if(img != null && !img.isEmpty())
			{
   
				ImageDescriptor desc = ImageDescriptor.createFromFile(Snippet002ApplicationWindow.class, img);
				setImageDescriptor(desc);
			}
		}
		
		public void run()
		{
   
			MessageBox dialog = new MessageBox(Display.getCurrent()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值