1 /**********************************************************************
2 * Copyright (c) 2005, 2013 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 // ------------------------------------------------------------------------
38 private static final int CHARACTERS_PER_COLUMN
= 100;
39 private static final int DEFAULT_CURSOR_HEIGHT
= 32;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 * The parent control where the tooltip must be drawn.
47 private Control fParent
= null;
51 private Shell fToolTipShell
= null;
55 private Text fTextBox
= null;
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
62 * Create a new tooltip for the given parent control
64 * @param parent the parent control.
66 public DiagramToolTip(Control parent
) {
68 fToolTipShell
= new Shell(fParent
.getShell(), SWT
.MULTI
);
69 fToolTipShell
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
70 fTextBox
= new Text(fToolTipShell
, SWT
.WRAP
| SWT
.MULTI
);
71 fTextBox
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
79 * Display the tooltip using the given text The tooltip will stay on screen until it is told otherwise
81 * @param value the text to display
83 public void showToolTip(String value
) {
84 if ((value
== null) || (value
.equalsIgnoreCase(""))) { //$NON-NLS-1$
85 fToolTipShell
.setVisible(false);
89 int w
= fToolTipShell
.getBounds().width
;
90 Point hr
= Display
.getDefault().getCursorLocation();
91 int cursorH
= DEFAULT_CURSOR_HEIGHT
;
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 GC gc
= new GC(fTextBox
);
106 FontMetrics fm
= gc
.getFontMetrics();
108 int width
= CHARACTERS_PER_COLUMN
* 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);
119 public void hideToolTip() {
120 fToolTipShell
.setVisible(false);
124 * @return parent control
127 protected Control
getParent() {
This page took 0.038429 seconds and 5 git commands to generate.