-
Notifications
You must be signed in to change notification settings - Fork 96
/
Win7ColumnGroupHeaderRenderer.java
124 lines (99 loc) · 3.42 KB
/
Win7ColumnGroupHeaderRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package org.eclipse.nebula.widgets.grid.internal.win7;
import org.eclipse.nebula.widgets.grid.GridColumnGroup;
import org.eclipse.nebula.widgets.grid.internal.DefaultColumnGroupHeaderRenderer;
import org.eclipse.nebula.widgets.grid.internal.ExpandToggleRenderer;
import org.eclipse.nebula.widgets.grid.internal.TextUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.widgets.Display;
/**
* Column group renderer which emulates a default Win7 L&F
*/
public class Win7ColumnGroupHeaderRenderer extends DefaultColumnGroupHeaderRenderer {
int leftMargin = 6;
int rightMargin = 6;
int topMargin = 3;
int bottomMargin = 3;
int imageSpacing = 3;
private ExpandToggleRenderer toggleRenderer = new ExpandToggleRenderer();
private TextLayout textLayout;
private Win7PaletteProvider palette;
private int truncationStyle = SWT.CENTER;
/**
* @param palette
*/
public Win7ColumnGroupHeaderRenderer(Win7PaletteProvider palette) {
this.palette = palette;
}
/**
* {@inheritDoc}
*/
public void paint(GC gc, Object value) {
GridColumnGroup group = (GridColumnGroup) value;
// set the font to be used to display the text.
gc.setFont(group.getHeaderFont());
Win7ColumnHeaderUtil.drawColumn(gc, getBounds(), palette, isHover(), isSelected(), isMouseDown());
int x = leftMargin;
if (group.getImage() != null) {
gc.drawImage(group.getImage(), getBounds().x + x, getBounds().y + topMargin);
x = group.getImage().getBounds().width + imageSpacing;
}
int width = getBounds().width - x - rightMargin;
if ((group.getStyle() & SWT.TOGGLE) != 0) {
width -= toggleRenderer.getSize().x;
}
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
if (!isWordWrap()) {
gc.drawString(TextUtils.getShortStr(gc, group.getText(), width,truncationStyle), getBounds().x + x,
getBounds().y + topMargin, true);
} else {
getTextLayout(gc, group);
textLayout.setWidth(width < 1 ? 1 : width);
textLayout.setText(group.getText());
if (group.getParent().isAutoHeight()) {
group.getParent().recalculateHeader();
}
textLayout.draw(gc, getBounds().x + x, getBounds().y + topMargin);
}
if ((group.getStyle() & SWT.TOGGLE) != 0) {
toggleRenderer.setHover(isHover() && getHoverDetail().equals("toggle"));
toggleRenderer.setExpanded(group.getExpanded());
toggleRenderer.setBounds(getToggleBounds());
toggleRenderer.paint(gc, null);
}
}
/**
* {@inheritDoc}
*/
public void setDisplay(Display display) {
super.setDisplay(display);
toggleRenderer.setDisplay(display);
palette.initializePalette(getDisplay(), Win7PaletteProvider.NORMAL_GRID_COLUMN_HEADER);
palette.initializePalette(getDisplay(), Win7PaletteProvider.HOVER_GRID_COLUMN_HEADER);
}
private void getTextLayout(GC gc, GridColumnGroup group) {
if (textLayout == null) {
textLayout = new TextLayout(gc.getDevice());
textLayout.setFont(gc.getFont());
group.getParent().addListener(SWT.Dispose, e -> textLayout.dispose());
}
}
/**
* Get the truncation style
* @return the truncation style.
*/
public int getTruncationStyle() {
return truncationStyle;
}
/**
* Set the truncation style to use when cell content is too large.
* @see SWT#LEFT
* @see SWT#CENTER
* @see SWT#RIGHT
* @param truncationStyle
*/
public void setTruncationStyle(int truncationStyle) {
this.truncationStyle = truncationStyle;
}
}