001: package net.xoetrope.builder.editor.components.swing;
002:
003: import java.awt.Color;
004: import java.awt.Component;
005: import java.awt.Dimension;
006: import java.awt.event.MouseEvent;
007: import java.awt.event.MouseListener;
008: import javax.swing.JComponent;
009: import javax.swing.JPanel;
010:
011: import net.xoetrope.xui.XListHolder;
012: import net.xoetrope.xui.XStateHolder;
013: import net.xoetrope.xui.XTextHolder;
014: import java.awt.event.ComponentListener;
015: import java.awt.event.ComponentEvent;
016: import java.awt.Font;
017: import net.xoetrope.xui.XAttributedComponent;
018:
019: /**
020: * A stand-in for a component while it is being edited. Some components are
021: * compound entities and we do not want the individual sub components to be
022: * selected instead of 'this' component. Some others react to the mouse and
023: * provide undesireable behavior on their own. This proxy adds the type of
024: * interface required by the editor.
025: * <p>Copyright (c) Xoetrope Ltd., 1998-2004</p>
026: * <p> $Revision: 1.4 $</p>
027: * <p> License: see License.txt</p>
028: */
029: public class XComponentProxy extends JComponent implements XTextHolder,
030: XListHolder, XStateHolder, MouseListener, ComponentListener,
031: XAttributedComponent {
032: Component proxiedComponent;
033: GlassPanel glassPanel;
034:
035: public XComponentProxy() {
036: setLayout(null);
037: glassPanel = new GlassPanel();
038: glassPanel.setOpaque(false);
039: glassPanel.setBackground(Color.red);
040:
041: }
042:
043: /**
044: * Set the component that is being proxied
045: * @param comp the component
046: */
047: public void setProxiedComponent(Component comp) {
048: proxiedComponent = comp;
049: // comp.addMouseListener( this );
050: glassPanel.addMouseListener(this );
051: addComponentListener(this );
052:
053: add(glassPanel);
054: add(comp);
055: }
056:
057: /**
058: * Get the proxied component
059: * @return the component
060: */
061: public Component getProxiedComponent() {
062: return proxiedComponent;
063: }
064:
065: /**
066: * Is the component focusable? Always returns true so that the component can
067: * be selected in the editor
068: * @return true
069: */
070: public boolean isFocusable() {
071: return true;
072: }
073:
074: //- XTextHolder methods-------------------------------------------------------
075: /**
076: * Set the text/label of a component
077: * @param label the new text
078: */
079: public void setText(String text) {
080: ((XTextHolder) proxiedComponent).setText(text);
081: }
082:
083: /**
084: * Get the text/label of a component
085: * @return the component's text
086: */
087: public String getText() {
088: return ((XTextHolder) proxiedComponent).getText();
089: }
090:
091: //- XTextHolder methods-------------------------------------------------------
092:
093: //- XStateHolder methods-------------------------------------------------------
094: /**
095: * Get the component state
096: * @return the object state
097: */
098: public Object getComponentState() {
099: return null;
100: }
101:
102: /**
103: * Set the component state
104: * @param the new component state
105: */
106: public void setComponentState(Object object) {
107: }
108:
109: //- XStateHolder methods-------------------------------------------------------
110:
111: //- XListHolder methods-------------------------------------------------------
112: /**
113: * Get the number of items in the list
114: * @return the number of items
115: */
116: public int getItemCount() {
117: return 0;
118: }
119:
120: /**
121: * Remove all items from the list
122: */
123: public void removeAll() {
124: }
125:
126: /**
127: * Add an item to the list
128: * @param s the new Item
129: */
130: public void addItem(String s) {
131: }
132:
133: /**
134: * Select an item
135: * @param i the index of the item to select
136: */
137: public void select(int i) {
138: }
139:
140: /**
141: * Select an item
142: * @param i the index of the item to select
143: */
144: public void select(Object o) {
145: }
146:
147: /**
148: * Get the selected object
149: * @return the selected object
150: */
151: public Object getSelectedObject() {
152: return null;
153: }
154:
155: //- XListHolder methods-------------------------------------------------------
156:
157: //- MouseListener methods-----------------------------------------------------
158: /**
159: * Invoked when the mouse button has been clicked (pressed
160: * and released) on a component.
161: */
162: public void mouseClicked(MouseEvent e) {
163: }
164:
165: /**
166: * Invoked when a mouse button has been pressed on a component.
167: */
168: public void mousePressed(MouseEvent e) {
169: }
170:
171: /**
172: * Invoked when a mouse button has been released on a component.
173: */
174: public void mouseReleased(MouseEvent e) {
175: MouseListener mel[] = this .getMouseListeners();
176: MouseEvent me = new MouseEvent(this , e.getID(), e.getWhen(), e
177: .getModifiers(), e.getX(), e.getY(), e.getClickCount(),
178: e.isPopupTrigger());
179: if (mel.length > 0)
180: mel[0].mouseReleased(me);
181: }
182:
183: /**
184: * Invoked when the mouse enters a component.
185: */
186: public void mouseEntered(MouseEvent e) {
187: }
188:
189: /**
190: * Invoked when the mouse exits a component.
191: */
192: public void mouseExited(MouseEvent e) {
193: }
194:
195: //- MouseListener methods-----------------------------------------------------
196:
197: //- ComponentListener methods-------------------------------------------------
198: /**
199: * Invoked when the component's size changes.
200: */
201: public void componentResized(ComponentEvent e) {
202: Dimension newSize = getSize();
203: proxiedComponent.setSize(newSize);
204: glassPanel.setSize(newSize);
205: }
206:
207: public void setForeground(Color c) {
208: proxiedComponent.setForeground(c);
209: }
210:
211: public void setBackground(Color c) {
212: proxiedComponent.setBackground(c);
213: }
214:
215: public void setFont(Font f) {
216: proxiedComponent.setFont(f);
217: }
218:
219: public void repaint() {
220: proxiedComponent.repaint();
221: super .repaint();
222: }
223:
224: public void setAttribute(String name, String value) {
225: if (proxiedComponent instanceof XAttributedComponent)
226: ((XAttributedComponent) proxiedComponent).setAttribute(
227: name, value);
228: }
229:
230: /**
231: * Invoked when the component's position changes.
232: */
233: public void componentMoved(ComponentEvent e) {
234: }
235:
236: /**
237: * Invoked when the component has been made visible.
238: */
239: public void componentShown(ComponentEvent e) {
240: }
241:
242: /**
243: * Invoked when the component has been made invisible.
244: */
245: public void componentHidden(ComponentEvent e) {
246: }
247: //- ComponentListener methods-------------------------------------------------
248: }
|