Search in sources :

Example 6 with MouseTrackAdapter

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();
            }
        });
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) Label(org.eclipse.swt.widgets.Label) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) SubscriptionManager(com.biglybt.pif.utils.subscriptions.SubscriptionManager) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) Button(org.eclipse.swt.widgets.Button) AERunnable(com.biglybt.core.util.AERunnable) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 7 with MouseTrackAdapter

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);
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseAdapter(org.eclipse.swt.events.MouseAdapter) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point)

Example 8 with MouseTrackAdapter

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;
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) MouseEvent(org.eclipse.swt.events.MouseEvent) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) Text(org.eclipse.swt.widgets.Text) AtomicReference(java.util.concurrent.atomic.AtomicReference) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) ScheduledFuture(java.util.concurrent.ScheduledFuture) Shell(org.eclipse.swt.widgets.Shell) Browser(org.eclipse.swt.browser.Browser)

Example 9 with MouseTrackAdapter

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);
                }
            }
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) KeyListener(org.eclipse.swt.events.KeyListener) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 10 with MouseTrackAdapter

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);
            }
        }
    });
}
Also used : IWorkbenchHelpSystem(org.eclipse.ui.help.IWorkbenchHelpSystem) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter)

Aggregations

MouseTrackAdapter (org.eclipse.swt.events.MouseTrackAdapter)16 MouseEvent (org.eclipse.swt.events.MouseEvent)15 Point (org.eclipse.swt.graphics.Point)9 MouseAdapter (org.eclipse.swt.events.MouseAdapter)7 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)6 Shell (org.eclipse.swt.widgets.Shell)5 PaintEvent (org.eclipse.swt.events.PaintEvent)4 PaintListener (org.eclipse.swt.events.PaintListener)4 GridData (org.eclipse.swt.layout.GridData)4 KeyEvent (org.eclipse.swt.events.KeyEvent)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Label (org.eclipse.swt.widgets.Label)3 MenuManager (org.eclipse.jface.action.MenuManager)2 ControlAdapter (org.eclipse.swt.events.ControlAdapter)2 ControlEvent (org.eclipse.swt.events.ControlEvent)2 Control (org.eclipse.swt.widgets.Control)2 Text (org.eclipse.swt.widgets.Text)2 XpathSelectDialog (com.amalto.workbench.dialogs.XpathSelectDialog)1 SortFieldSelectionFilter (com.amalto.workbench.dialogs.filter.SortFieldSelectionFilter)1