You know what I love about programming? The part where I get to solve interesting problems. You know what isn’t interesting? solving the same problem over and over again. Even less interesting is having to solve a problem that I know someone else has solved but where I can’t copy the answer. That’s not only uninteresting, it’s frustrating.
So, I’m writing a tool in Java and I need for it to allow the user to input styled text (simple typeface stuff – italics, bold, strikethrough). We’re not changing font family and we’re not laying it out for print; we just need to be able to capture this style stuff. And then persist it. Ultimately, it’s going to be stored as XHTML. So I look around, and sure enough, JTextPane turns out to be the thing I need to be able to display the text. Pretty soon we’ll want to have inline images that the text can flow around, and that component can handle those things. So, that’s great.
But wait, how do I hook it up so that the person using the program can start entering the text? How do I let the user switch styles? Shouldn’t there be some nice toolkit that lets me just do something like:
JEditorWidget myWidget = new JEditorWidget();
myFrame.setContentPane(myWidget);
…and that will get me something that looks like the swell What You See Is (Mostly) What You See editor that I’m using right now to write this post on WordPress.
But no. Instead, I get to wire up the editor pane and create style buttons and menu items and hook up action event listeners so that, in effect, even though all the widgets already exist I am still having to wire them up myself in order to make a simple word processor. Even though this is a task that has been done so many times that it’s a freakin’ sample app in the Java tutorial. But still, if you want to enter and edit styled text, you still have to create all the widgets and wire them up. This is different from, say, HttpClient or Log4J. This seems more like PGP, where the guys who write the library (for any value of library) seem disinclined to give you any clue as to how to use the damned thing. Thank heaven for StackExchange, where I can at least find a few examples of people who also had to write their own word processors.
Wow, wouldn’t it be rad if there were a library that just offered a scrollable editor pane with a row of style buttons across the top and it just took care of handling the current selection and applying the selected style to the current selection? I would actually pay money for that.
[EDIT:] Turns out that a bit more diligent searching results in a hit! Turns out that there is a commercial product that seems to do exactly what I want. I’ve downloaded the demo; we’ll see if I can get it to do what I need.
That’s one of my big frustrations with some of Apple’s iOS frameworks. A lot of it is entirely awesome – but some of it is only about 25-50% there. I want to have a map that does directions *in my app* OR that returns to my app when you arrive – nope. I want a camera view as good as the built in one, but that lets you take multiple pictures – nope. It’s not rocket science, and I am not the only one that wants this. It seems pretty obvious – why doesn’t it exist?