001: package org.osbl.client.wings.devtools;
002:
003: import javax.swing.*;
004: import java.awt.event.ActionEvent;
005: import java.awt.*;
006:
007: import org.wings.session.SessionManager;
008: import org.wings.SFrame;
009: import org.wings.SContainer;
010: import org.wings.SComponent;
011:
012: /**
013: * TODO: document me!!!
014: * <p/>
015: * <code>ContainerColoringDevTool</code>.
016: * User: rro
017: * Date: 31.07.2006
018: * Time: 13:58:21
019: *
020: * @author Roman Rädle
021: * @version $Revision$
022: */
023: public class ContainerColoringDevTool extends AbstractAction {
024:
025: ColoringTreeWalker treeWalker = new ColoringTreeWalker();
026:
027: /**
028: * Defines an <code>Action</code> object with a default
029: * description string and default icon.
030: */
031: public ContainerColoringDevTool() {
032: treeWalker.colored = (Boolean) SessionManager.getSession()
033: .getProperty("ContainerColoringDevTool", Boolean.FALSE);
034:
035: putValue(Action.NAME, "Layout Coloring - "
036: + (treeWalker.colored ? "OFF" : "ON"));
037: //putValue(Action.SMALL_ICON, XIcons.REPLACE);
038: }
039:
040: /**
041: * Invoked when an action occurs.
042: */
043: public void actionPerformed(ActionEvent e) {
044: SFrame frame = SessionManager.getSession().getRootFrame();
045:
046: treeWalker.walk(frame);
047:
048: treeWalker.colored = !treeWalker.colored;
049: SessionManager.getSession().setProperty(
050: "ContainerColoringDevTool", treeWalker.colored);
051:
052: putValue(Action.NAME, "Layout Coloring - "
053: + (treeWalker.colored ? "OFF" : "ON"));
054: }
055:
056: class ColoringTreeWalker implements ComponentTreeWalker {
057:
058: private boolean colored;
059:
060: private Color[] colors = new Color[] { Color.RED, Color.GREEN,
061: Color.BLUE, Color.CYAN, Color.MAGENTA, Color.ORANGE,
062: Color.PINK, Color.YELLOW };
063:
064: private int colorPosition = 0;
065:
066: public boolean walk(SComponent c) {
067:
068: if (c instanceof SContainer) {
069:
070: SContainer container = (SContainer) c;
071:
072: Color childColor = colors[colorPosition];
073:
074: if (container.getComponentCount() > 0) {
075:
076: boolean colorChanged = false;
077: for (SComponent child : container.getComponents()) {
078:
079: if (child instanceof SContainer) {
080: if (!colored) {
081: child.putClientProperty(
082: "default.background", child
083: .getBackground());
084: child.setBackground(childColor);
085:
086: if (!colorChanged) {
087: colorChanged = true;
088: colors[colorPosition] = colors[colorPosition]
089: .brighter();
090: colorPosition = ++colorPosition % 8;
091: }
092: } else {
093: colorPosition = 0;
094: Color color = (Color) child
095: .getClientProperty("default.background");
096: child.setBackground(color);
097: }
098: }
099:
100: walk(child);
101: }
102: }
103: }
104:
105: return false;
106: }
107: }
108: }
|