001: /*
002: * $RCSfile: RenderingError.java,v $
003: *
004: * Copyright 2006-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.4 $
028: * $Date: 2008/02/28 20:17:29 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.awt.GraphicsDevice;
035: import java.io.PrintStream;
036:
037: /**
038: * RenderingError is a container object that holds the details of
039: * a runtime error that occurs in the Java 3D rendering system.
040: *
041: * @since Java 3D 1.5
042: */
043: public class RenderingError extends Object {
044: private int errorCode = NO_ERROR;
045: private String errorMessage = null;
046: private String detailMessage = null;
047: private GraphicsDevice graphicsDevice = null;
048: private Canvas3D canvas = null;
049:
050: /**
051: * Indicates that no error occurred.
052: */
053: public static final int NO_ERROR = 0;
054:
055: /**
056: * Indicates that an unexpected rendering exception was caught by the
057: * Java 3D renderer thread.
058: */
059: public static final int UNEXPECTED_RENDERING_ERROR = 1;
060:
061: /**
062: * Indicates that an error occurred while getting the best graphics
063: * configuration or while testing whether a given graphics config is
064: * supported.
065: */
066: public static final int GRAPHICS_CONFIG_ERROR = 2;
067:
068: /**
069: * Indicates that an error occurred while creating an OpenGL or D3D
070: * graphics context. This can happen either when querying
071: * the Canvas3D properties or when rendering.
072: */
073: public static final int CONTEXT_CREATION_ERROR = 3;
074:
075: /**
076: * Indicates a error in creating a rendering buffer for an off-screen
077: * Canvas3D.
078: */
079: public static final int OFF_SCREEN_BUFFER_ERROR = 4;
080:
081: /**
082: * Constructs a new RenderingError object indicating no error. The
083: * error code is set to <code>NO_ERROR</code>. All other fields
084: * are initialized to null, including the error message.
085: */
086: public RenderingError() {
087: }
088:
089: /**
090: * Constructs a new RenderingError object with the given error code
091: * and message. All other fields are initialized to null.
092: *
093: * @param errorCode the error code for this rendering error.
094: * @param errorMessage a short error message describing this
095: * rendering error.
096: */
097: public RenderingError(int errorCode, String errorMessage) {
098: this .errorCode = errorCode;
099: this .errorMessage = errorMessage;
100: }
101:
102: /**
103: * Prints a verbose error report to System.err. This verbose
104: * output includes the error code, error message, detail message,
105: * and all relevant Java 3D objects.
106: */
107: public void printVerbose() {
108: printVerbose(System.err);
109: }
110:
111: /**
112: * Prints a verbose error report to the specified PrintStream.
113: * This verbose output includes the error code, error message,
114: * detail message, and all relevant Java 3D objects.
115: *
116: * @param printStream the print stream on which to print the error
117: * report.
118: */
119: public void printVerbose(PrintStream printStream) {
120: printStream.println(this );
121: if (graphicsDevice != null) {
122: printStream.println("graphicsDevice = " + graphicsDevice);
123: }
124: if (canvas != null) {
125: printStream.println("canvas = " + canvas);
126: }
127:
128: if (detailMessage != null) {
129: printStream.println();
130: printStream.println("Detail Message");
131: printStream.println("--------------");
132: printStream.println(detailMessage);
133: }
134: }
135:
136: /**
137: * Sets the error code for this rendering error. This represents the
138: * type of error that occurred.
139: *
140: * @param errorCode the error code for this rendering error.
141: */
142: public void setErrorCode(int errorCode) {
143: this .errorCode = errorCode;
144: }
145:
146: /**
147: * Returns the error code for this rendering error.
148: *
149: * @return the error code.
150: */
151: public int getErrorCode() {
152: return errorCode;
153: }
154:
155: /**
156: * Sets the error message for this rendering error. This is a short
157: * message describing the error, and is included as part of
158: * toString().
159: *
160: * @param errorMessage a short error message describing this
161: * rendering error.
162: */
163: public void setErrorMessage(String errorMessage) {
164: this .errorMessage = errorMessage;
165: }
166:
167: /**
168: * Returns the error message for this rendering error.
169: *
170: * @return a short error message describing this rendering error.
171: */
172: public String getErrorMessage() {
173: return errorMessage;
174: }
175:
176: /**
177: * Sets the detail message for this rendering error. This is a more
178: * detailed error message that is not included as part of toString().
179: *
180: * @param detailMessage a detailed message describing this
181: * error in more detail.
182: */
183: public void setDetailMessage(String detailMessage) {
184: this .detailMessage = detailMessage;
185: }
186:
187: /**
188: * Returns the detail message for this rendering error.
189: *
190: * @return the detail message for this rendering error.
191: */
192: public String getDetailMessage() {
193: return detailMessage;
194: }
195:
196: /**
197: * Sets the graphics device associated with this rendering error.
198: *
199: * @param graphicsDevice the graphics device associated with this rendering error.
200: */
201: public void setGraphicsDevice(GraphicsDevice graphicsDevice) {
202: this .graphicsDevice = graphicsDevice;
203: }
204:
205: /**
206: * Returns the graphics device associated with this rendering error.
207: *
208: * @return the graphics device associated with this rendering error.
209: */
210: public GraphicsDevice getGraphicsDevice() {
211: return this .graphicsDevice;
212: }
213:
214: /**
215: * Sets the canvas associated with this rendering error.
216: *
217: * @param canvas the canvas associated with this rendering error.
218: */
219: public void setCanvas3D(Canvas3D canvas) {
220: this .canvas = canvas;
221: }
222:
223: /**
224: * Returns the canvas associated with this rendering error.
225: *
226: * @return the canvas associated with this rendering error.
227: */
228: public Canvas3D getCanvas3D() {
229: return this .canvas;
230: }
231:
232: /**
233: * Returns a short string that describes this rendering error. The
234: * string is composed of the textual description of the errorCode,
235: * a ": ", and the errorMessage field. If the errorMessage is
236: * null then the ": " and the errorMessage are omitted.
237: *
238: * @return a string representation of this rendering error.
239: */
240: public String toString() {
241: // Concatenate string representation of error code with error message
242: String errorCodeStr;
243: switch (errorCode) {
244: case NO_ERROR:
245: errorCodeStr = "NO_ERROR";
246: break;
247: case UNEXPECTED_RENDERING_ERROR:
248: errorCodeStr = "UNEXPECTED_RENDERING_ERROR";
249: break;
250: case GRAPHICS_CONFIG_ERROR:
251: errorCodeStr = "GRAPHICS_CONFIG_ERROR";
252: break;
253: case CONTEXT_CREATION_ERROR:
254: errorCodeStr = "CONTEXT_CREATION_ERROR";
255: break;
256: case OFF_SCREEN_BUFFER_ERROR:
257: errorCodeStr = "OFF_SCREEN_BUFFER_ERROR";
258: break;
259:
260: default:
261: errorCodeStr = "UNKNOWN ERROR CODE (" + errorCode + ")";
262: }
263:
264: if (errorMessage == null) {
265: return errorCodeStr;
266: }
267:
268: return errorCodeStr + ": " + errorMessage;
269: }
270: }
|