Re: Copying a StyledDocument deeply
From: Thomas Weidenfeller (nobody_at_ericsson.invalid)
Date: 04/20/04
- Next message: Ben Wilson: "Re: how to convert a JTable to an image?"
- Previous message: vivian: "automated gui testing tools"
- In reply to: VI: "Copying a StyledDocument deeply"
- Next in thread: ak: "Re: Copying a StyledDocument deeply"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 20 Apr 2004 17:47:58 +0200
VI wrote:
> I
> immediately make a copy of this (to another instance oldDoc) in the
> constructor of the class (oldDoc = doc)
If "oldDoc = doc" is really your code (why didn't you show us your real
code?), then you are not copying the object, you are just duplicating
the reference. If this is the case, then of course comparing the objects
behind the references must result in them being equal, because both
references point to the very same object.
You are talking about StyledDocument, but that is an interface only.
Which class are you really using? But anyhow, AFAIR
DefaultStyledDocument and HTMLDocument don't support any convenient way
of deep-cloning (copying) them. The simplest but slightly inefficient
way might be to serialize/deserialize them to get a clone.
A better idea might be to register a document listener in order to be
informed about chnges.
In case you use HTMLDocument, you might want to examine the source code
and figure out the behavior of the c'tor
HTMLDocument(AbstractDocument.Content c, StyleSheet styles): Does it
clone arguments? Or do the getContent() and getStyleSheet() methods
return clones?
If they clone instead of just passing on references, a construct like
HTMLDocument backup =
new HTMLDocument(doc.getContent(), doc.getStyleSheet());
might give you what you want. I leave this as an excercise to you. The
source comes with every SDK in the scr.zip file.
/Thomas
- Next message: Ben Wilson: "Re: how to convert a JTable to an image?"
- Previous message: vivian: "automated gui testing tools"
- In reply to: VI: "Copying a StyledDocument deeply"
- Next in thread: ak: "Re: Copying a StyledDocument deeply"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|