??xml version="1.0" encoding="utf-8" standalone="yes"?>国产一区二区日韩,日本不卡视频一二三区,亚洲欧洲在线一区http://www.aygfsteel.com/JetGeng/category/11829.html我的Java天堂zh-cnTue, 27 Feb 2007 11:27:30 GMTTue, 27 Feb 2007 11:27:30 GMT60关于GEF中的Connectionhttp://www.aygfsteel.com/JetGeng/archive/2007/01/08/92407.htmlJet GengJet GengMon, 08 Jan 2007 09:09:00 GMThttp://www.aygfsteel.com/JetGeng/archive/2007/01/08/92407.htmlhttp://www.aygfsteel.com/JetGeng/comments/92407.htmlhttp://www.aygfsteel.com/JetGeng/archive/2007/01/08/92407.html#Feedback0http://www.aygfsteel.com/JetGeng/comments/commentRss/92407.htmlhttp://www.aygfsteel.com/JetGeng/services/trackbacks/92407.html?/font>gef目中连U一直扮演这个不可或~的角色。碰巧前D|间有个机会好好的看了q个部分的内宏V下面就把我的一点点认识和大家分享?/font>

首先要在模型上支持,能够保存q接的信息。对于不同的目有不同的要求。我们通过两个例子可以看一Ҏ?/font>

1?/font>http://www13.plala.or.jp/observe/GEF/CZ中的GEF6.zip Q下面称q个例子?/font>HelloWoldQ?/font>

q行的结果入下图所C:

hellwoui.jpg

它的模型可以使用如下的类图来表示Q?/font>

LineConnectionModel-i.jpg

用来描述Connection的分别是LineConnectionModel?/font>ArrowConnectionModelq两个类。这两个cȝ父类和图形模型(HellowModelQ相兟?/font>

2?/font>IBMU皮书中?/font>GEF范例(下面U这个例子ؓworkflow)

q行效果如下图:

gefrun.jpg

他的模型可用下面的类图描qͼ

gefredbook.jpg

其实q接的模型应该很单,他只要能保存他的两端的对象就好了。图形模型(?/font>HelloWold中的HelloModelQ能够保持与他相兌的连接(HelloWold中的LineConnectionModel?/font>ArrowConnectionModelQ?/font>

看完?/font>ModelQ我们下面就可以看看EditPart部分了?/font>

要看EditPart当然是要看最关键的了。也是和连接直接关联的EditPart了。分别察看了和连接相关的EditPartQ发C们都会实C个叫org.eclipse.gef.NodeEditPart的接口。如下图所C:

ShapeEditPart-a.jpg

?/font>nodeEditPart中有四个Ҏ需要实现。通过q个四个Ҏ的名字就可以看出他们?/font>Anchor2密切相关。下面就来看看这几个Ҏ的具体功能:

ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection);

当需要画q接的时候,通过q个Ҏ获取q接的源锚点。不这个锚点在什么位|,他取得以后直接就用它作ؓ源点了?/font>

ConnectionAnchor getSourceConnectionAnchor(Request request);

当在准备创徏q接的时候,通过Request来获取新q接的源锚点?/font>

另外的两个就不再啰嗦了。是Z获得目标的锚炏V?/font>


但是我们肯定看到?/font>HelloWold?/font>Workflow中的q接有点不一栗?/font>HelloWold中直接是囑օ上的Q?/font>workflow是通过q接基本囑օ上面的一个子囑օ而连接的。简单来说就是他们连接的anchor有点不一Pq样׃出现执行l果的不同?/font>

下面来看看他们到底是怎么实现的。根据上面提到的。锚点的获取是通过getSourceConnectionAnchor?/font>getTargetConnectionAnchorҎ来获取的。我们只需要好好比对一下他们这几个Ҏ的不同就可以了?/font>

HelloWold中的getSourceConnectionAnchor

public ConnectionAnchor getSourceConnectionAnchor(Request request) {

returnnew ChopboxAnchor(getFigure());

}

q里q单的创徏一? ChopboxAnchor 好了。这个就可以直接q到?/span>Figure上了?/span>

?/font>workflow中这个情늨微有一点复杂了。先不说Q还是看看他? getSourceConnectionAnchor 是怎么实现的?/font>

public ConnectionAnchor getSourceConnectionAnchor(

ConnectionEditPart connection) {

Connection edge = (Connection) connection.getModel();

return getNodeFigure().getConnectionAnchor(edge.getSource().getName());

}


/**

*returnsananchorgivenitsname

*

*@paramportNamenameoftheanchor

*@returntheanchorwiththename<code>portName</code>

*/

public ConnectionAnchor getConnectionAnchor(String portName) {

return (ConnectionAnchor)connectionAnchors.get( portName );

}


protected Hashtable connectionAnchors = new Hashtable(7);


/**

*Addaninputportanditsanchor

*

*@paramportName

*uniquenametorefertotheport

*/

publicvoid addInput(String portName) {

InputPortFigure inputPort = new InputPortFigure();

add(inputPort);


PortConnectionAnchor anchor = new PortConnectionAnchor(inputPort);

getTargetConnectionAnchors().add(anchor);

connectionAnchors.put(portName, anchor);

}


通过q几个方法可以看出它是在dInput时候就创徏好了一个和PortFigure 相关Anchorq把它保存v来。在要用的时候就把它取出来。这样就搞定了?/font>

具体的可以参考这两个例子的代码。好了,打完收工?/font>


参考文?/font>

IBM U皮?/font>

1?/span>荒野困兽(老脸归来)’blog

2?/span>GEF q阶Q第一部分: Anchor




Jet Geng 2007-01-08 17:09 发表评论
]]>
DragSourceEvent 中的坐标问题http://www.aygfsteel.com/JetGeng/archive/2007/01/05/92104.htmlJet GengJet GengFri, 05 Jan 2007 12:32:00 GMThttp://www.aygfsteel.com/JetGeng/archive/2007/01/05/92104.htmlhttp://www.aygfsteel.com/JetGeng/comments/92104.htmlhttp://www.aygfsteel.com/JetGeng/archive/2007/01/05/92104.html#Feedback0http://www.aygfsteel.com/JetGeng/comments/commentRss/92104.htmlhttp://www.aygfsteel.com/JetGeng/services/trackbacks/92104.html我想在我?/span>EditPartViewer中获取一个图形元素把它拖攑ֈ一?/span>swt控g中。实现在<<囑Ş~辑器中拖拽对象?/font>swt控g>>一文有提到了。不q我在处理的时候,q不是按照他的那个方式来做的。我是根据当前点Q?/span>DragSourceEventQ?/span>的位|来查找该点下的对象。看是否是我需要的对象Q如果是允许拖动。否则就不可以?/span>

问题在这里出来:当没有出现滚动条的时候一切都很正常,当一出现滚动条就L没有办法拖动了。最后才发现DragSourceEvent中的坐标是按照屏q来得,?/span>EditPartViewer 中的坐标是按照他的那?/span>viewer来得。这个地斚w要{换一下?/span>



q个转换的动作发现在jfireQ?/span>org.nightlabs.editor2d.util.EditorUtil https://svn.jfire.org/svn/main/trunk/org.nightlabs.editor2d/src/org/nightlabs/editor2d/util/EditorUtil.javaQ中有现成的。不多说了,拿来用吧?/p>

Jet Geng 2007-01-05 20:32 发表评论
]]>
囑Ş~辑器中拖拽对象到swt控ghttp://www.aygfsteel.com/JetGeng/archive/2006/11/11/80604.htmlJet GengJet GengSat, 11 Nov 2006 11:56:00 GMThttp://www.aygfsteel.com/JetGeng/archive/2006/11/11/80604.htmlhttp://www.aygfsteel.com/JetGeng/comments/80604.htmlhttp://www.aygfsteel.com/JetGeng/archive/2006/11/11/80604.html#Feedback0http://www.aygfsteel.com/JetGeng/comments/commentRss/80604.htmlhttp://www.aygfsteel.com/JetGeng/services/trackbacks/80604.html前面一D|间有一个需求就是从swt控g中拖拽对象到囑Ş~辑器中Q就?/span>class org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor 的儿子们Q编辑器?/span>

后来?span lang="zh-CN">惛_?/span>我需要从囑Ş~辑器中拖拽对象?/span>swt控g中又该怎么做?br />l过一D|间的探烦Q终于搞定了?/span>

C如下q程Q希望对需要的朋友有点帮助?/p>

首先有了《从SWT控g中托拽对象到GEF~辑器中》文中对addDropTargetListenerҎ使用的经历,很快q定我需要对GraphicalViewerd一?/span>DragSourceListener?/span>

想着到这个地Ҏ应该可以很快收工了。但是添加完了以后发?span lang="zh-CN">原来的拖动功能都没有?/span>Q这个怎么回事。谁在后面搞鬹{?/font>

l过一D|间的狂搜滥烦l于扑ֈ了问题的关键。因?font face="Times New Roman, serif">GEF不允许同时有两个zd DragSource ?/p>

它本w已l拥有一?font face="Times New Roman, serif">DragSource了(~辑器内部的托拽Q,我们q时候添加一个就会存在多

DragSource了。当我添加一个新?font face="Times New Roman, serif">DragSource时候我们新家的DragSource׃被认为是默认?font face="Times New Roman, serif">DragSource?/p>

他以前的DragSource失效了。这不是我像看到的?/p>

怎么处理。看C一个牛人的解决Ҏ?/p>


What I made to fix the problem was to only allow my DragSource to act under certain 
conditions (in my application this happens when you click and drag the mouse AND
 the SHIFT key is pressed). So when the SHIFT key is not pressed my DragSource does
nothing and the editor's internal drag and drop works fine?br />
public void dragStart(DragSourceEvent event)
{
...

if (!condition.isValid())
event.doit = false;

...
}

我尝试了一下这U状况,一下就搞定了?/span>
在我的项目中Q由于还有一些数据需要{化?font size="2">呵呵Q感觉不错?br />
参考文档:
http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg15754.html


Jet Geng 2006-11-11 19:56 发表评论
]]>从SWT控g中托拽对象到GEF~辑器中http://www.aygfsteel.com/JetGeng/archive/2006/09/12/69195.htmlJet GengJet GengTue, 12 Sep 2006 09:16:00 GMThttp://www.aygfsteel.com/JetGeng/archive/2006/09/12/69195.htmlhttp://www.aygfsteel.com/JetGeng/comments/69195.htmlhttp://www.aygfsteel.com/JetGeng/archive/2006/09/12/69195.html#Feedback6http://www.aygfsteel.com/JetGeng/comments/commentRss/69195.htmlhttp://www.aygfsteel.com/JetGeng/services/trackbacks/69195.html?font face="Times New Roman, serif">SWT控g中托拽对象到GEF~辑器中

一般情况下GEFE序都是采用如下的界面:


gef.jpg

新徏对象的操作时通过拖拽Palette中元素到~辑而获得。但是有时候可能需要从SWTQ操作系l拖一些元素到GEF~辑器中来?/p>

下面我就把创L拖拽q程大概的描qC下:

1、定义拖拽源Q?font face="Times New Roman, serif">DragSourceQ?/p>

2、定义拖拽目标的监听Q?font face="Times New Roman, serif">DropTargetQ?/p>

到这里对于一般的拖拽其实是可以完工了?/p>

q个部分可以参?font face="Times New Roman, serif">weidagang2046的专栏的?/a>DND入门学习?/a>

但是要能?font face="Times New Roman, serif">GraphicalViewerq个对象扮演?/font>DropTarget我们q需要做点其他的工作?/font>GraphicalViewerq个cLw提供了一?/font>addDropTargetListenerҎ。看到这个方法是不是一늋喜啊。如果有也是应该的,因ؓq个Ҏ是我们解决前面提出问题的关键?/font>

好了看看他的声明吧!

				
						
								public void addDropTargetListener(TransferDropTargetListener listener)
						
				
		

他这个参数居然不?/font> DropTargetListener 。这?/font> TransferDropTargetListener 是一个什么玩意啊Q?/font>

?/font> help 中查刎ͼ

public interface TransferDropTargetListener
extends TransferDropTargetListener

A DropTragetListener that handles one type of SWT Transfer. The purpose of a TransferDropTargetListener is to:

  • Determine enablement for a Drop operation. Enablement is often a function drop location, and/or criteria.

  • When enabled, optionally showing feedback on the DropTarget.

  • Performing the actualy Drop

DelegatingDropAdapter allows these functions to be implemented separately for unrelated types of Drags. DelegatingDropAdapter then combines the function of each TransferDropTargetListener, while allowing them to be implemented as if they were the only DragSourceListener.

偷下懒,׃译了?/font>

创徏如下cL实现q个接口Q?/font>

public class TreeNodeTransferDropTargetListener extends

AbstractTransferDropTargetListener {


public TreeNodeTransferDropTargetListener(EditPartViewer editPartViewer) {

// 改类默认是处? TextTransfer cd的拖拽事?/font>

super (editPartViewer,TextTransfer.getInstance());

// TODO Auto-generated constructor stub

}


@Override

protected void updateTargetRequest() {

}


}

我们q个拖拽x让他执行一?/font> create 命o。所以下面就是要重蝲他的 createTargetRequest() 用来处理 create 对象的请求( CreateRequestion Q?/font> CreateRequetion 需要用到一个类Q帮助我们创建对象的工厂cR?/font> GEF l了我们q样的一个接?/font> CreationFactory 。下面我们取实现他就好了?/p>


package org.eclipse.gef.examples.shapes.rcp.views;


import org.eclipse.gef.examples.shapes.model.EllipticalShape;

import org.eclipse.gef.requests.CreationFactory;


public class TypeCreationFactory implements CreationFactory {


public Object getNewObject() {

// TODO Auto-generated method stub

EllipticalShape label = new EllipticalShape();

return label;

}


public Object getObjectType() {

return EllipticalShape. class ;

}


}


注意Q这里的 getNewObject 是返回要创徏cȝ一个对象实例?/font> GetObjectType 需要返回需要创建对象的cR这个可不要搞反了?/font>

q样我们可以把我们? TreeNodeTransferDropTargetListener cM?/font> createTargetRequest Ҏ加上了?/font>


private TypeCreationFactory factory = new TypeCreationFactory();

protected Request createTargetRequest() {

CreateRequest request = new CreateRequest();

request.setFactory( factory );

return request;

}


好了q个时候不要客气了Q加?/font>

protected void handleDragOver() {

getCurrentEvent(). detail = DND. DROP_MOVE |DND. DROP_COPY ;

super .handleDragOver();

}


@Override

protected void handleDrop() {

//String s = (String)getCurrentEvent().data;

//factory.setText(s);

super .handleDrop();

}

q样的方法吧?/font>

q样q个功能完成了?/font>


参考文献:

http://www.aygfsteel.com/weidagang2046/archive/2006/09/05/67707.html

http://www.eclipse.org/articles/Article-GEF-dnd/GEF-dnd.html




Jet Geng 2006-09-12 17:16 发表评论
]]>
վ֩ģ壺 | | | | | ŷ| | | | Ӣ| | | Ұ| | «Ϫ| | | | | | ƽ| ˮ| ̩| | | | Ϸ| ˫| | | ʳ| | ֣| ̨| ϸ| | ˳ƽ| | | ɽ| |