2

How can I create popup window similar to the window used in eclipse jdt for javadoc. I need to show additional info when mouse hovers over a graph node.

enter image description here

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 に答える