简体   繁体   English

SWT中的FontRegistry和Dispose(JFace)

[英]FontRegistry and Dispose in SWT (JFace)

I'm learning how to use the FontRegistry and how it works. 我正在学习如何使用FontRegistry及其工作方式。 At the moment I have a centralized class (FontUtils) that at startup load all the font data like this: 目前,我有一个集中化的类(FontUtils),它在启动时会加载所有字体数据,如下所示:

fontRegistry.put("small",new FontData[]{new FontData("Tahoma",8, SWT.BOLD)});

Later on in my program I use this: 稍后在我的程序中,我将使用以下代码:

gc.setFont(FontUtils.getFont("small"));

I was wondering if I have to dispose the font created in the FontUtils, because basing on the documentation every time you create a font you should dispose it. 我想知道是否必须处理在FontUtils中创建的字体,因为每次创建字体时都基于文档,因此应该处理它。 But FontRegistry doesn't know anything about the creation of the font, indeed it doesn't have a method called dispose. 但是FontRegistry对字体的创建一无所知,实际上它没有名为dispose的方法。 Do I have to take care of the dispose by myself? 我需要自己照顾吗?

Fore instance using a variable that counts how many resources are using the font and if it's 0 dispose the font? 实例使用一个变量来计算使用字体的资源量,如果它是0,则丢弃该字体?

Because I'm going to do the same for ImageRegistry I thing the behavior is the same , right? 因为我将对ImageRegistry执行相同的操作,所以我的行为是相同的,对吗?

FontRegistry manages all the Fonts that it owns and deals with disposing of them. FontRegistry管理它拥有的所有字体并处理它们。

The JavaDoc says: JavaDoc说:

A font registry owns all of the font objects registered with it, and automatically disposes of them when the SWT Display that creates the fonts is disposed. 字体注册表拥有向其注册的所有字体对象,并在处置创建字体的SWT显示器后自动处置它们。 Because of this, clients do not need to (indeed, must not attempt to) dispose of font objects themselves. 因此,客户端不需要(实际上,绝对不能尝试)自己处置字体对象。

This is done using the disposeExec method of Display . 这是使用DisplaydisposeExec方法完成的。

ImageRegistry is the same: ImageRegistry相同:

An image registry owns all of the image objects registered with it, and automatically disposes of them when the SWT Display that creates the images is disposed. 图像注册表拥有向其注册的所有图像对象,并在创建图像的SWT显示器被放置时自动将其丢弃。 Because of this, clients do not need to (indeed, must not attempt to) dispose of these images themselves. 因此,客户端不需要(实际上,一定不要尝试)自己处置这些映像。

ImageRegistry does also have a dispose method if you want to dispose of images earlier. 如果您想更早处置图像, ImageRegistry也提供了dispose方法。

Note: It is possible to create an ImageRegistry using your own ResourceManager , in this case it is up to the resource manager to arrange disposal. 注意:可以使用您自己的ResourceManager创建ImageRegistry ,在这种情况下,由资源管理器来安排处置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM