Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Feedback on design of Word-like application

Status
Not open for further replies.

borbjo

Programmer
Mar 29, 2002
33
0
0
NO
I would like some feedback on the design of this 'Word'-like application:

The application
---------------------
I'm implementing a 'Word' kind of application with Paragraph and Character styles. Character styles inherit information from the paragraph styles they belong to, and paragraph styles may or may not inherit from other paragraph styles.

Each document in my application consist of several 'frames' which contain JTextPanes with styles.

There is a Paragraph Style editor and a Character Style editor. The different styles may be used and shared amongst the different frames and pages in each document.

The user specifies which paragraph styles that should be available in each frame (the character styles just follow the paragraph styles since they all belong to one and only one paragraph style).

How I'm thinking of doing it
----------------------------------------
Each JTextPane (frame) contain a StyleContext which I add styles to. I do not distinguish between char/pstyles - both are created with StyleContext.addStyle()

Character styles will be Style's with the Paragraph Style as their resolving parent.

But how will I distinguish between character styles belonging to a paragraph style, and paragraph styles that have another paragraph style as their resolving parent?

I need a central Style repository - but I can't use StyleContext for this, as I need to be able to restrict the styles that are available for each 'frame'.

So I'm considering a singelton which holds all available StyleContext's - and one StyleContext for each JTextPane.

Possible problems; when styles are updated I need to go through all frames to make sure the same styles are updated.

The styles need to hold extra information - eg. database ids and such. I will just add them as attributes, e.g. style.addAttribute(DATABASE_ID_CONSTANT, new Integer(102)) - Are there any problems with this approach? Will all these custom attributes be copied with style.copyAttributes() etc?

I'm adding listeners to each style, so that the frames are updated and repainted with the new style info when the styles are changed though the style editors.

The frame formatting info will need to be saved to a database - so I need a way of getting a document, retrieving the paragraph styles used (and positions - from, to) and the character styles used (positions) and their databse IDs.

Any feedback on the approach appreciated :)
 
1. Review AttributeSet, Style, and StyledDocument swing interfaces.

2. Look into Composite, Flyweight and Decorator Gang of Four patterns.

3. Checkout for your persistence needs.

Seems like some of the functionality is already implemented, and some of the current concerns are implementation details - worry about persistence after the object model is fleshed out, and don't worry about limiting an object's cardinality until it's necessary (singleton).
 
Thanks for that reply dbleyl :) ..

I'm already using the Composite pattern by GoF, and I'm using JAXB as the layer between the JDBC and the client application.

The reason I would use singelton is to access the same object from several different classes (e.g. if I would like to access the same style repository from different frames)
 
One of my main problems is how objects that are in use could be edited by the user (eg. Styles). Because the user should be able to choose "OK" og "Cancel" in the dialog where he edits the styles that are in use in the document.

Should I clone() a style before the user edits it? If so, I would need to update all frames with the cloned style.

Another alternative I can think of is to implement an UndoableEditEvent for each style change, and then undo each change if the user presses cancel.
 
borbjo,

Consider using HTML as your doc structure,
and CSS to manage styles. This would allow
you to access and manipulate the documents from the
DOM. You would only need a JTextEditor that supported
HTML and CSS.
 
borbjo: You cannot solve this problem, the user has to.
Give him the possibility to change a 'named style' or 'create a new style based on the current' which is: 'change the current style and save it under new name'.

But using a central-style-db might be problematic.
a) How do people interchange documents?
b) Scenario: User changes a named style (Letter), not knowing, that this will affect documents he saved before with the same style.
Months later he opens an old letter, which now may look poor. How can he remember which setting he changed?
But ofcourse it can be the interest of the user, to change a bunch of documents.

The main question is: How can we get rid of these users! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top