Paul,

You can subclass UIDefaults.ProxyLazyValue if you wish, but it will
only work if you override createValue and do the class loading yourself
in which case you're not really gaining anything by subclassing
UIDefaults.ProxyLazyValue rather than UIDefaults.LazyValue.  But this
a matter of taste; you end up doing the same work anyway.

It's a shame the Swing team didn't include the opportunity to pass
a classloader along with the class name into UIDefaults.ProxyLazyValue's
constructors.  Then you wouldn't have to duplicate the work they've
already done.

Regards

Dave Wathen
Goldman Sachs Asset Management
3rd Floor, Procession House
55 Ludgate Hill
London EC4M 7JN
+44 (0)20-7774-2998

It is not necessary to understand things in order to argue about them.
(Caron de Beaumarchais)


-----Original Message-----
From: Farwell, Paul [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 26, 2001 1:12 PM
To: 'Wathen, Dave '; ''[EMAIL PROTECTED]' '
Subject: RE: problem with UIDefaults.ProxyLazyValue


You are correct about the classloader issue. I experimented by making a
duplicate of UIDefaults.ProxyLazyValue and moved it to my own package. It
works perfectly fine. It relies on a simple call to Class.forName() which
apparently uses the bootstrap classpath within the javax.swing package but
uses the user classpath when it resides in my own package.

Since this is an applet, I cannot really muck with the bootstrap classpath,
but I can try to subclass ProxLazyValue. But I have a hunch that the call to
Class.forName() must be in my own package, not the javax package. I will
probably end up creating my own version of the class.

-----Original Message-----
From: Wathen, Dave
To: 'Farwell, Paul'; '[EMAIL PROTECTED]'
Sent: 2/26/01 3:23 AM
Subject: RE: problem with UIDefaults.ProxyLazyValue

Paul,

I think this is a class loader problem rather that a PLAF specific
problem.
The javax.swing classes are included in rt.jar and so will be loaded by
the
bootstrap class loader.  Classes in your application are not visible to
the
bootstrap class loader.  I can think of two solutions to this:

1) Jar up the classes you want to be lazily loaded and pass in the jar
using
the -Xbootclasspath/a:path option.  This should make your classes
visible to
the bootstrap class loader.

2) Subclass UIDefaults.LazyValue so that createValue does your own lazy
loading. This way you get many instances of your subclass of
UIDefaults.LazyValue instead of many instances of
UIDefaults.ProxyLazyValue,
and you still get the lazy loading.

(There is actually option 3: move the javax.swing classes out of rt.jar
but
I suspect that would be a breach of the licence.)

Regards

Dave Wathen
Goldman Sachs Asset Management
3rd Floor, Procession House
55 Ludgate Hill
London EC4M 7JN
+44 (0)20-7774-2998

It is not necessary to understand things in order to argue about them.
(Caron de Beaumarchais)


-----Original Message-----
From: Farwell, Paul [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 23, 2001 6:45 PM
To: '[EMAIL PROTECTED]'
Subject: problem with UIDefaults.ProxyLazyValue


Here's a question for a Look and Feel guru out there. Can I use
ProxyLazyValue to call my own methods? It appears to work only when
loading
classes from core JDK packages.

Our application does a fair amount of initialization of UIDefaults when
it
launches. Only a subset of the UI components are used by any individual
applet, so I want to load resources in a 'lazy' way, in the same way
that
BasicLookAndFeel and MetalLookAndFeel do. I borrowed the following code
from
these classes.


package com.kronos.wfc.wfp.uiframework;

public class GUIResources {
        
        public static void installLookAndFeel() {

      // Create a ProxyLazyValue for a tree icon:
      Object treeExpandIcon = new UIDefaults.ProxyLazyValue(
             "com.kronos.wfc.wfp.uiframework.GUIResources",             
             "getLazyExpandIcon");
        
                Object[] settings = {
                        // ...

         // lazily load the tree icons since the tree is not
         // used in most applets
         "Tree.expandedIcon", treeExpandIcon,
         "Tree.selectionBackground", selectionBackground,

                        // etc.
      };

      UIDefaults defaults = UIManager.getDefaults();
      defaults.putDefaults(settings);

        }

           // this method should be called 'lazily':

   public static Object getLazyExpandIcon() {
      System.out.println("Lazy request Exand image ");
      return getImage("/demoimages/minus.gif");
   }
}

It appears that the classloader cannot locate the class
("com.kronos.wfc.wfp.uiframework.GUIResources") with the lazy method. I
have
tripled check that the classname has been provided correctly.

Any Idea what the problem is?

(BTW - Using UIDefaults.LazyValue() DOES work, but that approach causes
the
creation of so many inner classes that it defeats the purpose of the
optimization).

Problem creating com.kronos.wfc.wfp.uiframework.GUIResources with method
getLazyExpandIcon and args { : java.lang.ClassNotFoundException:
com/kronos/wfc/wfp/uiframework/GUIResources

java.lang.Exception: Stack trace

        at java.lang.Thread.dumpStack(Thread.java:993)

        at
javax.swing.UIDefaults$ProxyLazyValue.createValue(UIDefaults.java:670)

        at javax.swing.UIDefaults.get(UIDefaults.java:145)

        at javax.swing.MultiUIDefaults.get(MultiUIDefaults.java:39)

        at javax.swing.UIManager.get(UIManager.java:536)

        at
javax.swing.plaf.basic.BasicTreeUI.installDefaults(BasicTreeUI.java:593)

        at
javax.swing.plaf.basic.BasicTreeUI.installUI(BasicTreeUI.java:525)

        at
javax.swing.plaf.metal.MetalTreeUI.installUI(MetalTreeUI.java:83)

        at javax.swing.JComponent.setUI(JComponent.java:325)

        at javax.swing.JTree.setUI(JTree.java:537)

        at javax.swing.JTree.updateUI(JTree.java:553)

        at javax.swing.JTree.<init>(JTree.java:513)

        at
com.kronos.wfc.wfp.uiframework.component.KronosTree.<init>(KronosTree.ja
va:1
87)

        at
com.kronos.wfc.applets.appletdemo.DemoTreePanel.init(DemoTreePanel.java:
84)

        at
com.kronos.wfc.applets.appletdemo.DemoTreePanel.<init>(DemoTreePanel.jav
a:35
)

        at
com.kronos.wfc.applets.appletdemo.SimpleRootPanel.createInitialDisplay(S
impl
eRootPanel.java:46)

        at
com.kronos.wfc.applets.appletdemo.SimpleRootPanel.<init>(SimpleRootPanel
.jav
a:21)

        at
com.kronos.wfc.applets.appletdemo.SimpleApplet.onLoad(SimpleApplet.java:
13)

        at
com.kronos.wfc.wfp.uiframework.baseapplet.KronosApplet.runBackgroundTask
(Kro
nosApplet.java:450)

        at
com.kronos.wfc.wfp.uiframework.utility.BuilderThread.run(BuilderThread.j
ava:
73)



_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to