2

如何为 javadoc 创建类似于 eclipse jdt 中使用的窗口的弹出窗口。当鼠标悬停在图形节点上时,我需要显示其他信息。

在此处输入图像描述

4

3 回答 3

3

我认为IInformationPresenter (eclipse.org API)接口可以在这里为您提供帮助。

可以在 IBM 找到关于如何使用它的精心编写的教程:

Berthold Daum 的“为 SWT 应用程序配备内容助手”

于 2012-04-17T12:32:43.240 回答
2

org.eclipse.jface.dialogs.PopupDialog似乎是一个很好的起点。

于 2012-04-18T08:34:43.710 回答
1

这里得到这个代码:

public class InfoPopUp extends PopupDialog {

    /**
     * The text control that displays the text.
     */
    private Text text;

    /**
     * The String shown in the popup.
     */
    private String contents = "";

    private final static int SHELL_STYLE = PopupDialog.INFOPOPUP_SHELLSTYLE;

    public InfoPopUp(Shell parent, String infoText) {
        this(parent, SHELL_STYLE, false, false, false, false, false, null,
                infoText);
    }

    public InfoPopUp(Shell parent, String titleText, String infoText) {
        this(parent, SHELL_STYLE, false, false, false, true, true, titleText,
                infoText);
    }

    public InfoPopUp(Shell parent, int shellStyle, boolean takeFocusOnOpen,
            boolean persistSize, boolean persistLocation,
            boolean showDialogMenu, boolean showPersistActions,
            String titleText, String infoText) {
        super(parent, shellStyle, takeFocusOnOpen, persistSize,
                persistLocation, showDialogMenu, showPersistActions, titleText,
                infoText);
    }

    /**
     * This method is used to show the animation by decreasing the x and y
     * coordinates and by setting the size dynamically.
     * 
     * @param shell
     *            of type {@link Shell}
     */
    private static void doAnimation(Shell shell) {
        Point shellArea = shell.getSize();
        int x = shellArea.x;
        int y = shellArea.y;
        while (x != -200) {
            try {
                shell.setSize(x--, y--);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    protected void fillDialogMenu(IMenuManager dialogMenu) {
        dialogMenu.addMenuListener(new IMenuListener() {
            public void menuAboutToShow(IMenuManager arg0) {
                handleShellCloseEvent();
            }
        });
    }

    protected void handleShellCloseEvent() {
        // Comment out the following if do not want any kind of animated effect.
        doAnimation(getShell());
        super.handleShellCloseEvent();
    }

    protected Control createDialogArea(Composite parent) {
        text = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.NO_FOCUS);
        text.setText(contents);
        return text;
    }

    protected void adjustBounds() {
        super.adjustBounds();
        // Point pt = getShell().getDisplay().getCursorLocation();
        // getShell().setBounds(pt.x,pt.y,rectangle.width,rectangle.height);
    }

    /**
     * Method to set the text contents of the InfoPop dialog
     * 
     * @param textContents
     *            of type String indicating the message
     */
    public void setText(String textContents) {
        this.contents = textContents;
    }

    protected Control createTitleMenuArea(Composite arg0) {
        Control ctrl = super.createTitleMenuArea(arg0);
        Composite composite = (Composite) ctrl;
        Control[] ctrls = composite.getChildren();

        ToolBar toolBar = (ToolBar) ctrls[1];
        ToolItem[] toolItems = toolBar.getItems();
        toolItems[0].setImage(Display.getDefault().getSystemImage(SWT.ICON_WARNING));

        return ctrl;
    }
}
于 2012-04-18T11:58:09.993 回答