1 /***
2 * ProxyComponent.java
3 *
4 * This file is part of the creme library.
5 * The creme library intends to ease the development effort of large
6 * applications by providing easy to use support classes.
7 *
8 * Copyright (C) 2004 Denis Bregeon
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * contact information: dbregeon@sourceforge.net
25 */
26 package org.jcreme.swing;
27
28 import java.awt.Component;
29 import java.awt.Cursor;
30 import java.awt.Dimension;
31 import java.awt.Graphics;
32
33 /***
34 * This component uses an underlying Component to provide the values and
35 * interactions. For instant it paints the content of the underlying Component.
36 *
37 * @author $Author: dbregeon $
38 * @version $Revision: 1.1 $
39 */
40 public class ProxyComponent extends Component {
41
42 /***
43 * The Proxied Component.
44 */
45 private Component underlyingComponent = null;
46
47 /***
48 * Enables to direct the MouseEvents from this to the underlyingComponent.
49 */
50 private BindingMouseHandler binder = null;
51
52 /***
53 * Creates a new ProxyComponent.
54 *
55 * @param c
56 * the underlying Component to use.
57 */
58 public ProxyComponent(Component c) {
59 this.underlyingComponent = c;
60 this.binder = new BindingMouseHandler(this.underlyingComponent);
61 addMouseListener(this.binder);
62 addMouseMotionListener(this.binder);
63 }
64
65 /***
66 * Gives access to the object that binds this Component to the underlying
67 * Component.
68 *
69 * @return the BindingMouseHandler that links this Component to the
70 * underlying Component.
71 */
72 public BindingMouseHandler getBinder() {
73 return this.binder;
74 }
75
76 /***
77 * @see java.awt.Component#paint(java.awt.Graphics)
78 */
79 public void paint(Graphics g) {
80 this.underlyingComponent.paint(g);
81 }
82
83 /***
84 * @see java.awt.Component#getCursor()
85 */
86 public Cursor getCursor() {
87 return this.underlyingComponent.getCursor();
88 }
89
90 /***
91 * @see java.awt.Component#isLightweight()
92 */
93 public boolean isLightweight() {
94 return this.underlyingComponent.isLightweight();
95 }
96
97 /***
98 * @see java.awt.Component#isOpaque()
99 */
100 public boolean isOpaque() {
101 return this.underlyingComponent.isOpaque();
102 }
103
104 /***
105 * @see java.awt.Component#setCursor(java.awt.Cursor)
106 */
107 public void setCursor(Cursor cursor) {
108 this.underlyingComponent.setCursor(cursor);
109 }
110
111 /***
112 * @see java.awt.Component#getPreferredSize()
113 */
114 public Dimension getPreferredSize() {
115 return this.underlyingComponent.getPreferredSize();
116 }
117 }