View Javadoc

1   /*
2    *  File: IMarkerRenderer.java 
3    *  Copyright (c) 2004-2009  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.Graphics;
24  
25  import de.jaret.util.ui.timebars.TimeBarMarker;
26  import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
27  import de.jaret.util.ui.timebars.TimeBarViewerInterface;
28  
29  /**
30   * Default marker renderer rendering the marker as a single line.
31   * 
32   * @author kliem
33   * @version $Id: DefaultMarkerRenderer.java 823 2009-02-04 21:20:58Z kliem $
34   */
35  public class DefaultMarkerRenderer implements IMarkerRenderer {
36      /** color used when the marker is dragged. */
37      protected Color _draggedColor = Color.BLUE;
38      /** color for marker rendering. */
39      protected Color _markerColor = Color.RED;
40  
41      /**
42       * {@inheritDoc}
43       */
44      public int getMarkerWidth(TimeBarMarker marker) {
45          return 4;
46      }
47  
48      /**
49       * {@inheritDoc}
50       */
51      public void renderMarker(TimeBarViewerDelegate delegate, Graphics graphics, TimeBarMarker marker, int x,
52              boolean isDragged) {
53          Color oldCol = graphics.getColor();
54          if (isDragged) {
55              graphics.setColor(_draggedColor);
56          } else {
57              graphics.setColor(_markerColor);
58          }
59          if (delegate.getOrientation().equals(TimeBarViewerInterface.Orientation.HORIZONTAL)) {
60              graphics.drawLine(x, 0, x, delegate.getDiagramRect().height + delegate.getXAxisHeight());
61          } else {
62              graphics.drawLine(0, x, delegate.getDiagramRect().height + delegate.getXAxisHeight(), x);
63          }
64  
65          graphics.setColor(oldCol);
66      }
67  
68  }