View Javadoc

1   /*
2    *  File: DefaultTimeBarRenderer.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation; either version 2 of the License, or
9    *  (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *  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, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package de.jaret.util.ui.timebars.swing.renderer;
21  
22  import java.awt.Color;
23  import java.awt.Rectangle;
24  
25  import javax.swing.JButton;
26  import javax.swing.JComponent;
27  
28  import de.jaret.util.date.Interval;
29  import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
30  import de.jaret.util.ui.timebars.swing.TimeBarViewer;
31  
32  /**
33   * A simple default renderer for intervals using a JButton. This default renderer provides the possibility to register
34   * timebar renderers for special classes.
35   * 
36   * @author Peter Kliem
37   * @version $Id: DefaultTimeBarRenderer.java 1073 2010-11-22 21:25:33Z kliem $
38   */
39  public class DefaultTimeBarRenderer implements TimeBarRenderer {
40      /** component used for rendering. */
41      protected JButton _component = new JButton();
42  
43  
44      /**
45       * {@inheritDoc}
46       */
47      public JComponent getTimeBarRendererComponent(TimeBarViewer tbv, Interval value, boolean isSelected,
48              boolean overlapping) {
49         return defaultGetTimeBarRendererComponent(tbv, value, isSelected, overlapping);
50      }
51  
52      /**
53       * {@inheritDoc}
54       */
55      public JComponent defaultGetTimeBarRendererComponent(TimeBarViewer tbv, Interval value, boolean isSelected,
56              boolean overlapping) {
57          _component.setText(value.toString());
58          _component.setToolTipText(value.toString());
59          if (isSelected) {
60              _component.setBackground(Color.BLUE);
61            } else {
62              _component.setBackground(Color.LIGHT_GRAY);
63          }
64          return _component;
65      }
66  
67      /**
68       * {@inheritDoc} Simple default implementation.
69       */
70  	public Rectangle getPreferredDrawingBounds(Rectangle intervalDrawingArea,
71  			TimeBarViewerDelegate delegate, Interval interval,
72  			boolean selected, boolean overlap) {
73  		return intervalDrawingArea;
74  	}
75  }