001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * JBoxButtonPopup.java
028: *
029: * Created on May 18, 2006, 12:00 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.box;
034:
035: import java.awt.Component;
036: import java.awt.Container;
037: import java.awt.event.ComponentEvent;
038: import java.awt.event.ComponentListener;
039: import javax.swing.JPopupMenu;
040: import javax.swing.SwingUtilities;
041:
042: /**
043: *
044: * @author gtoffoli
045: */
046: public class JBoxButtonPopup extends JPopupMenu {
047:
048: private Component parent;
049: private Component component;
050: private boolean installedTopListener = false;
051:
052: /** Creates a new instance of JBoxButtonPopup */
053: public JBoxButtonPopup(Component parent, Component c) {
054: super ();
055: this .setParentComponent(parent);
056: this .setComponent(c);
057: super .add(getComponent());
058:
059: }
060:
061: public void show() {
062: if (!installedTopListener) {
063: Container rootContainer = (Container) SwingUtilities
064: .getRootPane(getParentComponent());
065: rootContainer.addComponentListener(new ComponentListener() {
066: public void componentHidden(ComponentEvent e) {
067: setVisible(false);
068: }
069:
070: public void componentMoved(ComponentEvent e) {
071: setVisible(false);
072: }
073:
074: public void componentResized(ComponentEvent e) {
075: setVisible(false);
076: }
077:
078: public void componentShown(ComponentEvent e) {
079: setVisible(false);
080: }
081: });
082:
083: }
084: super .setPopupSize(getComponent().getPreferredSize());
085: // location specified is relative to comboBox
086: super .show(getParentComponent(), 0, getParentComponent()
087: .getHeight());
088: }
089:
090: public Component getParentComponent() {
091: return parent;
092: }
093:
094: public void setParentComponent(Component parent) {
095: this .parent = parent;
096: }
097:
098: public Component getComponent() {
099: return component;
100: }
101:
102: public void setComponent(Component component) {
103: this.component = component;
104: }
105:
106: }
|