de7b4e9a18482883aa567e3fc5525865b61f369d
1 /**********************************************************************
2 * Copyright (c) 2005, 2007 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.graphics
.FontMetrics
;
18 import org
.eclipse
.swt
.graphics
.GC
;
19 import org
.eclipse
.swt
.graphics
.Point
;
20 import org
.eclipse
.swt
.widgets
.Control
;
21 import org
.eclipse
.swt
.widgets
.Display
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
23 import org
.eclipse
.swt
.widgets
.Text
;
27 * This class is used to reproduce the same tooltip behavior on Windows and Linux when the mouse hovers over the
34 public class DiagramToolTip
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 * The parent control where the tooltip must be drawn.
42 protected Control fParent
= null;
46 protected Shell fToolTipShell
= null;
50 protected String fText
= null;
54 protected Text fTextBox
= null;
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Create a new tooltip for the given parent control
63 * @param parent the parent control.
65 public DiagramToolTip(Control parent
) {
67 fToolTipShell
= new Shell(fParent
.getShell(), SWT
.MULTI
);
68 fToolTipShell
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
69 fTextBox
= new Text(fToolTipShell
, SWT
.WRAP
| SWT
.MULTI
);
70 fTextBox
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * Display the tooltip using the given text The tooltip will stay on screen until it is told otherwise
80 * @param value the text to display
82 public void showToolTip(String value
) {
83 if ((value
== null) || (value
.equalsIgnoreCase(""))) { //$NON-NLS-1$
84 fToolTipShell
.setVisible(false);
89 int w
= fToolTipShell
.getBounds().width
;
90 Point hr
= Display
.getDefault().getCursorLocation();
92 for (int i
= 0; i
< Display
.getDefault().getCursorSizes().length
; i
++) {
93 if (Display
.getDefault().getCursorSizes()[i
].y
< cursorH
) {
94 cursorH
= Display
.getDefault().getCursorSizes()[i
].y
;
97 if (hr
.x
+ w
> Display
.getDefault().getBounds().width
) {
98 int tempX
= (hr
.x
+ w
) - Display
.getDefault().getBounds().width
;
99 if (tempX
> Display
.getDefault().getBounds().width
) {
104 fTextBox
.setText(value
);
105 int charactersPerColumn
= 100;
106 GC gc
= new GC(fTextBox
);
107 FontMetrics fm
= gc
.getFontMetrics();
109 int width
= charactersPerColumn
* fm
.getAverageCharWidth();
110 fTextBox
.setSize(fTextBox
.computeSize(width
, fTextBox
.getLineCount() * fTextBox
.getLineHeight()));
111 fToolTipShell
.setLocation(hr
.x
, hr
.y
+ cursorH
);
112 fToolTipShell
.setSize(fTextBox
.getSize());
113 fTextBox
.setVisible(true);
114 fToolTipShell
.setVisible(true);
121 public void hideToolTip() {
122 fToolTipShell
.setVisible(false);
This page took 0.03265 seconds and 5 git commands to generate.