use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_Control method test_addMouseListenerLorg_eclipse_swt_events_MouseListener.
@Test
public void test_addMouseListenerLorg_eclipse_swt_events_MouseListener() {
MouseListener listener = new MouseListener() {
@Override
public void mouseDown(MouseEvent e) {
eventOccurred = true;
}
@Override
public void mouseUp(MouseEvent e) {
eventOccurred = true;
}
@Override
public void mouseDoubleClick(MouseEvent e) {
eventOccurred = true;
}
};
control.addMouseListener(listener);
eventOccurred = false;
control.notifyListeners(SWT.MouseDown, new Event());
assertTrue(eventOccurred);
eventOccurred = false;
control.notifyListeners(SWT.MouseUp, new Event());
assertTrue(eventOccurred);
eventOccurred = false;
control.notifyListeners(SWT.MouseDoubleClick, new Event());
assertTrue(eventOccurred);
control.removeMouseListener(listener);
}
use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_Control method test_addMouseTrackListenerLorg_eclipse_swt_events_MouseTrackListener.
@Test
public void test_addMouseTrackListenerLorg_eclipse_swt_events_MouseTrackListener() {
MouseTrackListener listener = new MouseTrackListener() {
@Override
public void mouseEnter(MouseEvent e) {
eventOccurred = true;
}
@Override
public void mouseExit(MouseEvent e) {
eventOccurred = true;
}
@Override
public void mouseHover(MouseEvent e) {
eventOccurred = true;
}
};
control.addMouseTrackListener(listener);
eventOccurred = false;
control.notifyListeners(SWT.MouseEnter, new Event());
assertTrue(eventOccurred);
eventOccurred = false;
control.notifyListeners(SWT.MouseExit, new Event());
assertTrue(eventOccurred);
eventOccurred = false;
control.notifyListeners(SWT.MouseHover, new Event());
assertTrue(eventOccurred);
control.removeMouseTrackListener(listener);
}
use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.swt by eclipse.
the class CurvesSWTTab method createControlPanel.
/**
* Creates the widgets used to control the drawing.
*/
@Override
public void createControlPanel(Composite parent) {
if (cursor == null) {
cursor = parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
}
mouseMoveListener = e -> {
if (hovering && mouseDown) {
example.canvas.setCursor(cursor);
} else if (isHovering(e)) {
example.canvas.setCursor(cursor);
hovering = true;
} else {
example.canvas.setCursor(null);
hovering = false;
}
if (sLeftPtMoved) {
sDiffX1 = sDiffX1 + e.x - (int) sXPos - sRect1.x;
sDiffY1 = sDiffY1 + e.y - (int) sYPos - sRect1.y;
sRect1.x = e.x - (int) sXPos;
sRect1.y = e.y - (int) sYPos;
} else if (sRightPtMoved) {
sDiffX2 = sDiffX2 + e.x - (int) sXPos - sRect2.x;
sDiffY2 = sDiffY2 + e.y - (int) sYPos - sRect2.y;
sRect2.x = e.x - (int) sXPos;
sRect2.y = e.y - (int) sYPos;
} else if (wPt1Moved) {
wDiffX1 = wDiffX1 + e.x - (int) wXPos - wRect1.x;
wDiffY1 = wDiffY1 + e.y - (int) wYPos - wRect1.y;
wRect1.x = e.x - (int) wXPos;
wRect1.y = e.y - (int) wYPos;
} else if (wPt2Moved) {
wDiffX2 = wDiffX2 + e.x - (int) wXPos - wRect2.x;
wDiffY2 = wDiffY2 + e.y - (int) wYPos - wRect2.y;
wRect2.x = e.x - (int) wXPos;
wRect2.y = e.y - (int) wYPos;
} else if (tTopPt1Moved) {
tTopDiffX1 = tTopDiffX1 + e.x - (int) topTXPos - tTopRect1.x;
tTopDiffY1 = tTopDiffY1 + e.y - (int) topTYPos - tTopRect1.y;
tTopRect1.x = e.x - (int) topTXPos;
tTopRect1.y = e.y - (int) topTYPos;
} else if (tTopPt2Moved) {
tTopDiffX2 = tTopDiffX2 + e.x - (int) topTXPos - tTopRect2.x;
tTopDiffY2 = tTopDiffY2 + e.y - (int) topTYPos - tTopRect2.y;
tTopRect2.x = e.x - (int) topTXPos;
tTopRect2.y = e.y - (int) topTYPos;
} else if (tBotPt1Moved) {
tBotDiffX1 = tBotDiffX1 + e.x - (int) botTXPos - tBottomRect1.x;
tBotDiffY1 = tBotDiffY1 + e.y - (int) botTYPos - tBottomRect1.y;
tBottomRect1.x = e.x - (int) botTXPos;
tBottomRect1.y = e.y - (int) botTYPos;
} else if (tBotPt2Moved) {
tBotDiffX2 = tBotDiffX2 + e.x - (int) botTXPos - tBottomRect2.x;
tBotDiffY2 = tBotDiffY2 + e.y - (int) botTYPos - tBottomRect2.y;
tBottomRect2.x = e.x - (int) botTXPos;
tBottomRect2.y = e.y - (int) botTYPos;
}
example.redraw();
};
mouseListener = new MouseListener() {
@Override
public void mouseDoubleClick(MouseEvent e) {
}
/**
* Sent when a mouse button is pressed.
*
* @param e an event containing information about the mouse button press
*/
@Override
public void mouseDown(MouseEvent e) {
Rectangle r1 = new Rectangle(sRect1.x + (int) sXPos - 1, sRect1.y + (int) sYPos - 1, sRect1.width + 2, sRect1.height + 2);
Rectangle r2 = new Rectangle(sRect2.x + (int) sXPos - 1, sRect2.y + (int) sYPos - 1, sRect2.width + 2, sRect2.height + 2);
Rectangle w1 = new Rectangle(wRect1.x + (int) wXPos - 1, wRect1.y + (int) wYPos - 1, wRect1.width + 2, wRect1.height + 2);
Rectangle w2 = new Rectangle(wRect2.x + (int) wXPos - 1, wRect2.y + (int) wYPos - 1, wRect2.width + 2, wRect2.height + 2);
Rectangle tTop1 = new Rectangle(tTopRect1.x + (int) topTXPos - 1, tTopRect1.y + (int) topTYPos - 1, tTopRect1.width + 2, tTopRect1.height + 2);
Rectangle tTop2 = new Rectangle(tTopRect2.x + (int) topTXPos - 1, tTopRect2.y + (int) topTYPos - 1, tTopRect2.width + 2, tTopRect2.height + 2);
Rectangle tBot1 = new Rectangle(tBottomRect1.x + (int) botTXPos - 1, tBottomRect1.y + (int) botTYPos - 1, tBottomRect1.width + 2, tBottomRect1.height + 2);
Rectangle tBot2 = new Rectangle(tBottomRect2.x + (int) botTXPos - 1, tBottomRect2.y + (int) botTYPos - 1, tBottomRect2.width + 2, tBottomRect2.height + 2);
if (r1.contains(e.x, e.y)) {
sLeftPtMoved = true;
mouseDown = true;
} else if (r2.contains(e.x, e.y)) {
sRightPtMoved = true;
mouseDown = true;
} else if (w1.contains(e.x, e.y)) {
wPt1Moved = true;
mouseDown = true;
} else if (w2.contains(e.x, e.y)) {
wPt2Moved = true;
mouseDown = true;
} else if (tTop1.contains(e.x, e.y)) {
tTopPt1Moved = true;
mouseDown = true;
} else if (tTop2.contains(e.x, e.y)) {
tTopPt2Moved = true;
mouseDown = true;
} else if (tBot1.contains(e.x, e.y)) {
tBotPt1Moved = true;
mouseDown = true;
} else if (tBot2.contains(e.x, e.y)) {
tBotPt2Moved = true;
mouseDown = true;
}
}
/**
* Sent when a mouse button is released.
*
* @param e an event containing information about the mouse button release
*/
@Override
public void mouseUp(MouseEvent e) {
mouseDown = false;
if (isHovering(e)) {
example.canvas.setCursor(cursor);
} else {
example.canvas.setCursor(null);
}
if (sLeftPtMoved)
sLeftPtMoved = false;
if (sRightPtMoved)
sRightPtMoved = false;
if (wPt1Moved)
wPt1Moved = false;
if (wPt2Moved)
wPt2Moved = false;
if (tTopPt1Moved)
tTopPt1Moved = false;
if (tTopPt2Moved)
tTopPt2Moved = false;
if (tBotPt1Moved)
tBotPt1Moved = false;
if (tBotPt2Moved)
tBotPt2Moved = false;
example.redraw();
}
};
example.canvas.addMouseMoveListener(mouseMoveListener);
example.canvas.addMouseListener(mouseListener);
}
use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.swt by eclipse.
the class Bug514483_getCursorLocation method main.
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(0, 0, 600, 600);
Label parentShellLabel = new Label(shell, SWT.None);
parentShellLabel.setText("Parent widget.shell.\n" + "INSTRUCTIONS:\n" + "- Parent widget.shell should be maximized.\n" + "- Child widget.shell should be at x400 y400 (in yellow square).\n" + "- Click inside the child widget.shell, observe result coordinates below.\n" + "\n" + "The bug is that x,y is not relative to parent, but relative to child-widget.shell itself (0-200 range).\n" + "Expected coordinates: between ~400 to ~600. (i.e, relative to parent's x,y.)\n" + "Result Coordinates:");
parentShellLabel.setBounds(0, 0, 600, 200);
final Label resultLbl = new Label(shell, SWT.None);
resultLbl.setBounds(0, 180, 600, 100);
resultLbl.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
Label childShellLocation = new Label(shell, SWT.None);
childShellLocation.setText("Child Shell should be here.\nIf it is not, move it here \nmanually");
childShellLocation.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
childShellLocation.setBounds(400, 400, 200, 160);
Shell childShell = new Shell(shell, SWT.ON_TOP);
childShell.setBackground(display.getSystemColor(SWT.COLOR_DARK_YELLOW));
MouseAdapter clickListener = new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
Point loc = display.getCursorLocation();
resultLbl.setText(loc.toString());
if (// give user some slack.
loc.x > 300 && loc.x < 700 && loc.y > 300 && loc.y < 700)
resultLbl.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
else
resultLbl.setBackground(display.getSystemColor(SWT.COLOR_RED));
}
};
childShell.addMouseListener(clickListener);
// display.addFilter(SWT.KeyDown, new Listener() {
// public void handleEvent(Event e) {
// if (e.type == SWT.KeyDown) {
// switch (e.keyCode) {
// case SWT.F1:
// System.out.println("Passed");
// break;
// case SWT.F2:
// System.out.println("Failed");
// break;
// case SWT.F3:
// System.out.println("Skipped");
// break;
// case SWT.F4:
// System.out.println("Exit Test suite");
// break;
// }
// }
// }
// });
shell.open();
childShell.open();
childShell.setBounds(400, 400, 200, 200);
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.swt by eclipse.
the class Bug528549_browser_MouseFocusEventListeners method main.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(500, 200);
final Browser browser = new Browser(shell, SWT.NONE);
browser.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
System.out.println("Browser Focus lost " + e.toString());
}
@Override
public void focusGained(FocusEvent e) {
System.out.println("Browser Focus gained " + e.toString());
}
});
browser.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
System.out.println("Browser Mouse Up " + e.toString());
}
@Override
public void mouseDown(MouseEvent e) {
System.out.println("Browser Mouse Down " + e.toString());
}
@Override
public void mouseDoubleClick(MouseEvent e) {
System.out.println("Browse Mouse Double click " + e.toString());
}
});
// Below listeners already worked before bug. But good to have around.
browser.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
System.out.println("Browser key released " + e.toString());
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Browser key pressed " + e.toString());
}
});
browser.addMouseWheelListener(e -> System.out.println("Browser scroll event " + e.toString()));
// Generates a lot of events...
browser.addMouseMoveListener(e -> System.out.println("Browser mouse moved " + e.toString()));
Button jsOnButton = new Button(shell, SWT.PUSH);
jsOnButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
jsOnButton.setText("JS Off");
jsOnButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(false)));
Button jsOffButton = new Button(shell, SWT.PUSH);
jsOffButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
jsOffButton.setText("JS On");
jsOffButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setJavascriptEnabled(true)));
Button loadNextPage = new Button(shell, SWT.PUSH);
loadNextPage.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
loadNextPage.setText("Load next page");
loadNextPage.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browser.setText(getNewText())));
browser.setText(getNewText());
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Aggregations