001/*
002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
003 * Copyright (C) 2000-2011 The Gridarta Developers.
004 *
005 * This program is free software; you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation; either version 2 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License along
016 * with this program; if not, write to the Free Software Foundation, Inc.,
017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
018 */
019
020package net.sf.gridarta.gui.dialog.plugin.parameter;
021
022import java.awt.Component;
023import javax.swing.JComponent;
024import javax.swing.JSpinner;
025import javax.swing.SpinnerModel;
026
027/**
028 * Extends JSpinner to work around it's tooltip bug This bug has been fixed
029 * since Java 5.0 but we need this workaround for java 4.x users.
030 * @author tchize
031 */
032public class TooltipSpinner extends JSpinner {
033
034    private static final long serialVersionUID = -797350272052837471L;
035
036    public TooltipSpinner(final SpinnerModel model) {
037        super(model);
038    }
039
040    /**
041     * This override the JSpinner method to force the tooltip in all
042     * sub-components.
043     * @param text the tooltip to show
044     */
045    @Override
046    public void setToolTipText(final String text) {
047        forceTooltip(this, text);
048    }
049
050    private void forceTooltip(final JComponent tooltipComponent, final String tooltip) {
051        if (tooltipComponent == this) {
052            super.setToolTipText(tooltip);
053        } else {
054            tooltipComponent.setToolTipText(tooltip);
055        }
056        final Component[] components = tooltipComponent.getComponents();
057        for (final Component component : components) {
058            if (component instanceof JComponent) {
059                forceTooltip((JComponent) component, tooltip);
060            }
061        }
062    }
063
064}