Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

More HTMLEditorKit advice needed

Thread view: 
John English - 19 Mar 2004 14:01 GMT
After much experimentation, I've got something which can display an HTML
page and wich lets me modify bold & italic attributes of the text. But
I have some niggly questions:

1) To bolden, I obtain a MutableAttributeSet for the selected text and
   use addAttribute to add HTML.Tag.B but to cancel boldness I have to
   then use removeAttribute to remove both the HTML.Tag.B and
   Font-weight attributes. Am I doing this the right way? Do I really
   have to know what font styles to remove in addition to the tag I'm
   dealing with?

2) How do I arrange things to insert (e.g.) bold text when I don't have
   any text selected? In other words, I want to be able to click a
   button to turn boldening on or off at the current insertion point
   so that anything I type at that point is inserted as bold text (or
   not-bold in the middle of some bold text).

3) How do I insert line breaks <br> and paragraph styles (<h1>, <p>,
   <pre> and so on)?

If anyone can advise me I'd be very grateful. The documemtation doesn't
exactly go out of its way to make this clear...

---------------------------------------------------------------------
 John English                   | mailto:je@brighton.ac.uk
 Senior Lecturer                | http://www.it.bton.ac.uk/staff/je
 School of Computing Maths & IS | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton         |    -- see http://burks.bton.ac.uk
---------------------------------------------------------------------
Chris Smith - 19 Mar 2004 14:24 GMT
> After much experimentation, I've got something which can display an HTML
> page and wich lets me modify bold & italic attributes of the text. But
[quoted text clipped - 6 lines]
>     have to know what font styles to remove in addition to the tag I'm
>     dealing with?

Yes.  I think the intent was to make one implied by the other, but there
are gaps where StyleConstants and the corresponding HTML attributes get
out of sync.  In those cases, you have to remember to set both
appropriately.

> 2) How do I arrange things to insert (e.g.) bold text when I don't have
>     any text selected? In other words, I want to be able to click a
>     button to turn boldening on or off at the current insertion point
>     so that anything I type at that point is inserted as bold text (or
>     not-bold in the middle of some bold text).

See the StyledEditorKit.getInputAttributes method.  Storing an attribute
in there will cause it to be used for newly inserted text by the default
insertion actions.

> 3) How do I insert line breaks <br> and paragraph styles (<h1>, <p>,
>     <pre> and so on)?

It's not exactly trivial, and it depends on exactly what you plan to
insert.

> If anyone can advise me I'd be very grateful. The documemtation doesn't
> exactly go out of its way to make this clear...

I've done a lot of this work of dealing with quirks in HTMLEditorKit and
its associated classes, and MindIQ is attempting to release it as open-
source code.  I don't have the time at the moment, though, to clean it
up and prep it for release, though.  If you're interested in helping
with that, it may be easier than reinventing what we've already done.  
Contact me offline if you're interested.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.