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!
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.