001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * 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, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: HoverableShapedPanel.java,v 1.15 2005/12/04 13:46:03 jesper Exp $
023: package net.infonode.gui.hover.panel;
024:
025: import net.infonode.gui.hover.HoverEvent;
026: import net.infonode.gui.hover.HoverListener;
027: import net.infonode.gui.hover.hoverable.HoverManager;
028: import net.infonode.gui.hover.hoverable.Hoverable;
029: import net.infonode.gui.shaped.panel.ShapedPanel;
030:
031: import java.awt.*;
032: import java.util.ArrayList;
033:
034: /**
035: * @author johan
036: */
037: public class HoverableShapedPanel extends ShapedPanel implements
038: Hoverable {
039: private HoverListener hoverListener;
040:
041: private Component hoveredComponent;
042:
043: private boolean hovered = false;
044:
045: public HoverableShapedPanel(HoverListener listener) {
046: this (new BorderLayout(), listener, null);
047: }
048:
049: public HoverableShapedPanel(LayoutManager l, HoverListener listener) {
050: this (l, listener, null);
051: }
052:
053: public HoverableShapedPanel(LayoutManager l,
054: HoverListener listener, final Component hoveredComponent) {
055: super (l);
056: this .hoveredComponent = hoveredComponent != null ? hoveredComponent
057: : this ;
058: HoverManager.getInstance().addHoverable(this );
059: setHoverListener(listener);
060: }
061:
062: public HoverListener getHoverListener() {
063: return hoverListener;
064: }
065:
066: public void setHoverListener(HoverListener newHoverListener) {
067: if (hoverListener != newHoverListener) {
068: HoverListener oldHoverListener = hoverListener;
069:
070: // if (oldHoverListener != null && newHoverListener == null)
071: // HoverManager.getInstance().removeHoverable(this);
072:
073: hoverListener = newHoverListener;
074:
075: // if (oldHoverListener == null && newHoverListener != null)
076: // HoverManager.getInstance().addHoverable(this);
077:
078: if (oldHoverListener != null && newHoverListener != null
079: && hovered) {
080: HoverEvent event = new HoverEvent(hoveredComponent);
081: oldHoverListener.mouseExited(event);
082: newHoverListener.mouseEntered(event);
083: }
084: }
085: }
086:
087: public void hoverEnter() {
088: if (hoverListener != null) {
089: hovered = true;
090: hoverListener.mouseEntered(new HoverEvent(
091: HoverableShapedPanel.this .hoveredComponent));
092: }
093: }
094:
095: public void hoverExit() {
096: if (hoverListener != null) {
097: hovered = false;
098: hoverListener.mouseExited(new HoverEvent(
099: HoverableShapedPanel.this .hoveredComponent));
100: }
101: }
102:
103: public Component getHoveredComponent() {
104: return hoveredComponent;
105: }
106:
107: public boolean isHovered() {
108: return hovered;
109: }
110:
111: public boolean acceptHover(ArrayList enterableHoverables) {
112: return true;
113: }
114: }
|