MS Word like page managment [closed]

一曲冷凌霜 提交于 2019-12-11 22:53:53

问题


This is more of a logical problem/disscusion.

I have a text editing program that works similar to MS Wrod. It's document is composed out of pages.

One page is a JPanel (A) that holds pages contents. Onto that JPanel (A) page contents are added, which are other JPanels (B). Last element of page is always a Filler that fills all unoccupied space.

What I have to do is manage JPanel (B) migrations. When page gets filled last one should be moved onto the next one, and when space is freed on a page, I have to check if the first element of the next one fits into that space and move it up.

I try to achieve that with a component listener attached to the Filler. If Fillers height reaches zero, page is full, and if it enlarges, an element was removed (or its height decreased) from the page.

It seems rather simple, but there are some problems. JPanels (B) are not all of the same size.

That means that, when a JPanel (B) is removed from a page, more than one JPanel(B) from the next page can possibly fit onto that space. It also means that if height of the first JPanel (B) of a page is reduced, it may also fit onto the previous page (if it's new height is smaller than the one on the prevous page's Filler), and maybe if the decrease is big enough, more JPanels (B) from next page can be appended to the current.

Taking all that into consideration, quite amount of a code can be written based on that. But this all is very clumsy since it's all done inside a component listener.

Moving JPanels (B) around will trigger component listener of the previous/next page. I can avoid that by adding a boolean set to true while the listener code is executing and making listener only run if that boolean is false, but that doesn't invoke other pages listeners at all, which is not good again, they have to be invoked in the end.

I'd also like to add a sub-question here: If I invoke a listener from another listener, will it run immediatley or after the listener is done? If the answer is after, If I invoke it more than once, will it run only once or several times? What if a listener is invoked from itself?

My main question is, is there a way this Word-like page content managing can be achieved in a simpler manner in Java? Somehow create a set of components arranged in a way they manage all this automatically (something smillar to word wrap in JTextArea)?

I am only a beginner in Java and Swing so maybe there are some components that can be used for this, or maybe when several are combined together properly would act like this? Maybe some layout managed?

If I create some high JPanel, I could increase/decrease it's height, depending on page number, and maybe I could add somekind of vertical strips that act as a separators, if a component is added before it, if it's height is bigger that the space left to the separator, it's automatically put after it? That way I could create an illusion of pages.

Those are just some ideas, I hope some of them are possible or that someone has a better solution...


回答1:


That's the answer java-sl.com/articles.html read here 4 articles about pagination



来源:https://stackoverflow.com/questions/12657070/ms-word-like-page-managment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!