Java Code Examples for org.eclipse.swt.widgets.Control#addMouseListener()

The following examples show how to use org.eclipse.swt.widgets.Control#addMouseListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseMouseProvider.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Method to register the provider to chart viewer.
 */
protected void register() {
    IPlotArea plotArea = getChart().getPlotArea();
    Control control = plotArea.getControl();
    if (this instanceof MouseListener) {
        control.addMouseListener((MouseListener) this);
    }
    if (this instanceof MouseMoveListener) {
        control.addMouseMoveListener((MouseMoveListener) this);
    }
    if (this instanceof MouseWheelListener) {
        control.addMouseWheelListener((MouseWheelListener) this);
    }
    if (this instanceof MouseTrackListener) {
        control.addMouseTrackListener((MouseTrackListener) this);
    }
    if (this instanceof ICustomPaintListener) {
        plotArea.addCustomPaintListener((ICustomPaintListener) this);
    } else if (this instanceof PaintListener) {
        control.addPaintListener((PaintListener) this);
    }
    TmfAbstractToolTipHandler tooltipHandler = getTooltipHandler();
    if(tooltipHandler != null) {
        tooltipHandler.activateHoverHelp(control);
    }
}
 
Example 2
Source File: ContentAssistant.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Installs this closer on it's viewer's text widget.
 */
protected void install()
{
	Control control = fContentAssistSubjectControlAdapter.getControl();
	fControl = control;
	if (Helper.okToUse(control))
	{

		Shell shell = control.getShell();
		fShell = shell;
		shell.addControlListener(this);

		control.addMouseListener(this);
		control.addFocusListener(this);

		/*
		 * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors
		 */
		control.addDisposeListener(this);
	}
	if (fViewer != null)
	{
		fViewer.addViewportListener(this);
	}
}
 
Example 3
Source File: SearchResultView.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private void addMouseListenerRecursively(Control control, MouseListener listener) {
	if (control instanceof Button) {
		return;
	}

	control.addMouseListener(listener);

	if (control instanceof Composite) {
		Composite composite = (Composite) control;
		for (Control child : composite.getChildren()) {
			addMouseListenerRecursively(child, listener);
		}
	}
}
 
Example 4
Source File: SelectedResultView.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private void addMouseListenerRecursively(Control control, MouseListener listener) {
	if (control instanceof Button) {
		control.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_ARROW));
		return;
	}

	control.addMouseListener(listener);

	if (control instanceof Composite) {
		Composite composite = (Composite) control;
		for (Control child : composite.getChildren()) {
			addMouseListenerRecursively(child, listener);
		}
	}
}
 
Example 5
Source File: TmfBaseProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Method to register the provider to chart viewer.
 */
protected void register() {
    IPlotArea plotArea = getChart().getPlotArea();
    Control control = plotArea.getControl();
    if (this instanceof MouseListener) {
        control.addMouseListener((MouseListener) this);
    }
    if (this instanceof MouseMoveListener) {
        control.addMouseMoveListener((MouseMoveListener) this);
    }
    if (this instanceof MouseWheelListener) {
        control.addMouseWheelListener((MouseWheelListener) this);
    }
    if (this instanceof MouseTrackListener) {
        control.addMouseTrackListener((MouseTrackListener) this);
    }
    if (this instanceof ICustomPaintListener) {
        plotArea.addCustomPaintListener((ICustomPaintListener) this);
    } else if (this instanceof PaintListener) {
        control.addPaintListener((PaintListener) this);
    }
    TmfAbstractToolTipHandler tooltipHandler = getTooltipHandler();
    if(tooltipHandler != null) {
        tooltipHandler.activateHoverHelp(control);
    }


}
 
Example 6
Source File: CppStyleConsoleViewer.java    From CppStyle with MIT License 5 votes vote down vote up
@Override
protected void createControl(Composite parent, int styles) {
	super.createControl(parent, styles);
	setReadOnly();
	Control control = getTextWidget();
	control.addMouseListener(this);
}
 
Example 7
Source File: ClipboardCopy.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
public static void
 addCopyToClipMenu(
final Control				control,
final copyToClipProvider	provider )
 {
  MouseAdapter ml = (MouseAdapter)control.getData( MOUSE_LISTENER_KEY );
  
  if ( ml != null ){
  
	  control.removeMouseListener( ml );
  }
  
  ml =
	  new MouseAdapter()
	  {
		  @Override
		  public void
		  mouseDown(
			 MouseEvent e )
		  {
			  if ( control.isDisposed()){

				  return;
			  }

			  final String	text = provider.getText();

			  if ( control.getMenu() != null || text == null || text.length() == 0 ){

				  return;
			  }

			  if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))){

				  return;
			  }

			  final Menu menu = new Menu(control.getShell(),SWT.POP_UP);

			  MenuItem   item = new MenuItem( menu,SWT.NONE );

			  item.setData( MENU_ITEM_KEY, "" );

			  String	msg_text_id;

			  if ( provider instanceof copyToClipProvider2 ){

				  msg_text_id = ((copyToClipProvider2)provider).getMenuResource();

			  }else{

				  msg_text_id = "label.copy.to.clipboard";
			  }

			  item.setText( MessageText.getString( msg_text_id ));

			  item.addSelectionListener(
					  new SelectionAdapter()
					  {
						  @Override
						  public void
						  widgetSelected(
								  SelectionEvent arg0)
						  {
							  new Clipboard(control.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
						  }
					  });

			  control.setMenu( menu );

			  menu.addMenuListener(
					  new MenuAdapter()
					  {
						  @Override
						  public void
						  menuHidden(
								  MenuEvent arg0 )
						  {
							  if ( control.getMenu() == menu ){

								  control.setMenu( null );
							  }
						  }
					  });

			  menu.setVisible( true );
		  }
	  };
  
  control.setData( MOUSE_LISTENER_KEY, ml );
  
  control.addMouseListener( ml );
 }
 
Example 8
Source File: RenameInformationPopup.java    From typescript.java with MIT License 4 votes vote down vote up
private void addMoveSupport(final Shell popupShell, final Control movedControl) {
	movedControl.addMouseListener(new MouseAdapter() {

		@Override
		public void mouseDown(final MouseEvent downEvent) {
			if (downEvent.button != 1) {
				return;
			}

			final Point POPUP_SOURCE= popupShell.getLocation();
			final StyledText textWidget= fEditor.getViewer().getTextWidget();
			Point pSize= getExtent();
			int originalSnapPosition= fSnapPosition;

			/*
			 * Feature in Tracker: it is not possible to directly control the feedback,
			 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121300
			 * and https://bugs.eclipse.org/bugs/show_bug.cgi?id=121298#c1 .
			 *
			 * Workaround is to have an offscreen rectangle for tracking mouse movement
			 * and a manually updated rectangle for the actual drop target.
			 */
			final Tracker tracker= new Tracker(textWidget, SWT.NONE);

			final Point[] LOCATIONS= {
					textWidget.toControl(computePopupLocation(SNAP_POSITION_UNDER_RIGHT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_OVER_RIGHT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_UNDER_LEFT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_OVER_LEFT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_LOWER_RIGHT))
			};

			final Rectangle[] DROP_TARGETS= {
				Geometry.createRectangle(LOCATIONS[0], pSize),
				Geometry.createRectangle(LOCATIONS[1], pSize),
				new Rectangle(LOCATIONS[2].x, LOCATIONS[2].y + HAH, pSize.x, pSize.y),
				Geometry.createRectangle(LOCATIONS[3], pSize),
				Geometry.createRectangle(LOCATIONS[4], pSize)
			};
			final Rectangle MOUSE_MOVE_SOURCE= new Rectangle(1000000, 0, 0, 0);
			tracker.setRectangles(new Rectangle[] { MOUSE_MOVE_SOURCE, DROP_TARGETS[fSnapPosition] });
			tracker.setStippled(true);

			ControlListener moveListener= new ControlAdapter() {
				/*
				 * @see org.eclipse.swt.events.ControlAdapter#controlMoved(org.eclipse.swt.events.ControlEvent)
				 */
				@Override
				public void controlMoved(ControlEvent moveEvent) {
					Rectangle[] currentRects= tracker.getRectangles();
					final Rectangle mouseMoveCurrent= currentRects[0];
					Point popupLoc= new Point(
							POPUP_SOURCE.x + mouseMoveCurrent.x - MOUSE_MOVE_SOURCE.x,
							POPUP_SOURCE.y + mouseMoveCurrent.y - MOUSE_MOVE_SOURCE.y);

					popupShell.setLocation(popupLoc);

					Point ePopupLoc= textWidget.toControl(popupLoc);
					int minDist= Integer.MAX_VALUE;
					for (int snapPos= 0; snapPos < DROP_TARGETS.length; snapPos++) {
						int dist= Geometry.distanceSquared(ePopupLoc, LOCATIONS[snapPos]);
						if (dist < minDist) {
							minDist= dist;
							fSnapPosition= snapPos;
							fSnapPositionChanged= true;
							currentRects[1]= DROP_TARGETS[snapPos];
						}
					}
					tracker.setRectangles(currentRects);
				}
			};
			tracker.addControlListener(moveListener);
			boolean committed= tracker.open();
			tracker.close();
			tracker.dispose();
			if (committed) {
				getDialogSettings().put(SNAP_POSITION_KEY, fSnapPosition);
			} else {
				fSnapPosition= originalSnapPosition;
				fSnapPositionChanged= true;
			}
			updatePopupLocation(true);
			activateEditor();
		}
	});
}
 
Example 9
Source File: RenameInformationPopup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void addMoveSupport(final Shell popupShell, final Control movedControl) {
	movedControl.addMouseListener(new MouseAdapter() {

		@Override
		public void mouseDown(final MouseEvent downEvent) {
			if (downEvent.button != 1) {
				return;
			}

			final Point POPUP_SOURCE= popupShell.getLocation();
			final StyledText textWidget= fEditor.getViewer().getTextWidget();
			Point pSize= getExtent();
			int originalSnapPosition= fSnapPosition;

			/*
			 * Feature in Tracker: it is not possible to directly control the feedback,
			 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121300
			 * and https://bugs.eclipse.org/bugs/show_bug.cgi?id=121298#c1 .
			 *
			 * Workaround is to have an offscreen rectangle for tracking mouse movement
			 * and a manually updated rectangle for the actual drop target.
			 */
			final Tracker tracker= new Tracker(textWidget, SWT.NONE);

			final Point[] LOCATIONS= {
					textWidget.toControl(computePopupLocation(SNAP_POSITION_UNDER_RIGHT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_OVER_RIGHT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_UNDER_LEFT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_OVER_LEFT_FIELD)),
					textWidget.toControl(computePopupLocation(SNAP_POSITION_LOWER_RIGHT))
			};

			final Rectangle[] DROP_TARGETS= {
				Geometry.createRectangle(LOCATIONS[0], pSize),
				Geometry.createRectangle(LOCATIONS[1], pSize),
				new Rectangle(LOCATIONS[2].x, LOCATIONS[2].y + HAH, pSize.x, pSize.y),
				Geometry.createRectangle(LOCATIONS[3], pSize),
				Geometry.createRectangle(LOCATIONS[4], pSize)
			};
			final Rectangle MOUSE_MOVE_SOURCE= new Rectangle(1000000, 0, 0, 0);
			tracker.setRectangles(new Rectangle[] { MOUSE_MOVE_SOURCE, DROP_TARGETS[fSnapPosition] });
			tracker.setStippled(true);

			ControlListener moveListener= new ControlAdapter() {
				/*
				 * @see org.eclipse.swt.events.ControlAdapter#controlMoved(org.eclipse.swt.events.ControlEvent)
				 */
				@Override
				public void controlMoved(ControlEvent moveEvent) {
					Rectangle[] currentRects= tracker.getRectangles();
					final Rectangle mouseMoveCurrent= currentRects[0];
					Point popupLoc= new Point(
							POPUP_SOURCE.x + mouseMoveCurrent.x - MOUSE_MOVE_SOURCE.x,
							POPUP_SOURCE.y + mouseMoveCurrent.y - MOUSE_MOVE_SOURCE.y);

					popupShell.setLocation(popupLoc);

					Point ePopupLoc= textWidget.toControl(popupLoc);
					int minDist= Integer.MAX_VALUE;
					for (int snapPos= 0; snapPos < DROP_TARGETS.length; snapPos++) {
						int dist= Geometry.distanceSquared(ePopupLoc, LOCATIONS[snapPos]);
						if (dist < minDist) {
							minDist= dist;
							fSnapPosition= snapPos;
							fSnapPositionChanged= true;
							currentRects[1]= DROP_TARGETS[snapPos];
						}
					}
					tracker.setRectangles(currentRects);
				}
			};
			tracker.addControlListener(moveListener);
			boolean committed= tracker.open();
			tracker.close();
			tracker.dispose();
			if (committed) {
				getDialogSettings().put(SNAP_POSITION_KEY, fSnapPosition);
			} else {
				fSnapPosition= originalSnapPosition;
				fSnapPositionChanged= true;
			}
			updatePopupLocation(true);
			activateEditor();
		}
	});
}
 
Example 10
Source File: SWTUtil.java    From eclipse-cs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Adds support to a control which shows the tooltip of the control when the mouse button is
 * pressed on it.
 *
 * @param control
 *          the control
 */
public static void addTooltipOnPressSupport(Control control) {
  control.addMouseListener(new TooltipOnPressListener());
}
 
Example 11
Source File: ControlListItem.java    From thym with Eclipse Public License 1.0 2 votes vote down vote up
protected void registerChild(Control child) {
	child.addMouseListener(mouseListener);

}