1 /**********************************************************************
2 * Copyright (c) 2005, 2007, 2011 IBM Corporation and others.
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
7 * $Id: DiagramToolTip.java,v 1.3 2007/01/02 21:11:39 ewchan Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
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
;
25 * This class is used to reproduce the same tooltip behavior on Windows and Linux when the mouse hovers over the
30 public class DiagramToolTip
{
33 * The parent control where the tooltip must be drawn
35 protected Control parent
= null;
39 protected Shell toolTipShell
= null;
43 protected String text
= null;
44 protected Text textBox
= null;
46 // added for defect 141750 in order to allow proper text wrapping of the toolTip
50 * Create a new tooltip for the given parent control
52 * @param _parent the parent control
54 public DiagramToolTip(Control _parent
) {
56 toolTipShell
= new Shell(parent
.getShell(), SWT
.MULTI
);
57 toolTipShell
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
58 textBox
= new Text(toolTipShell
, SWT
.WRAP
| SWT
.MULTI
);
59 textBox
.setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_INFO_BACKGROUND
));
63 * Display the tooltip using the given text The tooltip will stay on screen until it is told otherwise
65 * @param value the text to display
67 public void showToolTip(String value
) {
68 if ((value
== null) || (value
.equalsIgnoreCase("")))//$NON-NLS-1$
70 toolTipShell
.setVisible(false);
75 int w
= toolTipShell
.getBounds().width
;
76 Point hr
= Display
.getDefault().getCursorLocation();
78 for (int i
= 0; i
< Display
.getDefault().getCursorSizes().length
; i
++) {
79 if (Display
.getDefault().getCursorSizes()[i
].y
< cursorH
)
80 cursorH
= Display
.getDefault().getCursorSizes()[i
].y
;
82 if (hr
.x
+ w
> Display
.getDefault().getBounds().width
) {
83 int tempX
= (hr
.x
+ w
) - Display
.getDefault().getBounds().width
;
84 if (tempX
> Display
.getDefault().getBounds().width
)
88 textBox
.setText(value
);
89 int charactersPerColumn
= 100;
90 GC gc
= new GC(textBox
);
91 FontMetrics fm
= gc
.getFontMetrics();
93 int width
= charactersPerColumn
* fm
.getAverageCharWidth();
94 textBox
.setSize(textBox
.computeSize(width
, textBox
.getLineCount() * textBox
.getLineHeight()));
95 toolTipShell
.setLocation(hr
.x
, hr
.y
+ cursorH
);
96 toolTipShell
.setSize(textBox
.getSize());
97 textBox
.setVisible(true);
98 toolTipShell
.setVisible(true);
105 public void hideToolTip() {
106 toolTipShell
.setVisible(false);
This page took 0.031293 seconds and 5 git commands to generate.