java 如何更改 Netbeans 字体和颜色预览文档?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/382174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 12:10:57  来源:igfitidea点击:

How to Change Netbeans Fonts and Colors Preview Document?

javanetbeansfontscolorsoptions

提问by Saterus

Within the Netbeans 6.5's Tools -> Options -> Fonts & Colors -> Syntax dialog, you have the ability to change the look and feel of the Netbeans text editor. When you select a language, you are presented with a preview of your font/color scheme. However, when I preview Java, there are far more options for syntax changes than are being displayed in that preview window. If I were able to view a more robust piece of code, I'd be able to see the immediate effect of more of the options.

在 Netbeans 6.5 的工具 -> 选项 -> 字体和颜色 -> 语法对话框中,您可以更改 Netbeans 文本编辑器的外观。当您选择一种语言时,您会看到字体/配色方案的预览。但是,当我预览 Java 时,语法更改的选项远多于该预览窗口中显示的选项。如果我能够查看更强大的代码段,我将能够看到更多选项的直接效果。

How can I supply a preview document to view my font/color changes?

如何提供预览文档以查看我的字体/颜色更改?

UPDATE:

更新:

After looking into this some more, I've been able to narrow down the problem a bit. From what I can tell, everything in Netbeans is considered a plugin. The GUI editor is a plugin, and even the text editor is a plugin. This means that what ever piece of Netbeans that actually analyzes Java code and does syntax highlights is also a plugin (since Java is just one of many languages Netbeans highlights, it makes sense this is a plugin).

在对此进行了更多研究之后,我已经能够稍微缩小问题的范围。据我所知,Netbeans 中的所有内容都被视为插件。GUI 编辑器是一个插件,甚至文本编辑器也是一个插件。这意味着任何真正分析 Java 代码并执行语法高亮显示的 Netbeans 也是一个插件(因为 Java 只是 Netbeans 高亮显示的众多语言之一,所以它是一个插件是有道理的)。

I think fromvega is on the right track with his suggestion. The tutorial for creating a manifest file editing plugin pointed me in the right direction. The tutorial eludes to a file used as a sample document used for font/color previews. It tells you how to create one inside this new plugin project. (Located in "Registering the Options in the NetBeans System Filesystem", part 4. About 4/5 of the way down the page.)

我认为 fromvega 的建议是正确的。创建清单文件编辑插件的教程为我指明了正确的方向。本教程避开了用作用于字体/颜色预览的示例文档的文件。它告诉你如何在这个新的插件项目中创建一个。(位于“在 NetBeans 系统文件系统中注册选项”,第 4 部分。大约页面下方的 4/5。)

My next line of thought was to look for the Java syntax editing mode plugin and find this file and update it with a richer example file. I looked in the installation directory and came up empty, but I found what looks like the appropriate files within my user settings directory. There is a config directory with a lot of subfolders within my user directory (Windows: C:\Documents and Settings\saterus.netbeans\config).

我的下一个想法是寻找 Java 语法编辑模式插件并找到此文件并使用更丰富的示例文件对其进行更新。我查看了安装目录并发现它是空的,但我在我的用户设置目录中找到了看起来像合适的文件。在我的用户目录(Windows:C:\Documents and Settings\saterus.netbeans\config)中有一个包含许多子文件夹的 config 目录。

I've been poking around inside this directory a bit, but have only found the xml files the manifest tutorial talks about. I have been unable to find the extensionless sample file for the Java plugin that I believe should be there.

我一直在这个目录中闲逛,但只找到了清单教程中提到的 xml 文件。我一直无法找到我认为应该在那里的 Java 插件的无扩展示例文件。

Since I've hit a brick wall for the moment, I thought I'd toss it back to the SO community and see if you guys might make the last leap and find the solution.

由于我暂时碰壁了,我想我会把它扔回 SO 社区,看看你们是否能做出最后的飞跃并找到解决方案。

采纳答案by Tor Norbye

The document which is displayed (for each mime type) is specified in a particular folder in the "system file system" (which is a NetBeans concept which is a virtual file system composed from contributions from individual modules; this is how functionality is dynamically registered in NetBeans).

显示的文档(对于每种 MIME 类型)在“系统文件系统”(这是一个 NetBeans 概念,它是由各个模块的贡献组成的虚拟文件系统;这就是动态注册功能的方式)中的特定文件夹中指定在 NetBeans 中)。

Modules typically specify their system file system contributions in a file named "layer.xml" in the plugin. The create plugin templates typically offer to create this for you.

模块通常在插件中名为“layer.xml”的文件中指定它们的系统文件系统贡献。创建插件模板通常会为您创建。

For example, here's how the Python example is registered:

例如,以下是 Python 示例的注册方式:

<filesystem>
    ...
    <folder name="OptionsDialog">
        <folder name="PreviewExamples">
            <folder name="text">
                <file name="x-python" url="PythonExample.py"/>
            </folder>
        </folder>
        ...

Here, PythonExample.py is a sample file in the same directory as the layer file.

此处,PythonExample.py 是与图层文件位于同一目录中的示例文件。

Therefore, what you need to do is create a plugin which overrides the existing registration(s) for the mime type(s) you care about and provide alternate sample documents. You may need to hide the existing registration first (see the _hidden part from http://doc.javanb.com/netbeans-api-javadoc-5-0-0/org-openide-filesystems/org/openide/filesystems/MultiFileSystem.html).

因此,您需要做的是创建一个插件,该插件覆盖您关心的 MIME 类型的现有注册并提供备用示例文档。您可能需要先隐藏现有的注册(请参阅 _hidden 部分来自http://doc.javanb.com/netbeans-api-javadoc-5-0-0/org-openide-filesystems/org/openide/filesystems/MultiFileSystem.html)。

Hopefully this guides you in the right direction.

希望这会引导您朝着正确的方向前进。

However, in thinking about it, we probably ought to make the preview area editable - so people can cut & paste whatever codefragment they care about right in there. This wouldn't be persistent, so whenever you change languages you get the original samples back - but it provides a quick way to see your own code. This shouldn't be just for the Fonts & Colors customization, but for the Formatting preview panels as well.

然而,在考虑它时,我们可能应该使预览区域可编辑 - 这样人们就可以在那里剪切和粘贴他们关心的任何代码片段。这不会是持久的,因此每当您更改语言时,您都会返回原始示例 - 但它提供了一种查看您自己的代码的快速方法。这不仅适用于字体和颜色自定义,也适用于格式预览面板。

I've filed an issue against NetBeans for this: http://www.netbeans.org/issues/show_bug.cgi?id=155964

我为此向 NetBeans 提出了一个问题: http://www.netbeans.org/issues/show_bug.cgi?id=155964

-- Tor

-- Tor

回答by Roja Buck

Just for anyone who wants to alter this themselves it is possible on a unix machine to use grep to locate the file i.e.

对于任何想要自己改变它的人来说,可以在 unix 机器上使用 grep 来定位文件,即

grep -lr "some part of the current sample code" /path/to/netbeans

I used this method to locate the ruby example filename and from that identified that it is kept in org-netbeans-modules-ruby.jar as a file called RubyExample. By simply altering that file I was able to construct a better sample file for my own use.

我使用这种方法来定位 ruby​​ 示例文件名,并从中确定它作为一个名为 RubyExample 的文件保存在 org-netbeans-modules-ruby.jar 中。通过简单地更改该文件,我能够构建一个更好的示例文件供我自己使用。

Hope this helps someone!

希望这对某人有帮助!

回答by fromvega

I think you can only accomplish that with a new plugin, since you need somekind of parsing to define what is what.

我认为您只能使用新插件来实现这一点,因为您需要某种解析来定义什么是什么。

Give a look a these tutorials, I haven't read them in details but they seem to show you how to do what you want:

看看这些教程,我还没有详细阅读它们,但它们似乎向您展示了如何做您想做的事:

http://platform.netbeans.org/tutorials/nbm-mfsyntax.htmlhttp://www.antonioshome.net/kitchen/netbeans/nbms-coloring.php

http://platform.netbeans.org/tutorials/nbm-mfsyntax.html http://www.antonioshome.net/kitchen/netbeans/nbms-coloring.php