01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Pavel Dolgov, Anton Avtamonov
19: * @version $Revision$
20: */package org.apache.harmony.awt;
21:
22: import java.awt.Component;
23: import java.awt.Rectangle;
24:
25: import org.apache.harmony.awt.gl.MultiRectArea;
26: import org.apache.harmony.awt.internal.nls.Messages;
27:
28: public class ClipRegion extends Rectangle {
29: private final MultiRectArea clip;
30:
31: public ClipRegion(final MultiRectArea clip) {
32: this .clip = new MultiRectArea(clip);
33: setBounds(clip.getBounds());
34: }
35:
36: public MultiRectArea getClip() {
37: return clip;
38: }
39:
40: @Override
41: public String toString() {
42: String str = clip.toString();
43: int i = str.indexOf('[');
44: str = str.substring(i);
45: if (clip.getRectCount() == 1) {
46: str = str.substring(1, str.length() - 1);
47: }
48: return getClass().getName() + str;
49: }
50:
51: public void convertRegion(final Component child,
52: final Component parent) {
53: convertRegion(child, clip, parent);
54: }
55:
56: public void intersect(final Rectangle rect) {
57: clip.intersect(rect);
58: }
59:
60: @Override
61: public boolean isEmpty() {
62: return clip.isEmpty();
63: }
64:
65: public static void convertRegion(final Component child,
66: final MultiRectArea region, final Component parent) {
67: int x = 0, y = 0;
68: Component c = child;
69: for (; c != null && c != parent; c = c.getParent()) {
70: x += c.getX();
71: y += c.getY();
72: }
73: if (c == null) {
74: // awt.51=Component expected to be a parent
75: throw new IllegalArgumentException(Messages
76: .getString("awt.51")); //$NON-NLS-1$
77: }
78: region.translate(x, y);
79: }
80: }
|