001: /*
002: * $RCSfile: CanvasViewEventCatcher.java,v $
003: *
004: * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.8 $
028: * $Date: 2008/02/28 20:17:20 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.ArrayList;
035: import java.awt.*;
036: import java.awt.event.*;
037:
038: /**
039: * The CanvasViewEventCatcher class is used to track events on a Canvas3D that
040: * may cause view matries to change.
041: *
042: */
043: class CanvasViewEventCatcher extends ComponentAdapter {
044:
045: // The canvas associated with this event catcher
046: private Canvas3D canvas;
047: private static final boolean DEBUG = false;
048:
049: CanvasViewEventCatcher(Canvas3D c) {
050: canvas = c;
051: }
052:
053: public void componentResized(ComponentEvent e) {
054: if (DEBUG) {
055: System.err.println("Component resized " + e);
056: }
057:
058: if (e.getComponent() == canvas) {
059: if (DEBUG) {
060: System.err.println("It is canvas!");
061: }
062: synchronized (canvas) {
063: synchronized (canvas.dirtyMaskLock) {
064: canvas.cvDirtyMask[0] |= Canvas3D.MOVED_OR_RESIZED_DIRTY;
065: canvas.cvDirtyMask[1] |= Canvas3D.MOVED_OR_RESIZED_DIRTY;
066: }
067: canvas.resizeGraphics2D = true;
068: }
069:
070: // see comment below
071: try {
072: canvas.newSize = canvas.getSize();
073: canvas.newPosition = canvas.getLocationOnScreen();
074: } catch (IllegalComponentStateException ex) {
075: }
076:
077: }
078: }
079:
080: public void componentMoved(ComponentEvent e) {
081: if (DEBUG) {
082: System.err.println("Component moved " + e);
083: }
084:
085: synchronized (canvas) {
086: synchronized (canvas.dirtyMaskLock) {
087: canvas.cvDirtyMask[0] |= Canvas3D.MOVED_OR_RESIZED_DIRTY;
088: canvas.cvDirtyMask[1] |= Canvas3D.MOVED_OR_RESIZED_DIRTY;
089: }
090: }
091: // Can't sync. with canvas lock since canvas.getLocationOnScreen()
092: // required Component lock. The order is reverse of
093: // removeNotify() lock sequence which required Component lock
094: // first, then canvas lock in removeComponentListener()
095:
096: try {
097: canvas.newSize = canvas.getSize();
098: canvas.newPosition = canvas.getLocationOnScreen();
099: } catch (IllegalComponentStateException ex) {
100: }
101:
102: }
103:
104: }
|