The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » Swing & AWT

Thread: Synth PLAF: How to define a fallback Look and Feel?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 10 - Last Post: Oct 13, 2006 3:43 AM by: kleopatra
stitzl

Posts: 22
Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 9, 2006 9:42 AM
  Click to reply to this thread Reply

Hi there,

I want to make an existing GUI skinnable by using the Synth pluggable look and feel. But I don't want to write the skins from scratch -- I'd rather like them to default to the given system look and feel, eg. the Windows look and feel on XP.

As Synth does not do this on it's own and rather shows blank panels and buttons without borders, has anybody an idea if a fallback on system defaults is possible at all?

I thought about setting the system L&F and defining Synth as the auxiliary look and feel, thus forcing the MultiLookAndFeel to combine them... Would that work?

Any thoughts on this topic?

Thanks for your input,
Lars

stitzl

Posts: 22
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 10, 2006 12:35 AM   in response to: stitzl
  Click to reply to this thread Reply

Just an update, as you all seem to be as clueless as I am: Using the system look and feel as the default, an Synth as an auxiliary L&F, thus triggering the use of the multiplexing look and feel represented by the MultiLookAndFeel class in the javax.swing.plaf.multi package like this
System.setProperty("swing.auxiliarylaf", SynthLookAndFeel.class.getName());
System.out.println(UIManager.getAuxiliaryLookAndFeels());
 
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
WILL NOT WORK -- as both provide graphical UI elements. Result: Both UIs are rendered on top of each other. :-(


Message was clarified by: stitzl


stitzl

Posts: 22
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 10, 2006 2:00 AM   in response to: stitzl
  Click to reply to this thread Reply

Another update: The naive approach to merge the UIDefaults of the Synth L&F with the UIDefaults of the Windows L&F won't work either. However, while the following makes the app completely unskinnable
    public static void main(String[] args) throws Exception {
        SynthLookAndFeel laf = new SynthLookAndFeel() {
            /**
             * @see javax.swing.plaf.synth.SynthLookAndFeel#getDefaults()
             */
            public UIDefaults getDefaults() {
                UIDefaults result = super.getDefaults();
 
                String className = UIManager.getSystemLookAndFeelClassName();
                try {
                    Class<?> lnfClass = Class.forName(className, true, Thread.currentThread()
                            .getContextClassLoader());
                    LookAndFeel override = (LookAndFeel) (lnfClass.newInstance());
 
                    result.putAll(override.getDefaults());
                } catch (Exception e) {
                    System.err.println("NOT OVERRIDDEN");
                }
                return result;
            }
        };
        
        laf.load(VoteDialog.class.getResourceAsStream("./style.xml"), VoteDialog.class);
        
        UIManager.setLookAndFeel(laf);
 
        // start application...
my second try at least gave the application a bit of the windows look, and some of the feel:
    public static void main(String[] args) throws Exception {
        SynthLookAndFeel laf = new SynthLookAndFeel() {
            /**
             * @see javax.swing.plaf.synth.SynthLookAndFeel#getDefaults()
             */
            public UIDefaults getDefaults() {
                UIDefaults result = null;
 
                String className = UIManager.getSystemLookAndFeelClassName();
                try {
                    Class<?> lnfClass = Class.forName(className, true, Thread.currentThread()
                            .getContextClassLoader());
                    LookAndFeel system = (LookAndFeel) (lnfClass.newInstance());
 
                    result = system.getDefaults();
                } catch (Exception e) {
                    System.err.println("NOT OVERRIDDEN");
                }
                
                if (result == null) {
                    result = super.getDefaults();
                } else {
                    UIDefaults override = super.getDefaults();
                    result.putAll(override);
                }
                
                return result;
            }
        };
        
        laf.load(VoteDialog.class.getResourceAsStream("./style.xml"), VoteDialog.class);
        
        UIManager.setLookAndFeel(laf);
 
        // start application...


Any comments would be highly appreciated!

Thanks, Lars

Scott Violet
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 10, 2006 11:15 AM   in response to: stitzl
  Click to reply to this thread Reply

Lars,

As you have found, this doesn't quite work. Taking elements from one
look and feel and trying to merge with another look and feel was never a
design point for Swing.

-Scott


stitzl

Posts: 22
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 11, 2006 1:44 AM   in response to: Scott Violet
  Click to reply to this thread Reply

Hi Scott,

thanks for your concise reply which means, as I take it, that -- when using Synth -- it is impossible to slightly modify the look of existing applications that use the system L&F without reverse engineering that L&F first and reimplementing it as a Synth XML file.

Sadly, as our application uses the Windows L&F (to "fit in"), simply extending the existing look and feel classes is out of question.

Using the Multiplexing Look and Feel does not seem to be working either, as I need to override (and not only extend) certain look elements -- see my second post.

Do you have other suggestions on how to modify an look of an existing L&F?

Thanks for your help,
Lars

evickroy

Posts: 674
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 11, 2006 6:38 AM   in response to: stitzl
  Click to reply to this thread Reply

Lars,
You might want to take a look at the Laf Plugin project at [1]. If you start with one of the existing 3rd party L&Fs that support the laf-plugin mechanism, then you could easily replace the UI delegate for specific components. This might not be exactly what you want, but it does make it possible.

Hope this helps.
Erik

[1] https://laf-plugin.dev.java.net/

Joshua Marinacci
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 11, 2006 8:41 AM   in response to: stitzl
  Click to reply to this thread Reply

If you just wish to modify the look of a single component or two,
then you might want look at the Painter project in SwingLabs.
Painters are delegates for painting which you attach to individual
components as you need them.

http://weblogs.java.net/blog/joshy/archive/2006/09/
introducing_pai_1.html
http://weblogs.java.net/blog/joshy/archive/2006/09/introducing_pai.html

You might also want to consider manually plugging in delegates to the
UIDefaults table. You can override the delegate for just a single
component. ex: put in a ButtonUI delegate to affect all buttons, but
not other components. This requires a lot of testing, however,
because delegates can often have interesting interactions.

- Josh

On Oct 11, 2006, at 1:44 AM, swing@javadesktop.org wrote:

> Hi Scott,
>
> thanks for your concise reply which means, as I take it, that --
> when using Synth -- it is impossible to slightly modify the look of
> existing applications that use the system L&F without reverse
> engineering that L&F first and reimplementing it as a Synth XML file.
>
> Sadly, as our application uses the Windows L&F (to "fit in"),
> simply extending the existing look and feel classes is out of
> question.
>
> Using the Multiplexing Look and Feel does not seem to be working
> either, as I need to override (and not only extend) certain look
> elements -- see my second post.
>
> Do you have other suggestions on how to modify an look of an
> existing L&F?
>
> Thanks for your help,
> Lars
> [Message sent by forum member 'stitzl' (stitzl)]
>
> http://forums.java.net/jive/thread.jspa?messageID=161854

- Blasting forth in three part harmony!


[att1.html]


kirillcool

Posts: 796
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 11, 2006 9:13 AM   in response to: stitzl
  Click to reply to this thread Reply

I'm curious - why doesn't MultiLookAndFeel work for you? If you just need to overlay something on top of the existing painting - it will do just that. If you need to replace some of the painting logic - why not extend the Windows*UI class and override the relevant painting methods?

kleopatra

Posts: 1,677
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 13, 2006 3:43 AM   in response to: kirillcool
  Click to reply to this thread Reply

> I'm curious - why doesn't MultiLookAndFeel work for
> you?

Beware, there's a (could be a show-stopper) bug against MultiLF:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6307075

We stumbled across it when using a MultiLF responsible for default context menus SwingX:

http://forums.java.net/jive/thread.jspa?threadID=7713

Cheers
Jeanette

Scott Violet
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 11, 2006 9:40 AM   in response to: stitzl
  Click to reply to this thread Reply

Lars,

It really depends upon what you are after. Subclassing the JComponent
subclass (such as JButton) and overriding paintComponent will work, but
is pretty heavy handed. You might instead try subclassing the
appropriate windows ComponentUI class, such as WindowsButtonUI, and
override the appropriate methods for the effect you're after.

-Scott


stitzl

Posts: 22
Re: Synth PLAF: How to define a fallback Look and Feel?
Posted: Oct 12, 2006 5:24 AM   in response to: Scott Violet
  Click to reply to this thread Reply

Hi Kirill, Scott,

extending classes from the com.sun.* packages is extremely discouraged at my I workplace, and last time I checked, this was in line with the official statements issued by Sun on this topic, as com.sun.* is not part of the official API. :-(

If, however, Sun would refactor the Windows L&F into a package below java.swing.plaf, subclassing the UI delegates of the Windows L&F definitely would be my first choice as well. ;-)

Using the Multi L&F to combine the Windows look and feel with Synth has the ugly side-effect that all widgets are rendered twice, one on top of the other. As some of them -- like JLabels -- are not opaque (and must not be), the UI becomes a cluttered mess. But this is what I actually expected after reading "Using the Multiplexing Look and Feel".[1]

Thanks for your valuable time and input! I have some options now, and if I find a solution that suits me, I'll post it here.

HAND, Lars :-)

[1] http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/plaf/multi/doc-files/multi_tsc.html




 XML java.net RSS