001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.plaf.jfc;
006:
007: import java.beans.*;
008: import java.awt.*;
009: import java.awt.event.*;
010:
011: import javax.swing.*;
012:
013: import com.javelin.swinglets.*;
014: import com.javelin.swinglets.plaf.*;
015: import com.javelin.swinglets.event.*;
016:
017: /**
018: * JFCContainerUI defines a look and feel for default Swing.
019: *
020: * @author Robin Sharp
021: */
022:
023: public class JFCContainerUI extends JFCComponentUI implements
024: SContainerUI {
025: /**
026: * Construct a JFCContainerUI, and construct a JContainer internally.
027: */
028: public JFCContainerUI() {
029: super (new JComponent() {
030: });
031: }
032:
033: /**
034: * Construct a JFCContainerUI, with a JFrame.
035: */
036: public JFCContainerUI(Component component) {
037: super (component);
038: }
039:
040: /**
041: * Update the header.
042: */
043: public void updateHeader(Object out, SComponent c) {
044: }
045:
046: /**
047: * Update the body.
048: */
049: public void update(Object out, SComponent c) {
050: }
051:
052: // EVENT ///////////////////////////////////////////////////////////
053:
054: /**
055: * Tell the underlying UI that the container has been changed
056: */
057: public void update(SComponent c, int id, int index) {
058: if (id == SContainerUI.COMPONENT_ADDED) {
059: if (index >= 0) {
060: ((JComponent) component)
061: .add(
062: (Component) ((JFCComponentUI) c.getUI()).component,
063: index);
064: } else {
065: ((JComponent) component)
066: .add((Component) ((JFCComponentUI) c.getUI()).component);
067: }
068: } else if (id == SContainerUI.COMPONENT_REMOVED) {
069: if (index >= 0) {
070: ((JComponent) component).remove(index);
071: } else {
072: ((JComponent) component)
073: .remove((Component) ((JFCComponentUI) c.getUI()).component);
074: }
075:
076: }
077: }
078:
079: /**
080: * Tell the underlying UI that the container has been changed
081: */
082: public void update(SComponent c, int id, Object constraint) {
083: if (id == SContainerUI.COMPONENT_ADDED) {
084: if (constraint != null) {
085: ((JComponent) component)
086: .add(
087: (Component) ((JFCComponentUI) c.getUI()).component,
088: constraint);
089: } else {
090: ((JComponent) component)
091: .add((Component) ((JFCComponentUI) c.getUI()).component);
092: }
093: } else if (id == SContainerUI.COMPONENT_REMOVED) {
094: ((JFrame) component).getContentPane().remove(
095: (Component) ((JFCComponentUI) c.getUI()).component);
096: }
097: }
098:
099: /**
100: * Listen for changes in the SComponent and mirror them in the component
101: */
102: public void propertyChange(PropertyChangeEvent event) {
103: if ("layoutManager".equals(event.getPropertyName())) {
104: ((Container) component)
105: .setLayout(((JFCLayoutUI) ((SLayoutManager) event
106: .getNewValue()).getLayoutUI()).layoutManager);
107: } else
108: super.propertyChange(event);
109: }
110:
111: }
|