Results 1 to 18 of 18
 06182010, 05:01 PM #1
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,018
 Blog Entries
 7
 Rep Power
 20
Tooltips; More or less Swing related
Greetings,
Suppose I have an infix expression, more exact: I have the abstract syntax tree of the expression. I have complete control over this AST and can 'visit' every node of it. It is easy to reconstruct the textual representation of such an expression. (or the postfix form or whatever).
I can even 'pretty print' it using a Graphics2D object, using several font sizes and colours for, say, the operators, builtin functions etc. no problem at all. Now I want to display such a 'pretty printed' expression in a tooltip. I could save the image generated on the Graphics2D object and load it as a file in my html text for the tooltip, but I don't want that.
Html and I don't like each other; we are never going to become friends, hence my question; is there an css definition (or similar) that can (partly) generate html for (more or less) simple infix mathematical expressions?
I realize this is more of an html question (version 3.2 I presume?) but I googled quite a bit and have not met anything half usefull. Any hints, tips, encouragement are appreciated. I just want infix expressions pretty printed on a tooltip.
kind regards,
Jos
 06202010, 09:35 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,018
 Blog Entries
 7
 Rep Power
 20
That was an understatement; man, do I hate that lousy markup language. I've been playing with it and have partial success; e.g. if I have this expression:
Java Code:(r*exp(i*PI))
<i>r</i>·<font color="#008000">e</font><sup></font><i>i</i>·<font color="#008000">π</font></sup>
and it looks quite nice if properly rendered. But I could find no way to properly print this:
Java Code:numerator  denominator
Java Code:numerator/denominator
a**(b**c) # ** is my symbol for the 'raise to the power' operator
is rendered as:
Java Code:bc a
I find that entire html thing a bunch of crap.
kind regards,
Jso
 06202010, 01:00 PM #3want to display such a 'pretty printed' expression in a tooltip
 06202010, 01:19 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,018
 Blog Entries
 7
 Rep Power
 20
My own Java program; when the mouse moves over such an expression (I am able to recognize over what thing the mouse is positioned) I want the expression displayed in a nice mathematical format in a tooltip; I can only deliver text for the tooltip to it has to be html text (the only markup possible).
I am halfway now but see my previous post for the deficiencies of that bloody html thing ;)
kind regards,
Jos
 06202010, 04:16 PM #5
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,372
 Blog Entries
 1
 Rep Power
 19
Didn't you try title property in XHTML, but I wonder how to handle it dynamically.
 06202010, 06:52 PM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,018
 Blog Entries
 7
 Rep Power
 20
AFAIK XHTML is just a better 'wellformed' HTML but it's rendering tags are just as lousy as HTML's capabilities. I generate HTML contents highly recursive (using the 'visitor' pattern) and it is highly structured, I think it is equal to XML's syntax but I don't see how that helps here. Care to enlighten me w.r.t. the problems I outlined above?
kind regards,
Jos
 06212010, 06:34 AM #7Senior Member
 Join Date
 Dec 2008
 Posts
 526
 Rep Power
 0
Something that way? But it is graphics only...
InformIT: Styling Swing Components with Java CSS > Extending Java CSS with a New Property Type
Do you want to get something like a math formula Maple effect?
I just wondering why don't you write a reg expression modules to analyze your x^2+blablabla and get a simple html with it x<sub>2</sub> x<sup>2</sup> etc? I am not quite sure the effect you really want to get so here are some tips... :rolleyes:
Google gives many tables just make an array ;)
Special Characters in HTML
Special Characters in HTML
gen
Math in HTML (and CSS)  presenting mathematical expressions on Web pages
and this <math> tag using (Emm... this one is more like Maple)
Help Displaying a formula  Wikipedia, the free encyclopedia
Mathematical Formulas in HTML 4.0Last edited by Webuser; 06212010 at 06:47 AM.
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
 06212010, 07:30 AM #8
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,372
 Blog Entries
 1
 Rep Power
 19
 06212010, 11:43 AM #9
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,018
 Blog Entries
 7
 Rep Power
 20
Let me try to explain it again; e.g. if I feed the following String to a, say, JLabel:
Java Code:"<html>This is line one<br>This is line two</html>"
kind regards,
Jos
 06222010, 04:34 AM #10Senior Member
 Join Date
 Dec 2008
 Posts
 526
 Rep Power
 0
I realize this is more of an html question (version 3.2 I presume?)
So a... JLabel and HTML right? That is the strategy you want to use?
Actually the tooltip can be created using tooltip API
How to Use Tool Tips (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
But I think JLabel and HTML is quite limited so you can replace this plan with another one just like the formulas image gen... MathML and so on...
and here it can be done using something like a jscl + JEuclid
http://jsclmeditor.sourceforge.net/
JEuclid 
I hope you know I mean ? :rolleyes:Last edited by Webuser; 06222010 at 05:30 AM.
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
 06222010, 07:43 AM #11
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,018
 Blog Entries
 7
 Rep Power
 20
Yes I know that ToolTip API and I know html; all you're saying is that I should use something else instead of html, right? So is my conclusion correct that html 3.2. isn't adequate for what I want to use it? Rendering of simple mathematical expressions is all I need ...
kind regards,
Jos
 06222010, 12:07 PM #12
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,372
 Blog Entries
 1
 Rep Power
 19
 06222010, 07:35 PM #13Senior Member
 Join Date
 Dec 2008
 Posts
 526
 Rep Power
 0
Not exactly. Sure you can use HTML for primitive math formulas but I think it is not enough if you want to use sqrt for example ;) so JEuclid is a good way to express sqrt or even more complicated things just like the matrix in a classic math view...
JEuclid uses mathML (MML) to gen an formula image so you have to parse the common Java math expression into MML before using it.
But I like the way because from this
<math mode="display" xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mi>x</mi>
<mo>=</mo>
<mfrac>
<mrow>
<mo form="prefix">−<! − ></mo>
<mi>b</mi>
<mo>±<! ± ></mo>
<msqrt>
<msup>
<mi>b</mi>
<mn>2</mn>
</msup>
<mo>−<! − ></mo>
<mn>4</mn>
<mo>⁢<! ⁢ ></mo>
<mi>a</mi>
<mo>⁢<! ⁢ ></mo>
<mi>c</mi>
</msqrt>
</mrow>
<mrow>
<mn>2</mn>
<mo>⁢<! ⁢ ></mo>
<mi>a</mi>
</mrow>
</mfrac>
</mrow>
</math>
Of course it is not HTML but MML ...Do as you wish, pal :rolleyes:Last edited by Webuser; 06222010 at 07:43 PM.
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
 06232010, 04:08 AM #14
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,372
 Blog Entries
 1
 Rep Power
 19
That's pretty cool I guess. I want to check it out very soon.
 06232010, 12:13 PM #15
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,018
 Blog Entries
 7
 Rep Power
 20
Why don't you people read? I wrote that I have complete control over the AST for my expression, I can generate whatever I want; the problem is that html 3.2. doesn't have the proper formatting tags (as far as I can tell). An example: writing N/D with the N above the D with a little division line between them looks like a mess.
Generating several (more than one) levels of superscript also fails miserably, although the generated tags are correct. I don't want to use any third party library, I can render my expressions quite well myself thank you. All I asked was: can html (plain) do it? As far as I can see now, it can't. Tiling the entire area with table cells and rows looks terrible too.
Until now all the answers just mentioned mathematical extensions to html but I find that overkill and I found the links myself already when I googled for information and I don't care if they all look 'cool' or whatever. It simply disappoints me that plain html 3.2 can't do it.
kind regards,
Jos
 06242010, 05:16 AM #16Senior Member
 Join Date
 Dec 2008
 Posts
 526
 Rep Power
 0
HTML can really can do this and it even supports the math tags and it is all the browser's thing... but can Java support these tags <math>x^2</math>? That is the question I guess
As I can remember it doesn't... So I would look for an alt way :rolleyes:
I just wondering how you think to work with sqrt() or pow() methods then?Last edited by Webuser; 06242010 at 05:19 AM.
 06242010, 09:36 AM #17
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,018
 Blog Entries
 7
 Rep Power
 20
Java implements version 3.2 for html with some 4.0 extensions; that <math> tag is not a supported one. I'm not looking for external extensions or half/half supported extensions. My question was simple: can html 3.2 render mathematical expressions and if so how? Now I use the radical root sign for the square root and I use superscript for the power function (ony one level is supported so: pow(a, pow(b, c)) displays miserably although the generated tags are 'correct': a<sup>b<sup>c</sup></sup>). A simple division can't be properly displayed either (the numerator above the denominator). The results are hardly better than the original infix functional notation ...
kind regards,
Jos
 06252010, 02:03 AM #18Senior Member
 Join Date
 Dec 2008
 Posts
 526
 Rep Power
 0
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
Similar Threads

tooltips for JTable column headers
By fossildoc in forum AWT / SwingReplies: 2Last Post: 12182008, 11:42 AM 
Related to JTrees
By swathi in forum AWT / SwingReplies: 1Last Post: 11212008, 06:50 AM 
Jboss related.
By CharanZ in forum IntroductionsReplies: 0Last Post: 10272008, 10:09 AM 
JNDI Related
By Ganeshag777 in forum Advanced JavaReplies: 0Last Post: 08132008, 01:18 PM 
JDBC Related
By Ganeshag777 in forum JDBCReplies: 2Last Post: 08132008, 12:42 PM
Bookmarks