GEF:什么时候产生Tool的实例?

通过查看EditDomain的源码可知。
/**
 * Listens to the PaletteViewer for changes in selection, and sets the Domain's Tool
 * accordingly.
 * 监听工具箱里面工具的选中
 */
private PaletteListener paletteListener = new PaletteListener() {
 public void activeToolChanged(PaletteViewer viewer, ToolEntry tool) {
  handlePaletteToolChanged();
 }
};


/*
 * 当选中了一个Tool时,就会创建一个Tool实例,并将这个Tool设置为EditDomain上的Active Tool
 */
private void handlePaletteToolChanged() {
 PaletteViewer paletteViewer = getPaletteViewer();
 if (paletteViewer != null) {
  ToolEntry entry = paletteViewer.getActiveTool();
  if (entry != null)
   setActiveTool(entry.createTool());
  else
   setActiveTool(getDefaultTool());
 }
}


/**
 * Sets the active Tool for this EditDomain. If a current Tool is active, it is
 * deactivated. The new Tool is told its EditDomain, and is activated.
 * @param tool the Tool
 */
public void setActiveTool(Tool tool) {
 if (activeTool != null)
  activeTool.deactivate();//使之前的activeTool不可用
 activeTool = tool;//替换activeTool
 if (activeTool != null) {
  activeTool.setEditDomain(this);
  activeTool.activate();//使之激活
 }
}

 

当然,也应该注意到,在EditDomain的构造方法处,载入了一个默认的Tool。
/**
 * Constructs an EditDomain and loads the default tool.
 */
public EditDomain() {
 loadDefaultTool();
}


/**
 * Loads the default Tool. If a palette has been provided and that palette has a default,
 * then that tool is loaded. If not, the EditDomain's default tool is loaded. By default,
 * this is the
{@link org.eclipse.gef.tools.SelectionTool}.
 */
public void loadDefaultTool() {
 setActiveTool(null);
 PaletteViewer paletteViewer = getPaletteViewer();
 if (paletteRoot != null && paletteViewer != null) {
  if (paletteRoot.getDefaultEntry() != null) {
   paletteViewer.setActiveTool(paletteRoot.getDefaultEntry());
   return;
  } else
   paletteViewer.setActiveTool(null);
 }
 setActiveTool(getDefaultTool());
}

/**
 * Returns the default tool for this edit domain. This will be a
{@link
 * org.eclipse.gef.tools.SelectionTool} unless specifically replaced using {@link
 * #setDefaultTool(Tool)}.
 * 默认的Tool为SelectionTool
 * @return The default Tool for this domain
 */
public Tool getDefaultTool() {
 if (defaultTool == null)
  defaultTool = new SelectionTool();
 return defaultTool;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值