View Javadoc

1   /*
2    *  File: DateStripRenderer.java 
3    *  Copyright (c) Peter Kliem (peter@kliemax.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.swt.renderer;
21  
22  import org.eclipse.swt.graphics.GC;
23  import org.eclipse.swt.graphics.Rectangle;
24  import org.eclipse.swt.printing.Printer;
25  
26  import de.jaret.util.date.JaretDate;
27  import de.jaret.util.swt.SwtGraphicsHelper;
28  import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
29  import de.jaret.util.ui.timebars.TimeBarViewerInterface;
30  import de.jaret.util.ui.timebars.swt.TimeBarViewer;
31  
32  /**
33   * A simple TimeScaleRenderer that will always show the starting date. This can be quite useful in combination with
34   * other TimeScaleRenderers using a CombiningTimeScaleRenderer.
35   * 
36   * @author kliem
37   * 
38   */
39  public class DateStripRenderer extends RendererBase implements TimeScaleRenderer {
40  
41      public DateStripRenderer() {
42          super(null);
43      }
44  
45      public DateStripRenderer(Printer printer) {
46          super(printer);
47      }
48  
49      @Override
50      public void draw(GC gc, Rectangle drawingArea, TimeBarViewerDelegate delegate, boolean top, boolean printing) {
51          boolean horizontal = delegate.getOrientation().equals(TimeBarViewerInterface.Orientation.HORIZONTAL);
52          JaretDate startDate = delegate.getStartDate().copy();
53          if (horizontal) {
54  
55              // clearbackground
56              // TODO
57              SwtGraphicsHelper.drawStringLeftAlignedVCenter(gc, startDate.toDisplayString(),
58                      delegate.getYAxisWidth() + 5, drawingArea.y + drawingArea.height / 2);
59              gc.drawLine(drawingArea.x, drawingArea.y + drawingArea.height - 1, drawingArea.x + drawingArea.width,
60                      drawingArea.y + drawingArea.height - 1);
61          } else {
62              SwtGraphicsHelper.drawStringVertical(gc, startDate.toDisplayString(), drawingArea.x , drawingArea.y + 5);
63  
64              
65              gc.drawLine(drawingArea.x+drawingArea.width-1, drawingArea.y, drawingArea.x+drawingArea.width-1,
66                      drawingArea.y + drawingArea.height - 1);
67  
68          }
69      }
70  
71      @Override
72      public String getToolTipText(TimeBarViewer tbv, Rectangle drawingArea, int x, int y) {
73          return null;
74      }
75  
76      @Override
77      public int getHeight() {
78          return scaleY(20);
79      }
80  
81      @Override
82      public void dispose() {
83          // nothing to dispose
84      }
85  
86      @Override
87      public TimeScaleRenderer createPrintRenderer(Printer printer) {
88          return new DateStripRenderer(printer);
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      public boolean supportsOptimizedScrolling() {
95          return false;
96      }
97  
98      
99  }