KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > view > PopupListener


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.view;
5
6 import java.awt.event.MouseAdapter JavaDoc;
7 import java.awt.event.MouseEvent JavaDoc;
8
9 import javax.swing.JPopupMenu JavaDoc;
10
11 /**
12  *
13  */

14 class PopupListener extends MouseAdapter JavaDoc {
15     private JPopupMenu JavaDoc popup;
16     
17     public void setPopup(JPopupMenu JavaDoc popup) {
18         this.popup = popup;
19     }
20     
21     public void mousePressed(MouseEvent JavaDoc e) {
22         maybeShowPopup(e);
23     }
24     public void mouseClicked(MouseEvent JavaDoc e) {
25         maybeShowPopup(e);
26     }
27     public void mouseReleased(MouseEvent JavaDoc e) {
28         maybeShowPopup(e);
29     }
30     
31     private void maybeShowPopup(MouseEvent JavaDoc e) {
32         if (popup != null && e.isPopupTrigger()) {
33             popup.show(e.getComponent(), e.getX(), e.getY());
34         }
35     }
36 }
37
Popular Tags