Results 1 to 18 of 18
- 06-18-2010, 05:01 PM #1
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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, built-in 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
- 06-20-2010, 09:35 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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:
My pretty printer can print this: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:
i.e. a simple division where the numerator is displayed above the denominator; I could use tables but they bring more trouble than they solve, so I am bound to display it as:Java Code:numerator --------- denominator
My renderer can only do one level of superscript so a simple expression as:Java Code:numerator/denominator
a**(b**c) # ** is my symbol for the 'raise to the power' operator
is rendered as:
while the generated code is 'correct': a<sup>b<sup>c</sup></sup>Java Code:bc a
I find that entire html thing a bunch of crap.
kind regards,
Jso
- 06-20-2010, 01:00 PM #3
Just curious: Who/what is displaying this tooltip? The browser, a java program or ?want to display such a 'pretty printed' expression in a tooltip
- 06-20-2010, 01:19 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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
- 06-20-2010, 04:16 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Didn't you try title property in XHTML, but I wonder how to handle it dynamically.
- 06-20-2010, 06:52 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
AFAIK XHTML is just a better 'well-formed' 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
- 06-21-2010, 06:34 AM #7
Senior 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; 06-21-2010 at 06:47 AM.
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
- 06-21-2010, 07:30 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 06-21-2010, 11:43 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Let me try to explain it again; e.g. if I feed the following String to a, say, JLabel:
I see a label with two lines of text. The text processing capabilities of JComponents can hande HTML code and so can a tooltip component, i.e. when you feed it html code in the String (text) it will render it. The html code has to be html 3.2. compliant. Now I want to display mathematical expressions in tooltips by using html code (the only control I have over tooltips is by supplying it a text String). There are no extensions, no external plugins, no nothing. Bare html code seems to be inadequate for rendering mathematical expressions in a decent way (see a few examples in one of my previous replies). So my question boils down to: is html (no extensions) the way to go here? Traversing the AST for the mathematical expression is not the problem here, I have complete control over it.Java Code:"<html>This is line one<br>This is line two</html>"
kind regards,
Jos
- 06-22-2010, 04:34 AM #10
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
But I thought you have finally began studying html :rolleyes: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://jscl-meditor.sourceforge.net/
JEuclid -
I hope you know I mean ? :rolleyes:Last edited by Webuser; 06-22-2010 at 05:30 AM.
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
- 06-22-2010, 07:43 AM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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
- 06-22-2010, 12:07 PM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 06-22-2010, 07:35 PM #13
Senior 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
ah... you can get 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; 06-22-2010 at 07:43 PM.
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
- 06-23-2010, 04:08 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That's pretty cool I guess. I want to check it out very soon.
- 06-23-2010, 12:13 PM #15
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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
- 06-24-2010, 05:16 AM #16
Senior 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; 06-24-2010 at 05:19 AM.
- 06-24-2010, 09:36 AM #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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
- 06-25-2010, 02:03 AM #18
Senior 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: 12-18-2008, 11:42 AM -
Related to JTrees
By swathi in forum AWT / SwingReplies: 1Last Post: 11-21-2008, 06:50 AM -
Jboss related.
By CharanZ in forum IntroductionsReplies: 0Last Post: 10-27-2008, 10:09 AM -
JNDI Related
By Ganeshag777 in forum Advanced JavaReplies: 0Last Post: 08-13-2008, 01:18 PM -
JDBC Related
By Ganeshag777 in forum JDBCReplies: 2Last Post: 08-13-2008, 12:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks