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 org.wings;
014:
015: import org.wings.io.Device;
016: import org.wings.plaf.LayoutCG;
017: import org.wings.session.SessionManager;
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020:
021: import java.io.IOException;
022: import java.io.ObjectInputStream;
023: import java.io.ObjectOutputStream;
024:
025: /**
026: * Base class for layout managers.
027: *
028: * @author <a href="mailto:engels@mercatis.de">Holger Engels</a>
029: */
030: public abstract class SAbstractLayoutManager implements SLayoutManager {
031: /**
032: * Apache jakarta commons logger
033: */
034: private final static Log log = LogFactory
035: .getLog(SAbstractLayoutManager.class);
036:
037: /**
038: * The code generation delegate, which is responsible for
039: * the visual representation of a layout.
040: */
041: protected transient LayoutCG cg;
042:
043: /**
044: * The container using this layout
045: */
046: protected SContainer container;
047:
048: /**
049: * Preferred size of component in pixel.
050: */
051: protected SDimension preferredSize = null;
052: protected int border = 0;
053:
054: protected SAbstractLayoutManager() {
055: updateCG();
056: }
057:
058: protected void setCG(LayoutCG newCG) {
059: cg = newCG;
060: }
061:
062: /**
063: * Return the look and feel delegate.
064: *
065: * @return the componet's cg
066: */
067: public LayoutCG getCG() {
068: return cg;
069: }
070:
071: /**
072: * Notification from the CGFactory that the L&F
073: * has changed.
074: *
075: * @see SComponent#updateCG
076: */
077: public void updateCG() {
078: setCG(SessionManager.getSession().getCGManager().getCG(this ));
079: }
080:
081: public void write(Device d) throws IOException {
082: cg.write(d, this );
083: }
084:
085: public void setContainer(SContainer c) {
086: container = c;
087: if (container != null) {
088: container.setPreferredSize(this .getPreferredSize());
089: }
090: }
091:
092: public SContainer getContainer() {
093: return container;
094: }
095:
096: /**
097: * Set the preferred size of the receiving {@link SLayoutManager} in pixel.
098: * It is not guaranteed that the {@link SLayoutManager} accepts this property because of
099: * missing implementations in the {@link SLayoutManager } cg or html properties.
100: * If <i>width</i> or <i>height</i> is zero, it is ignored and the browser
101: * defines the size.
102: *
103: * @see #getPreferredSize
104: */
105: public final void setPreferredSize(SDimension preferredSize) {
106: this .preferredSize = preferredSize;
107: }
108:
109: /**
110: * Get the preferred size of this {@link SLayoutManager }.
111: *
112: * @see #setPreferredSize
113: */
114: public final SDimension getPreferredSize() {
115: return this .preferredSize;
116: }
117:
118: private void readObject(ObjectInputStream in) throws IOException,
119: ClassNotFoundException {
120: // preprocessing, e. g. serialize static vars or transient variables as cipher text
121: in.defaultReadObject(); // default serialization
122: // do postprocessing here
123: }
124:
125: private void writeObject(ObjectOutputStream out) throws IOException {
126: try {
127: // preprocessing
128: out.defaultWriteObject(); // default
129: // postprocessing
130: } catch (IOException e) {
131: log.warn("Unexpected Exception", e);
132: throw e;
133: }
134: }
135:
136: /**
137: * Set the thickness of the border.
138: * Default is 0, which means no border.
139: *
140: * @param pixel thickness of the border
141: */
142: public void setBorder(int pixel) {
143: border = pixel;
144: }
145:
146: /**
147: * Returns the thickness of the border.
148: *
149: * @return thickness of the border
150: */
151: public int getBorder() {
152: return border;
153: }
154: }
|