java - 过度绘制 Eclipse RCP 应用程序的主 shell

标签 java eclipse eclipse-rcp

我一直在尝试“ overdraw ”Eclipse RCP 应用程序的主窗口,以便在应用程序启用屏幕录制功能时显示红色“录制”边框。

private boolean isActive;

private final ProgressMonitorDialog monitor;

private PaintListener paintListener;
private final int recordingFrameThickness = 5;  

public boolean toggle() {
  isActive = !isActive;

  try {
    // New state
    if (isActive) {
      monitor.run(true, false, new BackupExecutionBeginRecording(Display.getCurrent()));
      addRecordingFrame(Display.getCurrent().getActiveShell());
    }
    else {
      monitor.run(true, false, new BackupExecutionAfterRecording());
      removeRecoringFrame(Display.getCurrent().getActiveShell());
    }
  }
  catch (InvocationTargetException e) {
    System.err.println("Couldn't start backup task. Error: " + e.getMessage());
  }
  catch (InterruptedException e) {
    System.err.println("Backup thread was interrupted. Error: " + e.getMessage());
  }

  return isActive;
}

private void addRecordingFrame(Shell shell) {
  paintListener = new PaintListener() {

    @Override
    public void paintControl(PaintEvent e) {
      Rectangle clientArea = shell.getClientArea();
      e.gc.setLineWidth(recordingFrameThickness);
      e.gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
      e.gc.drawRectangle(clientArea);
    }
  };

  shell.addPaintListener(paintListener);
}

private void removeRecoringFrame(Shell shell) {
  shell.removePaintListener(paintListener);
}

正如您所看到的,我遵循的方法是等待应用程序主窗口绘制完毕,然后添加一个矩形。理论上,每次改变窗口大小或位置后,都应该重新渲染覆盖的红框。但似乎 PaintEvent 不是由应用程序的主 shell 调用的。

是否有其他方法可以在应用程序的现有布局上绘制某些内容,而不会阻止与下面的控件的交互?

最佳答案

Eclipse 平台通过在覆盖外壳上创建和绘制来实现此目的,该覆盖外壳被小心地放置在基本外壳的顶部。叠加层是使用 SWT.NO_TRIM | 创建的。 SWT.ON_TOP 及其位置跟踪底层基础 shell。请参阅 e4 Overlay举个例子。

关于java - 过度绘制 Eclipse RCP 应用程序的主 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50152708/

相关文章:

java - Spring MVC - 无法在 webapp/resources/创建文件

java - 使用 Eclipse 时,Ant 会在哪里寻找您的 Java Home?

c++ - Eclipse CDT 无法解析模板类的 std::vector

java - 如何占用Eclipse UI中的可用空间?

java - 获取数据存储时间

Java网络编程。关于 socket 的问题

java - Eclipse 插件开发 : How to drag element from Desktop to custom Node in Project Explorer

java - Appengine 应用程序的部署时间太长?

eclipse-rcp - 如何将文件添加到 Eclipse RCP 应用程序的根目录?

java - TreeViewer#update(对象元素,String[] 属性);属性指的是什么?