I posted this question over in the '
Java Intermediate' forum, but thought the nature of my question might be better suited for this forum.
Without going into too much background detail, I need to parse a bunch of words separated by spaces, like a long paragraph, into a list (probably an ArrayList.) Each element in the list will be a
String containing a section of the paragraph not to exceed a given length. I don't want to split any words. This is a non-graphical application (it's a web application.) This processing will be done in preparation to print onto (annotate) an image file.
In other words, I need a non-graphical
word wrapper.
I could write a class that does pretty much I've described to this point (although any sample code someone else already has working would be much appreciated.) The real kicker is that I want to be able to specify a font size and face for the method to take under consideration in calculating the contents of each String. I would need to somehow specify a maximum number of pixels(?) as the length of each line.
This class would also need to calculate the offset between the 'sentence' Strings to print them down the page (the image.)
Here's a high-level use case of how I'd envision this to work:
TextWrapper tw = new TextWrapper();
tw.setTextToWrap("Here's the stuff we want to wrap all over the place, blah, blah, blah");
tw.setFont(new Font("Arial",Font.PLAIN,10));
tw.setMaxPixels(1000);
tw.wrapIt();
for (int i = 0; i < tw.getNumLines(); i++) {
String nextLine = (String)tw.getLine(i);
// write out each line
}
Any suggestions to help me get started in the right direction on this? Thanks in advance for any assistance,
Rick <><