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.graphics.Rectangle;
26 import org.eclipse.swt.printing.Printer;
27 import org.eclipse.swt.widgets.Display;
28
29 import de.jaret.util.date.Interval;
30 import de.jaret.util.misc.FormatHelper;
31 import de.jaret.util.swt.SwtGraphicsHelper;
32 import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
33 import de.jaret.util.ui.timebars.TimeBarViewerInterface;
34 import de.jaret.util.ui.timebars.model.TimeBarRow;
35
36
37
38
39
40
41
42 public class DefaultGapRenderer extends RendererBase implements TimeBarGapRenderer {
43
44 private static final Color DEFAULT_COLOR = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
45
46
47
48
49
50
51 public DefaultGapRenderer(Printer printer) {
52 super(printer);
53 }
54
55
56
57
58 public DefaultGapRenderer() {
59 super(null);
60 }
61
62
63
64
65 public void draw(GC gc, TimeBarViewerDelegate delegate, TimeBarRow row, Interval i1, Interval i2,
66 Rectangle drawingArea, boolean printing) {
67 int ox = drawingArea.x;
68 int oy = drawingArea.y;
69 int width = drawingArea.width;
70 int height = drawingArea.height;
71
72 boolean horizontal = delegate.getOrientation() == TimeBarViewerInterface.Orientation.HORIZONTAL;
73
74 Color fg = gc.getForeground();
75
76 int diffminutes = (int) i2.getBegin().diffMinutes(i1.getEnd());
77 String timeString = FormatHelper.NFInt2Digits().format(diffminutes / 60) + ":"
78 + FormatHelper.NFInt2Digits().format(diffminutes % 60);
79 int twidth = SwtGraphicsHelper.getStringDrawingWidth(gc, timeString);
80 int theight = SwtGraphicsHelper.getStringDrawingHeight(gc, timeString);
81
82 gc.setForeground(DEFAULT_COLOR);
83
84 if (horizontal) {
85 if (width > twidth + 3 && height / 2 >= theight) {
86 SwtGraphicsHelper.drawStringCentered(gc, timeString, ox + width / 2, oy + height / 2 - 2);
87 }
88 } else {
89 if (height > theight + 3 && width / 2 >= twidth) {
90 SwtGraphicsHelper.drawStringCenteredAroundPoint(gc, timeString, ox + width / 2, oy + height / 2);
91 }
92 }
93
94 if (printing) {
95 gc.setLineWidth(getDefaultLineWidth());
96 }
97 if (horizontal) {
98 if (width > 15) {
99 SwtGraphicsHelper.drawArrowLine(gc, ox + 2, oy + height / 2, ox + width - 3, oy + height / 2,
100 scaleX(4), scaleY(3), true, true);
101 }
102 } else {
103 if (height > 15) {
104 SwtGraphicsHelper.drawArrowLineVertical(gc, ox + width / 2, oy + 2, ox + width / 2, oy + height - 3,
105 scaleX(3), scaleY(4), true, true);
106 }
107 }
108 gc.setLineWidth(1);
109
110 gc.setForeground(fg);
111 }
112
113
114
115
116 public void dispose() {
117
118 }
119
120
121
122
123 public TimeBarGapRenderer createPrintRenderer(Printer printer) {
124 DefaultGapRenderer renderer = new DefaultGapRenderer(printer);
125 return renderer;
126 }
127
128 }