我想知道为什么swt使用起来这么不方便。作为程序员,我们必须编写大量不必要的源代码。这里有一个例子。
Label label = new Label(parent, SWT.NONE);
label.setText("labelname");
最低限度是这样的:
createLabel(parent, "labelname");
我建立了一个便利库,我想知道是否有类似的东西或者为什么 SWT 或 JFace 不采用这种简单的方式。使用更多的构造函数来覆盖 80% 的编程任务有什么缺点吗?
更详细地看看我做了什么。
SWT:请更方便
I wondering why swt is so inconvenient to use. We as programmers have to produce tons of unnecessary source code. Here an example.
Label label = new Label(parent, SWT.NONE);
label.setText("labelname");
The minimum would be like this:
createLabel(parent, "labelname");
I build up a convenients library and I would like to know if there is something similar or why SWT or JFace don't go this simple way. Is there any drawback in having some more constructors that cover 80% of the programming task.
Have a more detailed look what I have done.
SWT: More Convenients Please
发布评论
评论(3)
我建议尝试 Google Window Builder Pro。它是 Eclipse 的一个插件,允许在 SWT、Swing、RCP、JFace 等中进行 GUI 的图形开发。 GWB 编写指定 GUI 布局的代码,您所要做的就是编写代码来处理事件。
I suggest trying Google Window Builder Pro. It is a plugin for Eclipse that allows for the graphical development of GUI's in SWT, Swing, RCP, JFace and others. GWB writes the code which specifies the GUI layout and all you must do is write code to handle events.
据我所知,没有这样的通用库。为 swt 控件创建提供一些基本工厂支持的一个实例是 JFace 表单小部件。另请查看此
org.eclipse.ui.forms.widgets.FormToolkit
。从您的实现来看,您似乎假设 GridLayout 为默认布局样式。除此之外,控件可能有许多与布局相关的数据,例如缩进(水平和垂直)、跨度等。这不容易用工厂方法覆盖。
如果您不想花费额外的精力来编写用于布局小部件的代码,那么请查看可视化编辑器 .org/archived/" rel="nofollow">http://www.eclipse.org/archived/。
此外,Eclipse 本身正在走向模型驱动一代 (http://www.eclipse.org/e4/)。如果我们会看到类似 Netbeans 的 SWT UI 设计器(顺便说一下,我已经使用 Eclipse 建模框架和 GEF 为我们的工具编写了一个版本),这并不奇怪。
尽管如此,我仍然建议您手动编写普通的布局代码,因为它将提高您对 SWT 的理解。
As far as I know there is no such generic library. The one instance which provides some basic factory support for swt control creation is JFace Form Widget. Also have a look at this
org.eclipse.ui.forms.widgets.FormToolkit
.From your implementation it appears that you are assuming the
GridLayout
as the default layouting style. Apart from that a control may have many layout related data like, its indentation (horizontal and vertical), span etc. Which is not easy to cover with factory methods.If you don't want to put in the extra effort of writing the code for layouting the widgets and all then have a look at the
Visual editor
at http://www.eclipse.org/archived/.Also, eclipse itself is moving towards the the Model Driven Generation (http://www.eclipse.org/e4/). It won't be a wonder if we will see a Netbeans like UI designer for SWT (by the way i have written a version for our tool using eclipse modelling framework and GEF).
Still I would suggest you to write the mundane layouting code by hand because it will improve your SWT understanding.
字节的生产成本非常低,而且我认为 SWT“使用起来非常不方便”——如果它是自动生成它的,那有什么不方便的呢?
我们的计算机速度如此之快,我们甚至无法察觉其中的差异……而且节省的时间是巨大的。
Bytes are very cheap to produce, and I'd debate that SWT "is so inconvenient to use" - well if it's automatically producing it, how is that inconvenient ?
Our computers are so fast that we couldn't even perceive the difference... and time saved is huge.