001: /*
002: * $RCSfile: QueryProperties.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.3 $
041: * $Date: 2007/02/09 17:21:46 $
042: * $State: Exp $
043: */
044:
045: package org.jdesktop.j3d.examples.package_info;
046:
047: import java.awt.GraphicsEnvironment;
048: import java.awt.GraphicsConfiguration;
049: import java.util.ArrayList;
050: import java.util.Collections;
051: import java.util.HashSet;
052: import java.util.Iterator;
053: import java.util.List;
054: import java.util.Map;
055: import javax.media.j3d.Canvas3D;
056: import javax.media.j3d.GraphicsConfigTemplate3D;
057: import javax.media.j3d.VirtualUniverse;
058: import javax.swing.JTextArea;
059:
060: public class QueryProperties extends javax.swing.JFrame {
061:
062: public static void printProps(JTextArea textArea, Map map,
063: String[] propList) {
064: // Create an alphabetical list of keys
065: List keyList = new ArrayList(map.keySet());
066: Collections.sort(keyList);
067: Iterator it;
068:
069: // Collection used to remember the properties we've already
070: // printed, so we don't print them twice
071: HashSet hs = new HashSet();
072:
073: // Print out the values for the caller-specified properties
074: String key;
075: for (int i = 0; i < propList.length; i++) {
076: int len = propList[i].length();
077: int idxWild = propList[i].indexOf('*');
078: if (idxWild < 0) {
079: key = propList[i];
080: if (!hs.contains(key)) {
081: textArea.append(key + " = " + map.get(key) + "\n");
082: hs.add(key);
083: }
084: } else if (idxWild == len - 1) {
085: String pattern = propList[i].substring(0, len - 1);
086: it = keyList.iterator();
087: while (it.hasNext()) {
088: key = (String) it.next();
089: if (key.startsWith(pattern) && !hs.contains(key)) {
090: textArea.append(key + " = " + map.get(key)
091: + "\n");
092: hs.add(key);
093: }
094: }
095: } else {
096: textArea
097: .append(propList[i]
098: + " = ERROR: KEY WITH EMBEDDED WILD CARD IGNORED\n");
099: }
100: }
101:
102: // Print out the values for those properties not already printed
103: it = keyList.iterator();
104: while (it.hasNext()) {
105: key = (String) it.next();
106: if (!hs.contains(key)) {
107: textArea.append(key + " = " + map.get(key) + "\n");
108: }
109: }
110:
111: }
112:
113: /** Creates new form QueryProperties */
114: public QueryProperties() {
115: initComponents();
116:
117: VirtualUniverse vu = new VirtualUniverse();
118: Map vuMap = vu.getProperties();
119: final String[] vuPropList = { "j3d.version", "j3d.vendor",
120: "j3d.specification.version",
121: "j3d.specification.vendor", "j3d.*"
122: // Just print all other properties in alphabetical order
123: };
124:
125: printProps(myTextArea, vuMap, vuPropList);
126: myTextArea.append("\n");
127:
128: GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
129:
130: /* We need to set this to force choosing a pixel format
131: that support the canvas.
132: */
133: template.setStereo(template.PREFERRED);
134: template.setSceneAntialiasing(template.PREFERRED);
135:
136: GraphicsConfiguration config = GraphicsEnvironment
137: .getLocalGraphicsEnvironment().getDefaultScreenDevice()
138: .getBestConfiguration(template);
139:
140: Map c3dMap = new Canvas3D(config).queryProperties();
141: final String[] c3dPropList = { "native.*",
142: "doubleBufferAvailable", "stereoAvailable",
143: "sceneAntialiasing*",
144: "compressedGeometry.majorVersionNumber",
145: "compressedGeometry.minorVersionNumber",
146: "compressedGeometry.*", "textureUnitStateMax",
147: "textureWidthMax", "textureHeightMax",
148: // Just print all other properties in alphabetical order
149: };
150:
151: printProps(myTextArea, c3dMap, c3dPropList);
152: }
153:
154: // ----------------------------------------------------------------
155:
156: /** This method is called from within the constructor to
157: * initialize the form.
158: * WARNING: Do NOT modify this code. The content of this method is
159: * always regenerated by the Form Editor.
160: */
161: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
162: private void initComponents() {
163: jScrollPane1 = new javax.swing.JScrollPane();
164: myTextArea = new javax.swing.JTextArea();
165:
166: setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
167: setTitle("QueryProperties");
168: jScrollPane1.setPreferredSize(new java.awt.Dimension(400, 500));
169: myTextArea.setColumns(20);
170: myTextArea.setEditable(false);
171: myTextArea.setRows(5);
172: jScrollPane1.setViewportView(myTextArea);
173:
174: getContentPane()
175: .add(jScrollPane1, java.awt.BorderLayout.CENTER);
176:
177: pack();
178: }// </editor-fold>//GEN-END:initComponents
179:
180: /**
181: * @param args the command line arguments
182: */
183: public static void main(String args[]) {
184: java.awt.EventQueue.invokeLater(new Runnable() {
185: public void run() {
186: new QueryProperties().setVisible(true);
187: }
188: });
189: }
190:
191: // Variables declaration - do not modify//GEN-BEGIN:variables
192: private javax.swing.JScrollPane jScrollPane1;
193: private javax.swing.JTextArea myTextArea;
194: // End of variables declaration//GEN-END:variables
195:
196: }
|