How to repropagate resolved styles?

Discussion in 'Java' started by Jan Burse, Aug 24, 2011.

  1. Jan Burse

    Jan Burse Guest

    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
    Jan Burse, Aug 24, 2011
    #1
    1. Advertising

  2. Jan Burse

    Jan Burse Guest

    Jan Burse schrieb:
    > 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
    Jan Burse, Aug 25, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zoro
    Replies:
    2
    Views:
    3,028
    =?ISO-8859-1?Q?Nicolai_J=F8rgensen?=
    Jul 5, 2003
  2. =?ISO-8859-1?Q?Dominik_Fr=F6hlich?=

    Resolved Signals

    =?ISO-8859-1?Q?Dominik_Fr=F6hlich?=, Feb 9, 2004, in forum: VHDL
    Replies:
    1
    Views:
    583
    Tim Hubberstey
    Feb 9, 2004
  3. jozo
    Replies:
    1
    Views:
    2,198
    Ralf Hildebrandt
    May 16, 2004
  4. Agusitn Rodriguez

    System.Web.Mail Issues Resolved

    Agusitn Rodriguez, Aug 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    294
    Jacob Yang [MSFT]
    Aug 18, 2003
  5. Efy.
    Replies:
    1
    Views:
    528
    Nicole Calinoiu
    Sep 22, 2003
Loading...

Share This Page