How to repropagate resolved styles?

J

Jan Burse

Dear All

Maybe somebody could help me with the following. I am using
two styles as follows:

private Style output;
private Style input;

SimpleAttributeSet aset = new SimpleAttributeSet();
aset.setResolveParent(input);
replaceRange("Hello", 0, 0, aset);

SimpleAttributeSet aset = new SimpleAttributeSet();
aset.setResolveParent(output);
replaceRange(" World!", 5, 5, aset);

What get is a mixed attributed text, but the attribute was
provided via resolve parent. This works fine, the text comes
out as expected.

Now I am doing a side effect as follows:

StyleConstants.setXXX(input, XXX).
StyleConstants.setXXX(output, XXX).
repaint();

The repaint has no effect. The text is shown the same as before.
But astonishingly when I do the following:

setEditable(false);
setEditable(true);

The resolve parent styles repropagate and the text changes as if
the resolve parents were logical styles on character level. Is
there another more proper way then calling setEditable twice, to
cause this update? Maybe something needs to be done earlier on, such
as registering the styles somewhere?

Any help appreciated.

Best Regards
 
J

Jan Burse

Jan said:
The repaint has no effect. The text is shown the same as before.
But astonishingly when I do the following:

setEditable(false);
setEditable(true);

The resolve parent styles repropagate and the text changes as if
the resolve parents were logical styles on character level.


I did some diggging. The setEditable() does fire a property change
event with the property name "editable", which in turn calls in
BasicTextUI the following method:

/**
* Flags model changes.
* This is called whenever the model has changed.
* It is implemented to rebuild the view hierarchy
* to represent the default root element of the
* associated model.
*/
protected void modelChanged() {
// create a view hierarchy
ViewFactory f = rootView.getViewFactory();
Document doc = editor.getDocument();
Element elem = doc.getDefaultRootElement();
setView(f.create(elem));
}

Can I cause a JTextPane to do a model rebuild as above
without firing a property change event? Problem is
I have to fire two property change events, one
true -> false
And another:
false -> true
Because the fire property change method checks whether
the old property value equals the new property value. And
does nothing when they are equal.

So is there a more direct way to cause a model change
than via multiple fire property change events?

Bye
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top