use of org.eclipse.swt.events.MouseListener in project tdi-studio-se by Talend.
the class StyledTextHandler method addListeners.
/**
* DOC amaumont Comment method "addListeners".
*/
private void addListeners() {
styledText.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
refreshProposalSize();
}
public void focusLost(FocusEvent e) {
}
});
styledText.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
}
public void controlResized(ControlEvent e) {
refreshProposalSize();
}
});
styledText.addExtendedModifyListener(new ExtendedModifyListener() {
public void modifyText(ExtendedModifyEvent event) {
updateCellExpression();
// System.out.println("ExtendedModifyListener modify text");
}
});
styledText.getContent().addTextChangeListener(new TextChangeListener() {
public void textChanged(TextChangedEvent event) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void textChanging(TextChangingEvent event) {
// System.out.println("textChanging");
}
public void textSet(TextChangedEvent event) {
// System.out.println("textSet");
}
});
styledText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
});
styledText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
});
styledText.addVerifyKeyListener(new VerifyKeyListener() {
public void verifyKey(VerifyEvent verifyEvent) {
if (verifyEvent.character == '\r' && contentProposalAdapter != null && contentProposalAdapter.isProposalOpened()) {
verifyEvent.doit = false;
} else {
verifyEvent.doit = true;
}
}
});
styledText.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void mouseDown(MouseEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void mouseUp(MouseEvent e) {
}
});
}
use of org.eclipse.swt.events.MouseListener in project tdi-studio-se by Talend.
the class StyledTextHandler method addListeners.
/**
* DOC amaumont Comment method "addListeners".
*/
private void addListeners() {
styledText.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
refreshProposalSize();
}
public void focusLost(FocusEvent e) {
}
});
styledText.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
}
public void controlResized(ControlEvent e) {
refreshProposalSize();
}
});
styledText.addExtendedModifyListener(new ExtendedModifyListener() {
public void modifyText(ExtendedModifyEvent event) {
// System.out.println("ExtendedModifyListener modify text");
updateCellExpression();
}
});
styledText.getContent().addTextChangeListener(new TextChangeListener() {
public void textChanged(TextChangedEvent event) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void textChanging(TextChangingEvent event) {
// System.out.println("textChanging");
}
public void textSet(TextChangedEvent event) {
// System.out.println("textSet");
}
});
styledText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
});
styledText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
});
styledText.addVerifyKeyListener(new VerifyKeyListener() {
public void verifyKey(VerifyEvent verifyEvent) {
if (verifyEvent.character == '\r' && contentProposalAdapter != null && contentProposalAdapter.isProposalOpened()) {
verifyEvent.doit = false;
} else {
verifyEvent.doit = true;
}
}
});
styledText.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void mouseDown(MouseEvent e) {
mapperManager.fireCurrentDirectEditApply();
highlightLineOfCursorPosition(styledText.getSelection());
}
public void mouseUp(MouseEvent e) {
}
});
}
use of org.eclipse.swt.events.MouseListener 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.MouseListener 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.MouseListener 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