Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Fixed two bugs. With the first bug, it was possible to get the close
Browse files Browse the repository at this point in the history
button to not disappear when leaving the plot. The second bug caused the
close button to appear off the edge of the plot.

Signed-off-by: Jordan Deyton <deytonjh@ornl.gov>
  • Loading branch information
Jordan Deyton committed Apr 9, 2015
1 parent f466a13 commit 2e10b88
Showing 1 changed file with 16 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
Expand Down Expand Up @@ -877,10 +876,6 @@ public void run() {
gridComposite.pack();
drawingComposite.pack();
pageComposite.layout();

// Remove the listener that
// shows/hides the close button.
child.removeMouseTrackListener(closeButtonListener);
}
return;
}
Expand All @@ -907,12 +902,16 @@ public void run() {

private void showCloseButton(MouseEvent e) {

// Get the Composite that triggered the event
Composite comp = (Composite) e.widget;

if (closeButton == null || closeButton.isDisposed()) {
// Get the Composite that triggered the event
Composite comp = (Composite) e.widget;

// Set up the close button
closeButton = new Button(comp, SWT.FLAT | SWT.CENTER);

// Add the close button listener to the close button, too.
closeButton.addMouseTrackListener(closeButtonListener);

closeButton.setText("X");
FontData[] smallFont = closeButton.getFont().getFontData();
for (FontData fd : smallFont) {
Expand Down Expand Up @@ -941,38 +940,22 @@ && isChildControl(c, (Composite) plot)) {

closeButton.pack();
pageComposite.layout();
}

// Set the location of the button to the upper right-hand corner
closeButton.setLocation(
comp.getBounds().width - closeButton.getBounds().width - 4, 0);
// Set the location of the button to the upper right-hand corner
closeButton.setLocation(
comp.getBounds().width - closeButton.getBounds().width - 4,
0);
}

return;
}

private void hideCloseButton(MouseEvent e) {

// Get the widget which triggered the event
Control c = null;
if (e.widget instanceof Composite) {
c = (Composite) e.widget;
} else {
c = (Control) e.widget;
}

// Check if the cursor has actually exited the canvas area, or is just
// positioned over one of its children (yes, this technically counts
// as a MouseExit event... ugh)
if (c instanceof Composite) {
for (Control child : ((Composite) c).getChildren()) {
if (child.getBounds().contains(new Point(e.x, e.y))) {
return;
}
}
}

// If the cursor has left the canvas area, dispose the closeButton
if (closeButton != null && !closeButton.isDisposed()) {
// If the cursor has left the canvas area and the close button, dispose
// the button.
if (closeButton != null && !closeButton.isDisposed()
&& !closeButton.getBounds().contains(e.x, e.y)) {
closeButton.dispose();
closeButton = null;
}
Expand Down

0 comments on commit 2e10b88

Please sign in to comment.