Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / java / awt / peer / swing / SwingContainerPeer.java
blob0b2fb992fb99a5d8213c9ace7d108547d1fd0e7d
1 /* SwingContainerPeer.java -- A Swing based peer for AWT containers
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.java.awt.peer.swing;
40 import java.awt.Component;
41 import java.awt.Container;
42 import java.awt.Graphics;
43 import java.awt.Insets;
44 import java.awt.Shape;
45 import java.awt.event.MouseEvent;
46 import java.awt.peer.ComponentPeer;
47 import java.awt.peer.ContainerPeer;
49 /**
50 * A peer for Container to be used with the Swing based AWT peers.
52 * @author Roman Kennke (kennke@aicas.com)
54 public class SwingContainerPeer
55 extends SwingComponentPeer
56 implements ContainerPeer
59 /**
60 * Creates a new SwingContainerPeer.
62 * @param awtCont
64 public SwingContainerPeer(Component awtCont)
66 init(awtCont, null);
69 /**
70 * Returns the insets of the container.
72 * This is implemented to return the insets of the Swing container.
74 * @return the insets of the container
76 public Insets insets()
78 Insets retVal;
79 if (swingComponent != null)
80 retVal = swingComponent.getJComponent().getInsets();
81 else
82 retVal = new Insets(0, 0, 0, 0);
83 return retVal;
86 /**
87 * Returns the insets of the container.
89 * This is implemented to return the insets of the Swing container.
91 * @return the insets of the container
93 public Insets getInsets()
95 return insets();
98 /**
99 * Called before the validation of this containers begins.
101 public void beginValidate()
103 // Nothing to do here.
107 * Called after the validation of this containers ended.
109 public void endValidate()
111 // Nothing to do here.
115 * Called before the layout of this containers begins.
117 public void beginLayout()
119 // Nothing to do here.
123 * Called after the layout of this containers ended.
125 public void endLayout()
127 // Nothing to do here.
131 * Returns <code>false</code> unconditionally. This method is not used at
132 * the moment.
134 * @return <code>false</code>
136 public boolean isPaintPending()
138 return false;
142 * Returns <code>false</code> unconditionally. This method is not used at
143 * the moment.
145 * @return <code>false</code>
147 public boolean isRestackSupported()
149 return false;
153 * This method is not used at the moment.
155 public void cancelPendingPaint(int x, int y, int width, int height)
157 // Nothing to do here.
161 * This method is not used at the moment.
163 public void restack()
165 // Nothing to do here.
169 * Triggers painting of a component. This calls peerPaint on all the child
170 * components of this container.
172 * @param g the graphics context to paint to
174 protected void peerPaint(Graphics g)
176 Container c = (Container) awtComponent;
177 Component[] children = c.getComponents();
178 for (int i = children.length - 1; i >= 0; --i)
180 Component child = children[i];
181 ComponentPeer peer = child.getPeer();
182 boolean translated = false;
183 boolean clipped = false;
184 Shape oldClip = g.getClip();
187 g.translate(child.getX(), child.getY());
188 translated = true;
189 g.setClip(0, 0, child.getWidth(), child.getHeight());
190 clipped = true;
191 if (peer instanceof SwingComponentPeer)
192 ((SwingComponentPeer) peer).peerPaint(g);
194 finally
196 if (translated)
197 g.translate(- child.getX(), - child.getY());
198 if (clipped)
199 g.setClip(oldClip);
205 * Handles mouse events by dispatching it to the correct component.
207 * @param ev the mouse event
209 protected void handleMouseEvent(MouseEvent ev)
211 Component comp = awtComponent.getComponentAt(ev.getPoint());
212 if (comp != null)
214 ComponentPeer peer = comp.getPeer();
215 if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
217 ev.translatePoint(comp.getX(), comp.getY());
218 ev.setSource(comp);
219 ((SwingComponentPeer) peer).handleMouseEvent(ev);
225 * Handles mouse events by dispatching it to the correct component.
227 * @param ev the mouse event
229 protected void handleMouseMotionEvent(MouseEvent ev)
231 Component comp = awtComponent.getComponentAt(ev.getPoint());
232 if (comp != null)
234 ComponentPeer peer = comp.getPeer();
235 if (awtComponent != comp && !comp.isLightweight() && peer instanceof SwingComponentPeer)
237 ev.translatePoint(comp.getX(), comp.getY());
238 ((SwingComponentPeer) peer).handleMouseMotionEvent(ev);