1 /**********************************************************************
2 * Copyright (c) 2005, 2012 IBM Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.graphics
.FontMetrics
;
17 import org
.eclipse
.swt
.graphics
.GC
;
18 import org
.eclipse
.swt
.graphics
.Point
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.swt
.widgets
.Shell
;
22 import org
.eclipse
.swt
.widgets
.Text
;
26 * This class is used to reproduce the same tooltip behavior on Windows and Linux when the mouse hovers over the
33 public class DiagramToolTip
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 * The parent control where the tooltip must be drawn.
41 protected Control fParent
= null;
45 protected Shell fToolTipShell
= null;
49 protected String fText
= null;
53 protected Text fTextBox
= null;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * Create a new tooltip for the given parent control
62 * @param parent the parent control.
64 public DiagramToolTip(Control parent
) {
66 fToolTipShell
= new Shell(fParent
.getShell(), SWT
.MULTI
);
67 fToolTipShell
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
68 fTextBox
= new Text(fToolTipShell
, SWT
.WRAP
| SWT
.MULTI
);
69 fTextBox
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 * Display the tooltip using the given text The tooltip will stay on screen until it is told otherwise
79 * @param value the text to display
81 public void showToolTip(String value
) {
82 if ((value
== null) || (value
.equalsIgnoreCase(""))) { //$NON-NLS-1$
83 fToolTipShell
.setVisible(false);
88 int w
= fToolTipShell
.getBounds().width
;
89 Point hr
= Display
.getDefault().getCursorLocation();
91 for (int i
= 0; i
< Display
.getDefault().getCursorSizes().length
; i
++) {
92 if (Display
.getDefault().getCursorSizes()[i
].y
< cursorH
) {
93 cursorH
= Display
.getDefault().getCursorSizes()[i
].y
;
96 if (hr
.x
+ w
> Display
.getDefault().getBounds().width
) {
97 int tempX
= (hr
.x
+ w
) - Display
.getDefault().getBounds().width
;
98 if (tempX
> Display
.getDefault().getBounds().width
) {
103 fTextBox
.setText(value
);
104 int charactersPerColumn
= 100;
105 GC gc
= new GC(fTextBox
);
106 FontMetrics fm
= gc
.getFontMetrics();
108 int width
= charactersPerColumn
* fm
.getAverageCharWidth();
109 fTextBox
.setSize(fTextBox
.computeSize(width
, fTextBox
.getLineCount() * fTextBox
.getLineHeight()));
110 fToolTipShell
.setLocation(hr
.x
, hr
.y
+ cursorH
);
111 fToolTipShell
.setSize(fTextBox
.getSize());
112 fTextBox
.setVisible(true);
113 fToolTipShell
.setVisible(true);
120 public void hideToolTip() {
121 fToolTipShell
.setVisible(false);
This page took 0.032507 seconds and 5 git commands to generate.