View Javadoc

1   /*
2    *  File: LineChartHeaderRenderer.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.examples.timebars.linechart.swt.renderer;
21  import org.eclipse.swt.SWT;
22  import org.eclipse.swt.graphics.Color;
23  import org.eclipse.swt.graphics.GC;
24  import org.eclipse.swt.graphics.Rectangle;
25  import org.eclipse.swt.printing.Printer;
26  import org.eclipse.swt.widgets.Display;
27  
28  import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
29  import de.jaret.util.ui.timebars.model.TimeBarRow;
30  import de.jaret.util.ui.timebars.model.TimeBarRowHeader;
31  import de.jaret.util.ui.timebars.swt.renderer.HeaderRenderer;
32  import de.jaret.util.ui.timebars.swt.renderer.RendererBase;
33  
34  /***
35   * Simple header renderer for the linechart example. Draws the lbels for the value markers.
36   * 
37   * @author Peter Kliem
38   * @version $Id: LineChartHeaderRenderer.java 801 2008-12-27 22:44:54Z kliem $
39   */
40  public class LineChartHeaderRenderer extends RendererBase implements HeaderRenderer {
41      /*** line width when printing. */
42      private static final int PRINTING_LINEWIDTH = 3;
43  
44      /***
45       * Constructor for printing use.
46       * 
47       * @param printer printing device
48       */
49      public LineChartHeaderRenderer(Printer printer) {
50          super(printer);
51      }
52  
53      /***
54       * Constructor for screen use.
55       * 
56       */
57      public LineChartHeaderRenderer() {
58          super(null);
59      }
60  
61      /***
62       * {@inheritDoc}
63       */
64      public void draw(GC gc, Rectangle drawingArea, TimeBarViewerDelegate delegate, TimeBarRowHeader header,
65              boolean selected, boolean printing) {
66          Color bg = gc.getBackground();
67  
68          gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
69          gc.fillRectangle(gc.getClipping());
70  
71          // draw lines for 10, 50, 90
72          Color fg = gc.getForeground();
73          gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_GRAY));
74          gc.setLineStyle(SWT.LINE_DASH);
75          // 10
76          int ly = LineChartRenderer.yForValue(drawingArea, 10);
77          gc.drawLine(0, ly, gc.getClipping().x + gc.getClipping().width, ly);
78          gc.drawString("10", 0, ly);
79          // 50
80          ly = LineChartRenderer.yForValue(drawingArea, 50);
81          gc.drawLine(0, ly, gc.getClipping().x + gc.getClipping().width, ly);
82          gc.drawString("50", 0, ly);
83          // 90
84          ly = LineChartRenderer.yForValue(drawingArea, 90);
85          gc.drawLine(0, ly, gc.getClipping().x + gc.getClipping().width, ly);
86          gc.drawString("90", 0, ly);
87  
88          gc.setLineStyle(SWT.LINE_SOLID);
89          gc.setForeground(fg);
90  
91          gc.setBackground(bg);
92      }
93  
94      /***
95       * {@inheritDoc}
96       */
97      public String getToolTipText(TimeBarRow row, Rectangle drawingArea, int x, int y) {
98          return null;
99      }
100 
101     /***
102      * {@inheritDoc}
103      */
104     public boolean contains(Rectangle drawingArea, int x, int y) {
105         return true;
106     }
107 
108     /***
109      * {@inheritDoc}
110      */
111     public void dispose() {
112         // nothing to dispose
113     }
114 
115     /***
116      * {@inheritDoc}
117      */
118     public HeaderRenderer createPrintRenderer(Printer printer) {
119         return new LineChartHeaderRenderer(printer);
120     }
121 }