Package voxo.client.listeners

Source Code of voxo.client.listeners.ButtonRemoveListener

/**
*
*/
package voxo.client.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

import voxo.client.actions.RemoveContactAction;
import voxo.client.controllers.ClientController;
import voxo.client.views.MainView;
import voxo.common.packets.ClientRequestPacket;

/**
* @author Thierry
*
*/
public class ButtonRemoveListener implements ActionListener {

  private MainView      mainView;
  private ClientController  c;

  public ButtonRemoveListener(MainView mainView, ClientController c) {

    this.mainView = mainView;
    this.c = c;
  }

  @Override
  public void actionPerformed(ActionEvent arg0) {

    if (!(mainView.getSelectedUser() == null)) {
      String msg = new String("Are you sure you want to delete " + mainView.getSelectedUser().getUsername() + "\n" + "from your contact list ?");

      // confirm to erase panels
      final JOptionPane optionPane = new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
      final JDialog dialog = new JDialog(mainView, "Click a button", true);

      dialog.setContentPane(optionPane);

      // listener for user response user
      optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
          String prop = e.getPropertyName();

          if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
            dialog.setVisible(false);
          }
        }
      });

      // afficher le dialogue
      dialog.pack();
      dialog.setVisible(true);

      // if yes, erase user
      int value = ((Integer) optionPane.getValue()).intValue();
      if (value == JOptionPane.YES_OPTION) {

        ClientRequestPacket p = new ClientRequestPacket(mainView.getMe().getUsername(), mainView.getSelectedUser().getUsername());
        new RemoveContactAction(c, p);
      }
    }
  }

}
TOP

Related Classes of voxo.client.listeners.ButtonRemoveListener

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.