Ejemplo n.º 1
0
 @Override
 public void activate(Control mapControl) {
   mapControl.addMouseListener(this);
   mapControl.addMouseMoveListener(this);
   mapControl.addMouseWheelListener(this);
   mapControl.addKeyListener(this);
 }
Ejemplo n.º 2
0
 private void createRulerContextMenu() {
   String id = getRulerContextMenuId();
   fRulerMenuManager = new MenuManager(id, id);
   fRulerMenuManager.setRemoveAllWhenShown(true);
   fRulerMenuManager.addMenuListener(getContextMenuListener());
   Control rulerControl = fVerticalRuler.getControl();
   setRulerContextMenu(fRulerMenuManager.createContextMenu(rulerControl));
   rulerControl.setMenu(getRulerContextMenu());
   rulerControl.addMouseListener(getRulerMouseListener());
 }
 public static void recursiveMouseListener(
     Control c, MouseListener listener, boolean includeListened) {
   if (includeListened
       || (!(c instanceof Hyperlink)
           && (c.getListeners(SWT.MouseUp).length == 0
               || c.getListeners(SWT.MouseDown).length == 0
               || c.getListeners(SWT.MouseDoubleClick).length == 0))) c.addMouseListener(listener);
   if (c instanceof Composite)
     for (Control child : ((Composite) c).getChildren())
       recursiveMouseListener(child, listener, includeListened);
 }
Ejemplo n.º 4
0
 public Resizer(Control c, int dir) {
   fDirection = dir;
   fControl = c;
   fLiveResize = !(fControl instanceof Sash);
   updateCursor(c, dir);
   fControl.addMouseListener(this);
   fControl.addMouseMoveListener(this);
   fControl.addDisposeListener(
       new DisposeListener() {
         public void widgetDisposed(DisposeEvent e) {
           fControl = null;
         }
       });
 }
Ejemplo n.º 5
0
 private void mouseEvent(Control control) {
   control.addMouseListener(mouseAdapter);
 }
Ejemplo n.º 6
0
    public void activateHoverHelp(final org.eclipse.swt.widgets.Control control) {
      control.addMouseListener(
          new org.eclipse.swt.events.MouseAdapter() {
            public void mouseDown(org.eclipse.swt.events.MouseEvent e) {
              if (tipShell.isVisible()) {
                tipShell.setVisible(false);
              }
            }
          });
      control.addMouseTrackListener(
          new org.eclipse.swt.events.MouseTrackAdapter() {
            public void mouseExit(org.eclipse.swt.events.MouseEvent e) {
              if (tipShell.isVisible()) {
                tipShell.setVisible(false);
              }
              tipWidget = null;
            }

            public void mouseHover(org.eclipse.swt.events.MouseEvent event) {
              org.eclipse.swt.graphics.Point pt =
                  new org.eclipse.swt.graphics.Point(event.x, event.y);
              org.eclipse.swt.widgets.Widget widget = event.widget;
              if (widget instanceof org.eclipse.swt.widgets.ToolBar) {
                org.eclipse.swt.widgets.ToolBar w = (org.eclipse.swt.widgets.ToolBar) widget;
                widget = w.getItem(pt);
              }
              if (widget instanceof org.eclipse.swt.widgets.Table) {
                org.eclipse.swt.widgets.Table w = (org.eclipse.swt.widgets.Table) widget;
                widget = w.getItem(pt);
              }
              if (widget instanceof org.eclipse.swt.widgets.Tree) {
                org.eclipse.swt.widgets.Tree w = (org.eclipse.swt.widgets.Tree) widget;
                widget = w.getItem(pt);
              }
              if (widget == null) {
                tipShell.setVisible(false);
                tipWidget = null;
                return;
              }
              if (widget == tipWidget) {
                return;
              }
              tipWidget = widget;
              tipPosition = control.toDisplay(pt);
              java.lang.String text = (java.lang.String) widget.getData("TIP_TEXT");
              org.eclipse.swt.graphics.Image image =
                  (org.eclipse.swt.graphics.Image) widget.getData("TIP_IMAGE");
              tipLabelText.setText(text != null ? text : "");
              tipLabelImage.setImage(image);
              tipShell.pack();
              setHoverLocation(tipShell, tipPosition);
              tipShell.setVisible(true);
            }
          });
      control.addHelpListener(
          new org.eclipse.swt.events.HelpListener() {
            public void helpRequested(org.eclipse.swt.events.HelpEvent event) {
              if (tipWidget == null) {
                return;
              }
              org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler handler =
                  (org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler)
                      tipWidget.getData("TIP_HELPTEXTHANDLER");
              if (handler == null) {
                return;
              }
              java.lang.String text = handler.getHelpText(tipWidget);
              if (text == null) {
                return;
              }
              if (tipShell.isVisible()) {
                tipShell.setVisible(false);
                org.eclipse.swt.widgets.Shell helpShell =
                    new org.eclipse.swt.widgets.Shell(parentShell, SWT.SHELL_TRIM);
                helpShell.setLayout(new org.eclipse.swt.layout.FillLayout());
                org.eclipse.swt.widgets.Label label =
                    new org.eclipse.swt.widgets.Label(helpShell, SWT.NONE);
                label.setText(text);
                helpShell.pack();
                setHoverLocation(helpShell, tipPosition);
                helpShell.open();
              }
            }
          });
    }
Ejemplo n.º 7
0
  /**
   * Enables customized hover help for a specified control
   *
   * @control the control on which to enable hoverhelp
   */
  public void install(final Control control) {

    informationPresenterManager.install(control);

    /*
     * Get out of the way if we attempt to activate the control underneath the tooltip
     */
    control.addMouseListener(
        new MouseAdapter() {
          public void mouseDown(MouseEvent e) {
            disposeOfCurrentTipShell();
          }
        });

    /*
     * Trap hover events to pop-up tooltip
     */
    control.addMouseTrackListener(
        new MouseTrackAdapter() {
          public void mouseExit(MouseEvent e) {
            disposeOfCurrentTipShell();
          }

          public void mouseHover(MouseEvent event) {
            Point pt = new Point(event.x, event.y);
            Widget widget = event.widget;
            if (widget instanceof ToolBar) {
              ToolBar w = (ToolBar) widget;
              widget = w.getItem(pt);
            }
            if (widget instanceof Table) {
              Table w = (Table) widget;
              widget = w.getItem(pt);
            }
            if (widget instanceof Tree) {
              Tree w = (Tree) widget;
              widget = w.getItem(pt);
            }
            if (widget == null) {
              disposeOfCurrentTipShell();
              return;
            }
            if (widget == tipWidget) {
              return;
            }

            tipWidget = widget;
            Object data = widget.getData(TIP_DATA);
            if (data == null) {
              return;
            }
            final String text;
            if (data instanceof String) {
              text = (String) data;
            } else {
              text = data.toString();
            }
            if (text == null) {
              return;
            }

            // It must be set before showing the tooltip, as we'll loose the focus to the tooltip
            // and the
            // currently active bindings will become inactive.
            KeySequence activateEditorBinding =
                KeyBindingHelper.getCommandKeyBinding("org.eclipse.ui.window.activateEditor");
            informationPresenterManager.setActivateEditorBinding(activateEditorBinding);
            Shell activeShell = UIUtils.getActiveShell();
            informationPresenterManager.setInitiallyActiveShell(activeShell);

            createControls();

            final Point pos = new Point(pt.x + 10, pt.y);
            ITooltipInformationProvider provider =
                new ITooltipInformationProvider() {

                  public Object getInformation(Control fControl) {
                    return text;
                  }

                  public Point getPosition(Control fControl) {
                    return pos;
                  }
                };

            if (presenter instanceof IInformationPresenterAsTooltip) {
              IInformationPresenterAsTooltip iInformationPresenterAsTooltip =
                  (IInformationPresenterAsTooltip) presenter;
              iInformationPresenterAsTooltip.setData(data);
            }
            informationPresenterManager.setInformationProvider(provider);
            informationPresenterManager.showInformation();
          }
        });
  }