View Javadoc

1   /*
2    *  File: DefaultMiscRenderer.java 
3    *  Copyright (c) 2004-2008  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.AlphaComposite;
23  import java.awt.Color;
24  import java.awt.Graphics;
25  import java.awt.Graphics2D;
26  import java.awt.Rectangle;
27  
28  import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
29  import de.jaret.util.ui.timebars.swing.TimeBarViewer;
30  
31  /**
32   * Default implementation of th misc renderer for the swing time bar viewer.
33   * 
34   * @author kliem
35   * @version $Id: DefaultMiscRenderer.java 881 2009-09-22 21:25:47Z kliem $
36   */
37  public class DefaultMiscRenderer implements IMiscRenderer {
38      /** color used for highlighting. */
39      public static final Color HIGHLIGHT_COLOR = Color.RED;
40  
41      /**
42       * {@inheritDoc}
43       */
44      public void renderRegionRect(Graphics graphics, TimeBarViewer tbv, TimeBarViewerDelegate delegate) {
45          if (delegate.getRegionRect() != null) {
46              Color color = graphics.getColor();
47              Rectangle rect = delegate.calcRect(delegate.getRegionRect());
48              graphics.setColor(Color.GRAY);
49              Graphics2D g2 = (Graphics2D) graphics;
50              g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
51              graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
52              g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
53              graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
54              graphics.setColor(color);
55          }
56      }
57  
58      /**
59       * {@inheritDoc}
60       */
61      public void renderSelectionRect(Graphics graphics, TimeBarViewer tbv, Rectangle selectionRect) {
62          Color old = graphics.getColor();
63      	graphics.setColor(Color.GRAY);
64          graphics.drawRect(selectionRect.x, selectionRect.y, selectionRect.width, selectionRect.height);
65          graphics.setColor(old);
66      }
67  
68      /**
69       * {@inheritDoc}
70       */
71      public void drawRowGridLine(Graphics graphics, int x1, int y1, int x2, int y2) {
72          Color color = graphics.getColor();
73          graphics.setColor(Color.LIGHT_GRAY);
74          graphics.drawLine(x1, y1, x2, y2);
75          graphics.setColor(color);
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      public void drawRowBackground(Graphics graphics, int x, int y, int width, int height, boolean selected,
82              boolean highlighted) {
83  
84          Color color = graphics.getColor();
85          if (selected) {
86              graphics.setColor(Color.BLUE);
87          } else { // highlighted
88              graphics.setColor(HIGHLIGHT_COLOR);
89          }
90          Graphics2D g2 = (Graphics2D) graphics;
91          g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
92          graphics.fillRect(x, y, width, height);
93          g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
94          graphics.setColor(color);
95  
96      }
97  
98  }