<Swing Dev> Extension method for AbstractDocument.Content?

Paulo Levi i30817 at gmail.com
Fri Jun 29 20:13:01 UTC 2012

On Fri, Jun 29, 2012 at 1:40 PM, Pavel Porvatov
<pavel.porvatov at oracle.com>wrote:

>  Hi Paulo,
> Hi Pavel.
> On Thu, Jun 21, 2012 at 2:13 PM, Pavel Porvatov <pavel.porvatov at oracle.com
> > wrote:
>> Hi Paulo,
>>  Hi. I've noticed that DefaultStyledDocument has a slowness issue when
>>> inserting text. Even if you subclass it and expose the faster method:
>>> protected void insert(int offset, ElementSpec[] data)
>>> the body of the method still uses a stringbuilder to append all char[]
>>> inside of the data before actually inserting into the content.
>>> This is because the only method for insertion in the default content
>>> interface is:
>>> public UndoableEdit insertString(int where, String str)
>>> Now if there are going to be extension methods in java 8, it would be
>>> nice to have a
>>> public UndoableEdit insert(int where, int index, int length, char[] str)
>>> default {
>>>   return insert(where, new String(index, length, str);
>>> }
>>  In which class do you suggest to add the new method?
> It would need to be part of AbstractDocument.Content with the new
> extension method feature in order to be able to be part of the public
> interface of Content and be useable generally without casts.
> Unfortunately we can't do that because of backward compatibility.

Why not? (this for java 8 with extension methods). I admit i hadn't thought
it through for* *javax.swing.text.GapContent
Since it's not final, using instanceof for the same effect in
DefaultStyledDocument.insert(int offset, ElementSpec[] data)
in the would be be a bad idea since the Content can be replaced.

However, with a extension method that only calls the string version in the
Content interface, and overriding that method in GapContent to copy the
char[]'s directly, and using that new Content method in
DefaultStyledDocument.insert(int offset, ElementSpec[] data)
would have the same effect.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20120629/fdff3b0c/attachment.html>

More information about the swing-dev mailing list