GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes pagination in jtextpane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "pagination in jtextpane" Watch "pagination in jtextpane" New topic
Author

pagination in jtextpane

mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
hi, here is a SSCCEE for pagination of jtextpane. it uses a stylededitorkit

my problem is if i change the content type to text/rtf or text/html it does not work. any idea what is wrong? both rtfeditorkit adn htmleditorkit inherit from stylededitorkit so the result should be the same but it is not

if anyone can give ideas or workaround, it would be greatly appreciated. thank you


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2191
    
    7
both rtfeditorkit adn htmleditorkit inherit from stylededitorkit


Yes they extend StyledEditKit, they don't extend CetiEditorKit, so they know nothing about your custom code.

mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
i mean

CetiEditorKit extends StyledEditorKit in the code

if i do

CetiEditorKit extends RTFEditorKit or HTMLEditorKit, it does not work in this mode
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
Mey be this would help
http://java-sl.com/Pagination_In_JEditorPane.html
?

If you don't need WYSIWYG but only preview pages and print you can use this
http://java-sl.com/JEditorPanePrinter.html

Actually the main problem of your code is that you try to replace views with your page views based on some elements name. HTMLEditorKit has different views structure and the views with the names your use just don't exist.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
hi stan, i saw your code before i created this top but it caters to only a stylededitorkit. if i use it as an htmleditorkit, it does not work
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
As I explained you are trying to replace incorrect views.

See http://java-sl.com/JEditorPaneStructureTool.html
As you can see on the screenshow (Views structure part) HTMLEditorKit uses different views for different elements. See BranchElement(body) and view for the element is BodyBlockView.

So try to debug your view factory and see which elements with names comes in the create() method and which views are created for the elements. The replace proper elements with your views. You views should extend proper HTML views classes.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
hi stan! thanks for the tip. i managed to integrate your sectionview, pageableparagraphview and multipageview to my working app

i just need to adjust the width and height of the wysiwyg area.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
hi stan. got a few questions

1) im trying to do a real time switch between pageable and normal view, does this require having to call setEditorKit again in pageable mode in order for the jtextcomponent to display them as paginated?

2) the pagination in the htmleditorkit works fine, unless if the text im writing is bulleted, it does not move the next bullet list to the next page. is this a view issue?
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
1) I think all you need is to pass a flag to the root view you have. E.g. via document.properties or directly to rootView. textPane.getUI().getRootView() and down to the necessary view. The view should check the flag and do your paginated layout or the original layout.

2)For the list view and guess for the table view you need to write something similar to ParagraphView. An algorithm to move children based on the pagination info you have from parent.

Actually the ListView and tableView extend the same BoxView so noting difficult to write the same code.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
i used the document.getProperty() approach inside the views and added super.method calls in your classes if it is not in multipage mode.

however, i noticed that when i resize my editor's jframe, the paint somehow gets messed up, until i resize it again. im thinking of doing a dirty hack that, if resized, will resize it programmatically again by 1 pixel perhaps.

anyone got ideas what methods get called when a resize occurs? validate()? revalidate()? etc?
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
i did a simpler and quicker hack instead. placing a flag in the editorkit class's viewfactory and calling textpane.setText() method to reload the current content. since my module doesnt deal with huge documents, this was a quicker workaround for me rather than doing modifying your classes.

as for html bullets, i figure id make use of your same pageableparagraphview class to paginate paragraphs since my bullets contain <li><p></p></li> inserthtml actions whenever i insert a bullet but when it gets to the next page, it seems to bring the whole <ul> block to the next page instead of the last <li></li> of the <ul> set.

my editorkit class looks something like this


any suggestions?
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
My suggestion is the same. Write the same functionality as for paragraphs for ListView.
Hierarchy is
BlockView (e.g. body)
ListView
ListItemView
ParagraphView

If you replace paragraph or list item views ListView remains the same block which can't be split.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
just to clarify. i'd have to create a view for listview, another for listitemview and maybe use the same pageableparagraphview class for a paragraphview? thanks
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
I have no simple answer. My solution supposes one level children pagination. It means if you list item contains several paragraphs and sum of heights of the paragraphs is bigger than page height the list item isn't split. In other words the pagination doesn't split nested elements.
So all you need is to create custom view for lists. The view should check list items heights and shift list items to the next page. If you need more complicated logic my simple example should be extended to adress the same pagination to nested elements.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
thanks for the quick reply and clarification.

think ill put this on hold as views are pretty complicated, so much more this bullet pageable view. your existing samples were helpful though for me accomplishing what i needed to do.
p anu
Greenhorn

Joined: Sep 21, 2011
Posts: 6
I am also facing the same problem. when is replace the StyledEditorKit with HTMLEditorKit, the view does not render the pageable. please post your cutomized Views for Pageable HtmlEditorKit
sahib Zar Khan
Greenhorn

Joined: Jan 09, 2014
Posts: 3
how did you do your scalling please let me know
 
GeeCON Prague 2014
 
subject: pagination in jtextpane