用 Java 设计源代码编辑器,设计问题:

发布于 2024-12-18 03:46:51 字数 450 浏览 0 评论 0原文

我开始用 Java 编写一个源代码编辑器作为个人项目/爱好。在我走上任何可怕的道路之前,我想问几个问题:

  • JTextPane 是用于编辑文本的合适组件吗?就我见过的例子而言,在大文件中设置文本样式似乎会变得非常麻烦,甚至可能非常慢/内存效率低下,因为在样式中使用字符串数组,它可能很快就会变得非常大。 (注意:除了编辑器中的文本之外,我还需要能够插入组件,例如图像。我只在 JTextPane 中看到了这样做的能力。)

    • 在内部使用 XML/HTML 标记文本并使用像 JPanel 这样简单的东西来渲染它是否会是一种计算/内存效率更高但不太简单的路线?
  • 将文件源加载到程序中时,更好的设计选择是加载整个文件,还是仅加载正在查看的内容,再加上一个小到中等大小的缓冲区?

  • 当我踏上漫长的爱好之旅时,任何其他建议将不胜感激!

I'm beginning to write a source-code editor in Java as a personal project/hobby. Before I lead myself down any awful paths, I would like to ask a few questions:

  • Is a JTextPane an appropriate component to use for editing the text? As far as examples I have seen go, it looks like it could become very troublesome and perhaps even very SLOW/memory inefficient to style text in large files, as String arrays are used in styling, which could become very large very quickly. (Note: I require the ability to insert components, such as images, in addition to text in my editor. I have only seen the ability to do so in JTextPane.)

    • Would internally marking up the text with XML/HTML and using something as simple as a JPanel to render it be a more computationally/memory efficient, albeit less simple, route?
  • When loading the source of the file into a program, would a better design choice be to load the entire file, or load only what is being viewed, plus a small to moderately-sized buffer?

  • Any other advice as I embark on a long journey of a hobby would be greatly appreciated!

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

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

发布评论

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

评论(1

梦萦几度 2024-12-25 03:46:51

Q1: 你尝试过吗?这当然足以开始,并且在此过程中您会遇到其他问题。只是尽量不要专门围绕它进行设计。也就是说,不要将自己安排在一个角落,以便以后可以根据需要切换。

Q2:我对此表示怀疑。

Q3:将整个文件加载到内存中 - 毫无疑问。您的计算机有大量 RAM,因此请充分利用它。

Q4:尝试几种不同的快速原型。几次失败的尝试并没有什么问题,只要你没有投入太多,并且在尝试时你能学到很多东西。

Q1: Have you tried it? Its certainly enough to start with, and you'll run into other issues along the way. Just try not to design around it exclusively. i.e. don't program yourself into a corner so you can switch later if you want.

Q2: I doubt it.

Q3: Load the entire file into memory - hands down. Your computer has a lot of RAM, so use it.

Q4: Try several different quick prototypes. There's nothing wrong with a few failed attempts if you don't invest too much in them and you learn a lot when you do them.

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