Results 1 to 18 of 18
  1. #1
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default 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

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by I wrote View Post
    Html and I don't like each other; we are never going to become friends, [ ... ]
    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))
    My pretty printer can print this:

    <i>r</i>&middot;<font color="#008000">e</font><sup></font><i>i</i>&middot;<font color="#008000">&pi;</font></sup>

    and it looks quite nice if properly rendered. But I could find no way to properly print this:

    Java Code:
    numerator
    ---------
    denominator
    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:

    a**(b**c) # ** is my symbol for the 'raise to the power' operator

    is rendered as:

    Java Code:
     bc
    a
    while the generated code is 'correct': a<sup>b<sup>c</sup></sup>

    I find that entire html thing a bunch of crap.

    kind regards,

    Jso

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    want to display such a 'pretty printed' expression in a tooltip
    Just curious: Who/what is displaying this tooltip? The browser, a java program or ?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Norm View Post
    Just curious: Who/what is displaying this tooltip? The browser, a java program or ?
    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

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Eranga View Post
    Didn't you try title property in XHTML, but I wonder how to handle it dynamically.
    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

  7. #7
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Question

    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.0
    Last 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 :)

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    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
    Actually that's why I'm stuck with my own answer on previous post, how dynamic changes are handle within it.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    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>"
    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.

    kind regards,

    Jos

  10. #10
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I realize this is more of an html question (version 3.2 I presume?)
    But I thought you have finally began studying html :rolleyes:

    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 :)

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Webuser View Post
    But I thought you have finally began studying html :rolleyes:

    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
    jscl-meditor - java symbolic computing library and mathematical editor
    JEuclid -

    I hope you know I mean ? :rolleyes:
    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

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  13. #13
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Thumbs up

    Quote Originally Posted by JosAH View Post
    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
    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">&#x2212;<!-- &minus; --></mo>
    <mi>b</mi>
    <mo>&#x00B1;<!-- &PlusMinus; --></mo>
    <msqrt>
    <msup>
    <mi>b</mi>
    <mn>2</mn>
    </msup>
    <mo>&#x2212;<!-- &minus; --></mo>
    <mn>4</mn>
    <mo>&#x2062;<!-- &InvisibleTimes; --></mo>
    <mi>a</mi>
    <mo>&#x2062;<!-- &InvisibleTimes; --></mo>
    <mi>c</mi>
    </msqrt>
    </mrow>
    <mrow>
    <mn>2</mn>
    <mo>&#x2062;<!-- &InvisibleTimes; --></mo>
    <mi>a</mi>
    </mrow>
    </mfrac>
    </mrow>
    </math>
    ah... you can get this



    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 :)

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Webuser View Post
    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:
    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

  16. #16
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    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
    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.

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Webuser View Post
    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?
    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

  18. #18
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    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
    Sure you can come around the sqrt(9) by a 9^(1/2) etc but that wouldn't be as classic math people used to see I guess :confused:
    I think plain HTML provides less ways to achieve a really good looking math expression. That's a pity... :(
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

Similar Threads

  1. tooltips for JTable column headers
    By fossildoc in forum AWT / Swing
    Replies: 2
    Last Post: 12-18-2008, 11:42 AM
  2. Related to JTrees
    By swathi in forum AWT / Swing
    Replies: 1
    Last Post: 11-21-2008, 06:50 AM
  3. Jboss related.
    By CharanZ in forum Introductions
    Replies: 0
    Last Post: 10-27-2008, 10:09 AM
  4. JNDI Related
    By Ganeshag777 in forum Advanced Java
    Replies: 0
    Last Post: 08-13-2008, 01:18 PM
  5. JDBC Related
    By Ganeshag777 in forum JDBC
    Replies: 2
    Last Post: 08-13-2008, 12:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •