001: /*
002: * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.geom;
027:
028: final class ChainEnd {
029: CurveLink head;
030: CurveLink tail;
031: ChainEnd partner;
032: int etag;
033:
034: public ChainEnd(CurveLink first, ChainEnd partner) {
035: this .head = first;
036: this .tail = first;
037: this .partner = partner;
038: this .etag = first.getEdgeTag();
039: }
040:
041: public CurveLink getChain() {
042: return head;
043: }
044:
045: public void setOtherEnd(ChainEnd partner) {
046: this .partner = partner;
047: }
048:
049: public ChainEnd getPartner() {
050: return partner;
051: }
052:
053: /*
054: * Returns head of a complete chain to be added to subcurves
055: * or null if the links did not complete such a chain.
056: */
057: public CurveLink linkTo(ChainEnd that) {
058: if (etag == AreaOp.ETAG_IGNORE
059: || that.etag == AreaOp.ETAG_IGNORE) {
060: throw new InternalError("ChainEnd linked more than once!");
061: }
062: if (etag == that.etag) {
063: throw new InternalError("Linking chains of the same type!");
064: }
065: ChainEnd enter, exit;
066: // assert(partner.etag != that.partner.etag);
067: if (etag == AreaOp.ETAG_ENTER) {
068: enter = this ;
069: exit = that;
070: } else {
071: enter = that;
072: exit = this ;
073: }
074: // Now make sure these ChainEnds are not linked to any others...
075: etag = AreaOp.ETAG_IGNORE;
076: that.etag = AreaOp.ETAG_IGNORE;
077: // Now link everything up...
078: enter.tail.setNext(exit.head);
079: enter.tail = exit.tail;
080: if (partner == that) {
081: // Curve has closed on itself...
082: return enter.head;
083: }
084: // Link this chain into one end of the chain formed by the partners
085: ChainEnd otherenter = exit.partner;
086: ChainEnd otherexit = enter.partner;
087: otherenter.partner = otherexit;
088: otherexit.partner = otherenter;
089: if (enter.head.getYTop() < otherenter.head.getYTop()) {
090: enter.tail.setNext(otherenter.head);
091: otherenter.head = enter.head;
092: } else {
093: otherexit.tail.setNext(enter.head);
094: otherexit.tail = enter.tail;
095: }
096: return null;
097: }
098:
099: public void addLink(CurveLink newlink) {
100: if (etag == AreaOp.ETAG_ENTER) {
101: tail.setNext(newlink);
102: tail = newlink;
103: } else {
104: newlink.setNext(head);
105: head = newlink;
106: }
107: }
108:
109: public double getX() {
110: if (etag == AreaOp.ETAG_ENTER) {
111: return tail.getXBot();
112: } else {
113: return head.getXBot();
114: }
115: }
116: }
|