Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kysmith-csg committed Nov 3, 2023
1 parent b5b1c40 commit 16d55ef
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 60 deletions.
43 changes: 23 additions & 20 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/PopUpHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
Expand Down Expand Up @@ -38,14 +38,14 @@ public abstract class PopUpHelper {

/**
* These style bits should be used when creating the Shell.
*
*
* @see #createShell()
*/
protected final int shellStyle;

/**
* Constructs a PopUpHelper to assist with popups on Control c.
*
*
* @param c the Control
* @since 2.0
*/
Expand All @@ -55,7 +55,7 @@ protected PopUpHelper(Control c) {

/**
* Constructs a PopUpHelper to display the given shell style popup.
*
*
* @param c the control on which the popup is active.
* @param shellStyle the SWT style bits for the shell
* @since 3.1
Expand All @@ -68,7 +68,7 @@ protected PopUpHelper(Control c, int shellStyle) {
/**
* Creates and returns the LightweightSystem object used by PopUpHelper to draw
* upon.
*
*
* @return the newly created LightweightSystem
* @since 2.0
*/
Expand All @@ -78,7 +78,7 @@ protected LightweightSystem createLightweightSystem() {

/**
* Creates a new Shell object with the style specified for this helper.
*
*
* @return the newly created Shell
* @since 2.0
*/
Expand All @@ -88,20 +88,22 @@ protected Shell createShell() {

/**
* Dispose of this PopUpHelper object.
*
*
* @since 2.0
*/
public void dispose() {
if (isShowing())
if (isShowing()) {
hide();
if (shell != null && !shell.isDisposed())
}
if (shell != null && !shell.isDisposed()) {
shell.dispose();
}
}

/**
* Returns this PopUpHelper's shell. If no shell exists for this PopUpHelper, a
* new shell is created and hookShellListeners() is called.
*
*
* @return the Shell
* @since 2.0
*/
Expand All @@ -116,7 +118,7 @@ protected Shell getShell() {
/**
* Returns the size needed to display the shell's trim. This method should not
* be called until the shell has been created.
*
*
* @return the size of the shells trim.
* @since 3.1
*/
Expand All @@ -129,7 +131,7 @@ protected Dimension getShellTrimSize() {
* Returns this PopUpHelper's LightweightSystem. If no LightweightSystem exists
* for this PopUpHelper, a new LightweightSystem is created with this
* PopUpHelper's Shell as its Control.
*
*
* @return the LightweightSystem
* @since 2.0
*/
Expand All @@ -143,28 +145,29 @@ protected LightweightSystem getLightweightSystem() {

/**
* Hides this PopUpHelper's Shell.
*
*
* @since 2.0
*/
protected void hide() {
if (shell != null && !shell.isDisposed())
if (shell != null && !shell.isDisposed()) {
shell.setVisible(false);
}
tipShowing = false;
}

/**
* Desired popup helper behavior is achieved by writing listeners that
* manipulate the behavior of the PopUpHelper's Shell. Override this method and
* add these listeners here.
*
*
* @since 2.0
*/
protected abstract void hookShellListeners();

/**
* Returns <code>true</code> if this PopUpHelper's Shell is visible,
* <code>false</code> otherwise.
*
*
* @return <code>true</code> if this PopUpHelper's Shell is visible
* @since 2.0
*/
Expand All @@ -174,7 +177,7 @@ public boolean isShowing() {

/**
* Sets the background color of this PopUpHelper's Shell.
*
*
* @param c the new background color
* @since 2.0
*/
Expand All @@ -184,7 +187,7 @@ public void setBackgroundColor(Color c) {

/**
* Sets the foreground color of this PopUpHelper's Shell.
*
*
* @param c the new foreground color
* @since 2.0
*/
Expand All @@ -194,7 +197,7 @@ public void setForegroundColor(Color c) {

/**
* Sets the bounds on this PopUpHelper's Shell.
*
*
* @param x the x coordinate
* @param y the y coordinate
* @param width the width
Expand All @@ -207,7 +210,7 @@ protected void setShellBounds(int x, int y, int width, int height) {

/**
* Displays this PopUpHelper's Shell.
*
*
* @since 2.0
*/
protected void show() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
Expand All @@ -14,10 +14,7 @@

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
Expand All @@ -35,8 +32,9 @@ class EditPartTipHelper extends org.eclipse.draw2d.PopUpHelper {
private ShellListener shellListener;

private static void setHelper(EditPartTipHelper helper) {
if (currentHelper != null && currentHelper != helper && currentHelper.isShowing())
if (currentHelper != null && currentHelper != helper && currentHelper.isShowing()) {
currentHelper.hide();
}
currentHelper = helper;
}

Expand All @@ -49,7 +47,7 @@ public EditPartTipHelper(Control c) {
* displays the tip at the coordianates specified by tipPosX and tipPosY. The
* given coordinates will be adjusted if the tip cannot be completely visible on
* the screen.
*
*
* @param tip The tool tip to be displayed.
* @param tipPosX X coordiante of tooltip to be displayed
* @param tipPosY Y coordinate of tooltip to be displayed
Expand Down Expand Up @@ -121,15 +119,13 @@ public void mouseExit(MouseEvent e) {
* cursor is no longer in the tooltip. This occurs in the rare case that a
* mouseEnter is not received on the tooltip when it appears.
*/
getShell().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
if (!getShell().getBounds().contains(eventPoint)) {
if (isShowing())
getShell().setCapture(false);
dispose();
getShell().addMouseMoveListener(e -> {
Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
if (!getShell().getBounds().contains(eventPoint)) {
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
}
});

Expand All @@ -139,17 +135,16 @@ public void mouseMove(MouseEvent e) {
shellListener = new ShellAdapter() {
@Override
public void shellDeactivated(ShellEvent event) {
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
Shell active = Display.getCurrent().getActiveShell();
if (getShell() == active || control.isDisposed() || control.getShell() == active
|| getShell().isDisposed())
return;
if (isShowing())
getShell().setCapture(false);
dispose();
Display.getCurrent().asyncExec(() -> {
Shell active = Display.getCurrent().getActiveShell();
if (getShell() == active || control.isDisposed() || control.getShell() == active
|| getShell().isDisposed()) {
return;
}
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
});
}
};
Expand All @@ -163,22 +158,17 @@ public void run() {
* dispose of the shell.
*/
if (SWT.getPlatform().equals("gtk")) { //$NON-NLS-1$
getShell().addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
Point cursorLoc = Display.getCurrent().getCursorLocation();
if (!getShell().getBounds().contains(cursorLoc)) {
// This must be run asynchronously. If not, other paint
// listeners may attempt to paint on a disposed control.
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
if (isShowing())
getShell().setCapture(false);
dispose();
}
});
}
getShell().addPaintListener(event -> {
Point cursorLoc = Display.getCurrent().getCursorLocation();
if (!getShell().getBounds().contains(cursorLoc)) {
// This must be run asynchronously. If not, other paint
// listeners may attempt to paint on a disposed control.
Display.getCurrent().asyncExec(() -> {
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
});
}
});
}
Expand Down

0 comments on commit 16d55ef

Please sign in to comment.