Java Swing/AWT 中的翻页效果

发布于 2024-12-09 02:15:37 字数 390 浏览 0 评论 0原文

我想在Swing中实现翻页效果 /AWT。 此处对该理论进行了详细解释。我的问题是,由于页面要包含文本,所以使用哪个是正确的 swing/awt 组件?另外,为了更深入一点,我应该如何解决这个问题?我的意思是我已经把理论摆在我面前,我知道我需要使用的工具,但我从来没有用 Swing/AWT 做过这样的事情,我是否需要掌握 Swing/AWT 的所有细节才能做到这一点这?

I would like to implement the page turn effect in Swing/AWT. The theory is pretty much explained here. My question is that since the page is to contain text, which is the correct swing/awt component to use? Also, to get a little deeper, how should I approach this problem? I mean I have the theory laid out before me, I know the tool I need to use, but I have never done anything like this with Swing/AWT, do I need to master all the minutiae of Swing/AWT to be able to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染柒℉ 2024-12-16 02:15:37

无论你做什么,你都必须实施你自己的绘图例程。由于您打算绘制的文本不会共享与其他组件绘制的文本的大多数特征(它将随着时间的推移而倾斜、旋转,并在页面的移动可见“边缘”处被剪裁),因此您还必须绘制文本。

在 SWING 和所有非控制台程序中,文本将像任何图形基元一样绘制到屏幕上。这需要一点学习;尤其是行距、字母间距、自动换行等细节。

这意味着我会考虑使用新的 swing UI 组件。 以下是如何编写自定义绘画。根据详细信息,您可能希望重用模型。一般来说,只编写视图比同时编写视图和模型更容易;但是,您必须平衡视图的需求与现有模型的适用性。

如果您选择现有模型,则应根据文档接口编写视图。您可以从 JTextPane 或 JTextArea 视图组件中获取指导​​,具体取决于您是否希望能够向文本“添加样式”。

不要忘记,视图实际上并不在结构良好的 Swing 组件中进行绘制。如果是这样,那么它将无法换肤(以遵循平台的主题)。这意味着,虽然您将提供 Swing 视图(通常具有 JPagedBook 之类的名称模式),但该视图必须耦合到实际绘制视图的 UIDelegate。这允许每个视图有多个 UIDelegate,每个 UIDelegate 包含如何以与平台的外观一致的方式渲染(绘制)视图的指令。

围绕此问题的最大问题通常是正确支持外观所需的额外工作,以及缺乏正确的 UIDelegate 注册知识(因此当视图绘制时,它会找到可以绘制它的东西)。为了使它像 Swing 的其余部分一样工作,额外的几个小时(或者几天,如果 GUI 组件编程对您来说有点陌生)是值得的。最后,您将拥有一个感觉不像库的“独立”部分的组件。

Whatever you do, you will have to implement your own drawing routines. As the text you intend to draw is going to not share most characteristics of the text drawn with other components (it will be angled, rotating over time, and clipped at a moving visible "edge" of the page), you will also have to draw the text.

In SWING, and in all non-console programs the text is drawn to the screen as would any graphics primitive. It takes a bit of learning; especially in the details of line spacing, letter spacing, word wrapping, etc.

That means I'd consider a new swing UI component. Here's how to write custom painting for one. Depending on the details, you may want to reuse a model. Generally it is easier to only write a view than a view and a model at the same time; however, you must balance the needs of the view with the suitability of the existing model.

If you choose an existing model, the Document interface is what you should code your view against. You can take your lead from the JTextPane or JTextArea view components, depeding on if you want the ability to "add style" to your text.

Don't forget that the view actually doesn't do the painting in a well structured Swing component. If it did, then it would not be able to be skinned (to follow the platform's theme). This means that while you will provide a Swing view (typically with a name pattern like JPagedBook), that view will have to be coupled to a UIDelegate which does the actual drawing of the view. This allows multiple UIDelegates for each view, with each UIDelegate containing the instructions of how to render (draw) the view in a manner that is consistent with the look-and-feel of the platform.

The biggest issues around this is typically the extra work involved to properly support look-and-feel, and the lack of knowledge of proper UIDelegate registration (so when the view draws, it finds something that will draw it). It's worth the extra few hours (or couple of days if GUI component programming is sort of new to you) to make it work like the rest of Swing. In the end you'll have a component that doesn't feel like a "separate" part of the library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文