001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/panels/PointSoundPanel.java,v 1.1 2005/04/20 22:21:07 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels;
019:
020: import javax.media.j3d.Sound;
021: import javax.media.j3d.PointSound;
022: import javax.media.j3d.MediaContainer;
023: import javax.vecmath.Point3f;
024: import java.awt.Color;
025:
026: import org.jdesktop.j3dfly.utils.gui.Tuple3fChangeListener;
027: import org.jdesktop.j3dfly.utils.gui.Tuple3fPanel;
028: import org.jdesktop.j3dfly.utils.gui.IntegerDocument;
029: import org.jdesktop.j3dfly.utils.gui.BoundsChangeListener;
030: import org.jdesktop.j3dfly.utils.gui.BoundsPanel;
031:
032: import org.jdesktop.j3dedit.scenegrapheditor.VisualToolManager;
033: import org.jdesktop.j3dedit.scenegraph.SGNode;
034: import org.jdesktop.j3dedit.scenegraph.SGNodeComponent;
035: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.NodeEditorPanel;
036: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.EditorPanelContainer;
037:
038: /**
039: * @author Paul Byrne
040: * @version 1.7, 01/18/02
041: */
042: public class PointSoundPanel extends NodeEditorPanel implements
043: Tuple3fChangeListener, BoundsChangeListener {
044:
045: private Point3f origPosition = new Point3f();
046: private boolean origEnabled;
047: private boolean origContinuous;
048: private boolean origReleaseEnable;
049: private int origLoop;
050: private float origPriority;
051: private javax.media.j3d.Bounds origSchedulingBounds;
052: private org.jdesktop.j3dedit.scenegrapheditor.visualtools.ShowBoundsVisualTool showBounds = null;
053:
054: private MediaContainerPanel mediaContainerPanel;
055:
056: /** Creates new form PointLightPanel */
057: public PointSoundPanel() {
058: super ();
059: frameTitle = "Point Sound";
060: initComponents();
061:
062: mediaContainerPanel = new MediaContainerPanel();
063: mediaContainerPanelParent.add(java.awt.BorderLayout.CENTER,
064: mediaContainerPanel);
065:
066: positionPanel.setChangeListener(this );
067: schedulingBoundsPanel.setBoundsChangeListener(this );
068: }
069:
070: /**
071: * Start editing this node
072: * Set the GUI components
073: */
074: public void startEdit(SGNode node, EditorPanelContainer frame) {
075:
076: mediaContainerPanel.startEdit(new SGNodeComponent(((Sound) node
077: .getJ3dNode()).getSoundData(), node.getContext()),
078: node, this );
079:
080: super .startEdit(node, frame);
081: }
082:
083: public void setReadOnly(boolean readOnly) {
084: super .setReadOnly(readOnly);
085: mediaContainerPanel.setReadOnly(readOnly);
086: schedulingBoundsPanel.setReadOnly(readOnly);
087: }
088:
089: /** This method is called from within the constructor to
090: * initialize the form.
091: * WARNING: Do NOT modify this code. The content of this method is
092: * always regenerated by the FormEditor.
093: */
094: private void initComponents() {//GEN-BEGIN:initComponents
095: jTabbedPane1 = new javax.swing.JTabbedPane();
096: jPanel2 = new javax.swing.JPanel();
097: jPanel1 = new javax.swing.JPanel();
098: continuousEnableCB = new javax.swing.JCheckBox();
099: loopCountL = new javax.swing.JLabel();
100: loopCountTF = new javax.swing.JTextField();
101: durationL = new javax.swing.JLabel();
102: durationTF = new javax.swing.JTextField();
103: soundEnableCB = new javax.swing.JCheckBox();
104: releaseEnableCB = new javax.swing.JCheckBox();
105: priorityTF = new javax.swing.JTextField();
106: jLabel1 = new javax.swing.JLabel();
107: jPanel3 = new javax.swing.JPanel();
108: positionPanelParent = new javax.swing.JPanel();
109: positionPanel = new org.jdesktop.j3dfly.utils.gui.Tuple3fPanel();
110: mediaContainerPanelParent = new javax.swing.JPanel();
111: schedulingBoundsPanelParent = new javax.swing.JPanel();
112: schedulingBoundsPanel = new org.jdesktop.j3dfly.utils.gui.BoundsPanel();
113: setLayout(new java.awt.BorderLayout());
114:
115: jPanel2.setLayout(new java.awt.GridBagLayout());
116: java.awt.GridBagConstraints gridBagConstraints1;
117:
118: jPanel1.setLayout(new java.awt.GridBagLayout());
119: java.awt.GridBagConstraints gridBagConstraints2;
120:
121: continuousEnableCB.setText("Continuous Enable");
122: continuousEnableCB
123: .addActionListener(new java.awt.event.ActionListener() {
124: public void actionPerformed(
125: java.awt.event.ActionEvent evt) {
126: continuousEnableCBActionPerformed(evt);
127: }
128: });
129:
130: gridBagConstraints2 = new java.awt.GridBagConstraints();
131: gridBagConstraints2.gridx = 0;
132: gridBagConstraints2.gridy = 1;
133: gridBagConstraints2.gridwidth = 2;
134: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
135: jPanel1.add(continuousEnableCB, gridBagConstraints2);
136:
137: loopCountL.setText("Loop Count");
138:
139: gridBagConstraints2 = new java.awt.GridBagConstraints();
140: gridBagConstraints2.gridx = 0;
141: gridBagConstraints2.gridy = 3;
142: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
143: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
144: jPanel1.add(loopCountL, gridBagConstraints2);
145:
146: loopCountTF
147: .setToolTipText("Number of times sound is played, use -1 for continuous play");
148: loopCountTF.setText("000000");
149: loopCountTF.setDocument(new IntegerDocument());
150: loopCountTF.addFocusListener(new java.awt.event.FocusAdapter() {
151: public void focusLost(java.awt.event.FocusEvent evt) {
152: loopCountTFFocusLost(evt);
153: }
154: });
155: loopCountTF
156: .addInputMethodListener(new java.awt.event.InputMethodListener() {
157: public void inputMethodTextChanged(
158: java.awt.event.InputMethodEvent evt) {
159: loopCountTFInputMethodTextChanged(evt);
160: }
161:
162: public void caretPositionChanged(
163: java.awt.event.InputMethodEvent evt) {
164:
165: }
166: });
167:
168: gridBagConstraints2 = new java.awt.GridBagConstraints();
169: gridBagConstraints2.gridx = 1;
170: gridBagConstraints2.gridy = 3;
171: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
172: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
173: jPanel1.add(loopCountTF, gridBagConstraints2);
174:
175: durationL.setText("Duration (ms)");
176:
177: gridBagConstraints2 = new java.awt.GridBagConstraints();
178: gridBagConstraints2.gridx = 0;
179: gridBagConstraints2.gridy = 4;
180: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
181: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
182: jPanel1.add(durationL, gridBagConstraints2);
183:
184: durationTF.setEditable(false);
185: durationTF.setText(" ");
186:
187: gridBagConstraints2 = new java.awt.GridBagConstraints();
188: gridBagConstraints2.gridx = 1;
189: gridBagConstraints2.gridy = 4;
190: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
191: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
192: jPanel1.add(durationTF, gridBagConstraints2);
193:
194: soundEnableCB.setLabel("Enable");
195: soundEnableCB.setText("enabled");
196: soundEnableCB
197: .addActionListener(new java.awt.event.ActionListener() {
198: public void actionPerformed(
199: java.awt.event.ActionEvent evt) {
200: soundEnableCBActionPerformed(evt);
201: }
202: });
203:
204: gridBagConstraints2 = new java.awt.GridBagConstraints();
205: gridBagConstraints2.gridwidth = 2;
206: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
207: jPanel1.add(soundEnableCB, gridBagConstraints2);
208:
209: releaseEnableCB.setText("Release Enable");
210: releaseEnableCB
211: .addActionListener(new java.awt.event.ActionListener() {
212: public void actionPerformed(
213: java.awt.event.ActionEvent evt) {
214: releaseEnableCBActionPerformed(evt);
215: }
216: });
217:
218: gridBagConstraints2 = new java.awt.GridBagConstraints();
219: gridBagConstraints2.gridx = 0;
220: gridBagConstraints2.gridy = 2;
221: gridBagConstraints2.gridwidth = 2;
222: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
223: jPanel1.add(releaseEnableCB, gridBagConstraints2);
224:
225: priorityTF.setEditable(false);
226: priorityTF.setText("jTextField1");
227:
228: gridBagConstraints2 = new java.awt.GridBagConstraints();
229: gridBagConstraints2.gridx = 1;
230: gridBagConstraints2.gridy = 5;
231: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
232: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
233: jPanel1.add(priorityTF, gridBagConstraints2);
234:
235: jLabel1.setText("Priority");
236:
237: gridBagConstraints2 = new java.awt.GridBagConstraints();
238: gridBagConstraints2.gridx = 0;
239: gridBagConstraints2.gridy = 5;
240: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 4);
241: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
242: jPanel1.add(jLabel1, gridBagConstraints2);
243:
244: gridBagConstraints1 = new java.awt.GridBagConstraints();
245: gridBagConstraints1.gridx = 0;
246: gridBagConstraints1.gridy = 0;
247: jPanel2.add(jPanel1, gridBagConstraints1);
248:
249: jTabbedPane1.addTab("Sound", jPanel2);
250:
251: jPanel3.setLayout(new java.awt.BorderLayout());
252:
253: positionPanelParent.setLayout(new java.awt.BorderLayout());
254: positionPanelParent.setPreferredSize(new java.awt.Dimension(
255: 132, 98));
256: positionPanelParent
257: .setBorder(new javax.swing.border.TitledBorder(
258: new javax.swing.border.EtchedBorder(),
259: "Position"));
260: positionPanelParent.setMinimumSize(new java.awt.Dimension(132,
261: 98));
262:
263: java.awt.GridBagConstraints gridBagConstraints3;
264:
265: positionPanelParent.add(positionPanel,
266: java.awt.BorderLayout.CENTER);
267:
268: jPanel3.add(positionPanelParent, java.awt.BorderLayout.CENTER);
269:
270: jTabbedPane1.addTab("Position", jPanel3);
271:
272: mediaContainerPanelParent
273: .setLayout(new java.awt.BorderLayout());
274:
275: jTabbedPane1.addTab("Media Container",
276: mediaContainerPanelParent);
277:
278: schedulingBoundsPanelParent.add(schedulingBoundsPanel);
279:
280: jTabbedPane1.addTab("Scheduling Bounds",
281: schedulingBoundsPanelParent);
282:
283: add(jTabbedPane1, java.awt.BorderLayout.CENTER);
284:
285: }//GEN-END:initComponents
286:
287: private void loopCountTFFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_loopCountTFFocusLost
288: // Add your handling code here:
289: setUpdateRequired(true);
290: try {
291: ((Sound) node.getJ3dNode()).setLoop(Integer
292: .parseInt(loopCountTF.getText()));
293: } catch (NumberFormatException e) {
294: // Should never get here as format is checked by IntegerDocument
295: e.printStackTrace();
296: throw new RuntimeException("Number Format Error");
297: }
298: }//GEN-LAST:event_loopCountTFFocusLost
299:
300: private void loopCountTFInputMethodTextChanged(
301: java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_loopCountTFInputMethodTextChanged
302: // Add your handling code here:
303: try {
304: int loop = Integer.parseInt(loopCountTF.getText());
305: if (loop != origLoop) {
306: setUpdateRequired(true);
307: ((Sound) node.getJ3dNode()).setLoop(loop);
308: }
309: } catch (NumberFormatException e) {
310: // Should never get here as format is checked by IntegerDocument
311: e.printStackTrace();
312: throw new RuntimeException("Number Format Error");
313: }
314: }//GEN-LAST:event_loopCountTFInputMethodTextChanged
315:
316: private void releaseEnableCBActionPerformed(
317: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_releaseEnableCBActionPerformed
318: // Add your handling code here:
319: ((Sound) node.getJ3dNode()).setReleaseEnable(releaseEnableCB
320: .isSelected());
321: setUpdateRequired(true);
322: }//GEN-LAST:event_releaseEnableCBActionPerformed
323:
324: private void jCheckBox1ActionPerformed(
325: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
326: // Add your handling code here:
327: }//GEN-LAST:event_jCheckBox1ActionPerformed
328:
329: private void continuousEnableCBActionPerformed(
330: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_continuousEnableCBActionPerformed
331: // Add your handling code here:
332: setUpdateRequired(true);
333: ((PointSound) node.getJ3dNode())
334: .setContinuousEnable(continuousEnableCB.isSelected());
335: }//GEN-LAST:event_continuousEnableCBActionPerformed
336:
337: private void loadFileBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadFileBActionPerformed
338: // Add your handling code here:
339: }//GEN-LAST:event_loadFileBActionPerformed
340:
341: private void soundEnableCBActionPerformed(
342: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_soundEnableCBActionPerformed
343: // Add your handling code here:
344: setUpdateRequired(true);
345: ((PointSound) node.getJ3dNode()).setEnable(soundEnableCB
346: .isSelected());
347: }//GEN-LAST:event_soundEnableCBActionPerformed
348:
349: public void setControls() {
350: PointSound sound = (PointSound) node.getJ3dNode();
351:
352: mediaContainerPanel.setControls();
353:
354: origEnabled = sound.getEnable();
355: origContinuous = sound.getContinuousEnable();
356: origReleaseEnable = sound.getReleaseEnable();
357: origLoop = sound.getLoop();
358: origPriority = sound.getPriority();
359: origSchedulingBounds = sound.getSchedulingBounds();
360:
361: soundEnableCB.setSelected(origEnabled);
362: continuousEnableCB.setSelected(origContinuous);
363: releaseEnableCB.setSelected(origReleaseEnable);
364: loopCountTF.setText(Integer.toString(origLoop));
365: durationTF.setText(Long.toString(sound.getDuration()));
366: priorityTF.setText(Float.toString(origPriority));
367:
368: sound.getPosition(origPosition);
369: positionPanel.setTuple(origPosition);
370: schedulingBoundsPanel.setBounds(origSchedulingBounds);
371: }
372:
373: public void applyChanges() {
374: setControls();
375: mediaContainerPanel.applyChanges();
376: setUpdateRequired(false);
377: }
378:
379: public void resetChanges() {
380: PointSound sound = (PointSound) node.getJ3dNode();
381: sound.setEnable(origEnabled);
382: sound.setContinuousEnable(origContinuous);
383: sound.setReleaseEnable(origReleaseEnable);
384: sound.setPosition(origPosition);
385: sound.setLoop(origLoop);
386: sound.setSchedulingBounds(origSchedulingBounds);
387: mediaContainerPanel.resetChanges();
388: setControls();
389: setUpdateRequired(false);
390: }
391:
392: protected void setReadCapabilityBits(javax.media.j3d.Node node) {
393: PointSound sound = (PointSound) node;
394:
395: sound.setCapability(PointSound.ALLOW_ENABLE_READ);
396: sound.setCapability(PointSound.ALLOW_SOUND_DATA_READ);
397: sound.setCapability(PointSound.ALLOW_POSITION_READ);
398: sound.setCapability(PointSound.ALLOW_LOOP_READ);
399: sound.setCapability(PointSound.ALLOW_CONT_PLAY_READ);
400: sound.setCapability(PointSound.ALLOW_DURATION_READ);
401: sound.setCapability(PointSound.ALLOW_RELEASE_READ);
402: sound.setCapability(PointSound.ALLOW_PRIORITY_READ);
403: sound.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_READ);
404:
405: mediaContainerPanel.setReadCapabilityBits(sound.getSoundData());
406: }
407:
408: protected void setReadWriteCapabilityBits(javax.media.j3d.Node node) {
409: PointSound sound = (PointSound) node;
410:
411: sound.setCapability(PointSound.ALLOW_ENABLE_READ);
412: sound.setCapability(PointSound.ALLOW_ENABLE_WRITE);
413: sound.setCapability(PointSound.ALLOW_SOUND_DATA_READ);
414: sound.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE);
415: sound.setCapability(PointSound.ALLOW_POSITION_READ);
416: sound.setCapability(PointSound.ALLOW_POSITION_WRITE);
417: sound.setCapability(PointSound.ALLOW_LOOP_READ);
418: sound.setCapability(PointSound.ALLOW_LOOP_WRITE);
419: sound.setCapability(PointSound.ALLOW_CONT_PLAY_READ);
420: sound.setCapability(PointSound.ALLOW_CONT_PLAY_WRITE);
421: sound.setCapability(PointSound.ALLOW_DURATION_READ);
422: sound.setCapability(PointSound.ALLOW_RELEASE_READ);
423: sound.setCapability(PointSound.ALLOW_RELEASE_WRITE);
424: sound.setCapability(PointSound.ALLOW_PRIORITY_READ);
425: sound.setCapability(PointSound.ALLOW_PRIORITY_WRITE);
426: sound.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_READ);
427: sound.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_WRITE);
428:
429: mediaContainerPanel.setReadWriteCapabilityBits(sound
430: .getSoundData());
431: }
432:
433: // Variables declaration - do not modify//GEN-BEGIN:variables
434: private javax.swing.JTabbedPane jTabbedPane1;
435: private javax.swing.JPanel jPanel2;
436: private javax.swing.JPanel jPanel1;
437: private javax.swing.JCheckBox continuousEnableCB;
438: private javax.swing.JLabel loopCountL;
439: private javax.swing.JTextField loopCountTF;
440: private javax.swing.JLabel durationL;
441: private javax.swing.JTextField durationTF;
442: private javax.swing.JCheckBox soundEnableCB;
443: private javax.swing.JCheckBox releaseEnableCB;
444: private javax.swing.JTextField priorityTF;
445: private javax.swing.JLabel jLabel1;
446: private javax.swing.JPanel jPanel3;
447: private javax.swing.JPanel positionPanelParent;
448: private org.jdesktop.j3dfly.utils.gui.Tuple3fPanel positionPanel;
449: private javax.swing.JPanel mediaContainerPanelParent;
450: private javax.swing.JPanel schedulingBoundsPanelParent;
451: private org.jdesktop.j3dfly.utils.gui.BoundsPanel schedulingBoundsPanel;
452:
453: // End of variables declaration//GEN-END:variables
454:
455: /**
456: * Called whenever the user changes the values in the Point3fPanel
457: */
458: public void pointChanged(Tuple3fPanel source, float x, float y,
459: float z) {
460: if (source == positionPanel)
461: ((PointSound) node.getJ3dNode()).setPosition(new Point3f(x,
462: y, z));
463: }
464:
465: public void boundsChanged(BoundsPanel source,
466: javax.media.j3d.Bounds bounds) {
467: if (source == schedulingBoundsPanel)
468: ((PointSound) node.getJ3dNode())
469: .setSchedulingBounds(bounds);
470: }
471:
472: public void showBounds(BoundsPanel source, boolean show) {
473: if (showBounds == null) {
474: showBounds = (org.jdesktop.j3dedit.scenegrapheditor.visualtools.ShowBoundsVisualTool) VisualToolManager
475: .getManager()
476: .getVisualTool(
477: org.jdesktop.j3dedit.scenegrapheditor.visualtools.ShowBoundsVisualTool.class);
478: if (showBounds == null) {
479: showBounds = new org.jdesktop.j3dedit.scenegrapheditor.visualtools.ShowBoundsVisualTool();
480: VisualToolManager.getManager().addTool(showBounds);
481: }
482: }
483:
484: if (source == schedulingBoundsPanel)
485: showBounds.showSchedulingBounds(show, node);
486: }
487: }
|