word processing

B

bob

What sort of data structures would be best for storing a document for a
word processing program in memory (it supports images/text and various
font sizes/faces... think Microsoft Word)? I got this wrong in an
interview and am curious about it.
 
R

Roedy Green

What sort of data structures would be best for storing a document for a
word processing program in memory (it supports images/text and various
font sizes/faces... think Microsoft Word)? I got this wrong in an
interview and am curious about it.

JTextPane. It will work with HTML or RTF. You can cook up a simple
word processor in a few lines.

http://mindprod.com/jgloss/jtextpane.html
 
Z

zero

JTextPane is not a data structure, it's a GUI component.

There are plenty of ways to store text in memory, but I am partial to
arrays or linked lists of lines.

Would be hard to include the images, fonts, colours, ...

How about a tree-like structure with nodes that define the text attributes
and leaves with the actual text or embedded objects.

If you're looking for an existing Java class, then StyledDocument and its
implementing classes is the obvious choice. I believe a JTextPane uses a
StyledDocument internally too.
 
R

Roedy Green

JTextPane is not a data structure, it's a GUI component.

It uses the Document interface for the model part which would be
implemented for example by HTMLDocument.
 
C

Chris Smith

Roedy Green said:
It uses the Document interface for the model part which would be
implemented for example by HTMLDocument.

Yes, but in a quite profound sense, Jeff is right. JTextPane is NOT a
data structure. It's an interface, and with some effort can be
implemented to provide a way of accessing information from any number of
data structures.

For example, I have a back-burner project for work right now. We want
to implement Swing's Document to provide a transparent adapter to a W3C
DOM, such that the authoritative copy of the data is kept in the W3C
DOM, and the Swing Document class is only used to get data from there to
the JEditorPane for display. I could do the same thing for a different
data structure format that's not even remotely tree-based at all. If
so, you just make up the tree structure synthetically inside the model
adapter.

So no, JTextPane really isn't a data structure, nor does it imply any
specific data structure.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

Yes, but in a quite profound sense, Jeff is right. JTextPane is NOT a
data structure. It's an interface, and with some effort can be
implemented to provide a way of accessing information from any number of
data structures.

OP asked "What sort of data structures would be best for storing a
document for a word processing program in memory".

For that he needs both a GUI and memory model.

There is no rule that says you must answer every question literally.

A pox on any prissy nerd who bawls someone out for suggests reading up
on JTables when a newbies asks how do you store table data for display
..
 
M

Monique Y. Mudama

What sort of data structures would be best for storing a document
for a word processing program in memory (it supports images/text and
various font sizes/faces... think Microsoft Word)? I got this wrong
in an interview and am curious about it.

What was your answer?

Typically, an interview question should be about finding out whether
you can think through a problem, not necessarily being right. If they
had a single data structure in mind and marked you "wrong" for not
being a mind reader, well, that wasn't a good interview technique.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top