home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / all java / quicktime for java / musicmixer / src / mixer / display / masterdisplay.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  2.2 KB  |  80 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. package mixer.display;
  9.  
  10. import java.awt.*;
  11. import java.awt.event.*;
  12. import javax.swing.*;
  13. import javax.swing.event.*;
  14. import quicktime.*;
  15. import quicktime.app.audio.*;
  16.  
  17. import mixer.mc.*;
  18.  
  19. /** This class represents a special kind of channel, which we call the master
  20.  *  control.  Master controls can only have their volume and mute status controlled
  21.  *  by the mixer.
  22.  */
  23. public class MasterDisplay extends ChannelDisplay {    
  24.  
  25.     /** The contructor just needs to know which MixerComponents object it is creating
  26.       * the display for.
  27.       */
  28.     public MasterDisplay (MixerComponents mixer) throws QTException {
  29.         this (mixer, true, false, false, true);
  30.     }
  31.  
  32.     protected MasterDisplay (MixerComponents mixer, boolean mute, boolean solo, boolean balance, boolean volume) throws QTException {
  33.         super (mixer, mute, solo, balance, volume);
  34.     }
  35.     
  36.     /* This is the ActionListener needed for mute buttons in master controls. */
  37.     void addMuteAction (JCheckBox b) {
  38.         try {
  39.             b.setSelected (mixer.getMaster().isMuted());
  40.             b.addActionListener(new ActionListener() {
  41.                 public void actionPerformed(ActionEvent e) {
  42.                     try {
  43.                         if (((JCheckBox) e.getSource()).isSelected())
  44.                             mixer.getMaster().setMuted(true);
  45.                         else
  46.                             mixer.getMaster().setMuted(false);
  47.                     }
  48.                     catch (QTException ex) {
  49.                         throw new QTRuntimeException (ex);
  50.                     }
  51.                 }
  52.             });
  53.         } catch (QTException e) {
  54.             throw new QTRuntimeException (e);
  55.         }
  56.     }
  57.  
  58.     /* This is the ActionListener needed for volume controls. */
  59.     void addVolumeAction (JSlider b) {
  60.         try {
  61.             b.setValue((int)(mixer.getMaster().getVolume() * 66.0F));
  62.  
  63.             b.addChangeListener(new ChangeListener() {
  64.                 public void stateChanged(ChangeEvent e) {
  65.                     try {
  66.                         Integer tmp = new Integer(((JSlider) e.getSource()).getValue());
  67.                         float v = tmp.floatValue();
  68.                         v = v / 66.0F;
  69.                         mixer.getMaster().setVolume(v);
  70.                     }
  71.                     catch (QTException ex) {
  72.                         throw new QTRuntimeException (ex);
  73.                     }
  74.                 }
  75.             });
  76.         } catch (QTException e) {
  77.             throw new QTRuntimeException (e);
  78.         }
  79.     }
  80. }