use of org.eclipse.swt.events.MouseTrackAdapter in project BiglyBT by BiglySoftware.
the class BuddyPluginViewBetaChat method buildRSSButton.
private void buildRSSButton(Composite parent) {
boolean sharing_view = chat.getViewType() == BuddyPluginBeta.VIEW_TYPE_SHARING;
Runnable create_it = new Runnable() {
public void run() {
try {
String url = encodeRSSURL(chat);
SubscriptionManager sm = PluginInitializer.getDefaultInterface().getUtilities().getSubscriptionManager();
Map<String, Object> options = new HashMap<>();
if (chat.isAnonymous()) {
options.put(SubscriptionManager.SO_ANONYMOUS, true);
}
options.put(SubscriptionManager.SO_NAME, chat.getName());
sm.requestSubscription(new URL(url), options);
} catch (Throwable e) {
Debug.out(e);
}
}
};
if (sharing_view) {
Label rss_button = new Label(parent, SWT.NONE);
final Image rss_image_normal = ImageLoader.getInstance().getImage("image.sidebar.subscriptions");
final Image rss_image_gray = ImageLoader.getInstance().getImage("image.sidebar.subscriptions-gray");
rss_button.setImage(rss_image_gray);
rss_button.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
GridData grid_data = new GridData(GridData.FILL_HORIZONTAL);
grid_data.widthHint = rss_image_gray.getBounds().width;
grid_data.heightHint = rss_image_gray.getBounds().height;
rss_button.setLayoutData(grid_data);
rss_button.setToolTipText(MessageText.getString("azbuddy.dchat.rss.subscribe.info"));
rss_button.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseExit(MouseEvent arg0) {
rss_button.setImage(rss_image_gray);
rss_button.redraw();
}
@Override
public void mouseEnter(MouseEvent arg0) {
rss_button.setImage(rss_image_normal);
rss_button.redraw();
}
});
rss_button.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
create_it.run();
}
});
} else {
Button rss_button = new Button(parent, SWT.PUSH);
Image rss_image = ImageLoader.getInstance().getImage("image.sidebar.subscriptions");
rss_button.setImage(rss_image);
GridData grid_data = new GridData(GridData.FILL_HORIZONTAL);
grid_data.widthHint = rss_image.getBounds().width;
grid_data.heightHint = rss_image.getBounds().height;
rss_button.setLayoutData(grid_data);
// rss_button.setEnabled(false);
rss_button.setToolTipText(MessageText.getString("azbuddy.dchat.rss.subscribe.info"));
rss_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent ev) {
create_it.run();
}
});
}
}
use of org.eclipse.swt.events.MouseTrackAdapter in project eclipse.platform.releng by eclipse.
the class ConfigurationBlock method addHighlight.
protected void addHighlight(final Composite parent, final Label labelControl, final Combo comboBox) {
comboBox.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
highlight(parent, labelControl, comboBox, HIGHLIGHT_NONE);
}
@Override
public void focusGained(FocusEvent e) {
highlight(parent, labelControl, comboBox, HIGHLIGHT_FOCUS);
}
});
MouseTrackAdapter labelComboListener = new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
highlight(parent, labelControl, comboBox, comboBox.isFocusControl() ? HIGHLIGHT_FOCUS : HIGHLIGHT_MOUSE);
}
@Override
public void mouseExit(MouseEvent e) {
if (!comboBox.isFocusControl())
highlight(parent, labelControl, comboBox, HIGHLIGHT_NONE);
}
};
comboBox.addMouseTrackListener(labelComboListener);
labelControl.addMouseTrackListener(labelComboListener);
class MouseMoveTrackListener extends MouseTrackAdapter implements MouseMoveListener, MouseListener {
@Override
public void mouseExit(MouseEvent e) {
if (!comboBox.isFocusControl())
highlight(parent, labelControl, comboBox, HIGHLIGHT_NONE);
}
@Override
public void mouseMove(MouseEvent e) {
int color = comboBox.isFocusControl() ? HIGHLIGHT_FOCUS : isAroundLabel(e) ? HIGHLIGHT_MOUSE : HIGHLIGHT_NONE;
highlight(parent, labelControl, comboBox, color);
}
@Override
public void mouseDown(MouseEvent e) {
if (isAroundLabel(e))
comboBox.setFocus();
}
@Override
public void mouseDoubleClick(MouseEvent e) {
// not used
}
@Override
public void mouseUp(MouseEvent e) {
// not used
}
private boolean isAroundLabel(MouseEvent e) {
int lx = labelControl.getLocation().x;
Rectangle c = comboBox.getBounds();
int x = e.x;
int y = e.y;
boolean isAroundLabel = lx - 5 < x && x < c.x && c.y - 2 < y && y < c.y + c.height + 2;
return isAroundLabel;
}
}
MouseMoveTrackListener parentListener = new MouseMoveTrackListener();
parent.addMouseMoveListener(parentListener);
parent.addMouseTrackListener(parentListener);
parent.addMouseListener(parentListener);
MouseAdapter labelClickListener = new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
comboBox.setFocus();
}
};
labelControl.addMouseListener(labelClickListener);
}
use of org.eclipse.swt.events.MouseTrackAdapter in project hale by halestudio.
the class BrowserTip method showToolTip.
/**
* Show the tool tip
*
* @param control the tip control
* @param posx the x-position
* @param posy the y-position
* @param toolTip the tool tip string
* @param addBounds additional bounds that will be treated as if in the
* tooltip (the tooltip won't hide if the cursor is inside these
* bounds), may be <code>null</code>
* @param addBoundsControl the control the addBounds coordinates are
* relative to, <code>null</code> if addBounds is in display
* coordinates or no addBounds is provided
*
* @return the tool shell
*/
public Shell showToolTip(Control control, int posx, int posy, String toolTip, final Rectangle addBounds, final Control addBoundsControl) {
final Shell toolShell = new Shell(control.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
FillLayout layout = new FillLayout();
toolShell.setLayout(layout);
try {
if (plainText) {
Text text = new Text(toolShell, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
text.setFont(control.getDisplay().getSystemFont());
text.setForeground(control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
text.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
text.setText(toolTip);
} else {
Browser browser = new Browser(toolShell, SWT.NONE);
browser.setFont(control.getDisplay().getSystemFont());
browser.setForeground(control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
browser.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
browser.setText(toolTip);
}
Point pt = control.toDisplay(posx, posy);
Rectangle bounds = control.getDisplay().getBounds();
Point size = toolShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int width = Math.min(toolTipWidth, size.x);
/*
* On Windows XP (not on 7) computeSize seems to result in a size
* where the whole text is pressed into one line. We try to fix this
* by using the... "widthFactor"! (only for small computed heights)
*/
int widthFactor = (size.y < 30) ? (size.x / width) : (1);
int height = Math.min(toolTipHeight, size.y * widthFactor + heightAdjustment);
int x = (pt.x + width > bounds.x + bounds.width) ? (bounds.x + bounds.width - width) : (pt.x);
int y = (pt.y + height > bounds.y + bounds.height) ? (bounds.y + bounds.height - height) : (pt.y);
toolShell.setBounds(x, y, width, height);
final Point initCursor = toolShell.getDisplay().getCursorLocation();
toolShell.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseExit(MouseEvent e) {
hideToolTip(toolShell);
}
});
final AtomicReference<ScheduledFuture<?>> closeTimerRef = new AtomicReference<ScheduledFuture<?>>();
ScheduledFuture<?> closeTimer = scheduleService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
if (!toolShell.isDisposed()) {
toolShell.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
// check if cursor is over tooltip
if (!toolShell.isDisposed()) {
Point cursor = toolShell.getDisplay().getCursorLocation();
if (!cursor.equals(initCursor)) {
Rectangle bounds = toolShell.getBounds();
if (addBounds != null) {
Rectangle add;
if (addBoundsControl != null) {
Point addP = addBoundsControl.toDisplay(addBounds.x, addBounds.y);
add = new Rectangle(addP.x, addP.y, addBounds.width, addBounds.height);
} else {
add = addBounds;
}
bounds = bounds.union(add);
}
if (!bounds.contains(cursor)) {
hideToolTip(toolShell);
ScheduledFuture<?> closeTimer = closeTimerRef.get();
if (closeTimer != null)
closeTimer.cancel(true);
}
}
} else {
ScheduledFuture<?> closeTimer = closeTimerRef.get();
if (closeTimer != null)
closeTimer.cancel(true);
}
}
});
} else {
// disposed -> cancel timer
ScheduledFuture<?> closeTimer = closeTimerRef.get();
if (closeTimer != null)
closeTimer.cancel(true);
}
}
}, 2 * HOVER_DELAY, 1000, TimeUnit.MILLISECONDS);
closeTimerRef.set(closeTimer);
toolShell.setVisible(true);
toolShell.setFocus();
return toolShell;
} catch (SWTError err) {
log.error(err.getMessage(), err);
return null;
}
}
use of org.eclipse.swt.events.MouseTrackAdapter in project cubrid-manager by CUBRID.
the class SelectedLoactionComparator method bindListener.
/**
*
* Bind the linsteners
*/
private void bindListener() {
tableCursor.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent event) {
handleMouseUp(event);
}
public void mouseDown(MouseEvent event) {
handleMouseDown(event);
}
public void mouseDoubleClick(MouseEvent event) {
handleMouseDoubleClick(event);
}
});
tableCursor.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent event) {
handleMouseMove(event);
}
});
table.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent event) {
handleMouseUp(event);
}
public void mouseDown(MouseEvent event) {
handleMouseDown(event);
}
public void mouseDoubleClick(MouseEvent event) {
handleMouseDoubleClick(event);
}
});
table.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseExit(MouseEvent e) {
Rectangle bound = table.getClientArea();
if (!bound.contains(e.x, e.y)) {
handleMouseExit(e);
}
}
});
table.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent event) {
handleMouseMove(event);
}
});
table.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent event) {
handleKeyReleased(event);
}
public void keyPressed(KeyEvent event) {
handleKeyPressed(event);
}
});
tableCursor.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent event) {
handleKeyReleased(event);
}
public void keyPressed(KeyEvent event) {
handleKeyPressed(event);
if (ctrlPressed) {
if (event.keyCode == SWT.ARROW_DOWN) {
int maxY = getMaxY();
int minX = getMinX();
int maxX = getMaxX();
int y = maxY + 1;
if (maxY > -1 && minX > -1 && maxX > -1 && y < table.getItemCount()) {
tableCursor.setSelection(y, maxX);
for (int x = minX; x <= maxX; x++) {
Point p = new Point(x, y);
addSelectPoint(p, true);
drawSelectedItem(p, true);
}
}
} else if (event.keyCode == SWT.ARROW_UP) {
int maxY = getMaxY();
int minX = getMinX();
int maxX = getMaxX();
int y = maxY;
if (maxY > -1 && minX > -1 && maxX > -1 && y > 0) {
tableCursor.setSelection(y - 1, maxX);
for (int x = minX; x <= maxX; x++) {
Point p = new Point(x, y);
removeSelectPoint(p, true);
drawUnselectedItem(p, true);
}
}
} else if (event.keyCode == SWT.ARROW_LEFT) {
int maxY = getMaxY();
int minY = getMinY();
int maxX = getMaxX();
if (maxY > -1 && minY > -1 && maxX > 0) {
tableCursor.setSelection(maxY, maxX - 1);
for (int y = minY; y <= maxY; y++) {
Point p = new Point(maxX, y);
removeSelectPoint(p, true);
drawUnselectedItem(p, true);
}
}
} else if (event.keyCode == SWT.ARROW_RIGHT) {
int maxY = getMaxY();
int minY = getMinY();
int maxX = getMaxX();
int columnCount = table.getColumnCount();
if (maxY > -1 && minY > -1 && maxX + 1 < columnCount) {
int x = maxX + 1;
tableCursor.setSelection(maxY, x);
for (int y = minY; y <= maxY; y++) {
Point p = new Point(x, y);
addSelectPoint(p, true);
drawSelectedItem(p, true);
}
}
}
} else if (!ctrlPressed && !shiftPressed) {
if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_LEFT || event.keyCode == SWT.ARROW_RIGHT) {
selectedList.clear();
int y = table.indexOf(tableCursor.getRow());
int x = tableCursor.getColumn();
Point p = new Point(x, y);
addSelectPoint(p, true);
drawSelectedItems(true);
}
}
}
});
}
use of org.eclipse.swt.events.MouseTrackAdapter in project tdi-studio-se by Talend.
the class AbstractScdDialog method addContextHelp.
public void addContextHelp(Control control, final String contextId) {
final IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
helpSystem.setHelp(control, contextId);
control.addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseEnter(MouseEvent e) {
if (getTray() != null) {
helpSystem.displayHelp(contextId);
}
}
});
}
Aggregations