转换一个AWT应用SWT / JFace的 [英] Converting an AWT application to SWT/JFace

查看:139
本文介绍了转换一个AWT应用SWT / JFace的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在与来自AWT转换小型/中型项目SWT的想法玩弄,虽然Swing是没有完全出来的图片呢。
我在想在主窗口转换为SWT_AWT桥对象,但我不知道的语义对这项工作如何。在那之后,我打算更新对话的对话,但不一定是一个版本内。这可能吗?

I am currently toying with the idea of converting a small/medium sized project from AWT to SWT, although Swing is not totally out of the picture yet. I was thinking about converting the main window to an SWT_AWT bridge object, but I have no idea how the semantics for this work. After that, I plan to update dialog for dialog, but not necessarily within one release. Is this possible?

已经有人做过这样的转换,可以给我一些提示?是否有可能连一个教程的地方在那里?是否有可能连一个工具,可以自动完成这部分?我曾尝试使用Google,但无济于事。

Has someone done a conversion like this and can give me some hints? Is there maybe even a tutorial somewhere out there? Is there maybe even a tool that can automate parts of this? I have tried googling, but to no avail.

更新:一个额外的一点是:目前,这是一个NetBeans项目。可能是帮助或没有,我不知道。

Update: One additional thing is: Currently, this is a netbeans project. Might be of help or not, I don't know.

推荐答案

我们已经做了这好几次。的但仅仅是因为我们正在从一个Swing应用程序将Eclipse RCP应用程序的不是因为我们喜欢的事情搞乱。该项目将真正让你知道你已经从你的观点code分离控制器/型号code。

We have done this quite a few times. But only because we are going from a Swing application to an Eclipse RCP application not because we like messing with things. This project will really let you know whether you've separated your controller/model code from your view code.

一个建议是不要一次尝试和转换的一切。你最终会与一群混合code,这并不在所有的工作中。您可以在门户网站转换开始。我认为一个选项卡,对话中的任何门户网站或窗口,基本上是自给自足的单位。如果您有打开了一个窗口,创建SWT窗口,但要它的内容已有AWT / Swing的。这应该是相当简单的,让你习惯了(我真的希望他们不是喝醉了,有一个很好的理由)实例化和关联父/子控件的方式。

One suggestion is to not try and convert everything all at once. You will end up with a bunch of mixed code that doesn't work at all. You can start at converting portals. I would consider a portal anything within a Tab, Dialog, or Window, essentially self contained unit. If you have a window that opens up, create the Window in SWT, but make it's contents the existing AWT/Swing. This should be fairly straight forward and allow you to get used to the (I really hope they weren't drunk and had a good reason for this) way of instantiating and associating parent/child controls.

这可以发生的一个疑难杂症与透明部件。摆动,有一个窗口类的异常在Java中所​​有的渲染。这使得它很容易使事情你想要的方式。在SWT中,有一些限制:

One gotcha that can occur is with transparent components. Swing, with the exception of a "window" class is all rendered in Java. This makes it very easy to render things the way you want them. In SWT, there are some restrictions:


  • 边框。如果你使用SWT.BORDER你被卡住任何颜色的本地组件使用。最好的办法是使用PaintListener和渲染自己的边界,如果你想他们在一个不同的样式或颜色。

  • 透明标签,进度条。我一直没能得到标签或进度条有一个透明的背景。如果你希望他们承担父母的颜色,或绘图您将需要呈现文本和其他控制自己。

  • 控制。有复合材料和控制SWT。想控制作为做所有的原生API调用的基本原生控制。这些不能被继承,这使得事情困难。

  • 表会给你最麻烦。让您尝试一个JTable转换为表格或TableViewer中前确保一切稳定。你会花这些一段时间,特别是如果你有自定义的编辑器。

我还没有研究为什么SWT设计它的方式。我猜必须有一个很好的理由。如果有人有一个博客或防御它的设计,所以我不必寻找它这样做将是巨大的。一旦它的发布,因为他们有没有相关性的问题,我会删除这些行。

I have not researched why SWT was designed the way it was. I am guessing there HAD to be a good reason. It would be great if someone had a blog or defense to it's design so I don't have to search for it. Once it's posted I'll remove these lines since they have no relevance to the question.

加入

我要补充一点,因为你有一个现有的产品我假设的作品。我可以给你建议最好的一块是不要让你的code进入状态,它不能编译和运行。如果您在转换和任何工作,你检查始终运行并执行(尽管SWT / AWT / Swing的之间的视觉差异),你能救自己的长远许多头痛的问题。你能做的最糟糕的事情就是尽量一次全部解决这一点,并在同一时间让你的code处于不稳定状态数周。

I want to add that since you have an existing product I assume works. The best piece of advice I can give you is to never let your code get into a state that it cannot compile and run. If you work on your conversion and whatever you check in always runs and executes (despite the visual differences between SWT/AWT/Swing) you will save yourself many headaches in the long run. The worst thing you can do is try to tackle this all at once and get your code in an unstable state for weeks at a time.

这篇关于转换一个AWT应用SWT / JFace的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆