1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package de.jaret.examples.timebars.millis.swt.renderer;
21
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.date.JaretDate;
29 import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
30 import de.jaret.util.ui.timebars.strategy.ITickProvider;
31 import de.jaret.util.ui.timebars.swt.renderer.AbstractGridRenderer;
32 import de.jaret.util.ui.timebars.swt.renderer.GridRenderer;
33
34 /***
35 * Simple grid renderer for the milli example.
36 *
37 * @author Peter Kliem
38 * @version $Id: MilliGrid.java 856 2009-04-02 18:54:40Z kliem $
39 */
40 public class MilliGrid extends AbstractGridRenderer implements GridRenderer {
41 /*** color of the major grid. */
42 private Color _colorMajorGrid;
43
44 /*** color of the minor grid. */
45 private Color _colorMinorGrid;
46
47 public MilliGrid(Printer printer) {
48 super(printer);
49 _colorMajorGrid = new Color(printer, 200, 200, 200);
50 _colorMinorGrid = new Color(printer, 230, 230, 230);
51
52 }
53
54 public MilliGrid() {
55 super(null);
56 _colorMajorGrid = new Color(Display.getCurrent(), 200, 200, 200);
57 _colorMinorGrid = new Color(Display.getCurrent(), 230, 230, 230);
58 }
59
60 /***
61 * {@inheritDoc}
62 */
63 public void draw(GC gc, TimeBarViewerDelegate delegate, Rectangle drawingArea, boolean printing) {
64 int ox = drawingArea.x;
65 int oy = drawingArea.y;
66 int width = drawingArea.width;
67 int height = drawingArea.height;
68
69 Color fg = gc.getForeground();
70
71
72 JaretDate date = delegate.getStartDate().copy();
73
74 while (date.diffMilliSeconds(delegate.getMinDate()) % MilliScale.MAJOR != 0) {
75 date.advanceMillis(-1);
76 }
77
78 JaretDate save = date.copy();
79
80 date = save.copy();
81
82 if (printing) {
83 gc.setLineWidth(3);
84 }
85 gc.setForeground(_colorMinorGrid);
86 while (delegate.xForDate(date) < ox + width) {
87 JaretDate eosc = MilliScale.endOfSpecialScaling(delegate, date);
88 if (eosc == null) {
89 int x = delegate.xForDate(date);
90 gc.drawLine(x, oy, x, oy + height);
91
92 date.advanceMillis(MilliScale.MINOR);
93 } else {
94 long diff = eosc.diffMilliSeconds(date);
95 date.advanceMillis(diff+MilliScale.MINOR);
96 }
97 }
98
99 date = save.copy();
100
101 gc.setForeground(_colorMajorGrid);
102 while (delegate.xForDate(date) < ox + width) {
103 JaretDate eosc = MilliScale.endOfSpecialScaling(delegate, date);
104 if (eosc == null) {
105 int x = delegate.xForDate(date);
106 gc.drawLine(x, oy, x, oy + height);
107 date.advanceMillis(MilliScale.MAJOR);
108 } else {
109 long diff = eosc.diffMilliSeconds(date);
110 date.advanceMillis(diff+MilliScale.MAJOR);
111 }
112 }
113 gc.setLineWidth(1);
114 gc.setForeground(fg);
115 }
116
117 /***
118 * {@inheritDoc}
119 */
120 public void dispose() {
121 _colorMajorGrid.dispose();
122 _colorMinorGrid.dispose();
123 }
124
125 /***
126 * {@inheritDoc}
127 */
128 public GridRenderer createPrintRenderer(Printer printer) {
129 MilliGrid renderer = new MilliGrid(printer);
130 return renderer;
131 }
132
133 public void setTickProvider(ITickProvider tickProvider) {
134
135
136 }
137 }