Showing the changes to java/pkg/sun/java2d/pipe/RegionIterator.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,101 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package sun.java2d.pipe; | ||
| 27 | |||
| 28 | import java.awt.Rectangle; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * This class defines the API for iterating through the bands | ||
| 32 | * of a region object. | ||
| 33 | */ | ||
| 34 | public class RegionIterator { | ||
| 35 | Region region; | ||
| 36 | int curIndex; | ||
| 37 | int numXbands; | ||
| 38 | |||
| 39 | RegionIterator(Region r) { | ||
| 40 | region = r; | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Returns a new RegionIterator object representing the same | ||
| 45 | * iteration state as this object to allow multiple iteration | ||
| 46 | * branches from the current position. | ||
| 47 | */ | ||
| 48 | public RegionIterator createCopy() { | ||
| 49 | RegionIterator r = new RegionIterator(region); | ||
| 50 | r.curIndex = this.curIndex; | ||
| 51 | r.numXbands = this.numXbands; | ||
| 52 | return r; | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Copies the iteration state from this RegionIterator object | ||
| 57 | * into another RegionIterator object to allow multiple iteration | ||
| 58 | * branches from the current position. | ||
| 59 | */ | ||
| 60 | public void copyStateFrom(RegionIterator ri) { | ||
| 61 | if (this.region != ri.region) { | ||
| 62 | throw new InternalError("region mismatch"); | ||
| 63 | } | ||
| 64 | this.curIndex = ri.curIndex; | ||
| 65 | this.numXbands = ri.numXbands; | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Moves the iteration state to the beginning of the next | ||
| 70 | * Y range in the region returning true if one is found | ||
| 71 | * and recording the low and high Y coordinates of the | ||
| 72 | * range in the array at locations 1 and 3 respectively. | ||
| 73 | */ | ||
| 74 | public boolean nextYRange(int range[]) { | ||
| 75 | curIndex += numXbands * 2; | ||
| 76 | numXbands = 0; | ||
| 77 | if (curIndex >= region.endIndex) { | ||
| 78 | return false; | ||
| 79 | } | ||
| 80 | range[1] = region.bands[curIndex++]; | ||
| 81 | range[3] = region.bands[curIndex++]; | ||
| 82 | numXbands = region.bands[curIndex++]; | ||
| 83 | return true; | ||
| 84 | } | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Moves the iteration state to the beginning of the next | ||
| 88 | * X band in the current Y range returning true if one is | ||
| 89 | * found and recording the low and high X coordinates of | ||
| 90 | * the range in the array at locations 0 and 2 respectively. | ||
| 91 | */ | ||
| 92 | public boolean nextXBand(int range[]) { | ||
| 93 | if (numXbands <= 0) { | ||
| 94 | return false; | ||
| 95 | } | ||
| 96 | numXbands--; | ||
| 97 | range[0] = region.bands[curIndex++]; | ||
| 98 | range[2] = region.bands[curIndex++]; | ||
| 99 | return true; | ||
| 100 | } | ||
| 101 | } | ||