001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.plaf.jfc;
006:
007: import java.awt.*;
008: import java.awt.event.*;
009: import java.beans.*;
010: import java.util.*;
011:
012: import javax.swing.*;
013:
014: import com.javelin.swinglets.*;
015: import com.javelin.swinglets.plaf.*;
016:
017: /**
018: * JFCFrameUI defines a look and feel for Swing.
019: *
020: * @author Robin Sharp
021: */
022:
023: public class JFCFrameUI extends JFCContainerUI implements SFrameUI {
024: /**
025: * Construct a JFCFrameUI, and construct a JFrame internally.
026: */
027: public JFCFrameUI() {
028: super (new JFrame());
029: }
030:
031: /**
032: * Construct a JFCFrameUI, with a JFrame.
033: */
034: public JFCFrameUI(JFrame frame) {
035: super (frame);
036: }
037:
038: // DISPATCH & EVENTS //////////////////////////////////////////////////////
039:
040: /**
041: * @see com.javelin.swinglets.plaf.SComponentUI.addListener()
042: */
043: public void addListener(EventListener listener) {
044: if (listener instanceof WindowListener)
045: ((JFrame) component)
046: .addWindowListener((WindowListener) listener);
047: else if (listener instanceof FocusListener)
048: ((JFrame) component)
049: .addFocusListener((FocusListener) listener);
050: else
051: super .addListener(listener);
052: }
053:
054: /**
055: * @see com.javelin.swinglets.plaf.SComponentUI.removeListener()
056: */
057: public void removeListener(EventListener listener) {
058: if (listener instanceof WindowListener)
059: ((JFrame) component)
060: .removeWindowListener((WindowListener) listener);
061: else if (listener instanceof FocusListener)
062: ((JFrame) component)
063: .removeFocusListener((FocusListener) listener);
064: else
065: super .removeListener(listener);
066: }
067:
068: /**
069: * Listen for changes in the SFrame and mirror them in the component
070: */
071: public void propertyChange(PropertyChangeEvent event) {
072: //System.out.println( "PC F=" + event.getPropertyName() );
073:
074: if ("title".equals(event.getPropertyName()))
075: ((JFrame) component).setTitle((String) event.getNewValue());
076: else if ("layoutManager".equals(event.getPropertyName())) {
077: ((JFrame) component)
078: .getContentPane()
079: .setLayout(
080: ((JFCLayoutUI) ((SLayoutManager) event
081: .getNewValue()).getLayoutUI()).layoutManager);
082: } else
083: super .propertyChange(event);
084: }
085:
086: /**
087: * Tell the underlying UI that the container has been changed
088: */
089: public void update(SComponent c, int id, int index) {
090: if (id == SContainerUI.COMPONENT_ADDED) {
091: if (index >= 0) {
092: ((JFrame) component)
093: .getContentPane()
094: .add(
095: (Component) ((JFCComponentUI) c.getUI()).component,
096: index);
097: } else {
098: ((JFrame) component)
099: .getContentPane()
100: .add(
101: (Component) ((JFCComponentUI) c.getUI()).component);
102: }
103: } else if (id == SContainerUI.COMPONENT_REMOVED) {
104: if (index >= 0) {
105: ((JFrame) component).getContentPane().remove(index);
106: } else {
107: ((JFrame) component)
108: .getContentPane()
109: .remove(
110: (Component) ((JFCComponentUI) c.getUI()).component);
111: }
112:
113: }
114: }
115:
116: /**
117: * Tell the underlying UI that the container has been changed
118: */
119: public void update(SComponent c, int id, Object constraint) {
120: if (id == SContainerUI.COMPONENT_ADDED) {
121: if (constraint != null) {
122: ((JFrame) component)
123: .getContentPane()
124: .add(
125: (Component) ((JFCComponentUI) c.getUI()).component,
126: constraint);
127: } else {
128: ((JFrame) component)
129: .getContentPane()
130: .add(
131: (Component) ((JFCComponentUI) c.getUI()).component);
132: }
133: } else if (id == SContainerUI.COMPONENT_REMOVED) {
134: ((JFrame) component).getContentPane().remove(
135: (Component) ((JFCComponentUI) c.getUI()).component);
136: }
137: }
138:
139: }
|