package textbackground;


import com.ulcjava.base.application.*;
import com.ulcjava.base.application.util.*;
import com.ulcjava.base.application.event.*;
import com.ulcjava.base.client.UITextField;
import com.ulcjava.base.development.DevelopmentRunner;
import com.ulcjava.base.shared.internal.Anything;
import com.ulcjava.base.application.util.Color;
import javax.swing.UIManager;

/**
 * The code snippet shows that the default background color for a non-editable ULCTextComponent is not properly
 * set, it seems to be the same as for an editable ULCTextComponent. In Swing (cf. code snippet BackgroundColorSwing
 * it works as expected)
 *
 * Version: ULC 6.1, java 1.5
 *
 * Thanks for your support.
 * --Christoph  , 01.06.2006
 */

public class BackgroundColorULC extends AbstractApplication {

  ULCFrame frame = new ULCFrame("Code snippet - Non-Editable Fields and Background Color");
  ULCBoxPane rootBox = new ULCBoxPane(true) ;

  ULCBoxPane txtBox  = new ULCBoxPane();
  ULCTextField txtField1 = new ULCTextField();
  ULCTextField txtField2 = new ULCTextField();

  ULCButton  button1   = new ULCButton("Toggle Background Color of Input Field");
  ULCButton  button2   = new ULCButton("Toggle Background Color of Display Field");

  public void start() {
    frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
    frame.setSize(new Dimension(800, 150));
    frame.add(rootBox);
    rootBox.add(ULCBoxPane.BOX_EXPAND_CENTER, txtBox);
    rootBox.add(ULCBoxPane.BOX_EXPAND_EXPAND, new ULCFiller());

    // text Box -------------------------------------------------------------------------------------------
    txtBox.setColumns(2);
    txtBox.setRows(2);
    txtBox.setBorder(BorderFactory.createTitledBorder("Display only Fields and Background Color"));

    txtBox.add(ULCBoxPane.BOX_LEFT_CENTER, button1);  txtBox.add(ULCBoxPane.BOX_EXPAND_CENTER, txtField1);
    txtBox.add(ULCBoxPane.BOX_LEFT_CENTER, button2);  txtBox.add(ULCBoxPane.BOX_EXPAND_CENTER, txtField2);
   
    txtField1.setText( txtField1.getBackground().toString() );
    final Color highlight = Color.yellow;

    final Color backgroundColor1 = txtField1.getBackground();

    button1.addActionListener(new IActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (txtField1.getBackground() == backgroundColor1) txtField1.setBackground(highlight);
        else txtField1.setBackground(backgroundColor1);
        txtField1.setText( txtField1.getBackground().toString() );
      }
    });

    txtField2.setEditable(false);
    txtField2.setBackground(ClientContext.getColor("TextField.disabledBackground"));
    final Color backgroundColor2 = txtField2.getBackground();
    txtField2.setText( txtField2.getBackground().toString() );
   
    
    button2.addActionListener(new IActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (txtField2.getBackground() == backgroundColor2)
            txtField2.setBackground(highlight);
        else 
            txtField2.setBackground(backgroundColor2);   
        txtField2.setText( txtField2.getBackground().toString() );
      }
    });

    // ------------------------------------------------------------------------------------------------------
    frame.setVisible(true);
  }

  public static final String METAL   = "javax.swing.plaf.metal.MetalLookAndFeel";
  public static final String MOTIF   = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
  public static final String WINDOWS = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";

  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(WINDOWS);
    }
    catch (Exception ex) {}
    DevelopmentRunner.setApplicationClass(BackgroundColorULC.class);
    DevelopmentRunner.main(args);
  }
}