Package games.stendhal.client.gui.buddies

Source Code of games.stendhal.client.gui.buddies.BuddyPanel$BuddyPanelMouseListener

/* $Id: BuddyPanel.java,v 1.18 2011/02/11 17:10:45 kiheru Exp $ */
/***************************************************************************
*                   (C) Copyright 2003-2010 - Stendhal                    *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.client.gui.buddies;

import games.stendhal.client.gui.MousePopupAdapter;

import java.awt.event.MouseEvent;

import javax.swing.JList;
import javax.swing.JPopupMenu;

/**
* JList that can show popup menues for buddies. Use <code>BuddyListModel</code>
* with this.
*/
class BuddyPanel extends JList {
  /**
   * serial version uid
   */
  private static final long serialVersionUID = -1728697267036233233L;

  /**
   * The amount of pixels that popup menus will be shifted up and left from
   * the clicking point.
   */
  private static final int POPUP_OFFSET = 10;

  /**
   * Create a new BuddyList.
   *
   * @param model associated list model
   */
  protected BuddyPanel(final BuddyListModel model) {
    super(model);
    setCellRenderer(new BuddyLabel());
    setOpaque(false);
    this.setFocusable(false);
    this.addMouseListener(new BuddyPanelMouseListener());
  }
 
  /**
   * MouseListener for triggering the buddy list popup menus.
   */
  private class BuddyPanelMouseListener extends MousePopupAdapter {
    @Override
    protected void showPopup(final MouseEvent e) {
      int index = BuddyPanel.this.locationToIndex(e.getPoint());
      Object obj = BuddyPanel.this.getModel().getElementAt(index);
      if (obj instanceof Buddy) {
        Buddy buddy = (Buddy) obj;
        final JPopupMenu popup = new BuddyLabelPopMenu(buddy.getName(), buddy.isOnline());
        popup.show(e.getComponent(), e.getX() - POPUP_OFFSET, e.getY() - POPUP_OFFSET);
      }
    }
  }
}
TOP

Related Classes of games.stendhal.client.gui.buddies.BuddyPanel$BuddyPanelMouseListener

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.