<Swing Dev> New member needs to understand interacting with HTML in Swing
Bob Futrelle
bob.futrelle at gmail.com
Wed Jul 31 01:41:47 UTC 2013
I devised what I'd call a hokey workaround that enables me to find
the numerical UID of any selected text token(s). It consists of
adding a styled span as a prefix to every word. Each span contains
the numerical UID of the token that follows it.
The HTML markup is substantially elaborated as, e.g.,
myPane.setText("<head><style type=\"text/css\"> .tn{
font-size:0px;}</style></head>" +
"<span class=\"tn\">0000000</span>while <span
class=\"tn\">0000001</span>having <span class=\"tn\">0000002</span>no " +
"<span class=\"tn\">0000003</span>effect <span
class=\"tn\">0000004</span>on "+
"<span class=\"tn\">0000005</span>cytochrome <span
class=\"tn\">0000006</span><em>c</em>");
where 'myPane' is defined as,
myPane = new JEditorPane();
myPane.setContentType("text/html");
The pane displays "while having no effect on cytochrome *c*"
with c in italics and the normal interword spacing.
There is no evidence in the display that the numerical IDs of the tokens
underlie the text.
The 'Print' menu item in my little app is:
else if (cmd.equals("Print")) {
System.out.println(myPane.getSelectedText());
}
When "cytochrome" is selected in the JEditorPane,
the Print command prints
0000005cytochrome
so I know precisely which token was selected, even if
there were other occurrences of "cytochrome".
If the pair "no effect" is selected, the output print is,
0000002no 0000003effect
Such multi-word items are important in biomedical text, e.g., "propidium
iodide" is a
single chemical compound with a two-word name, cf. "sodium chloride".
My workaround operates by massaging the HTML source.
So I've used what Swing offers out of the box,
avoiding possibly trickier solutions.
- Bob
On Tue, Jul 30, 2013 at 2:26 PM, Bob Futrelle <bob.futrelle at gmail.com>wrote:
> My first post here.
>
> I've used Swing for years, but my current goals call
> for advanced development on my part.
> I tokenize HTML article text from the biology research literature.
> When a user clicks on or selects an item in a Swing GUI, I need to know
> exactly which token was selected, since I keep all sorts of
> information about the syntax and semantics every token, phrase, etc.
>
> I am willing to use whatever HTML rendering is available
> in Swing editor kits. If the HTML markup strays outside
> of Swing's capabilities, I'm willing to alter the HTML sources
> as a workaround.
>
> My previous experiments in this domain were frustrating
> (too early a version of Java/Swing?).
>
> I intend to restart some HTML experiments soon, but would welcome
> any pointers you people might have.
>
> As you can see, I'm not working at a developer's level,
> involved with Swing implementation details, bugs, or fixes.
> So this may not be the best list for me.
> But considering the demands my system will make on Swing,
> this may be the only place with participants that have the
> needed level of expertise.
>
> Though I recently retired, I'm working harder than ever
> on my ambitious NLP text mining system.
> I currently use Java 6 and Eclipse,
> Mac OS 10.8.4, MacBook Pro.
>
> Thanks in advance for any advice you might provide.
>
> - Bob Futrelle
> Emeritus professor of computer and info science
> Northeastern University
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20130730/d857f94d/attachment.html>
More information about the swing-dev
mailing list