001: /*
002: * @(#)ImageConsumerQueue.java 1.13 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package sun.awt.image;
029:
030: import java.awt.image.ImageConsumer;
031:
032: public class ImageConsumerQueue {
033: ImageConsumerQueue next;
034: ImageConsumer consumer;
035: boolean interested;
036: Object securityContext;
037: boolean secure;
038:
039: static ImageConsumerQueue removeConsumer(ImageConsumerQueue cqbase,
040: ImageConsumer ic, boolean stillinterested) {
041: ImageConsumerQueue cqprev = null;
042: for (ImageConsumerQueue cq = cqbase; cq != null; cq = cq.next) {
043: if (cq.consumer == ic) {
044: if (cqprev == null) {
045: cqbase = cq.next;
046: } else {
047: cqprev.next = cq.next;
048: }
049: cq.interested = stillinterested;
050: break;
051: }
052: cqprev = cq;
053: }
054: return cqbase;
055: }
056:
057: static boolean isConsumer(ImageConsumerQueue cqbase,
058: ImageConsumer ic) {
059: for (ImageConsumerQueue cq = cqbase; cq != null; cq = cq.next) {
060: if (cq.consumer == ic) {
061: return true;
062: }
063: }
064: return false;
065: }
066:
067: ImageConsumerQueue(InputStreamImageSource src, ImageConsumer ic) {
068: consumer = ic;
069: interested = true;
070: // ImageReps do their own security at access time.
071: if (ic instanceof ImageRepresentation) {
072: ImageRepresentation ir = (ImageRepresentation) ic;
073: if (ir.image.source != src) {
074: throw new SecurityException(
075: "ImageRep added to wrong image source");
076: }
077: secure = true;
078: } else {
079: SecurityManager security = System.getSecurityManager();
080: if (security != null) {
081: securityContext = security.getSecurityContext();
082: } else {
083: securityContext = null;
084: }
085: }
086: }
087:
088: public ImageConsumer getConsumer() {
089: return this .consumer;
090: }
091:
092: public String toString() {
093: return ("["
094: + consumer
095: + ", "
096: + (interested ? "" : "not ")
097: + "interested"
098: + (securityContext != null ? ", " + securityContext
099: : "") + "]");
100: }
101: }
|