MS Word之类的页面管理 [英] MS Word like page managment

查看:136
本文介绍了MS Word之类的页面管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这更多是逻辑上的问题/讨论.

This is more of a logical problem/disscusion.

我有一个文本编辑程序,其工作原理与MS Wrod类似.它的文档是由几页组成的.

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

一个页面是一个JPanel(A),其中包含页面内容.在该JPanel(A)页面内容上添加了其他JPanels(B).页面的最后一个元素始终是填充所有未占用空间的填充物.

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.

我要做的是管理JPanel(B)迁移.当页面被填满时,最后一个应该移到下一个,并且当页面上的空间被释放时,我必须检查下一个的第一个元素是否适合该空间并将其向上移动.

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.

我尝试通过将组件侦听器附加到Filler来实现这一目标. 如果填充物"高度达到零,则页面已满,如果页面放大,则从页面中删除了一个元素(或降低了其高度).

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.

这似乎很简单,但是存在一些问题. JPanels(B)的大小不尽相同.

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

这意味着,当从页面中删除一个JPanel(B)时,会从一个页面中删除一个以上的JPanel(B). 下一页可能适合该空间.这也意味着,如果页面的第一个JPanel(B)的高度减小,则它也可能适合上一页(如果它的新高度小于先前页面的Filler的高度),并且减小的幅度可能是足够大,可以将下一页的更多JPanels(B)附加到当前页面.

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.

移动JPanels(B)将触发上一页/下一页的组件侦听器.我可以通过在执行侦听器代码时添加一个设置为true的布尔值设置,并使侦听器仅在该布尔值为false时才运行,来避免这种情况,但这根本不会调用其他页面侦听器,这再次不好,它们必须最后被调用.

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?

我的主要问题是,有没有一种方法可以在Java中以更简单的方式实现类似Word的页面内容管理?以某种方式创建了一组组件,这些组件以它们自动管理所有这些组件的方式排列(在JTextArea中是自动换行的东西)?

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

我只是Java和Swing的初学者,所以也许有一些组件可以用于此目的,或者当将某些组件正确组合在一起时会表现出这种效果吗? 也许可以管理一些布局?

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?

如果我创建一些较高的JPanel,则可以增加/减小其高度,具体取决于页码,也许我可以添加一些用作分隔符的垂直条,如果在其之前添加了一个组件,或者它的高度是大于分隔符的剩余空间,它会自动放置在分隔符之后吗?这样一来,我就可以营造一种错觉的页面.

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

推荐答案

这就是答案 java-sl.com/articles.html在此处阅读有关分页的4篇文章

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

这篇关于MS Word之类的页面管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆