Home » Eclipse Projects » Standard Widget Toolkit (SWT) » rich tooltips/managing colors with FormText
|
Re: rich tooltips/managing colors with FormText [message #551376 is a reply to message #551364] |
Fri, 06 August 2010 08:24 |
Henno Vermeulen Messages: 126 Registered: July 2009 |
Senior Member |
|
|
For interested people, here is my current tooltip implementation and a snippet that uses it:
package nl.hm.ilja.ui;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormText;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* A tooltip for a {@link Control} which shows a text that can be marked up
* using Eclipse UI Forms {@link FormText} tags.
*
* <p>
* Our goal is to have a fancy tooltip with simple html markup like in Swings
* tooltips. This is the best implementation I could think of; see my forum post
* <a href="http://www.eclipse.org/forums/index.php?t=msg&goto=551364&S=15e3e271d91f521d26beb7b2ba809148#msg_551364"
* >here</a>. I wouldn't cry if we could later switch back to a true html markup
* tooltip, this could be easier if we separate tooltip view from data, see
* issue: OBLII-154.
*
* <p>
* This class supports the following colors. Just <a
* href="http://blog.platinumsolutions.com/node/155">add more</a> when needed!
* <ul>
* <li>"red": SWT.COLOR_RED</li>
* <li>"yellow": SWT.COLOR_YELLOW</li>
* </ul>
*
* <p>
* Idea was taken from <a href="http://www.ibm.com/developerworks/opensource/library/os-eclipse-forms/index.html"
* > this blog</a>.
*
* <p>
* For more info on how to use see the {@link FormText} javadoc, the blog or <a
* href="http://demo.spars.info/j/frameset.cgi?compo_id=150159&mode=frameset&ref=3&method=34&q=org&hl=org&CASE=0&MORPHO=1&location=1111111111111111111&LANG=1"
* >this example</a>, or my {@link ManualTestFancyToolTip}.
*
* @author Henno Vermeulen
*/
public class FancyToolTip extends ToolTip {
private final String text;
public FancyToolTip(Control control, String text) {
super(control);
this.text = text;
}
@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
Form form = toolkit.createForm(parent);
form.getBody().setLayout(new FillLayout());
FormText formText = toolkit.createFormText(form.getBody(), true);
// Parse tags but do not expand URLs because they don't make much
// sense in a tooltip.
formText.setText(text, true, false);
FormColors colors = toolkit.getColors();
addColors(formText, colors);
return parent;
}
private void addColors(FormText formText, FormColors colors) {
addSystemColor(SWT.COLOR_RED, "red", formText, colors);
addSystemColor(SWT.COLOR_YELLOW, "yellow", formText, colors);
}
private void addSystemColor(int colorCode, String key, FormText formText,
FormColors colors) {
colors.createColor(key, colors.getSystemColor(colorCode));
formText.setColor(key, colors.getColor(key));
}
}
package nl.hm.ilja.ui;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class ManualTestFancyToolTip {
public static void main(String[] args) {
final Display display = new Display();
Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
public void run() {
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new ManualTestFancyToolTip().createPartControl(shell);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
});
}
protected static void createPartControl(Shell shell) {
shell.setLayout(new FillLayout());
Text text = new Text(shell, SWT.NONE);
text.setText("Hover over me to show tooltip");
String string = "<form><p>This is a simple <b>test</b></p>"
+ "<p>And this too.</p>"
+ "<p>And <span color=\"red\">here</span> are "
+ "some <span color=\"yellow\">colors</span>.</p>"
+ "<p>Test with list items:</p>"
+ "<li>A default (bulleted) list item.</li>"
+ "<li>Another bullet list item.</li>" + "</form>";
new FancyToolTip(text, string);
shell.setSize(300, 200);
}
}
|
|
|
Re: rich tooltips/managing colors with FormText [message #551383 is a reply to message #551376] |
Fri, 06 August 2010 08:27 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
I think JFace-Text has a component they use to display the JavaDoc
information and it understands HTML-Commands.
Tom
Am 06.08.10 10:24, schrieb SlowStrider:
> For interested people, here is my current tooltip implementation and a
> snippet that uses it:
>
>
> package nl.hm.ilja.ui;
>
> import org.eclipse.jface.window.ToolTip;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Event;
> import org.eclipse.ui.forms.FormColors;
> import org.eclipse.ui.forms.widgets.Form;
> import org.eclipse.ui.forms.widgets.FormText;
> import org.eclipse.ui.forms.widgets.FormToolkit;
>
> /**
> * A tooltip for a {@link Control} which shows a text that can be marked up
> * using Eclipse UI Forms {@link FormText} tags.
> * * <p>
> * Our goal is to have a fancy tooltip with simple html markup like in
> Swings
> * tooltips. This is the best implementation I could think of; see my
> forum post
> * <a
> href=" http://www.eclipse.org/forums/index.php?t=msg&goto=55136 4&S=15e3e271d91f521d26beb7b2ba809148#msg_551364"
>
> * >here</a>. I wouldn't cry if we could later switch back to a true html
> markup
> * tooltip, this could be easier if we separate tooltip view from data, see
> * issue: OBLII-154.
> * * <p>
> * This class supports the following colors. Just <a
> * href="http://blog.platinumsolutions.com/node/155">add more</a> when
> needed!
> * <ul>
> * <li>"red": SWT.COLOR_RED</li>
> * <li>"yellow": SWT.COLOR_YELLOW</li>
> * </ul>
> * * <p>
> * Idea was taken from <a
> href=" http://www.ibm.com/developerworks/opensource/library/os-ecli pse-forms/index.html"
>
> * > this blog</a>.
> * * <p>
> * For more info on how to use see the {@link FormText} javadoc, the blog
> or <a
> *
> href=" http://demo.spars.info/j/frameset.cgi?compo_id=150159&mo de=frameset&ref=3&method=34&q=org&hl=org& ;CASE=0&MORPHO=1&location=1111111111111111111&LA NG=1"
>
> * >this example</a>, or my {@link ManualTestFancyToolTip}.
> * * @author Henno Vermeulen
> */
> public class FancyToolTip extends ToolTip {
>
> private final String text;
>
> public FancyToolTip(Control control, String text) {
> super(control);
> this.text = text;
> }
>
> @Override
> protected Composite createToolTipContentArea(Event event, Composite
> parent) {
> FormToolkit toolkit = new FormToolkit(parent.getDisplay());
> Form form = toolkit.createForm(parent);
> form.getBody().setLayout(new FillLayout());
>
> FormText formText = toolkit.createFormText(form.getBody(), true);
> // Parse tags but do not expand URLs because they don't make much
> // sense in a tooltip.
> formText.setText(text, true, false);
>
> FormColors colors = toolkit.getColors();
> addColors(formText, colors);
> return parent;
> }
>
> private void addColors(FormText formText, FormColors colors) {
> addSystemColor(SWT.COLOR_RED, "red", formText, colors);
> addSystemColor(SWT.COLOR_YELLOW, "yellow", formText, colors);
> }
>
> private void addSystemColor(int colorCode, String key, FormText
> formText,
> FormColors colors) {
> colors.createColor(key, colors.getSystemColor(colorCode));
> formText.setColor(key, colors.getColor(key));
> }
> }
>
>
>
> package nl.hm.ilja.ui;
>
> import org.eclipse.core.databinding.observable.Realm;
> import org.eclipse.jface.databinding.swt.SWTObservables;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
>
> public class ManualTestFancyToolTip {
>
> public static void main(String[] args) {
> final Display display = new Display();
> Realm.runWithDefault(SWTObservables.getRealm(display), new
> Runnable() {
> public void run() {
>
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> new ManualTestFancyToolTip().createPartControl(shell);
> shell.pack();
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> }
> });
> }
>
> protected static void createPartControl(Shell shell) {
> shell.setLayout(new FillLayout());
> Text text = new Text(shell, SWT.NONE);
> text.setText("Hover over me to show tooltip");
> String string = "<form><p>This is a simple <b>test</b></p>"
> + "<p>And this too.</p>"
> + "<p>And <span color=\"red\">here</span> are "
> + "some <span color=\"yellow\">colors</span>.</p>"
> + "<p>Test with list items:</p>"
> + "<li>A default (bulleted) list item.</li>"
> + "<li>Another bullet list item.</li>" + "</form>";
> new FancyToolTip(text, string);
> shell.setSize(300, 200);
> }
>
> }
>
|
|
|
Re: rich tooltips/managing colors with FormText [message #551384 is a reply to message #551383] |
Fri, 06 August 2010 08:28 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Could be JDT-UI also - not sure yet.
Tom
Am 06.08.10 10:27, schrieb Tom Schindl:
> Hi,
>
> I think JFace-Text has a component they use to display the JavaDoc
> information and it understands HTML-Commands.
>
> Tom
>
> Am 06.08.10 10:24, schrieb SlowStrider:
>> For interested people, here is my current tooltip implementation and a
>> snippet that uses it:
>>
>>
>> package nl.hm.ilja.ui;
>>
>> import org.eclipse.jface.window.ToolTip;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.layout.FillLayout;
>> import org.eclipse.swt.widgets.Composite;
>> import org.eclipse.swt.widgets.Control;
>> import org.eclipse.swt.widgets.Event;
>> import org.eclipse.ui.forms.FormColors;
>> import org.eclipse.ui.forms.widgets.Form;
>> import org.eclipse.ui.forms.widgets.FormText;
>> import org.eclipse.ui.forms.widgets.FormToolkit;
>>
>> /**
>> * A tooltip for a {@link Control} which shows a text that can be marked up
>> * using Eclipse UI Forms {@link FormText} tags.
>> * * <p>
>> * Our goal is to have a fancy tooltip with simple html markup like in
>> Swings
>> * tooltips. This is the best implementation I could think of; see my
>> forum post
>> * <a
>> href=" http://www.eclipse.org/forums/index.php?t=msg&goto=55136 4&S=15e3e271d91f521d26beb7b2ba809148#msg_551364"
>>
>> * >here</a>. I wouldn't cry if we could later switch back to a true html
>> markup
>> * tooltip, this could be easier if we separate tooltip view from data, see
>> * issue: OBLII-154.
>> * * <p>
>> * This class supports the following colors. Just <a
>> * href="http://blog.platinumsolutions.com/node/155">add more</a> when
>> needed!
>> * <ul>
>> * <li>"red": SWT.COLOR_RED</li>
>> * <li>"yellow": SWT.COLOR_YELLOW</li>
>> * </ul>
>> * * <p>
>> * Idea was taken from <a
>> href=" http://www.ibm.com/developerworks/opensource/library/os-ecli pse-forms/index.html"
>>
>> * > this blog</a>.
>> * * <p>
>> * For more info on how to use see the {@link FormText} javadoc, the blog
>> or <a
>> *
>> href=" http://demo.spars.info/j/frameset.cgi?compo_id=150159&mo de=frameset&ref=3&method=34&q=org&hl=org& ;CASE=0&MORPHO=1&location=1111111111111111111&LA NG=1"
>>
>> * >this example</a>, or my {@link ManualTestFancyToolTip}.
>> * * @author Henno Vermeulen
>> */
>> public class FancyToolTip extends ToolTip {
>>
>> private final String text;
>>
>> public FancyToolTip(Control control, String text) {
>> super(control);
>> this.text = text;
>> }
>>
>> @Override
>> protected Composite createToolTipContentArea(Event event, Composite
>> parent) {
>> FormToolkit toolkit = new FormToolkit(parent.getDisplay());
>> Form form = toolkit.createForm(parent);
>> form.getBody().setLayout(new FillLayout());
>>
>> FormText formText = toolkit.createFormText(form.getBody(), true);
>> // Parse tags but do not expand URLs because they don't make much
>> // sense in a tooltip.
>> formText.setText(text, true, false);
>>
>> FormColors colors = toolkit.getColors();
>> addColors(formText, colors);
>> return parent;
>> }
>>
>> private void addColors(FormText formText, FormColors colors) {
>> addSystemColor(SWT.COLOR_RED, "red", formText, colors);
>> addSystemColor(SWT.COLOR_YELLOW, "yellow", formText, colors);
>> }
>>
>> private void addSystemColor(int colorCode, String key, FormText
>> formText,
>> FormColors colors) {
>> colors.createColor(key, colors.getSystemColor(colorCode));
>> formText.setColor(key, colors.getColor(key));
>> }
>> }
>>
>>
>>
>> package nl.hm.ilja.ui;
>>
>> import org.eclipse.core.databinding.observable.Realm;
>> import org.eclipse.jface.databinding.swt.SWTObservables;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.layout.FillLayout;
>> import org.eclipse.swt.widgets.Display;
>> import org.eclipse.swt.widgets.Shell;
>> import org.eclipse.swt.widgets.Text;
>>
>> public class ManualTestFancyToolTip {
>>
>> public static void main(String[] args) {
>> final Display display = new Display();
>> Realm.runWithDefault(SWTObservables.getRealm(display), new
>> Runnable() {
>> public void run() {
>>
>> Shell shell = new Shell(display);
>> shell.setLayout(new FillLayout());
>> new ManualTestFancyToolTip().createPartControl(shell);
>> shell.pack();
>> shell.open();
>>
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch())
>> display.sleep();
>> }
>> }
>> });
>> }
>>
>> protected static void createPartControl(Shell shell) {
>> shell.setLayout(new FillLayout());
>> Text text = new Text(shell, SWT.NONE);
>> text.setText("Hover over me to show tooltip");
>> String string = "<form><p>This is a simple <b>test</b></p>"
>> + "<p>And this too.</p>"
>> + "<p>And <span color=\"red\">here</span> are "
>> + "some <span color=\"yellow\">colors</span>.</p>"
>> + "<p>Test with list items:</p>"
>> + "<li>A default (bulleted) list item.</li>"
>> + "<li>Another bullet list item.</li>" + "</form>";
>> new FancyToolTip(text, string);
>> shell.setSize(300, 200);
>> }
>>
>> }
>>
>
|
|
|
Re: rich tooltips/managing colors with FormText [message #551389 is a reply to message #551384] |
Fri, 06 August 2010 09:02 |
Henno Vermeulen Messages: 126 Registered: July 2009 |
Senior Member |
|
|
Thank you Tom. I tried some googling and found for example this blog with hovers over a text editor.
My fear is that it will take me several hours or longer of searching google and noodling around with code until I can turn this info into a simple html tooltip on an SWT control... At least my time estimate is unclear.
I was hoping someone knew an out of the box solution. Otherwise for the moment, I think i'll stick to the FormEditor markup which seems to work good enough at the moment.
[Updated on: Fri, 06 August 2010 09:03] Report message to a moderator
|
|
| | |
Goto Forum:
Current Time: Thu Sep 19 06:11:44 GMT 2024
Powered by FUDForum. Page generated in 0.03201 seconds
|