문제

I'm struggling with this problem for a week. I try to write a program in java that can edit ebooks. My choosed ebook format is fictionbook which contains its data in an xml like file. I can open this file and generate a sourceview in a JTextComponent. There are two togglebuttons in my editor preview and sourceview. They using the same JTextComponent for display. When the user clicks on the sourceview it display the choosen file source(plain xml). I generate the preview from this source by parsing the data i need to display.If i change something in the sourceview it will be displayed in the preview too because its generated from there, my problem is how can i made this backwards. So if i change something in preview it will change in the source too.

도움이 되었습니까?

해결책

It's kind of hard to see this as a JDOM-specific question. The underlying representation could be pretty much anything. Normally a preview is just that: a view of the end result that wouldn't be directly editable. If you wish to be able to edit both the source and through a WYSIWYG view, you'll need to investigate the model-view-controller pattern.

The underlying XML would be your model. Both the XML editor view and the WYSIWYG view (your current preview) would then be views AND controllers. Currently this is only the case for your XML editor, whereas the preview is nothing but a view.

Changing the underlying XML from the preview sounds difficult, unless each node can somehow be identified (like via an id attribute). You'll need some additional underlying data in your preview to do this coupling in the other direction.

I'm not certain a JDOM Document is the best model for your purposes. Maybe you're better of using something like JAXB to have simple JavaBeans to represent the model which can then be marshalled to XML and unmarshalled from XML. So you get:

                    model: JavaBeans with JAXB annotations
                      ^
                      |
    (directly) +--------------------------------------+ (through JAXB)
               |                                      |
WYSIWYG editor: view + controller             XML editor: view + controller

But that's just my first impression. Investigate existing editors to find out good method for doing this. Maybe checking out IDE plugins/modules could be interesting, since IDEs typically allow multiple types of editors to change an underlying data model.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top