KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > box > JBoxButtonPopup


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * JBoxButtonPopup.java
28  *
29  * Created on May 18, 2006, 12:00 PM
30  *
31  */

32
33 package it.businesslogic.ireport.gui.box;
34
35 import java.awt.Component JavaDoc;
36 import java.awt.Container JavaDoc;
37 import java.awt.event.ComponentEvent JavaDoc;
38 import java.awt.event.ComponentListener JavaDoc;
39 import javax.swing.JPopupMenu JavaDoc;
40 import javax.swing.SwingUtilities JavaDoc;
41
42 /**
43  *
44  * @author gtoffoli
45  */

46 public class JBoxButtonPopup extends JPopupMenu JavaDoc {
47     
48     private Component JavaDoc parent;
49     private Component JavaDoc component;
50     private boolean installedTopListener = false;
51     
52     /** Creates a new instance of JBoxButtonPopup */
53     public JBoxButtonPopup(Component JavaDoc parent, Component JavaDoc c) {
54         super();
55         this.setParentComponent(parent);
56         this.setComponent(c);
57         super.add(getComponent());
58
59     }
60     
61      public void show()
62     {
63         if (!installedTopListener)
64         {
65               Container JavaDoc rootContainer = (Container JavaDoc)SwingUtilities.getRootPane(getParentComponent());
66               rootContainer.addComponentListener(new ComponentListener JavaDoc() {
67                   public void componentHidden(ComponentEvent JavaDoc e) {
68                       setVisible(false);
69                   }
70                   public void componentMoved(ComponentEvent JavaDoc e) {
71                       setVisible(false);
72                   }
73                   public void componentResized(ComponentEvent JavaDoc e) {
74                       setVisible(false);
75                   }
76                   public void componentShown(ComponentEvent JavaDoc e) {
77                       setVisible(false);
78                   }
79               } );
80
81         }
82         super.setPopupSize(getComponent().getPreferredSize());
83         // location specified is relative to comboBox
84
super.show(getParentComponent(), 0, getParentComponent().getHeight());
85     }
86
87     public Component JavaDoc getParentComponent() {
88         return parent;
89     }
90
91     public void setParentComponent(Component JavaDoc parent) {
92         this.parent = parent;
93     }
94
95     public Component JavaDoc getComponent() {
96         return component;
97     }
98
99     public void setComponent(Component JavaDoc component) {
100         this.component = component;
101     }
102
103 }
104
Popular Tags