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.util.*;
010: import java.beans.*;
011:
012: import javax.swing.*;
013: import javax.swing.border.*;
014:
015: import com.javelin.swinglets.*;
016: import com.javelin.swinglets.plaf.*;
017: import com.javelin.swinglets.border.*;
018:
019: /**
020: * JFCComponentUI defines a look and feel for Swing.
021: *
022: * @author Robin Sharp
023: */
024:
025: public class JFCComponentUI implements SComponentUI,
026: PropertyChangeListener {
027: /**
028: * Construct a JFC Component
029: */
030: public JFCComponentUI(Component component) {
031: this .component = component;
032: }
033:
034: /**
035: * Get the look and feel class.
036: */
037: public Class getLookAndFeel() {
038: return JFCLookAndFeel.class;
039: }
040:
041: /**
042: * Update any FrameSets
043: */
044: public void initFrameSets(SComponent c) {
045: }
046:
047: /**
048: * Update the header.
049: */
050: public void updateHeader(Object out, SComponent c) {
051: }
052:
053: /**
054: * Render the script code in the the Header.
055: */
056: public void updateScript(Object out, SComponent c) {
057: }
058:
059: /**
060: * Update the component header.
061: */
062: public void updateComponentHeader(Object out, SComponent c) {
063: };
064:
065: /**
066: * Update the body.
067: */
068: public void update(Object out, SComponent c) {
069: }
070:
071: /**
072: * Update the script event handlers.
073: */
074: public void updateEvent(Object out, SComponent c) {
075: }
076:
077: /**
078: * Tell the underlying UI that the container has been changed
079: */
080: public void update(SComponent c, int id, int index) {
081: };
082:
083: /**
084: * Update the component footer.
085: */
086: public void updateComponentFooter(Object out, SComponent c) {
087: };
088:
089: /**
090: * Tell the underlying UI that the container has been changed
091: */
092: public void update(SComponent c, int id, Object constraint) {
093: };
094:
095: // EVENTS ///////////////////////////////////////////////////////////////
096:
097: /**
098: * @see com.javelin.swinglets.plaf.SComponentUI.addListener()
099: */
100: public void addListener(EventListener listener) {
101: if (listener instanceof ComponentListener)
102: ((JComponent) component)
103: .addComponentListener((ComponentListener) listener);
104: else if (listener instanceof FocusListener)
105: ((JComponent) component)
106: .addFocusListener((FocusListener) listener);
107: else if (listener instanceof KeyListener)
108: ((JComponent) component)
109: .addKeyListener((KeyListener) listener);
110: else if (listener instanceof MouseListener)
111: ((JComponent) component)
112: .addMouseListener((MouseListener) listener);
113: else if (listener instanceof MouseMotionListener)
114: ((JComponent) component)
115: .addMouseMotionListener((MouseMotionListener) listener);
116: }
117:
118: /**
119: * @see com.javelin.swinglets.plaf.SComponentUI.removeListener()
120: */
121: public void removeListener(EventListener listener) {
122: if (listener instanceof ComponentListener)
123: ((JComponent) component)
124: .removeComponentListener((ComponentListener) listener);
125: else if (listener instanceof FocusListener)
126: ((JComponent) component)
127: .removeFocusListener((FocusListener) listener);
128: else if (listener instanceof KeyListener)
129: ((JComponent) component)
130: .removeKeyListener((KeyListener) listener);
131: else if (listener instanceof MouseListener)
132: ((JComponent) component)
133: .removeMouseListener((MouseListener) listener);
134: else if (listener instanceof MouseMotionListener)
135: ((JComponent) component)
136: .removeMouseMotionListener((MouseMotionListener) listener);
137: }
138:
139: /**
140: * Adds the listeners to receive component events from
141: * the SComponent at initialisation.
142: */
143: public void addListeners(SComponent component)
144: throws TooManyListenersException {
145: //System.out.println( "Add PCL" + component.getClass().getName() );
146: component.addPropertyChangeListener(this );
147: }
148:
149: /**
150: * Removes all the listeners that received component events from
151: * the SComponent at initialisation.
152: */
153: public void removeListeners(SComponent component) {
154: component.removePropertyChangeListener(this );
155: }
156:
157: /**
158: * Listen for changes in the SComponent and mirror them in the component
159: */
160: public void propertyChange(PropertyChangeEvent event) {
161: //System.out.println( "PC C=" + event.getPropertyName() );
162:
163: if ("name".equals(event.getPropertyName()))
164: ((Component) component).setName((String) event
165: .getNewValue());
166: else if ("visible".equals(event.getPropertyName())) {
167: //System.out.println( "VISIBLE" );
168: ((Component) component).setVisible(((Boolean) event
169: .getNewValue()).booleanValue());
170: } else if ("enabled".equals(event.getPropertyName()))
171: ((Component) component).setEnabled(((Boolean) event
172: .getNewValue()).booleanValue());
173: else if ("foreground".equals(event.getPropertyName()))
174: ((Component) component).setForeground((Color) event
175: .getNewValue());
176: else if ("background".equals(event.getPropertyName()))
177: ((Component) component).setBackground((Color) event
178: .getNewValue());
179: else if ("size".equals(event.getPropertyName()))
180: ((Component) component).setSize((Dimension) event
181: .getNewValue());
182: else if ("cursor".equals(event.getPropertyName()))
183: ((Component) component).setCursor((Cursor) event
184: .getNewValue());
185: else if ("font".equals(event.getPropertyName())) {
186: SFont font = (SFont) event.getNewValue();
187: ((Component) component).setFont(new Font(font.getName(),
188: font.getStyle(), font.getSize()));
189: } else if ("locale".equals(event.getPropertyName())) {
190: ((Component) component).setLocale((Locale) event
191: .getNewValue());
192: } else if ("toolTipText".equals(event.getPropertyName()))
193: ((JComponent) component).setToolTipText((String) event
194: .getNewValue());
195: //else
196: //if( "border".equals( event.getPropertyName() ) )
197: // ((Component)component).setBorder( (Border)event.getNewValue() );
198:
199: }
200:
201: protected Component component;
202: }
|