/* PLAFSimpleExample.java
 * Pluggable look-and-feel test for JMultiLineLabel, adopted from 
 * the SimpleExample.java sample program from Swing 1.1beta3
 * standard distribution.
 *
 *  (C) Copyright 1998
 *  Wildcrest Associates
 *  http://www.wildcrest.com
 *  
 * This source code may be freely used, modified, incorporated, and
 * distributed without restriction as part of any software that uses
 * JMultiLineLabel by Wildcrest Associates.

 * @(#)SimpleExample.java	1.20 98/03/20
 *
 * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 *
 */

import com.wildcrest.jmultilinelabel.*;
import java.awt.*;
import java.awt.event.*;

//import com.sun.java.swing.*;	// Swing 1.0.x and JDK 1.2beta4
import javax.swing.*;			// Swing 1.1beta3 and JDK 1.2 final

/**
 * An application that displays a JButton, JLabel, and JMultiLineLabel
 * and several JRadioButtons.
 * The JRadioButtons determine the look and feel used by the application.
 */



public class PLAFSimpleExample extends JPanel {
    static JFrame frame;

    static String metal= "Metal";
    //static String metalClassName = "com.sun.java.swing.plaf.metal.MetalLookAndFeel";
    static String metalClassName = "javax.swing.plaf.metal.MetalLookAndFeel";

    static String motif = "Motif";
    static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
    //static String motifClassName = "javax.swing.plaf.motif.MotifLookAndFeel";

    static String windows = "Windows";
    static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    //static String windowsClassName = "javax.swing.plaf.windows.WindowsLookAndFeel";

    JRadioButton metalButton, motifButton, windowsButton;

    public PLAFSimpleExample() {
	// Create the buttons.
	JButton button = new JButton("This is a JButton");
        button.setMnemonic('t'); //for looks only; button does nada

	JLabel label = new JLabel("This is a JLabel");
	//uncomment combinations of these to verify override of PLAF
	//label.setForeground(Color.red);
	//label.setBackground(Color.pink); label.setOpaque(true);
	//label.setFont(new Font("Monospaced", Font.BOLD, 16));

        JMultiLineLabel jmll = new JMultiLineLabel("This is a JMultiLineLabel",200);
	//uncomment combinations of these to verify override of PLAF
	//jmll.setForeground(Color.red);
	//jmll.setBackground(Color.pink); jmll.setOpaque(true);
	//jmll.setFont(new Font("Monospaced", Font.BOLD, 16));

	metalButton = new JRadioButton(metal);
        metalButton.setMnemonic('o'); 
	metalButton.setActionCommand(metalClassName);

	motifButton = new JRadioButton(motif);
        motifButton.setMnemonic('m'); 
	motifButton.setActionCommand(motifClassName);

	windowsButton = new JRadioButton(windows);
        windowsButton.setMnemonic('w'); 
	windowsButton.setActionCommand(windowsClassName);

	// Group the radio buttons.
	ButtonGroup group = new ButtonGroup();
	group.add(metalButton);
	group.add(motifButton);
	group.add(windowsButton);

        // Register a listener for the radio buttons.
	RadioListener myListener = new RadioListener();
	metalButton.addActionListener(myListener);
	motifButton.addActionListener(myListener);
	windowsButton.addActionListener(myListener);

	((FlowLayout) getLayout()).setHgap(20);
	add(button);
	add(label);
        add(jmll);
	add(metalButton);
	add(motifButton);
	add(windowsButton);
    }


    /** An ActionListener that listens to the radio buttons. */
    class RadioListener implements ActionListener {
	public void actionPerformed(ActionEvent e) {
	    String lnfName = e.getActionCommand();

            try {
		UIManager.setLookAndFeel(lnfName);
		SwingUtilities.updateComponentTreeUI(frame);
		frame.pack();
            } 
	    catch (Exception exc) {
		JRadioButton button = (JRadioButton)e.getSource();
		button.setEnabled(false);
		updateState();
                System.err.println("Could not load LookAndFeel: " + lnfName);
            }
	    
	}
    }

    public void updateState() {
	 String lnfName = UIManager.getLookAndFeel().getClass().getName();
	 if (lnfName.indexOf(metal) >= 0) {
	     metalButton.setSelected(true);
	 } else if (lnfName.indexOf(windows) >= 0) {
	     windowsButton.setSelected(true);
	 } else if (lnfName.indexOf(motif) >= 0) {
	     motifButton.setSelected(true);
	 } else {
	     System.err.println("SimpleExample is using an unknown L&F: " + lnfName);
	 }
    }

    public static void main(String s[]) {
	/* 
	   NOTE: By default, the look and feel will be set to the
	   Cross Platform Look and Feel (which is currently Metal).
	   The user may someday be able to override the default
	   via a system property. If you as the developer want to
	   be sure that a particular L&F is set, you can do so
	   by calling UIManager.setLookAndFeel(). For example, the
	   first code snippet below forcibly sets the UI to be the
	   System Look and Feel. The second code snippet forcibly
	   sets the look and feel to the Cross Platform L&F.

	   Snippet 1:
	      try {
	          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	      } catch (Exception exc) {
	          System.err.println("Error loading L&F: " + exc);
	      }

	   Snippet 2:
	      try {
	          UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
	      } catch (Exception exc) {
	          System.err.println("Error loading L&F: " + exc);
              }
	*/

	PLAFSimpleExample panel = new PLAFSimpleExample();
	
	frame = new JFrame("PLAFSimpleExample");
	frame.addWindowListener(new WindowAdapter() {
	    public void windowClosing(WindowEvent e) {System.exit(0);}
	});

	frame.getContentPane().add("Center", panel);
	frame.pack();
	frame.setVisible(true);
	
	panel.updateState();

    }
}
