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: import java.io.*;
022: import java.util.*;
023:
024: import net.ar.webonswing.*;
025: import net.ar.webonswing.helpers.*;
026: import net.ar.webonswing.render.templates.*;
027: import net.ar.webonswing.visitor.*;
028: import net.ar.webonswing.wrapping.*;
029:
030: /**
031: * Permite ubicar los subcomponentes por medio de una clave, y luego, cuando se invoca a "doLayout" es asociado a un "hueco" de la plantilla.
032: *
033: * @author Fernando Damian Petrola
034: */
035: public class TemplateLayout implements LayoutManager, Serializable {
036: protected Map theComponents;
037: protected Template theTemplate;
038:
039: public TemplateLayout(KeyPositionTemplate aTemplate) {
040: theTemplate = aTemplate;
041: theComponents = new HashMap();
042: }
043:
044: public TemplateLayout(Template aTemplate) {
045: theTemplate = aTemplate;
046: theComponents = new HashMap();
047: }
048:
049: public void addLayoutComponent(String name, Component comp) {
050: theComponents.put(name, comp);
051: }
052:
053: public void layoutContainer(Container parent) {
054: for (Iterator i = theComponents.keySet().iterator(); i
055: .hasNext();) {
056: String theKey = i.next().toString();
057: Component theComponent = (Component) theComponents
058: .get(theKey);
059:
060: VisualComponent theComponentWrapper = null;
061:
062: if (WosFramework.isActive())
063: theComponentWrapper = WosFramework.getInstance()
064: .getHierarchyWrapper().getComponentWrapper(
065: theComponent);
066:
067: if (theComponentWrapper != null || !WosFramework.isActive()) {
068: Rectangle theBounds = ((KeyPositionTemplate) theTemplate)
069: .addKey(theKey, theComponentWrapper);
070: theComponent.setBounds(theBounds);
071: }
072: }
073: }
074:
075: public String getName(Component aComponent) {
076: for (Iterator i = theComponents.keySet().iterator(); i
077: .hasNext();) {
078: String theKey = i.next().toString();
079: Component theComponent = (Component) theComponents
080: .get(theKey);
081:
082: if (theComponent == aComponent)
083: return theKey;
084: }
085:
086: return null;
087: }
088:
089: public void removeLayoutComponent(Component comp) {
090: for (Iterator i = theComponents.keySet().iterator(); i
091: .hasNext();) {
092: String theKey = i.next().toString();
093: Component theComponent = (Component) theComponents
094: .get(theKey);
095:
096: if (theComponent == comp)
097: i.remove();
098: }
099: }
100:
101: public Dimension preferredLayoutSize(Container parent) {
102: return new Dimension(1000, 1000);
103: }
104:
105: public Dimension minimumLayoutSize(Container parent) {
106: return new Dimension(1000, 1000);
107: }
108:
109: public Template getTemplate() {
110: try {
111: return (Template) ((PublicCloneable) theTemplate).clone();
112: } catch (CloneNotSupportedException e) {
113: throw new WebOnSwingException("Cannot clone the template: "
114: + this , e);
115: }
116: }
117:
118: public void setTemplate(Template aTemplate) {
119: this .theTemplate = (KeyPositionTemplate) aTemplate;
120: }
121:
122: }
|