001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets;
006:
007: import java.util.*;
008: import java.io.*;
009:
010: import com.javelin.swinglets.plaf.*;
011:
012: /**
013: * SLayoutManager is used to layout SComponents in a SContainer.
014: *
015: * @author Robin Sharp
016: */
017:
018: public abstract class SLayoutManager {
019: /**
020: * Returns the name of the L&F class that renders this layout.
021: */
022: public Class getUIClass() {
023: return SLayoutManager.class;
024: }
025:
026: /**
027: * Get the Layout UI
028: */
029: public SLayoutUI getLayoutUI() {
030: if (layoutUI == null) {
031: throw new IllegalStateException("Unknown Layout for "
032: + getUIClass().getName());
033: }
034:
035: return layoutUI;
036: }
037:
038: /**
039: * Set the Containers LookAndFeel.
040: */
041: public void setLookAndFeel(SLookAndFeel lookAndFeel) {
042: this .lookAndFeel = lookAndFeel;
043: layoutUI = lookAndFeel.getLayoutUI(this );
044: }
045:
046: /**
047: * Get the Parents LookAndFeel
048: */
049: public SLookAndFeel getLookAndFeel() {
050: return lookAndFeel;
051: }
052:
053: /**
054: * Adds the specified with constraints to the layout manager.
055: */
056: public abstract void addComponent(SComponent component,
057: Object constraint);
058:
059: /**
060: * Remove a component.
061: */
062: public abstract void removeComponent(SComponent component);
063:
064: /**
065: * Lays out the container in the specified panel.
066: */
067: public void layoutContainer(SContainer parent, Object out) {
068: //Ist time around get the look and feel
069: if (lookAndFeel == null) {
070: lookAndFeel = parent.getLookAndFeel();
071: layoutUI = lookAndFeel.getLayoutUI(this );
072: }
073:
074: //In case the L&F changed update the l&f
075: if (lookAndFeel != parent.getLookAndFeel()) {
076: lookAndFeel = parent.getLookAndFeel();
077: layoutUI = lookAndFeel.getLayoutUI(this );
078: }
079:
080: if (layoutUI != null) {
081: layoutUI.layoutContainer(parent, out);
082: } else {
083: throw new IllegalStateException("Unknown "
084: + getUIClass().getName() + " for "
085: + parent.getLookAndFeel());
086: }
087: }
088:
089: /**
090: * Invalidates the layout, indicating that if the layout manager
091: * has cached information it should be discarded.
092: */
093: public void invalidateLayout(SContainer target) {
094: }
095:
096: // PRIVATE /////////////////////////////////////////////////////////
097:
098: protected SLayoutUI layoutUI;
099: protected SLookAndFeel lookAndFeel;
100:
101: }
|