void setText(String t, Control hoverNear, 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 = hoverNear.getLocation().x <= targetControl .getLocation().x; setNewShape(); } } if (hoverNear != null) { Point extent = getExtent(); int y = -extent.y - hah + 1; int x = arrowOnLeft ? -hao + haw / 2 : -extent.x + hao + haw / 2; hoverShell.setLocation(hoverNear.toDisplay(x, 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.drawString(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, Control hoverNear, 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 = hoverNear.getLocation().x <= targetControl .getLocation().x; setNewShape(); } } if (hoverNear != null) { Point extent = getExtent(); int y = -extent.y - hah + 1; int x = arrowOnLeft ? -hao + haw / 2 : -extent.x + hao + haw / 2; hoverShell.setLocation(hoverNear.toDisplay(x, y)); } }
void setText(String t, Control hoverNear, 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 = hoverNear.getLocation().x <= targetControl .getLocation().x; setNewShape(); } } if (hoverNear != null) { Point extent = getExtent(); int y = -extent.y - hah + 1; int x = arrowOnLeft ? -hao + haw / 2 : -extent.x + hao + haw / 2; hoverShell.setLocation(hoverNear.toDisplay(x, 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.drawString(text, hm, hm); if (!MAC) { pe.gc.drawPolygon(getPolygon(true)); } }); hoverShell.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { hideHover(); } }); }
/** * Add any listeners needed on the target control. */ private void addControlListeners() { control.addDisposeListener(event -> { if (hover != null) { hover.dispose(); } }); control.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent event) { controlFocusGained(); } @Override public void focusLost(FocusEvent event) { controlFocusLost(); } }); }
/** * Add any listeners needed on the target control. */ private void addControlListeners() { control.addDisposeListener(event -> { if (hover != null) { hover.dispose(); } }); control.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent event) { controlFocusGained(); } @Override public void focusLost(FocusEvent event) { controlFocusLost(); } }); }
/** * Hide any hover popups that are currently showing on the control. * Normally, 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 control. This method can be * used to hide a hover that was shown using <code>showHoverText</code>, * or to programatically hide the current decoration hover. * * <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. * Normally, 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 control. This method can be * used to hide a hover that was shown using <code>showHoverText</code>, * or to programatically hide the current decoration hover. * * <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. * Normally, 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 control. This method can be * used to hide a hover that was shown using <code>showHoverText</code>, * or to programatically hide the current decoration hover. * * <p> * This message has no effect if there is no current hover. * */ public void hideHover() { if (hover != null) { hover.setVisible(false); } }
private void showHoverText(String text, Control hoverNear) { if (text == null) { hideHover(); return; } // RAP [fappel]: (mis-)use images toolTipText for the decorations' description hoverNear.setToolTipText( text ); // RAPEND: [bm] if (hover == null) { hover = new Hover(hoverNear.getShell()); } hover.setText(text, hoverNear, control); hover.setVisible(true); }
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 }; }
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 }; }
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(); } } }
void setNewShape() { Region oldRegion = region; region = new Region(); region.add(getPolygon(false)); hoverShell.setRegion(region); if (oldRegion != null) { oldRegion.dispose(); } } }
public void widgetDisposed(DisposeEvent event) { if (hover != null) { hover.dispose(); } } });
private void showHoverText(String text, Control hoverNear) { if (text == null) { hideHover(); return; } if (hover == null) { hover = new Hover(hoverNear.getShell()); } hover.setText(text, hoverNear, control); hover.setVisible(true); }
private void showHoverText(String text, Control hoverNear) { if (text == null) { hideHover(); return; } if (hover == null) { hover = new Hover(hoverNear.getShell()); } hover.setText(text, hoverNear, control); hover.setVisible(true); }