1 4 package com.tc.admin.common; 5 6 import java.awt.event.MouseAdapter ; 7 import java.awt.event.MouseEvent ; 8 9 import javax.swing.JComponent ; 10 import javax.swing.JPopupMenu ; 11 12 15 16 public class XPopupListener extends MouseAdapter { 17 protected JComponent m_target; 18 protected JPopupMenu m_popupMenu; 19 20 public XPopupListener() { 21 super(); 22 } 23 24 public XPopupListener(JComponent target) { 25 this(); 26 m_target = target; 27 } 28 29 public void setTarget(JComponent target) { 30 if(m_target != null) { 31 if(m_popupMenu != null) { 32 m_target.removeMouseListener(this); 33 m_target.remove(m_popupMenu); 34 } 35 } 36 37 if((m_target = target) != null) { 38 if(m_popupMenu != null) { 39 m_target.add(m_popupMenu); 40 m_target.addMouseListener(this); 41 } 42 } 43 } 44 45 public void mousePressed(MouseEvent e) { 46 testPopup(e); 47 } 48 49 public void mouseReleased(MouseEvent e) { 50 testPopup(e); 51 } 52 53 public void testPopup(MouseEvent e) { 54 if(e.isPopupTrigger()) { 55 m_popupMenu.show(m_target, e.getX(), e.getY()); 56 } 57 } 58 59 public void setPopupMenu(JPopupMenu popupMenu) { 60 if(m_popupMenu != null) { 61 m_target.removeMouseListener(this); 62 m_target.remove(m_popupMenu); 63 } 64 65 if((m_popupMenu = popupMenu) != null) { 66 m_target.add(popupMenu); 67 m_target.addMouseListener(this); 68 } 69 } 70 71 public JPopupMenu getPopupMenu() { 72 return m_popupMenu; 73 } 74 } 75 | Popular Tags |