gpt4 book ai didi

java - 如何从 Eclipse RCP 中的现有透视图获取新窗口

转载 作者:行者123 更新时间:2023-12-01 11:53:32 24 4
gpt4 key购买 nike

我目前是 Eclipse RCP/SWT 和 Jface 的新手。我正在尝试使用按钮从现有 View 创建一个新的弹出窗口。它类似于 MessageBox,但 MessageBox 的功能有限我需要在我的第二个“shell”/窗口上使用 SWT.graphics。因此,一旦我获得第二个窗口,我就应该得到一个数字。

现在有两个问题:

  1. 我不知道如何通过当前视角中的单击来创建新窗口。我提到了这个here但又不满足。

  2. 我不知道如何集成两个文件 DrawExamples.javaView.java 以便在 View 中打开一个窗口。 Java,它从 DrawExample.java 获取绘制代码。

到目前为止我的进展:

 View.java()


{
public void createPartControl(final Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
// Provide the input to the ContentProvider
viewer.setInput(new String[] {"One", "Two", "Three"});
final FormLayout layout = new FormLayout();
layout.marginHeight = 5;
layout.marginWidth = 5;

//set layout for parent
parent.setLayout(layout);

//create a button or any other widget
Button button2 = new Button(parent, SWT.PUSH);
button2.setText("B2");
button2.addSelectionListener(new SelectionAdapter() {
@Override

public void widgetSelected(SelectionEvent e)
{// I want to generate new Window here. Not a new View like the one i have created above. From the Object of DrawExample Class So that i can keep things modular. Drawing in Once class and windowing in one class.`

});
//create FormData and set each of its sides
FormData formData = new FormData();
formData.top = new FormAttachment(0, 0);
formData.bottom = new FormAttachment(50, 0);
formData.left = new FormAttachment(10, 0);
formData.right = new FormAttachment(60, 0);

//set FormDate for button
button2.setLayoutData(formData);
}
}

DrawExample 类。

    import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class DrawExample {
public static void main(String[] args){
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Drawing Example");

Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.setSize(150, 150);
canvas.setLocation(20, 20);
shell.open();
shell.setSize(200, 220);

GC gc = new GC(canvas);
gc.drawRoundRectangle(11, 11, 89, 44, 25, 15);
gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
gc.fillRoundRectangle(10,10,90,45,25,15);
Font font = new Font(display,"Arial",12,SWT.BOLD | SWT.ITALIC);
//gc.drawText("Hello World",5,5);
gc.setFont(font);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
gc.drawText("Hello World",10,20,true);

gc.dispose();
font.dispose();
//gc.drawOval(65, 10, 30, 35);
//gc.drawLine(130, 10, 90, 80);
//gc.drawPolygon(new int[] { 20, 70, 45, 90, 70, 70 });
//gc.drawPolyline(new int[] { 10, 120, 70, 100, 100, 130, 130, 75 });
gc.dispose();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

最佳答案

如果您想在 View 中生成通用 shell,您始终可以使用

生成一个
Shell=new Shell(getViewSite().getPage().getWorkbenchWindow().getShell());

但我不认为这是推荐的方式。

关于java - 如何从 Eclipse RCP 中的现有透视图获取新窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28608839/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com