Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 216618 Details for
Bug 344024
Diagram node tooltips should match form tooltips
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
first attempt at showing native tooltip
Bug344024-patch.txt (text/plain), 10.48 KB, created by
Ling Hao
on 2012-05-31 20:17:19 EDT
(
hide
)
Description:
first attempt at showing native tooltip
Filename:
MIME Type:
Creator:
Ling Hao
Created:
2012-05-31 20:17:19 EDT
Size:
10.48 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.sapphire.ui.swt.gef >Index: src/org/eclipse/sapphire/ui/swt/gef/SapphireDiagramEditor.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui.swt.gef/src/org/eclipse/sapphire/ui/swt/gef/SapphireDiagramEditor.java,v >retrieving revision 1.29 >diff -u -r1.29 SapphireDiagramEditor.java >--- src/org/eclipse/sapphire/ui/swt/gef/SapphireDiagramEditor.java 31 May 2012 19:44:42 -0000 1.29 >+++ src/org/eclipse/sapphire/ui/swt/gef/SapphireDiagramEditor.java 1 Jun 2012 00:15:30 -0000 >@@ -152,6 +152,7 @@ > private GraphicalViewerKeyHandler graphicalViewerKeyHandler; > private SapphireDiagramKeyHandler diagramKeyHandler; > private ContextButtonManager contextButtonManager = null; >+ private SapphireToolTipHelper toolTipHelper = null; > > // Diagram header, borrowed from org.eclipse.ui.forms.widgets.Form class > private FormHeading header; >@@ -771,6 +772,14 @@ > return contextButtonManager; > } > >+ public SapphireToolTipHelper getToolTipHelper() >+ { >+ if (toolTipHelper == null) { >+ toolTipHelper = new SapphireToolTipHelper(this.getGraphicalViewer().getControl()); >+ } >+ return toolTipHelper; >+ } >+ > @Override > public void createPartControl(Composite parent) > { >Index: src/org/eclipse/sapphire/ui/swt/gef/SapphireToolTipHelper.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/swt/gef/SapphireToolTipHelper.java >diff -N src/org/eclipse/sapphire/ui/swt/gef/SapphireToolTipHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/swt/gef/SapphireToolTipHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,171 @@ >+package org.eclipse.sapphire.ui.swt.gef; >+ >+import java.util.Timer; >+import java.util.TimerTask; >+ >+import org.eclipse.draw2d.IFigure; >+import org.eclipse.draw2d.geometry.Dimension; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.ToolTip; >+ >+public class SapphireToolTipHelper { >+ >+ private Control control; >+ private Shell shell; >+ private Display display; >+ >+ private Timer timer; >+ private IFigure currentTipSource; >+ private ToolTip tooltip; >+ private boolean tipShowing; >+ >+ public SapphireToolTipHelper(Control c) { >+ this.control = c; >+ } >+ >+ public void dispose() { >+ if (isShowing()) >+ hide(); >+ } >+ >+ public boolean isShowing() { >+ return tipShowing; >+ } >+ >+ protected ToolTip getToolTip() { >+ if (tooltip == null) { >+ display = control.getDisplay(); >+ shell = new Shell(display, SWT.None); >+ tooltip = new ToolTip(shell, SWT.None); >+ } >+ return tooltip; >+ } >+ >+ protected void hide() { >+ if (!tooltip.isDisposed()) { >+ tooltip.setVisible(false); >+ } >+ tipShowing = false; >+ } >+ >+ protected void show() { >+ getToolTip().setVisible(true); >+ tipShowing = true; >+ } >+ >+ private Point computeWindowLocation(int eventX, int eventY) { >+ //org.eclipse.swt.graphics.Rectangle clientArea = control.getDisplay().getClientArea(); >+ org.eclipse.swt.graphics.Rectangle clientArea = display.getClientArea(); >+ Point preferredLocation = new Point(eventX, eventY + 26); >+ >+// System.out.println("clientArea: " + clientArea); >+// System.out.println(" " + eventX + ", " + (eventY + 26)); >+ >+ // TODO find the tooltip size >+ Dimension tipSize = new Dimension(10, 10); >+ >+ // Adjust location if tip is going to fall outside display >+ if (preferredLocation.y + tipSize.height > clientArea.height) >+ preferredLocation.y = eventY - tipSize.height; >+ >+ if (preferredLocation.x + tipSize.width > clientArea.width) >+ preferredLocation.x -= (preferredLocation.x + tipSize.width) >+ - clientArea.width; >+ >+ return preferredLocation; >+ } >+ >+ public void displayToolTipNear(IFigure hoverSource, String text, int eventX, int eventY) { >+ displayToolTipNear(hoverSource, new ToolTipInfo(text), eventX, eventY); >+ } >+ >+ public void displayToolTipNear(IFigure hoverSource, ToolTipInfo info, int eventX, int eventY) { >+ if (hoverSource != currentTipSource) { >+ System.out.println("displayToolTipNear"); >+ if (info.getMessage() != null) { >+ getToolTip().setMessage(info.getMessage()); >+ } else { >+ getToolTip().setMessage(""); >+ } >+ if (info.getHeader() != null) { >+ getToolTip().setText(info.getHeader()); >+ } else { >+ getToolTip().setText(""); >+ } >+ >+ Point displayPoint = computeWindowLocation(eventX, eventY); >+// Point zero = control.toDisplay(new Point(0,0)); >+// System.out.println(zero); >+// Point anotherOne = control.toControl(displayPoint.x, displayPoint.y); >+// System.out.println(anotherOne); >+// Point shellOne = control.getShell().toControl(displayPoint.x, displayPoint.y); >+// System.out.println(shellOne); >+// Point mapOne = control.getDisplay().map(control, null, displayPoint); >+// System.out.println(mapOne); >+// displayPoint = control.toDisplay(displayPoint); >+// System.out.println(displayPoint); >+ displayPoint = control.toDisplay(displayPoint); >+ getToolTip().setLocation(displayPoint); >+ show(); >+ >+ currentTipSource = hoverSource; >+ timer = new Timer(true); >+ timer.schedule(new TimerTask() { >+ public void run() { >+ Display.getDefault().asyncExec(new Runnable() { >+ public void run() { >+ hide(); >+ timer.cancel(); >+ } >+ }); >+ } >+ }, 5000); >+ } >+ } >+ >+ public void hideToolTip() { >+ if (isShowing()) { >+ System.out.println("hideToolTip"); >+ hide(); >+ timer.cancel(); >+ } >+ currentTipSource = null; >+ } >+ >+ public static class ToolTipInfo { >+ private String header; >+ private String message; >+ >+ public ToolTipInfo() { >+ } >+ >+ public ToolTipInfo(final String message) { >+ this.message = message; >+ } >+ >+ public ToolTipInfo(final String header, final String message) { >+ this.header = header; >+ this.message = message; >+ } >+ >+ public String getHeader() { >+ return header; >+ } >+ >+ public void setHeader(String header) { >+ this.header = header; >+ } >+ >+ public String getMessage() { >+ return message; >+ } >+ >+ public void setMessage(String message) { >+ this.message = message; >+ } >+ } >+} >Index: src/org/eclipse/sapphire/ui/swt/gef/figures/NodeFigure.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui.swt.gef/src/org/eclipse/sapphire/ui/swt/gef/figures/NodeFigure.java,v >retrieving revision 1.2 >diff -u -r1.2 NodeFigure.java >--- src/org/eclipse/sapphire/ui/swt/gef/figures/NodeFigure.java 23 May 2012 18:05:49 -0000 1.2 >+++ src/org/eclipse/sapphire/ui/swt/gef/figures/NodeFigure.java 1 Jun 2012 00:15:32 -0000 >@@ -15,13 +15,18 @@ > import org.eclipse.draw2d.IFigure; > import org.eclipse.draw2d.Label; > import org.eclipse.draw2d.LayoutListener; >+import org.eclipse.draw2d.MouseEvent; >+import org.eclipse.draw2d.MouseMotionListener; > import org.eclipse.draw2d.PositionConstants; > import org.eclipse.draw2d.RoundedRectangle; > import org.eclipse.draw2d.TextUtilities; > import org.eclipse.draw2d.XYLayout; > import org.eclipse.draw2d.geometry.Dimension; >+import org.eclipse.draw2d.geometry.Point; > import org.eclipse.draw2d.geometry.Rectangle; > import org.eclipse.sapphire.ui.Bounds; >+import org.eclipse.sapphire.ui.swt.gef.SapphireToolTipHelper; >+import org.eclipse.sapphire.ui.swt.gef.model.DiagramModel; > import org.eclipse.sapphire.ui.swt.gef.model.DiagramResourceCache; > import org.eclipse.swt.SWT; > import org.eclipse.swt.graphics.Color; >@@ -55,7 +60,16 @@ > > private boolean selected; > private boolean hasFocus; >+ >+ private DiagramModel model; >+ >+ private String toolTipText; > >+ public NodeFigure(boolean hasImage, DiagramResourceCache resourceCache, DiagramModel model) { >+ this(hasImage, resourceCache); >+ this.model = model; >+ } >+ > public NodeFigure(boolean hasImage, DiagramResourceCache resourceCache) { > this.hasImage = hasImage; > this.resourceCache = resourceCache; >@@ -80,6 +94,34 @@ > } > }); > >+ this.addMouseMotionListener(new MouseMotionListener.Stub() { >+ @Override >+ public void mouseHover(MouseEvent me) { >+ showToolTip(me); >+ } >+ >+ @Override >+ public void mouseExited(MouseEvent me) { >+ hideToolTip(me); >+ } >+ }); >+ >+ } >+ >+ private void showToolTip(MouseEvent me) { >+ if (toolTipText != null) { >+ Point point = new Point(me.x, me.y); >+ translateToAbsolute(point); >+ SapphireToolTipHelper helper = model.getSapphireDiagramEditor().getToolTipHelper(); >+ helper.displayToolTipNear(this, toolTipText, point.x, point.y); >+ } >+ } >+ >+ private void hideToolTip(MouseEvent me) { >+ if (toolTipText != null) { >+ SapphireToolTipHelper helper = model.getSapphireDiagramEditor().getToolTipHelper(); >+ helper.hideToolTip(); >+ } > } > > public void refreshConstraints(Bounds labelBounds, Bounds iconBounds) { >@@ -111,9 +153,13 @@ > private void setTooltipText(String text) { > Dimension d = TextUtilities.INSTANCE.getStringExtents(text, labelFigure.getFont()); > if (d.width + 5 >= getBounds().width) { >- this.setToolTip(new Label(text)); >- } else { >+ toolTipText = text; > this.setToolTip(null); >+ //this.setToolTip(new Label(text)); >+ } else { >+ //this.setToolTip(new Label(text)); >+ toolTipText = null; >+ //this.setToolTip(null); > } > } > >Index: src/org/eclipse/sapphire/ui/swt/gef/parts/DiagramNodeEditPart.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui.swt.gef/src/org/eclipse/sapphire/ui/swt/gef/parts/DiagramNodeEditPart.java,v >retrieving revision 1.4 >diff -u -r1.4 DiagramNodeEditPart.java >--- src/org/eclipse/sapphire/ui/swt/gef/parts/DiagramNodeEditPart.java 21 May 2012 20:05:51 -0000 1.4 >+++ src/org/eclipse/sapphire/ui/swt/gef/parts/DiagramNodeEditPart.java 1 Jun 2012 00:15:32 -0000 >@@ -74,7 +74,7 @@ > @Override > protected IFigure createFigure() { > ImageData imageData = getCastedModel().getModelPart().getImage(); >- return new NodeFigure(imageData != null, getCastedModel().getDiagramModel().getResourceCache()); >+ return new NodeFigure(imageData != null, getCastedModel().getDiagramModel().getResourceCache(), getCastedModel().getDiagramModel()); > } > > @Override
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 344024
: 216618