在 Netbeans 平台中处理和显示没有文件扩展名的文件的最佳方式?

发布于 2024-12-08 12:37:56 字数 972 浏览 0 评论 0原文

我有一个必须为我工作的公司处理的项目,这基本上意味着我必须处理和显示没有任何文件扩展名的文件。我无法更改他们生成这些文件的方式,因此我需要一些有关处理此类文件的最佳方法的建议。 DataSystems API 似乎只处理带有扩展名的文件,那么这是否意味着我必须只使用 FileSystems API?如果是这样,我将欣赏使用 FileObject 作为它们实际表示的 Node 和 Children 类的一些示例。

万分感谢,非常感谢任何帮助。

在花了一些时间阅读 Netbeans 平台网站上提供的材料后,我对上述目标有一些疑问。

为了澄清我的目标: 1. 我有一个文件夹(在应用程序安装路径之外),其中包含没有扩展名的文件。每个文件代表一个兴趣点,包含空格分隔的文本数据,这些数据稍后将用于通过各种绘图软件绘制图形。 2. 我想将这些文件显示为一个模块中的节点,并可能使用一个单独的模块来更新这些文件。更新将包含一个按钮,该按钮将导致下载压缩文件、解压缩该文件、读取其内容并解释该内容以确定如何更新文本数据文件。 3. 也许在节点表示的 FileObject 上有内容更改侦听器,以便显示/指示(可能通过图标更改?)文件内容的更改。 4. 我还希望能够在文本编辑器中显示由单击的节点表示的 FileObject 中包含的文本数据(只读),但这就是我需要能够对这些 FileObject 和节点执行的操作。代表他们。 4. 在 Nodes 和 ExplorerView API 的帮助下,让另一个模块显示迄今为止下载的所有压缩文件(假设我再次想要显示“下载”文件夹中的所有文件)。在这里,我可能想向这些文件添加“语义含义”,因为它们不是普通的 zip/Jar 文件,因此可能对此模块使用 DataSystems API。

此时我脑海中最主要的问题是,将该文件夹中的所有文件表示为节点的正确方法是什么,以及该节点的子类和相应的 Children 类是什么样子。在示例中使用“APIObject”,如果不需要在第一个模块中使用 DataSystems API,我想设置用 FileObject 替换该对象?

我想再次感谢您的帮助,真的很感激。

I have a project that i have to tackle for the company I'm working for and it basically means I have to handle and display files without any file extension. I'm not able to change the way they produce these files so I need some advice on the best way to deal with these kinds of files. The DataSystems API seems to only take care of files with extensions, so does that mean I have to make use of the FileSystems API only? If so I would appreciate some samples of Node and Children classes using the FileObject as what they actually represent.

Thanks a mil, really appreciate any help.

After spending some time reading through the material available from the Netbeans Platform website, I'm left with a few questions regarding my goal as mentioned above.

To clarify my objective:
1. I have a folder (outside of the application installation path) which contains files without extensions. Each file represent a point of interest, containing space-separated text data that will later be used to draw graphs by various graphing softwares.
2. I want to display these files as nodes in one module with perhaps a separate module for updating of these files. Updating will encompass a button that will cause the downloading of a compressed file, uncompressing this file, read its contents and interpret that contents to determine how the text data files will be updated.
3. Perhaps have content change listeners on the FileObjects represented by the nodes in order to display/indicate (perhaps via icon change?) the change of file contents.
4. I also want to be able to display the text data (read-only) contained in the FileObject represented by the clicked node in a text editor, but that is all I need to be able to do with these FileObjects and the nodes that represent them.
4. Have another module displaying all the compressed files downloaded to date (assuming that again I will want to display all the files in a 'download' folder) with the help of the Nodes and ExplorerView API. Here I might want to add 'semantic meaning' to these files since they are not average zip/Jar files, thus perhaps using the DataSystems API for this module.

The most dominant question in my mind at this point is what the correct way would be to represent all the files in this folder as nodes, and what this node's subclass and the corresponding Children class would look like. In the examples the "APIObject" is used, I want to set about replacing that object with FileObject if it is not necessary to use the DataSystems API in the first module?

Again I want to thank you for any help, it really is appreciated.

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

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

发布评论

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

评论(2

最初的梦 2024-12-15 12:37:57

好的,阅读您的更新。所以,我想说,在某些时候您肯定需要 DataObject。要点:

  1. 要将 DataObjects“链接”到 FileObjetcs,您需要一个 DataLoader。它是一个 DataObjects 工厂,仅针对某些类型的文件被激活。基本上:

    DataObject dataObject = DataObject.find(fileObject);
    

    参见http://wiki.netbeans.org/DevFaqDataLoader

  2. 虽然它对于 DataLoader 来说很常见使用文件扩展名来确认文件类型,这不是唯一的方法。事实上,DataLoaders 使用 MIME 类型,并且 MIMEResolver 类可用于将 MIME 类型分配给给定文件。同样,最简单的事情是查看扩展名,但您的代码也可以查看内容来猜测(http://wiki.netbeans.org/DevFaqFileRecognition)。基本上,您必须使用单一方法来实现 MIMEResolver:

    public String findMIMEType (FileObject fileObject);
    

它可以做任何它想做的事情,然后将 MIMEResolver 注册到系统中(请参阅 http://bits.netbeans.org/dev/javadoc/org-openide-filesystems/org/openide/filesystems/doc-files/HOWTO-MIME.html 了解详细信息)。

此时,DataObject.find() 将能够实例化您自己的 DataObject 子类。

  1. DataObject 有一个 createNodeDelegate(),可用于创建一个 Node 并将其放入视图中进行渲染。它将自动使用 DataObject 的名称进行渲染,默认情况下是 FileObject 的名称。如果我没记错的话(但目前我不确定),平台本身应该能够为目录创建正确的 DataObject,这将自动为每个包含的文件创建一个带有子节点的 Node。

  2. 要查看内容,您可以查看编辑器 API。不幸的是我不熟悉它,但一般来说它应该可以通过使用 MIME 类型再次激活,它将您之前定义的 MIME 类型与“纯文本”样式相关联。看这里 http:// /bits.netbeans.org/dev/javadoc/org-openide-text/org/openide/text/doc-files/api.html 并且不要担心文档的长度,因为它也解释诸如更改您不感兴趣的内容。

  3. 一旦您能够呈现文件树,请使用 FilterNode 从视图中隐藏一些子级(请参阅 http: //wiki.netbeans.org/DevFaqNodesDecorating)。

Ok, read your update. So, I'd say that definitely at some point you need DataObjects. The key points:

  1. To "link" DataObjects to FileObjetcs you need a DataLoader. It's a factory of DataObjects, that gets activated only for some kind of files. Basically:

    DataObject dataObject = DataObject.find(fileObject);
    

    See http://wiki.netbeans.org/DevFaqDataLoader

  2. While it's common for a DataLoader to use a file extension to ack a file type, it's not the only way to go. Indeed, DataLoaders use MIME types and a MIMEResolver class can be used to assign a MIME type to a given file. Again, the easiest thing is to look at the extension, but your code can also look at contents to guess (http://wiki.netbeans.org/DevFaqFileRecognition). Basically you have to implement your MIMEResolver with a single method:

    public String findMIMEType (FileObject fileObject);
    

that can do whatever it wants, then you register the MIMEResolver into the system (see http://bits.netbeans.org/dev/javadoc/org-openide-filesystems/org/openide/filesystems/doc-files/HOWTO-MIME.html for details).

At this point, DataObject.find() will be able to instantiate your own subclass of DataObject.

  1. DataObject has got a createNodeDelegate() which can be used to create a Node to put into an view for rendering. It will automaticaly render with the name of the DataObject, which by default is the name of the FileObject. If I recall correctly (but at the moment I'm unsure), the Platform on its own should be able to create the proper DataObject for a directory, which would automatically create a Node with children for each contained file.

  2. For looking at contents, you might have a look at the Editor API. Unfortunately I'm not acquainted with it, but generically speaking it should be activatable again by using MIME types, that its associating the MIME type you've previously defined to a "plain text" style. Look here http://bits.netbeans.org/dev/javadoc/org-openide-text/org/openide/text/doc-files/api.html and don't be worried by the lenght of the document, as it also explains stuff such as changing the contents, that you're not interested to.

  3. Once you are able to render a tree of files, by using FilterNode to hide some children from view (see http://wiki.netbeans.org/DevFaqNodesDecorating).

神魇的王 2024-12-15 12:37:57

首先,一些基本点:

  1. 文件由文件系统 API 表示,因此您肯定会使用它。 FileObject 管理扩展名不是问题,因为如果您的文件没有扩展名,它将是一个“”字符串。

  2. DataObjects 是另一块。您使用它们来表示由文件(准确地说是 FileObject)支持的模型实体并且具有一些语义(通常通过子类化 DataObject 并添加方法来实现)。对于“某些语义”,我的意思不仅仅是拥有一堆数据(例如字节序列),而是被解释的数据。我的意思是:如果您的应用程序要提供文件系统资源管理器的典型功能,即复制、移动、删除文件等……,FileSystems API 就足够了:您不需要解释数据。例如,如果您想要实现一个照片处理应用程序,它还提供过滤等功能...,您可能需要有一个 PhotoDataObject 子类 DataObject,您可以在其中放置额外的语义。这意味着具有从文件读取数据并创建 BufferedImage 或其他表示形式的方法。这只是一个粗略的介绍方式,但我们可以稍后细化细节。当然,DataObject 比 FileObject 更加复杂,您应该仅在需要时才使用它们。

  3. 您关于节点和子项的问题与显示内容有关,而不是操作它(对此 DataObject 和 FileObject 就足够了)。 Nodes API 是用于创建表示模型的通用 API,表示模型是在屏幕上呈现的一种数据结构。它可以是您想要的任何内容,当然包括文件系统或数据对象。我没有看到没有扩展名的文件有任何具体问题,就好像它们没有扩展名一样,它们只会在没有扩展名的情况下呈现。在任何情况下,对 Node 进行子类化,您都可以根据需要控制在屏幕上呈现内容的方式。

要提供一些有意义的代码示例,您需要从我刚刚在第 1、2 和 3 点中描述的角度指定更多您需要的内容。

First, some basic points:

  1. Files are represented by the Filesystems API, so you'll be using it for sure. It's not a problem that FileObject manages an extension, as it will be a "" string in case your files don't have an extension.

  2. DataObjects are another piece. You use them to represent a model entity which is backed by a file (a FileObject, to be precise) and has got some semantics (that you usually implement by subclassing DataObject and adding methods). With "some semantics" I mean something more than merely having a bunch of data such as a sequence of bytes, but data that are interpreted. I mean: if your application is going to provide the typical functions of a file system explorer, that is copying, moving, deleting files etc..., the FileSystems API is enough: you don't need to interpret data. If you e.g. want to implement a photo manipulation application, which also offers functions such as filtering etc..., it's likely that you need to have a PhotoDataObject subclassing DataObject where you put the extra semantics. This implies having methods for reading the data from the file and creating e.g. a BufferedImage, or another representation. This is just a rough way to introduce things, but we can refine to details later. DataObjects are of course and additional complexity over FileObjects, and you should use them only if you need them.

  3. Your question about Nodes and Children is related to displaying stuff, rather than manipulating it (for which DataObject and FileObject are enough). The Nodes API is a generic one for creating a presentation model, that is a data structure that is rendered on the screen. It can be anything you want, of course including a FileSystem or DataObject. I don't see any specific problem with files without extension, as if they don't have an extension they will be just rendered without extension. In any case, subclassing Node you can control the way stuff is rendered on the screen as you want.

To provide some meaningful code example requires that you specify more what you need, in the perspective that I've just described in points 1, 2 and 3.

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