⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 popupcontroller.java

📁 ErGo是一个很早的Java通用围棋服务器(IGS/NNGS)客户端程序。有全部源码和文档
💻 JAVA
字号:
package ergo.ui;

// $Id: PopupController.java,v 1.4 1999/08/29 02:42:24 sigue Exp $

/*
 *  Copyright (C) 1999  Carl L. Gay and Antranig M. Basman.
 *  See the file copyright.txt, distributed with this software,
 *  for further information.
 */

import ergo.util.Util;
import ergo.util.Debug;
import java.awt.Component;
import java.awt.PopupMenu;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/** Popup menu controller.
 * Create a PopupController and add it as a MouseListener to any
 * component that should have a popup menu.  That component, and
 * any Container behind it in the Z-order that wants to add items
 * to the popup menu should implement the PopupContributor interface.
 */
public class PopupController implements MouseListener {
  
  private PopupMenu popup;

  private PopupController () {}  // prohibit zero arg constructor call.

  public PopupController (Component popupParent, String title) {
    if (title == null)
      title = "Options";
    popup = new PopupMenu(title);
    popupParent.add(popup);
  }

  public void mouseEntered (MouseEvent e) {}
  public void mouseExited  (MouseEvent e) {}
  public void mouseClicked (MouseEvent e) {}

  // Windows and OS/2 do popups during mouseReleased()
  //
  public void mouseReleased (MouseEvent e) {
    if (!Util.isUnix() && e.isPopupTrigger())
      doPopup(e);
  }

  // Unix does popups during mousePressed()
  //
  public void mousePressed (MouseEvent e) {
    if (Util.isUnix() && e.isPopupTrigger())
      doPopup(e);
  }

  private void doPopup (MouseEvent e) {
    Component c = e.getComponent();
    popup.removeAll();
    fillPopup(e, c, c);
    if (popup.getItemCount() > 0)
      popup.show(c, e.getX(), e.getY());
  }

  /** Give each component in the hierarchy an opportunity to add items to the popup menu.
   */
  private void fillPopup (MouseEvent e, Component c, Component orig) {
    if (c instanceof PopupContributor) {
      PopupContributor pc = (PopupContributor) c;
      pc.populatePopupMenu(popup, orig, e.getX(), e.getY());
      if (!pc.allowMoreItems(orig))
	return;  // Don't allow parents to add any more items.
    }
    if (c.getParent() != null)
      fillPopup(e, c.getParent(), orig);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -