1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package de.jaret.util.ui.timebars.swt.renderer;
21
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.graphics.Color;
24 import org.eclipse.swt.graphics.GC;
25 import org.eclipse.swt.printing.Printer;
26 import org.eclipse.swt.widgets.Display;
27
28 import de.jaret.util.ui.timebars.TimeBarMarker;
29 import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
30 import de.jaret.util.ui.timebars.TimeBarViewerInterface;
31
32
33
34
35
36
37
38 public class DefaultTimeBarMarkerRenderer extends RendererBase implements TimeBarMarkerRenderer {
39
40 private static final Color MARKER_ACTIVE_COLOR = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
41
42
43 private static final Color MARKER_COLOR = Display.getCurrent().getSystemColor(SWT.COLOR_RED);
44
45
46
47
48
49
50 public DefaultTimeBarMarkerRenderer(Printer printer) {
51 super(printer);
52 }
53
54
55
56
57
58 public DefaultTimeBarMarkerRenderer() {
59 super(null);
60 }
61
62
63
64
65 public void draw(GC gc, TimeBarViewerDelegate tbv, TimeBarMarker marker, boolean isDragged, boolean printing) {
66 boolean horizontal = tbv.getOrientation().equals(TimeBarViewerInterface.Orientation.HORIZONTAL);
67 Color oldCol = gc.getForeground();
68
69 if (!printing) {
70 if (isDragged) {
71 gc.setForeground(MARKER_ACTIVE_COLOR);
72 } else {
73 gc.setForeground(MARKER_COLOR);
74 }
75 } else {
76 gc.setForeground(_printer.getSystemColor(SWT.COLOR_DARK_MAGENTA));
77 gc.setLineWidth(getDefaultLineWidth());
78 }
79
80 if (horizontal) {
81 int startY = Math.min(tbv.getXAxisRect().y, tbv.getDiagramRect().y);
82 int x = tbv.xForDate(marker.getDate());
83 int height = tbv.getXAxisRect().height + tbv.getDiagramRect().height;
84 gc.drawLine(x, startY, x, startY + height);
85 } else {
86 int startX = Math.min(tbv.getXAxisRect().x, tbv.getDiagramRect().x);
87 int y = tbv.xForDate(marker.getDate());
88 int width = tbv.getXAxisRect().width + tbv.getDiagramRect().width;
89 gc.drawLine(startX, y, startX + width, y);
90 }
91 gc.setLineWidth(1);
92 gc.setForeground(oldCol);
93
94 }
95
96
97
98
99 public void dispose() {
100
101 }
102
103
104
105
106 public int getWidth(TimeBarMarker marker) {
107 return scaleX(4);
108 }
109
110
111
112
113 public TimeBarMarkerRenderer createPrintRenderer(Printer printer) {
114 return new DefaultTimeBarMarkerRenderer(printer);
115 }
116
117 }