<Swing Dev> [9] Review request for 8132119 Provide public API for text related methods in SwingUtilities2

Andrej Golovnin andrej.golovnin at gmail.com
Mon Jan 25 09:44:39 UTC 2016


Hi Alexandr,

> Could you review the updated fix:
> http://cr.openjdk.java.net/~alexsch/8132119/webrev.07/

src/java.desktop/share/classes/javax/swing/plaf/ComponentUI.java:

- in the line 56 there is one space too much before the "private" keyword.
- the empty line 91 is not needed.

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java:

- the line 74 can be removed.

src/java.desktop/share/classes/sun/swing/SwingUtilities2.java:

- in the line 2101 javadocs should mention that the component may be null.
  At least SwingUtilities2.clipStringIfNecessary allows it.

src/java.desktop/share/classes/javax/swing/plaf/TextUIDrawing.java:

- in the line 103 javadocs should mention that the component may be null.

>
> - public TextUIDrawing interface is added to the javax.swing.plaf package
> - public "TextUIDrawing getTextUIDrawing()" method is added to the
> ComponentUI class
> - L&F sets an instance of the TextUIDrawing to look and feel defaults using
> "uiDrawing.text" property
> - Look and Feel delegates use the instance of the TextUIDrawing for text
> drawing and measuring

Some thoughts on the current design/implementation:

By adding a field to the ComponentUI class the current implementation increases
memory consumption for all Swing applications. And you get the feeling that
there are different implementations of TextUIDrawing per ComponentUI instances.
Personally I can't imagine to have different implementations of
TextUIDrawing for
a given LookAndFeel. If I would design/implement it, then I would
implement it as
a property of the LookAndFeel class (similar to LayoutStyle) and not
the ComponentUI.
Developers can use then the following code to obtain the instance of
TextUIDrawing:

UIManager.getLookAndFeel().getUIDrawing() // or
UIManager.getLookAndFeelUIDrawing() // use this static method as a
short cut for the line above.

You can use this methods then in JDK too.

And maybe rename the TextUIDrawing class to just UIDrawing and add
more useful methods,
e.g. a method to create a composite font, a method to convert DLUs to pixels.

Best regards,
Andrej Golovnin



More information about the swing-dev mailing list