001: /*
002: * $RCSfile: DepthFuncTest.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.2 $
041: * $Date: 2007/02/09 17:21:35 $
042: * $State: Exp $
043: */
044:
045: package org.jdesktop.j3d.examples.depth_func;
046:
047: import javax.media.j3d.*;
048:
049: /**
050: *The goal of that example is to show the use of different ZBuffer comparison modes.
051: */
052: public class DepthFuncTest extends javax.swing.JFrame {
053:
054: RenderFrame rf;
055:
056: /**
057: * Creates new form DepthFuncTest
058: */
059: public DepthFuncTest() {
060: initComponents();
061: }
062:
063: /** This method is called from within the constructor to
064: * initialize the form.
065: * WARNING: Do NOT modify this code. The content of this method is
066: * always regenerated by the Form Editor.
067: */
068: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
069: private void initComponents() {
070: java.awt.GridBagConstraints gridBagConstraints;
071:
072: jPanel1 = new javax.swing.JPanel();
073: jLabel1 = new javax.swing.JLabel();
074: normalComboBox = new javax.swing.JComboBox();
075: wfCheckBox = new javax.swing.JCheckBox();
076: jPanel2 = new javax.swing.JPanel();
077: jLabel3 = new javax.swing.JLabel();
078: shadedComboBox = new javax.swing.JComboBox();
079: shadedCheckBox = new javax.swing.JCheckBox();
080: jPanel3 = new javax.swing.JPanel();
081: jLabel4 = new javax.swing.JLabel();
082: rotatingComboBox = new javax.swing.JComboBox();
083:
084: getContentPane().setLayout(new java.awt.GridBagLayout());
085:
086: setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
087: jPanel1.setBorder(new javax.swing.border.TitledBorder(
088: "WireFrame Object"));
089: jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
090: jLabel1.setText("Depth function");
091: jLabel1.setToolTipText("Mode for normal object");
092: jPanel1.add(jLabel1);
093: jLabel1.getAccessibleContext().setAccessibleParent(
094: shadedComboBox);
095:
096: normalComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
097: normalComboBox.setModel(new javax.swing.DefaultComboBoxModel(
098: new String[] { "ALWAYS", "NEVER", "EQUAL", "NOT_EQUAL",
099: "LESS", "LESS_OR_EQUAL", "GREATER",
100: "GREATER_OR_EQUAL" }));
101: normalComboBox.setSelectedIndex(6);
102: normalComboBox
103: .setPreferredSize(new java.awt.Dimension(150, 22));
104: normalComboBox
105: .addActionListener(new java.awt.event.ActionListener() {
106: public void actionPerformed(
107: java.awt.event.ActionEvent evt) {
108: normalComboBoxActionPerformed(evt);
109: }
110: });
111:
112: jPanel1.add(normalComboBox);
113:
114: wfCheckBox.setFont(new java.awt.Font("Dialog", 0, 12));
115: wfCheckBox.setText("Write Depth Buffer");
116: wfCheckBox
117: .setToolTipText("Depth will be written for the object, if selected");
118: wfCheckBox
119: .addActionListener(new java.awt.event.ActionListener() {
120: public void actionPerformed(
121: java.awt.event.ActionEvent evt) {
122: wfCheckBoxActionPerformed(evt);
123: }
124: });
125:
126: jPanel1.add(wfCheckBox);
127:
128: gridBagConstraints = new java.awt.GridBagConstraints();
129: gridBagConstraints.gridx = 0;
130: gridBagConstraints.gridy = 0;
131: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
132: getContentPane().add(jPanel1, gridBagConstraints);
133:
134: jPanel2.setBorder(new javax.swing.border.TitledBorder(
135: "Shaded Object"));
136: jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
137: jLabel3.setText("Depth Function");
138: jLabel3.setToolTipText("Mode of shaded object");
139: jPanel2.add(jLabel3);
140:
141: shadedComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
142: shadedComboBox.setModel(new javax.swing.DefaultComboBoxModel(
143: new String[] { "ALWAYS", "NEVER", "EQUAL", "NOT_EQUAL",
144: "LESS", "LESS_OR_EQUAL", "GREATER",
145: "GREATER_OR_EQUAL" }));
146: shadedComboBox.setSelectedIndex(4);
147: shadedComboBox
148: .addActionListener(new java.awt.event.ActionListener() {
149: public void actionPerformed(
150: java.awt.event.ActionEvent evt) {
151: shadedComboBoxActionPerformed(evt);
152: }
153: });
154:
155: jPanel2.add(shadedComboBox);
156:
157: shadedCheckBox.setFont(new java.awt.Font("Dialog", 0, 12));
158: shadedCheckBox.setSelected(true);
159: shadedCheckBox.setText("Write Depth Buffer");
160: shadedCheckBox
161: .setToolTipText("Depth will be written for the object, if selected");
162: shadedCheckBox
163: .addActionListener(new java.awt.event.ActionListener() {
164: public void actionPerformed(
165: java.awt.event.ActionEvent evt) {
166: shadedCheckBoxActionPerformed(evt);
167: }
168: });
169:
170: jPanel2.add(shadedCheckBox);
171:
172: gridBagConstraints = new java.awt.GridBagConstraints();
173: gridBagConstraints.gridx = 0;
174: gridBagConstraints.gridy = 1;
175: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
176: getContentPane().add(jPanel2, gridBagConstraints);
177:
178: jPanel3.setBorder(new javax.swing.border.TitledBorder(
179: "Rotating Cube"));
180: jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
181: jLabel4.setText("Raster Operator");
182: jLabel4
183: .setToolTipText("Raster mode of rotating object (try NOOP)");
184: jPanel3.add(jLabel4);
185:
186: rotatingComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
187: rotatingComboBox
188: .setModel(new javax.swing.DefaultComboBoxModel(
189: new String[] { "CLEAR", "AND", "AND_REVERSE",
190: "COPY", "AND_INVERTED", "NOOP", "XOR",
191: "OR", "NOR", "EQUIV", "INVERT",
192: "OR_REVERSE", "COPY_INVERTED",
193: "OR_INVERTED", "NAND", "SET" }));
194: rotatingComboBox.setSelectedIndex(3);
195: rotatingComboBox
196: .addActionListener(new java.awt.event.ActionListener() {
197: public void actionPerformed(
198: java.awt.event.ActionEvent evt) {
199: rotatingComboBoxActionPerformed(evt);
200: }
201: });
202:
203: jPanel3.add(rotatingComboBox);
204:
205: gridBagConstraints = new java.awt.GridBagConstraints();
206: gridBagConstraints.gridx = 0;
207: gridBagConstraints.gridy = 2;
208: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
209: getContentPane().add(jPanel3, gridBagConstraints);
210:
211: setBounds(0, 0, 403, 240);
212: }
213:
214: // </editor-fold>//GEN-END:initComponents
215:
216: private void rotatingComboBoxActionPerformed(
217: java.awt.event.ActionEvent evt)//GEN-FIRST:event_rotatingComboBoxActionPerformed
218: {//GEN-HEADEREND:event_rotatingComboBoxActionPerformed
219: String selectedItem = rotatingComboBox.getSelectedItem()
220: .toString(); // how to avoid a cast and all that goes with it. (lazyness)
221: int mode = RenderingAttributes.ROP_COPY;
222: if ("CLEAR".equals(selectedItem)) {
223: mode = RenderingAttributes.ROP_CLEAR;
224: } else if ("AND".equals(selectedItem)) {
225: mode = RenderingAttributes.ROP_AND;
226: } else if ("AND_REVERSE".equals(selectedItem)) {
227: mode = RenderingAttributes.ROP_AND_REVERSE;
228: } else if ("COPY".equals(selectedItem)) {
229: mode = RenderingAttributes.ROP_COPY;
230: } else if ("AND_INVERTED".equals(selectedItem)) {
231: mode = RenderingAttributes.ROP_AND_INVERTED;
232: } else if ("NOOP".equals(selectedItem)) {
233: mode = RenderingAttributes.ROP_NOOP;
234: } else if ("XOR".equals(selectedItem)) {
235: mode = RenderingAttributes.ROP_XOR;
236: } else if ("OR".equals(selectedItem)) {
237: mode = RenderingAttributes.ROP_OR;
238: } else if ("NOR".equals(selectedItem)) {
239: mode = RenderingAttributes.ROP_NOR;
240: } else if ("EQUIV".equals(selectedItem)) {
241: mode = RenderingAttributes.ROP_EQUIV;
242: } else if ("INVERT".equals(selectedItem)) {
243: mode = RenderingAttributes.ROP_INVERT;
244: } else if ("OR_REVERSE".equals(selectedItem)) {
245: mode = RenderingAttributes.ROP_OR_REVERSE;
246: } else if ("COPY_INVERTED".equals(selectedItem)) {
247: mode = RenderingAttributes.ROP_COPY_INVERTED;
248: } else if ("OR_INVERTED".equals(selectedItem)) {
249: mode = RenderingAttributes.ROP_OR_INVERTED;
250: } else if ("NAND".equals(selectedItem)) {
251: mode = RenderingAttributes.ROP_NAND;
252: } else if ("SET".equals(selectedItem)) {
253: mode = RenderingAttributes.ROP_SET;
254: } else {
255: System.out.println("oops. wrong mode in ROP combo: "
256: + selectedItem);
257: }
258: rf.setRotatingObjectROPMode(mode);
259: }//GEN-LAST:event_rotatingComboBoxActionPerformed
260:
261: private void shadedCheckBoxActionPerformed(
262: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shadedCheckBoxActionPerformed
263: rf.setStaticObjectDBWriteStatus(shadedCheckBox.isSelected());
264: }//GEN-LAST:event_shadedCheckBoxActionPerformed
265:
266: private void wfCheckBoxActionPerformed(
267: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wfCheckBoxActionPerformed
268: rf.setStaticWFObjectDBWriteStatus(wfCheckBox.isSelected());
269: }//GEN-LAST:event_wfCheckBoxActionPerformed
270:
271: private void shadedComboBoxActionPerformed(
272: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shadedComboBoxActionPerformed
273: int func = RenderingAttributes.LESS_OR_EQUAL;
274: String selectedItem = shadedComboBox.getSelectedItem()
275: .toString(); // how to avoid a cast and all that goes with it. (lazyness)
276: rf.setStaticObjectTestFunc(getID(selectedItem));
277: }//GEN-LAST:event_shadedComboBoxActionPerformed
278:
279: private void normalComboBoxActionPerformed(
280: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_normalComboBoxActionPerformed
281: int func = RenderingAttributes.LESS_OR_EQUAL;
282: String selectedItem = normalComboBox.getSelectedItem()
283: .toString(); // how to avoid a cast and all that goes with it. (lazyness)
284: rf.setStaticWFObjectTestFunc(getID(selectedItem));
285: }//GEN-LAST:event_normalComboBoxActionPerformed
286:
287: int getID(String selectedItem) {
288: int func = RenderingAttributes.LESS_OR_EQUAL;
289: if ("LESS_OR_EQUAL".equals(selectedItem)) {
290: func = RenderingAttributes.LESS_OR_EQUAL;
291: } else if ("NEVER".equals(selectedItem)) {
292: func = RenderingAttributes.NEVER;
293: } else if ("ALWAYS".equals(selectedItem)) {
294: func = RenderingAttributes.ALWAYS;
295: } else if ("GREATER".equals(selectedItem)) {
296: func = RenderingAttributes.GREATER;
297: } else if ("GREATER_OR_EQUAL".equals(selectedItem)) {
298: func = RenderingAttributes.GREATER_OR_EQUAL;
299: } else if ("LESS".equals(selectedItem)) {
300: func = RenderingAttributes.LESS;
301: } else if ("EQUAL".equals(selectedItem)) {
302: func = RenderingAttributes.EQUAL;
303: } else if ("NOT_EQUAL".equals(selectedItem)) {
304: func = RenderingAttributes.NOT_EQUAL;
305: }
306: return func;
307: }
308:
309: /**
310: * @param args the command line arguments
311: */
312: public static void main(String args[]) {
313: java.awt.EventQueue.invokeLater(new Runnable() {
314: public void run() {
315: DepthFuncTest dpt = new DepthFuncTest();
316: dpt.rf = new RenderFrame(dpt);
317: dpt.setVisible(true);
318: dpt.rf.setVisible(true);
319: }
320: });
321: }
322:
323: // Variables declaration - do not modify//GEN-BEGIN:variables
324: private javax.swing.JLabel jLabel1;
325: private javax.swing.JLabel jLabel3;
326: private javax.swing.JLabel jLabel4;
327: private javax.swing.JPanel jPanel1;
328: private javax.swing.JPanel jPanel2;
329: private javax.swing.JPanel jPanel3;
330: private javax.swing.JComboBox normalComboBox;
331: private javax.swing.JComboBox rotatingComboBox;
332: private javax.swing.JCheckBox shadedCheckBox;
333: private javax.swing.JComboBox shadedComboBox;
334: private javax.swing.JCheckBox wfCheckBox;
335: // End of variables declaration//GEN-END:variables
336:
337: }
|