Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

process of installing UI delegate

 
krishna prasad gunasekaran
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please go to this url, so that you can understand my question.

http://java.sun.com/products/jfc/tsc/articles/architecture/ui_install/index.html

Question 1

1.UIManager.getUI(button);
2.uiDefaults.getUI(button);
3.Class.forName("class name");


these three methods reutrned the same result.In my case, the result was,
com.sun.java.swing.plaf.windows.WindowsButtonUI@ad80ad8

the first one is used by updateUI(), second one is used by hashtable(UIDefaults) of a particular look-and-feel.
why are we using the third one when it's job is already done by the previous two. it also leads us to some casting problem?


Question 2

we use class returned from Class.forName() to call createUI(). How to cast from Class to that particular component UI class? apart from this createUI() has a different declaration, it's static and takes a JComponent arg.

Krishna prasad
 
Brian Cole
Author
Ranch Hand
Posts: 923
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by krisp prasad:
Please go to this url, so that you can understand my question.

http://java.sun.com/products/jfc/tsc/articles/architecture/ui_install/index.html


That chart is slightly off, I think. For example, the line that reads uiDefaults.getUI("ButtonUI") should actually be uiDefaults.get("ButtonUI"), as UIDefaults.getUI() doesn't take a String parameter and it appears correctly nearer the top of the chart.

Question 1

1.UIManager.getUI(button);
2.uiDefaults.getUI(button);

(2.5) uiDefaults.getUIClass("class name"); // I added this to your quote
3.Class.forName("class name");


these three methods reutrned the same result.In my case, the result was,
com.sun.java.swing.plaf.windows.WindowsButtonUI@ad80ad8

the first one is used by updateUI(), second one is used by hashtable(UIDefaults) of a particular look-and-feel.
why are we using the third one when it's job is already done by the previous two.


I'm not sure what you mean by its "job is already done by the previous two." These are chained calls:
a) UIDefaults.getUIClass() returns the result of the call to Class.forName()
b) UIDefaults.getUI() returns the result of calling the static createUI() method (via reflection) on the Class returned by UIDefaults.getUIClass()
c) UIManager.getUI() returns the result of the call to UIDefaults.getUI()

So it's not surprising that (1) and (2) return the same value, and you are mistaken about (3) because Class.forName() returns WindowsButtonUI.class, not an instance of that class.

To add a bit of confusion, each of the steps (a), (b), and (c) may be short-circuited by a cache lookup. [In the case of (b) the java.lang.reflect.Method object is cached, but the createUI() method is always called. Often that method is implemented to return the same instance over and over.] So Class.forName("com.sun.java.swing.plaf.windows.WindowsButtonUI") should only ever be called once.

Question 2

we use class returned from Class.forName() to call createUI(). How to cast from Class to that particular component UI class? apart from this createUI() has a different declaration, it's static and takes a JComponent arg.


You can't cast from Class to ComponentUI, but why would you want to? You are correct that the Class instance is used to call createUI(). This is step (b) mentioned above.

The return type of createUI is ComponentUI, so I don't understand your casting trouble. (If you like you may cast it further. For example, feel free to cast the value returned from MetalButtonUI.createUI() from ComponentUI to MetalButtonUI. But this doesn't seem to be what you're complaining about.) Are you trying to reimplement the UIDefaults.getUI() method or something??

[edit: typos and a goof]
[ June 04, 2007: Message edited by: Brian Cole ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!