001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package wingset;
014:
015: import org.apache.commons.logging.Log;
016: import org.apache.commons.logging.LogFactory;
017: import org.wings.SAnchor;
018: import org.wings.SBorderLayout;
019: import org.wings.SComponent;
020: import org.wings.SConstants;
021: import org.wings.SContainer;
022: import org.wings.SDimension;
023: import org.wings.SLabel;
024: import org.wings.SPanel;
025: import org.wings.SResourceIcon;
026: import org.wings.border.SBorder;
027: import org.wings.border.SEmptyBorder;
028: import org.wings.border.SLineBorder;
029: import org.wings.event.SComponentAdapter;
030: import org.wings.event.SComponentEvent;
031: import org.wings.plaf.WingSetExample;
032: import org.wings.plaf.css.Utils;
033:
034: import java.awt.Color;
035: import java.awt.Insets;
036:
037: /**
038: * A basic WingSet Pane, which implements some often needed functions.
039: *
040: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
041: */
042: abstract public class WingSetPane extends SPanel implements SConstants,
043: WingSetExample {
044: protected final static Log log = LogFactory
045: .getLog(WingSetPane.class);
046: private static final SResourceIcon SOURCE_LABEL_ICON = new SResourceIcon(
047: "org/wings/icons/source_java.png");
048: private boolean initialized = false;
049: private SComponent controlsComponent;
050: private SComponent exampleComponent;
051: private String exampleName;
052: private String group;
053:
054: public WingSetPane() {
055: setLayout(new SBorderLayout());
056: setPreferredSize(SDimension.FULLAREA);
057:
058: SAnchor anchor = new SAnchor("../"
059: + getClass().getName().substring(
060: getClass().getName().indexOf('.') + 1)
061: + ".java");
062: anchor.setTarget("sourceWindow");
063: anchor.add(new SLabel("View Java Source Code",
064: SOURCE_LABEL_ICON));
065: anchor.setPreferredSize(SDimension.FULLWIDTH);
066:
067: SPanel south = new SPanel();
068: if (!Utils.isMSIE(this )) {
069: south.setBorder(new SEmptyBorder(0, 1, 0, 1));
070: }
071: south.setPreferredSize(SDimension.FULLWIDTH);
072: south.add(anchor);
073:
074: SBorder border = new SLineBorder(1, new Insets(0, 3, 0, 6));
075: border.setColor(new Color(255, 255, 255), SConstants.TOP);
076: border.setColor(new Color(255, 255, 255), SConstants.LEFT);
077: border.setColor(new Color(190, 190, 190), SConstants.RIGHT);
078: border.setColor(new Color(190, 190, 190), SConstants.BOTTOM);
079: south.setBorder(border);
080: south.setBackground(new Color(240, 240, 240));
081:
082: add(south, SBorderLayout.SOUTH);
083:
084: // lazily initialize components when first shown
085: addComponentListener(new SComponentAdapter() {
086: public void componentShown(SComponentEvent e) {
087: activateExample();
088: }
089:
090: public void componentHidden(SComponentEvent e) {
091: // TODO FIXME : Uncommenting the following line MUST work but doesnt:
092: // I leads to the correct unregistering of headers.
093: // Switch between XCalendar and XColorpicker i.e. --> Application hangs.
094: // passivateExample();
095: }
096: });
097: }
098:
099: /**
100: * @inheritDoc
101: */
102: public final void activateExample() {
103: if (!initialized) {
104: controlsComponent = createControls();
105: if (controlsComponent != null) {
106: if (!Utils.isMSIE(this )
107: && controlsComponent instanceof SContainer) {
108: controlsComponent.setBorder(new SEmptyBorder(0, 1,
109: 0, 1));
110: }
111: controlsComponent
112: .setVerticalAlignment(SConstants.TOP_ALIGN);
113: if (controlsComponent.getHorizontalAlignment() == SConstants.NO_ALIGN) {
114: controlsComponent
115: .setHorizontalAlignment(SConstants.LEFT_ALIGN);
116: }
117: add(controlsComponent, SBorderLayout.NORTH);
118: }
119:
120: exampleComponent = createExample();
121: if (exampleComponent != null) {
122: if (!Utils.isMSIE(this )) {
123: exampleComponent.setBorder(new SEmptyBorder(0, 1,
124: 1, 1));
125: }
126: if (exampleComponent.getVerticalAlignment() == SConstants.NO_ALIGN) {
127: exampleComponent
128: .setVerticalAlignment(SConstants.TOP_ALIGN);
129: }
130: if (exampleComponent.getHorizontalAlignment() == SConstants.NO_ALIGN) {
131: exampleComponent
132: .setHorizontalAlignment(SConstants.CENTER_ALIGN);
133: }
134: add(exampleComponent, SBorderLayout.CENTER);
135: }
136: initialized = true;
137: }
138: }
139:
140: /**
141: * @inheritDoc
142: */
143: public final void passivateExample() {
144: // Dumb: Always dropp all components to test header deregistration etc.
145: // Maybe make this configurable per example
146: remove(controlsComponent);
147: remove(exampleComponent);
148: initialized = false;
149: }
150:
151: protected abstract SComponent createControls();
152:
153: protected abstract SComponent createExample();
154:
155: /**
156: * @inheritDoc
157: */
158: public SComponent getExample() {
159: return this ;
160: }
161:
162: /**
163: * @inheritDoc
164: */
165: public String getExampleName() {
166: if (exampleName == null)
167: naming();
168: return exampleName;
169: }
170:
171: /**
172: * @inheritDoc
173: */
174: public String getExampleGroup() {
175: if (group == null)
176: naming();
177: return group;
178: }
179:
180: private void naming() {
181: exampleName = getClass().getName();
182: exampleName = exampleName.substring(exampleName
183: .lastIndexOf('.') + 1);
184: if (exampleName.endsWith("Example")) {
185: group = getExampleName().startsWith("X") ? "wingX"
186: : "wingS";
187: exampleName = exampleName.substring(0, exampleName.length()
188: - "Example".length());
189: } else if (exampleName.endsWith("Test")) {
190: group = "Test";
191: exampleName = exampleName.substring(0, exampleName.length()
192: - "Test".length());
193: } else if (exampleName.endsWith("Experiment")) {
194: group = "Experiment";
195: exampleName = exampleName.substring(0, exampleName.length()
196: - "Experiment".length());
197: }
198: }
199: }
|