如何创建带有单独标签的 GEF 图?
我一直在尝试创建一个由两部分组成的 Draw2D 图 - 一个中心可调整大小的形状,例如圆形或矩形,以及底部的可编辑标签。此类图形的一个示例是您在计算机桌面上看到的图标/标签。
第一次尝试是创建一个带有两个子子图形的父容器图形 - 一个形状图形放置在中央,一个标签放置在底部。它还实现了 HandleBounds,以便仅在上部形状子图上进行选择和调整大小。事实证明这不是一个有效的解决方案,因为随着标签随着文本的增多而变宽,主要父图形也会变宽,因此中心形状图形也会变宽。换句话说,整个父图形与子标签图形一样宽。
我正在寻找的是一个保持形状图形大小但允许标签图形宽度独立增长的图形。与桌面图标完全相同的行为。
I've been trying to create a Draw2D Figure that consists of two parts - a central resizeable shape, such as a circle or rectangle, and an editable label for the bottom part. An example of this type of figure is the icon/label you see on a computer's Desktop.
The first attempt was to create a parent container figure with two child sub-figures - a shape figure placed centrally and a label placed at the bottom. It also implemented HandleBounds so that selection and resizing occurs only on the upper shape sub-figure. This turned out not to be a working solution because as the label gets wider with more text so does the main parent figure and consequently the central shape figure. In other words the overall parent figure is as wide as the child label figure.
What I'm seeking is a Figure that maintains the size of the shape figure but allows the width of the label figure to grow independently. Exactly the same behaviour as a desktop icon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我现在明白你的问题了。不可能做你想做的事:
父图形不能小于其子图形之一,否则该子图形将不可见!
Ok I get your question right now. It's impossible to do what you want:
The parent figure can't be smaller than one of its children or this child will not be visible !!!
您必须使用 XYLayout 创建一个容器图形,并使用
IFigure.add(IFigure child, Object constraint 在此布局内“手动”放置和“调整”2 个(形状和标签)子图形的大小)
方法,具有类型为 Rectangle (Draw2d) 的约束使用代码示例进行编辑
以下是您的图形类的示例:
这不是一个干净的类,但它应该是一个很好的入口,向您展示如何实现你的目标。这是一个基于纯 Draw2d 的示例,没有任何 Gef 代码,因此形状的大小调整是通过单击黄色椭圆(尺寸减小)和绿色标签(恢复初始尺寸)来完成的
。创建了一个简单的 Eclipse 视图,如下所示:
希望这可以有所帮助,
马努
You have to create a container figure as you mentioned with an XYLayout and "manually" place and "size" the 2 (the shape and the label) children figure inside this layout using the
IFigure.add(IFigure child, Object constraint)
method with a Constraint of type Rectangle (Draw2d)Edit with code sample
Here is an example of what your figure class could look like:
This is not a clean class but it should be a good entry to show you how to achieve your goal. This is an example based on pure Draw2d without any Gef code, thus the resizing of the shape is done by clicking in the yellow Ellipse (the size is decreased) and on the green label (the initial size is restored)
To test this class I created a simple Eclipse view as following:
Hope this can help,
Manu