hover = new Hover(hoverNear.getShell()); hover.setText(text, getDecorationRectangle(control.getParent()), control); hover.setVisible(true);
void setText(String t, Rectangle decorationRectangle, Control targetControl) { if (t == null) { t = EMPTY; } if (!t.equals(text)) { Point oldSize = getExtent(); text = t; hoverShell.redraw(); Point newSize = getExtent(); if (!oldSize.equals(newSize)) { // set a flag that indicates the direction of arrow arrowOnLeft = decorationRectangle.x <= targetControl .getLocation().x; setNewShape(); } } Point extent = getExtent(); int y = -extent.y - hah + 1; int x = arrowOnLeft ? -hao + haw / 2 : -extent.x + hao + haw / 2; Point hoverSize = hoverShell.getSize(); Rectangle hoverBounds = control.getDisplay().map(control.getParent(), null, decorationRectangle.x + x, decorationRectangle.y + y, hoverSize.x, hoverSize.y); hoverShell.setLocation(hoverBounds.x, hoverBounds.y); }
Hover(Shell parent) { final Display display = parent.getDisplay(); hoverShell = new Shell(parent, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); hoverShell.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); hoverShell.setForeground(display .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); hoverShell.addPaintListener(pe -> { pe.gc.drawText(text, hm, hm); if (!MAC) { pe.gc.drawPolygon(getPolygon(true)); } }); hoverShell.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { hideHover(); } }); }
hover = new Hover(hoverNear.getShell()); hover.setText(text, getDecorationRectangle(control.getParent()), control); hover.setVisible(true);
/** * Something has changed, requiring redraw. Redraw the decoration and update * the hover text if appropriate. */ protected void update() { if (control == null || control.isDisposed()) { return; } Rectangle rect = getDecorationRectangle(control.getShell()); // If this update is happening due to an image reset, we need to make // sure we clear the area from the old image. // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=212501 if (previousDecorationRectangle != null) { rect = rect.union(previousDecorationRectangle); } // Redraw this rectangle in all children control.getShell() .redraw(rect.x, rect.y, rect.width, rect.height, true); control.getShell().update(); if (hover != null && getDescriptionText() != null) { hover.setText(getDescriptionText(), getDecorationRectangle(control .getParent()), control); } previousDecorationRectangle = null; }
/** * Something has changed, requiring redraw. Redraw the decoration and update * the hover text if appropriate. */ protected void update() { if (control == null || control.isDisposed()) { return; } Rectangle rect = getDecorationRectangle(control.getShell()); // If this update is happening due to an image reset, we need to make // sure we clear the area from the old image. // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=212501 if (previousDecorationRectangle != null) { rect = rect.union(previousDecorationRectangle); } // Redraw this rectangle in all children control.getShell() .redraw(rect.x, rect.y, rect.width, rect.height, true); control.getShell().update(); if (hover != null && getDescriptionText() != null) { hover.setText(getDescriptionText(), getDecorationRectangle(control .getParent()), control); } previousDecorationRectangle = null; }
Hover(Shell parent) { final Display display = parent.getDisplay(); hoverShell = new Shell(parent, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); hoverShell.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); hoverShell.setForeground(display .getSystemColor(SWT.COLOR_INFO_FOREGROUND)); hoverShell.addPaintListener(pe -> { pe.gc.drawText(text, hm, hm); if (!MAC) { pe.gc.drawPolygon(getPolygon(true)); } }); hoverShell.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { hideHover(); } }); }
void setText(String t, Rectangle decorationRectangle, Control targetControl) { if (t == null) { t = EMPTY; } if (!t.equals(text)) { Point oldSize = getExtent(); text = t; hoverShell.redraw(); Point newSize = getExtent(); if (!oldSize.equals(newSize)) { // set a flag that indicates the direction of arrow arrowOnLeft = decorationRectangle.x <= targetControl .getLocation().x; setNewShape(); } } Point extent = getExtent(); int y = -extent.y - hah + 1; int x = arrowOnLeft ? -hao + haw / 2 : -extent.x + hao + haw / 2; Point hoverSize = hoverShell.getSize(); Rectangle hoverBounds = control.getDisplay().map(control.getParent(), null, decorationRectangle.x + x, decorationRectangle.y + y, hoverSize.x, hoverSize.y); hoverShell.setLocation(hoverBounds.x, hoverBounds.y); }
/** * Hide any hover popups that are currently showing on the control. When * {@link #setShowHover(boolean)} has been set to <code>true</code>, a * decoration's description text will be shown in an info hover over the * field's control as long as the mouse hovers over the decoration, and will * be hidden when the mouse exits the decoration. This method can be used to * hide a hover, whether it was shown explicitly using * {@link #showHoverText(String)}, or was showing because the user was * hovering in the decoration. * <p> * This message has no effect if there is no current hover. * */ public void hideHover() { if (hover != null) { hover.setVisible(false); } }
/** * Hide any hover popups that are currently showing on the control. When * {@link #setShowHover(boolean)} has been set to <code>true</code>, a * decoration's description text will be shown in an info hover over the * field's control as long as the mouse hovers over the decoration, and will * be hidden when the mouse exits the decoration. This method can be used to * hide a hover, whether it was shown explicitly using * {@link #showHoverText(String)}, or was showing because the user was * hovering in the decoration. * <p> * This message has no effect if there is no current hover. * */ public void hideHover() { if (hover != null) { hover.setVisible(false); } }
/** * Dispose this ControlDecoration. Unhook any listeners that have been * installed on the target control. This method has no effect if the * receiver is already disposed. */ public void dispose() { if (control == null) { return; } if (hover != null) { hover.dispose(); hover = null; } removeControlListeners(); control = null; }
/** * Dispose this ControlDecoration. Unhook any listeners that have been * installed on the target control. This method has no effect if the * receiver is already disposed. */ public void dispose() { if (control == null) { return; } if (hover != null) { hover.dispose(); hover = null; } removeControlListeners(); control = null; }
int[] getPolygon(boolean border) { Point e = getExtent(); int b = border ? 1 : 0; if (arrowOnLeft) { return new int[] { 0, 0, e.x - b, 0, e.x - b, e.y - b, hao + haw, e.y - b, hao + haw / 2, e.y + hah - b, hao, e.y - b, 0, e.y - b, 0, 0 }; } return new int[] { 0, 0, e.x - b, 0, e.x - b, e.y - b, e.x - hao - b, e.y - b, e.x - hao - haw / 2, e.y + hah - b, e.x - hao - haw, e.y - b, 0, e.y - b, 0, 0 }; }
void setNewShape() { Region oldRegion = region; region = new Region(); region.add(getPolygon(false)); hoverShell.setRegion(region); if (oldRegion != null) { oldRegion.dispose(); } } }
int[] getPolygon(boolean border) { Point e = getExtent(); int b = border ? 1 : 0; if (arrowOnLeft) { return new int[] { 0, 0, e.x - b, 0, e.x - b, e.y - b, hao + haw, e.y - b, hao + haw / 2, e.y + hah - b, hao, e.y - b, 0, e.y - b, 0, 0 }; } return new int[] { 0, 0, e.x - b, 0, e.x - b, e.y - b, e.x - hao - b, e.y - b, e.x - hao - haw / 2, e.y + hah - b, e.x - hao - haw, e.y - b, 0, e.y - b, 0, 0 }; }
void setNewShape() { Region oldRegion = region; region = new Region(); region.add(getPolygon(false)); hoverShell.setRegion(region); if (oldRegion != null) { oldRegion.dispose(); } } }