1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Bug 430804 (add tooltip infrastructure in visualizer)

Change-Id: I99180f6dc13260d87b513f0e6459598db0310a17
Signed-off-by: Xavier Raynaud <xavier.raynaud@kalray.eu>
Reviewed-on: https://git.eclipse.org/r/23668
Reviewed-by: Marc Dumais <marc.dumais@ericsson.com>
IP-Clean: Marc Dumais <marc.dumais@ericsson.com>
Tested-by: Marc Dumais <marc.dumais@ericsson.com>
This commit is contained in:
Xavier Raynaud 2014-04-02 13:54:38 +02:00 committed by Marc Dumais
parent d844a16e83
commit 50f5d7cd6f
3 changed files with 39 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Tilera Corporation and others.
* Copyright (c) 2012, 2014 Tilera Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,14 +7,18 @@
*
* Contributors:
* William R. Swanson (Tilera Corporation)
* Xavier Raynaud (Kalray) - Bug 430804
*******************************************************************************/
package org.eclipse.cdt.visualizer.ui.canvas;
import java.util.ArrayList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
// ---------------------------------------------------------------------------
@ -43,6 +47,22 @@ public class GraphicCanvas extends BufferedCanvas
public GraphicCanvas(Composite parent) {
super(parent);
m_objects = new ArrayList<IGraphicObject>();
Listener mouseListener = new Listener() {
public void handleEvent(Event event) {
switch (event.type) {
case SWT.MouseEnter:
case SWT.MouseMove:
IGraphicObject obj = getGraphicObject(event.x, event.y);
if (obj != null) {
String tooltip = obj.getTooltip(event.x, event.y);
setToolTipText(tooltip);
}
break;
}
}
};
addListener(SWT.MouseMove, mouseListener);
addListener(SWT.MouseEnter, mouseListener);
}
/** Dispose method. */

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Tilera Corporation and others.
* Copyright (c) 2012, 2014 Tilera Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* William R. Swanson (Tilera Corporation)
* Xavier Raynaud (Kalray) - Bug 430804
*******************************************************************************/
package org.eclipse.cdt.visualizer.ui.canvas;
@ -275,4 +276,9 @@ public class GraphicObject
*/
public void paintDecorations(GC gc) {
}
@Override
public String getTooltip(int x, int y) {
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Tilera Corporation and others.
* Copyright (c) 2012, 2014 Tilera Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* William R. Swanson (Tilera Corporation)
* Xavier Raynaud (Kalray) - Bug 430804
*******************************************************************************/
package org.eclipse.cdt.visualizer.ui.canvas;
@ -32,6 +33,15 @@ public interface IGraphicObject
*/
public void paint(GC gc, boolean decorations);
/**
* Return the tooltip to display when mouse stays on this object.
* It may return <code>null</code> if there is nothing to display.
* @param x the x coordinate
* @param y the y coordinate
* @return the tooltip to display on this object.
*/
public String getTooltip(int x, int y);
/** Returns true if object has decorations to paint. */
public boolean hasDecorations();