Package org.jdesktop.wonderland.modules.orb.client.cell

Source Code of org.jdesktop.wonderland.modules.orb.client.cell.OrbDialog

/**
* Project Wonderland
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., All Rights Reserved
*
* Redistributions in source code form must reproduce the above
* copyright and this condition.
*
* The contents of this file are subject to the GNU General Public
* License, Version 2 (the "License"); you may not use this file
* except in compliance with the License. A copy of the License is
* available at http://www.opensource.org/licenses/gpl-license.php.
*
* Sun designates this particular file as subject to the "Classpath"
* exception as provided by Sun in the License file that accompanied
* this code.
*/
package org.jdesktop.wonderland.modules.orb.client.cell;

import java.util.ResourceBundle;
import org.jdesktop.wonderland.client.cell.ChannelComponent;
import org.jdesktop.wonderland.client.softphone.SoftphoneControlImpl;
import org.jdesktop.wonderland.common.cell.CellID;
import org.jdesktop.wonderland.modules.orb.common.messages.OrbAttachMessage;
import org.jdesktop.wonderland.modules.orb.common.messages.OrbChangeNameMessage;
import org.jdesktop.wonderland.modules.orb.common.messages.OrbEndCallMessage;
import org.jdesktop.wonderland.modules.orb.common.messages.OrbMuteCallMessage;
import org.jdesktop.wonderland.modules.orb.common.messages.OrbSetVolumeMessage;
import org.jdesktop.wonderland.modules.presencemanager.client.PresenceManager;

/**
*
* @author  jp
* @author Ronny Standtke <ronny.standtke@fhnw.ch>
*/
public class OrbDialog extends javax.swing.JDialog {

    private static final ResourceBundle BUNDLE = ResourceBundle.getBundle(
            "org/jdesktop/wonderland/modules/orb/client/cell/Bundle");
    private static final String BYSTANDERS = BUNDLE.getString("Bystanders");
    private static final String ATTACH = BUNDLE.getString("Attach");
    private static final String DETACH = BUNDLE.getString("Detach");
    private static final String MUTE = BUNDLE.getString("Mute");
    private static final String UNMUTE = BUNDLE.getString("Unmute");
    private OrbCell orbCell;
    private ChannelComponent channelComp;
    private CellID avatarCellID;
    private PresenceManager pm;
    private String username;
    private BystandersDialog bystandersDialog;

    private VolumeConverter volumeConverter;

    /** Creates new form OrbDialog */
    public OrbDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

  volumeConverter = new VolumeConverter(volumeSlider.getMinimum(),
      volumeSlider.getMaximum());
    }

    public OrbDialog(OrbCell orbCell, ChannelComponent channelComp,
            CellID avatarCellID, PresenceManager pm) {

        this.orbCell = orbCell;
        this.channelComp = channelComp;
        this.avatarCellID = avatarCellID;
        this.pm = pm;

        username = orbCell.getUsername();

        initComponents();

  volumeConverter = new VolumeConverter(volumeSlider.getMinimum(),
      volumeSlider.getMaximum());

        if (orbCell.getPlayerWithVpCallID() != null) {
            //attachButton.setEnabled(false);
            attachButton.setText(BYSTANDERS);
            endCallButton.setEnabled(false);
            muteButton.setEnabled(false);
            nameTextField.setEnabled(false);
        }

        setTitle(username);
        setVisible(true);
    }

    public void orbDetached() {
        attachButton.setText(ATTACH);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nameLabel = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        volumeLabel = new javax.swing.JLabel();
        volumeSlider = new javax.swing.JSlider();
        endCallButton = new javax.swing.JButton();
        muteButton = new javax.swing.JButton();
        attachButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/jdesktop/wonderland/modules/orb/client/cell/Bundle"); // NOI18N
        nameLabel.setText(bundle.getString("OrbDialog.nameLabel.text")); // NOI18N

        nameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameTextFieldActionPerformed(evt);
            }
        });

        volumeLabel.setText(bundle.getString("OrbDialog.volumeLabel.text")); // NOI18N

        volumeSlider.setMinorTickSpacing(10);
        volumeSlider.setPaintTicks(true);
        volumeSlider.setPreferredSize(new java.awt.Dimension(200, 29));
        volumeSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                volumeSliderStateChanged(evt);
            }
        });

        endCallButton.setText(bundle.getString("OrbDialog.endCallButton.text")); // NOI18N
        endCallButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                endCallButtonActionPerformed(evt);
            }
        });

        muteButton.setText(bundle.getString("OrbDialog.muteButton.text")); // NOI18N
        muteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                muteButtonActionPerformed(evt);
            }
        });

        attachButton.setText(bundle.getString("OrbDialog.attachButton.text")); // NOI18N
        attachButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                attachButtonActionPerformed(evt);
            }
        });

        okButton.setText(bundle.getString("OrbDialog.okButton.text")); // NOI18N
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(nameLabel)
                            .add(volumeLabel))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(nameTextField)
                            .add(volumeSlider, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .add(91, 91, 91))
                    .add(layout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(endCallButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(muteButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(attachButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(okButton)))
                .addContainerGap())
        );

        layout.linkSize(new java.awt.Component[] {nameLabel, volumeLabel}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(nameLabel)
                    .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(volumeLabel)
                    .add(volumeSlider, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(endCallButton)
                    .add(muteButton)
                    .add(attachButton)
                    .add(okButton))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void endCallButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_endCallButtonActionPerformed
    channelComp.send(new OrbEndCallMessage(orbCell.getCellID()));
    orbCell.removeMouseListener();
    setVisible(false);
}//GEN-LAST:event_endCallButtonActionPerformed

private void attachButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_attachButtonActionPerformed
    String text = attachButton.getText();
    if (BYSTANDERS.equals(text)) {
        if (bystandersDialog == null) {
            bystandersDialog = new BystandersDialog(orbCell, pm);
        }

        bystandersDialog.setVisible(true);
        return;
    }

    CellID cellID = orbCell.getCellID();
    if (ATTACH.equals(text)) {
        attachButton.setText(DETACH);
        channelComp.send(new OrbAttachMessage(cellID, avatarCellID, true));
    } else {
        attachButton.setText(ATTACH);
        channelComp.send(new OrbAttachMessage(cellID, avatarCellID, false));
    }
}//GEN-LAST:event_attachButtonActionPerformed

private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
    setVisible(false);
}//GEN-LAST:event_okButtonActionPerformed

private void muteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_muteButtonActionPerformed
    CellID cellID = orbCell.getCellID();
    if (MUTE.equals(muteButton.getText())) {
        muteButton.setText(UNMUTE);
        channelComp.send(new OrbMuteCallMessage(cellID, true));
    } else {
        muteButton.setText(MUTE);
        channelComp.send(new OrbMuteCallMessage(cellID, false));
    }
}//GEN-LAST:event_muteButtonActionPerformed

private void nameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameTextFieldActionPerformed
    String name = nameTextField.getText();

    if (name.length() > 0) {
        username = name;

        setTitle(name);

        channelComp.send(new OrbChangeNameMessage(orbCell.getCellID(), name));
    }
}//GEN-LAST:event_nameTextFieldActionPerformed

private void volumeSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_volumeSliderStateChanged
    float volume = volumeConverter.getVolume(volumeSlider.getValue());

    SoftphoneControlImpl sc = SoftphoneControlImpl.getInstance();

    channelComp.send(new OrbSetVolumeMessage(orbCell.getCellID(), sc.getCallID(), volume));
}//GEN-LAST:event_volumeSliderStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                OrbDialog dialog = new OrbDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton attachButton;
    private javax.swing.JButton endCallButton;
    private javax.swing.JButton muteButton;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JButton okButton;
    private javax.swing.JLabel volumeLabel;
    private javax.swing.JSlider volumeSlider;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of org.jdesktop.wonderland.modules.orb.client.cell.OrbDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.