org.wings.SAbstractLayoutManager Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2000,2005 wingS development team.
*
* This file is part of wingS (http://wingsframework.org).
*
* wingS is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* Please see COPYING for the complete licence.
*/
package org.wings;
import org.wings.io.Device;
import org.wings.plaf.LayoutCG;
import org.wings.session.SessionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Base class for layout managers.
*
* @author Holger Engels
*/
public abstract class SAbstractLayoutManager
implements SLayoutManager {
/**
* Apache jakarta commons logger
*/
private final static Logger log = LoggerFactory.getLogger(SAbstractLayoutManager.class);
/**
* The code generation delegate, which is responsible for
* the visual representation of a layout.
*/
protected transient LayoutCG cg;
/**
* The container using this layout
*/
protected SContainer container;
/**
* Preferred size of component in pixel.
*/
protected SDimension preferredSize = null;
protected int border = 0;
protected SAbstractLayoutManager() {
updateCG();
}
protected void setCG(LayoutCG newCG) {
cg = newCG;
}
/**
* Return the look and feel delegate.
*
* @return the componet's cg
*/
public LayoutCG getCG() {
return cg;
}
/**
* Notification from the CGFactory that the L&F
* has changed.
*
* @see SComponent#updateCG
*/
@Override
public void updateCG() {
cg = SessionManager.getSession().getCGManager().getCG(this);
}
@Override
public void write(Device d)
throws IOException {
cg.write(d, this);
}
@Override
public void setContainer(SContainer c) {
container = c;
if (container != null) {
container.setPreferredSize(this.preferredSize);
}
}
@Override
public SContainer getContainer() {
return container;
}
/**
* Set the preferred size of the receiving {@link SLayoutManager} in pixel.
* It is not guaranteed that the {@link SLayoutManager} accepts this property because of
* missing implementations in the {@link SLayoutManager } cg or html properties.
* If width or height is zero, it is ignored and the browser
* defines the size.
*
* @see #getPreferredSize
*/
public final void setPreferredSize(SDimension preferredSize) {
this.preferredSize = preferredSize;
}
/**
* Get the preferred size of this {@link SLayoutManager }.
*
* @see #setPreferredSize
*/
public final SDimension getPreferredSize() {
return this.preferredSize;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
// preprocessing, e. g. serialize static vars or transient variables as cipher text
in.defaultReadObject(); // default serialization
// do postprocessing here
}
private void writeObject(ObjectOutputStream out) throws IOException {
try {
// preprocessing
out.defaultWriteObject(); // default
// postprocessing
} catch (IOException e) {
log.warn("Unexpected Exception", e);
throw e;
}
}
/**
* Set the thickness of the border.
* Default is 0, which means no border.
*
* @param pixel thickness of the border
*/
@Override
public void setBorder(int pixel) {
border = pixel;
}
/**
* Returns the thickness of the border.
*
* @return thickness of the border
*/
@Override
public int getBorder() {
return border;
}
}