001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy 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 Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.gui.component.renderer;
020
021import java.awt.Component;
022import java.awt.Rectangle;
023
024import javax.swing.JSlider;
025import javax.swing.JTable;
026import javax.swing.JTree;
027import javax.swing.table.TableCellRenderer;
028import javax.swing.tree.TreeCellRenderer;
029
030/**
031 * @author Stephane
032 */
033public class SliderCellRenderer extends JSlider implements TableCellRenderer, TreeCellRenderer
034{
035    /**
036     * 
037     */
038    private static final long serialVersionUID = -3945777382338073635L;
039
040    public SliderCellRenderer()
041    {
042        super(0, 1000);
043    }
044
045    @Override
046    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
047            int row, int column)
048    {
049        if (value instanceof Integer)
050        {
051            final int intValue = ((Integer) value).intValue();
052
053            if (getValue() != intValue)
054                setValue(intValue);
055        }
056
057        return this;
058    }
059
060    @Override
061    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
062            boolean leaf, int row, boolean hasFocus)
063    {
064        if (value instanceof Integer)
065        {
066            final int intValue = ((Integer) value).intValue();
067
068            if (getValue() != intValue)
069                setValue(intValue);
070        }
071
072        return this;
073    }
074
075    /**
076     * Overridden for performance reasons.
077     */
078    @Override
079    public void invalidate()
080    {
081    }
082
083    /**
084     * Overridden for performance reasons.
085     */
086    @Override
087    public void validate()
088    {
089    }
090
091    /**
092     * Overridden for performance reasons.
093     */
094    @Override
095    public void revalidate()
096    {
097    }
098
099    /**
100     * Overridden for performance reasons.
101     */
102    @Override
103    public void repaint(long tm, int x, int y, int width, int height)
104    {
105    }
106
107    /**
108     * Overridden for performance reasons.
109     */
110    @Override
111    public void repaint(Rectangle r)
112    {
113    }
114
115    /**
116     * Overridden for performance reasons.
117     * 
118     * @since 1.5
119     */
120    @Override
121    public void repaint()
122    {
123    }
124}