001: /*
002: * $Id: TextComponentExample.java 2750 2006-08-02 08:10:54Z hengels $
003: * Copyright 2006 wingS development team.
004: *
005: * This file is part of wingS (http://wingsframework.org).
006: *
007: * wingS is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU Lesser General Public License
009: * as published by the Free Software Foundation; either version 2.1
010: * of the License, or (at your option) any later version.
011: *
012: * Please see COPYING for the complete licence.
013: */
014:
015: package org.wingx.example;
016:
017: import java.awt.event.ActionEvent;
018: import java.awt.event.ActionListener;
019: import javax.swing.event.ChangeEvent;
020: import org.wings.SButton;
021: import org.wings.SComponent;
022: import org.wings.SDimension;
023: import org.wings.SForm;
024: import org.wings.SGridLayout;
025: import org.wings.SLabel;
026: import org.wings.SPanel;
027: import org.wings.SToggleButton;
028: import org.wings.plaf.WingSetExample;
029: import org.wings.border.SLineBorder;
030: import org.wings.event.SAjaxChangeListener;
031: import org.wingx.XColorPicker;
032:
033: /**
034: * Example demonstrating the component XColorPicker.
035: * @author Christian Schyma
036: */
037: public class XColorPickerExample implements WingSetExample {
038: private SForm form;
039:
040: public void activateExample() {
041: final SPanel colorPanel = new SPanel();
042: final XColorPicker picker = new XColorPicker();
043:
044: colorPanel.setBorder(new SLineBorder(1));
045: colorPanel.setPreferredSize(new SDimension(150, 100));
046: SLabel label = new SLabel(
047: "this is an individual SPanel component "
048: + "that gets colored by the color picker to the left");
049: label.setWordWrap(true);
050: colorPanel.add(label);
051:
052: picker.addAjaxChangeListener(new SAjaxChangeListener() {
053: public void stateChanged(ChangeEvent e) {
054: colorPanel.setBackground(((XColorPicker) e.getSource())
055: .getSelectedColor());
056: }
057: });
058:
059: final SButton updatePanelButton = new SButton("update panel");
060: updatePanelButton.setVisible(false);
061: final SToggleButton toggleImmediateUpdateButton = new SToggleButton(
062: "disable immediate updates");
063:
064: SPanel buttonPanel = new SPanel(new SGridLayout(2, 1));
065: buttonPanel.add(updatePanelButton);
066: buttonPanel.add(toggleImmediateUpdateButton);
067:
068: updatePanelButton.addActionListener(new ActionListener() {
069: public void actionPerformed(ActionEvent e) {
070: // just to simulate a POST
071: }
072: });
073:
074: toggleImmediateUpdateButton
075: .addActionListener(new ActionListener() {
076: public void actionPerformed(ActionEvent e) {
077: picker.setImmediateUpdate(!picker
078: .isImmediateUpdate());
079: updatePanelButton.setVisible(!updatePanelButton
080: .isVisible());
081:
082: }
083: });
084:
085: SGridLayout gridLayout = new SGridLayout(3);
086: gridLayout.setHgap(50);
087: form = new SForm(gridLayout);
088: form.add(picker);
089: form.add(colorPanel);
090: form.add(buttonPanel);
091: }
092:
093: public void passivateExample() {
094: //To change body of implemented methods use File | Settings | File Templates.
095: }
096:
097: public SComponent getExample() {
098: return form;
099: }
100:
101: public String getExampleName() {
102: return "XColorPicker";
103: }
104:
105: public String getExampleGroup() {
106: return "Experiment";
107: }
108: }
|