A recent desktop app of mine had a line of ToolBar buttons, each with the same image, and I needed to distinguish between them. So I added a toolTip field to the fwt::Button class.
The Java implementation uses getToolTipText() / setToolTipText() on SWTs Control / ToolItem classes and the Javascript implementation simply adds a title attribute to the wrapping div elements.
Brian, I'll email you the patch - it's pretty small.
SlimerDude Thu 9 Jul 2015
A recent desktop app of mine had a line of ToolBar buttons, each with the same image, and I needed to distinguish between them. So I added a
toolTipfield to the fwt::Button class.The Java implementation uses
getToolTipText()/setToolTipText()on SWTsControl/ToolItemclasses and the Javascript implementation simply adds atitleattribute to the wrappingdivelements.Brian, I'll email you the patch - it's pretty small.
Edit
Figured I could just paste the patch here:
diff -r fdaadd1365a3 src/fwt/fan/Button.fan --- a/src/fwt/fan/Button.fan Wed Jul 08 14:21:11 2015 -0400 +++ b/src/fwt/fan/Button.fan Thu Jul 09 13:16:41 2015 +0100 @@ -68,6 +68,11 @@ native Str text ** + ** The button's tool tip. Defaults to "". + ** + native Str toolTip + + ** ** Image to display on button. Defaults to null. ** native Image? image diff -r fdaadd1365a3 src/fwt/java/ButtonPeer.java --- a/src/fwt/java/ButtonPeer.java Wed Jul 08 14:21:11 2015 -0400 +++ b/src/fwt/java/ButtonPeer.java Thu Jul 09 13:16:41 2015 +0100 @@ -77,6 +77,15 @@ public void set(Widget w, String v) { if (w instanceof Button) ((Button)w).setText(v); else ((ToolItem)w).setText(v); } }; + // Str toolTip := "" + public String toolTip(fan.fwt.Button self) { return toolTip.get(); } + public void toolTip(fan.fwt.Button self, String v) { toolTip.set(v); } + public final Prop.StrProp toolTip = new Prop.StrProp(this, "") + { + public String get(Widget w) { return (w instanceof Button) ? ((Button)w).getToolTipText() : ((ToolItem)w).getToolTipText(); } + public void set(Widget w, String v) { if (w instanceof Button) ((Button)w).setToolTipText(v); else ((ToolItem)w).setToolTipText(v); } + }; + // Image image := null public fan.gfx.Image image(fan.fwt.Button self) { return image.get(); } public void image(fan.fwt.Button self, fan.gfx.Image v) { image.set(v); } diff -r fdaadd1365a3 src/fwt/js/ButtonPeer.js --- a/src/fwt/js/ButtonPeer.js Wed Jul 08 14:21:11 2015 -0400 +++ b/src/fwt/js/ButtonPeer.js Thu Jul 09 13:16:41 2015 +0100 @@ -67,6 +67,10 @@ fan.fwt.ButtonPeer.prototype.text$ = function(self, val) { this.m_text = val; } fan.fwt.ButtonPeer.prototype.m_text = ""; +fan.fwt.ButtonPeer.prototype.toolTip = function(self) { return this.m_toolTip; } +fan.fwt.ButtonPeer.prototype.toolTip$ = function(self, val) { this.m_toolTip = val; } +fan.fwt.ButtonPeer.prototype.m_toolTip = ""; + fan.fwt.ButtonPeer.prototype.m_pressed = false; fan.fwt.ButtonPeer.prototype.create = function(parentElem, self) @@ -93,7 +97,7 @@ div.className = "_fwt_Button_ push"; div.style.font = fan.fwt.WidgetPeer.fontToCss( this.m_font==null ? fan.fwt.DesktopPeer.$sysFont : this.m_font); - + div.title = this.m_toolTip; var $this = this; div.onmousedown = function(event) { @@ -164,6 +168,7 @@ check.style.marginRight = "6px"; var div = this.emptyDiv(); + div.title = this.m_toolTip; with (div.style) { font = fan.fwt.WidgetPeer.fontToCss(this.m_font==null ? fan.fwt.DesktopPeer.$sysFont : this.m_font); @@ -247,6 +252,7 @@ { var div = this.elem.firstChild; div.tabIndex = this.m_enabled ? 0 : -1; + div.title = this.m_toolTip; // set def if (this.m_def == true) fan.fwt.WidgetPeer.addClassName(div, "def"); @@ -309,6 +315,7 @@ self.m_mode == fan.fwt.ButtonMode.m_radio) { var div = this.elem; + div.title = this.m_toolTip; div.style.color = self.m_fg ? self.m_fg.toCss() : (this.m_enabled ? "#000" : "#444"); // set state