001: //WebOnSwing - Web Application Framework
002: //Copyright (C) 2003 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package net.ar.webonswing.swing.layouts;
019:
020: import java.awt.*;
021:
022: import javax.swing.*;
023:
024: import net.ar.webonswing.*;
025: import net.ar.webonswing.render.templates.*;
026: import net.ar.webonswing.render.templates.html.*;
027:
028: public class PropagateTemplateLayoutByOrder extends TemplateLayout
029: implements LayoutManager2 {
030: public PropagateTemplateLayoutByOrder(KeyPositionTemplate aTemplate) {
031: super (aTemplate);
032: }
033:
034: public void layoutContainer(Container aParent) {
035: Component[] components = aParent.getComponents();
036: for (int i = 0; i < components.length; i++) {
037: Container theComponent = (Container) components[i];
038: KeyPositionHtmlTemplate theHtmlTemplate = (KeyPositionHtmlTemplate) theTemplate;
039:
040: if (theComponent.getComponentCount() > 0) {
041: if (theComponent.getLayout() instanceof GridLayout
042: || theComponent.getLayout() instanceof TemplateFlowLayout)
043: setTemplateFlowLayout(theComponent);
044: else {
045: if (i < theHtmlTemplate.getElementCount()) {
046: HtmlTemplate theSubTemplate = theHtmlTemplate
047: .getClonedSubTemplateAt(i);
048: if (theSubTemplate != null)
049: theComponent
050: .setLayout(new PropagateTemplateLayoutByOrder(
051: new KeyPositionHtmlTemplate(
052: theSubTemplate)));
053: } else
054: theComponent.getParent().setLayout(
055: new TemplateLayout(
056: new HtmlDivsTemplate()));
057: }
058: }
059:
060: if (theComponent instanceof JComponent)
061: if (i < theHtmlTemplate.getElementCount())
062: theHtmlTemplate.addKey(theHtmlTemplate
063: .getElementAt(i).getId().toString(),
064: WosFramework.getInstance()
065: .getHierarchyWrapper()
066: .getComponentWrapper(theComponent));
067: else
068: theComponent.getParent().setLayout(
069: new TemplateLayout(new HtmlDivsTemplate()));
070: }
071: }
072:
073: protected void setTemplateFlowLayout(Container theContainer) {
074: theContainer.setLayout(new TemplateFlowLayout());
075:
076: Component[] components = theContainer.getComponents();
077: for (int i = 0; i < components.length; i++) {
078: Container theComponent = (Container) components[i];
079:
080: if (theTemplate.getElementCount() > 0) {
081: HtmlTemplate theHtmlTemplate = (HtmlTemplate) theTemplate
082: .getElementAt(0).getContent();
083: HtmlTemplate theSubTemplate = theHtmlTemplate
084: .getClonedSubTemplate("");
085: theComponent
086: .setLayout(new PropagateTemplateLayoutByOrder(
087: new KeyPositionHtmlTemplate(
088: theSubTemplate)));
089: }
090: }
091: }
092:
093: public float getLayoutAlignmentX(Container aTarget) {
094: return 0;
095: }
096:
097: public float getLayoutAlignmentY(Container aTarget) {
098: return 0;
099: }
100:
101: public void invalidateLayout(Container aTarget) {
102: }
103:
104: public Dimension maximumLayoutSize(Container aTarget) {
105: return new Dimension(640, 480);
106: }
107:
108: public void addLayoutComponent(Component aComponent,
109: Object aConstraints) {
110: }
111: }
|