use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultColumnFooterRenderer method computeSize.
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridColumn column = (GridColumn) value;
gc.setFont(column.getFooterFont());
int x = 0;
x += leftMargin;
x += gc.stringExtent(column.getText()).x + rightMargin;
int y = 0;
y += topMargin;
y += gc.getFontMetrics().getHeight();
y += bottomMargin;
if (column.getFooterImage() != null) {
x += column.getFooterImage().getBounds().width + imageSpacing;
y = Math.max(y, topMargin + column.getFooterImage().getBounds().height + bottomMargin);
}
return new Point(x, y);
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultColumnFooterRenderer method paint.
/**
* {@inheritDoc}
*/
public void paint(GC gc, Object value) {
GridColumn column = (GridColumn) value;
// set the font to be used to display the text.
gc.setFont(column.getFooterFont());
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height);
gc.drawLine(getBounds().x, getBounds().y, getBounds().x + getBounds().width, getBounds().y);
int x = leftMargin;
if (column.getFooterImage() != null) {
gc.drawImage(column.getFooterImage(), getBounds().x + x, getBounds().y + getBounds().height - bottomMargin - column.getFooterImage().getBounds().height);
x += column.getFooterImage().getBounds().width + imageSpacing;
}
int width = getBounds().width - x;
if (column.getSort() == SWT.NONE) {
width -= rightMargin;
}
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
int y = getBounds().y + getBounds().height - bottomMargin - gc.getFontMetrics().getHeight();
String text = TextUtils.getShortString(gc, column.getFooterText(), width);
if (column.getAlignment() == SWT.RIGHT) {
int len = gc.stringExtent(text).x;
if (len < width) {
x += width - len;
}
} else if (column.getAlignment() == SWT.CENTER) {
int len = gc.stringExtent(text).x;
if (len < width) {
x += (width - len) / 2;
}
}
gc.drawString(text, getBounds().x + x, y, true);
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultColumnHeaderRenderer method getTextBounds.
/**
* {@inheritDoc}
*/
public Rectangle getTextBounds(Object value, boolean preferred) {
GridColumn column = (GridColumn) value;
int x = leftMargin;
if (column.getImage() != null) {
x += column.getImage().getBounds().width + imageSpacing;
}
GC gc = new GC(column.getParent());
gc.setFont(column.getParent().getFont());
int y = getBounds().height - bottomMargin - gc.getFontMetrics().getHeight();
Rectangle bounds = new Rectangle(x, y, 0, 0);
Point p = gc.stringExtent(column.getText());
bounds.height = p.y;
if (preferred) {
bounds.width = p.x;
} else {
int width = getBounds().width - x;
if (column.getSort() == SWT.NONE) {
width -= rightMargin;
} else {
width -= arrowMargin + arrowRenderer.getSize().x + arrowMargin;
}
bounds.width = width;
}
gc.dispose();
return bounds;
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultRowHeaderRenderer method paint.
/**
* {@inheritDoc}
*/
public void paint(GC gc, Object value) {
GridItem item = (GridItem) value;
String text = getHeaderText(item);
gc.setFont(getDisplay().getSystemFont());
Color background = getHeaderBackground(item);
if (background == null) {
background = getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
}
gc.setBackground(background);
if (isSelected() && item.getParent().getCellSelectionEnabled()) {
gc.setBackground(item.getParent().getCellHeaderSelectionBackground());
}
gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height + 1);
if (!item.getParent().getCellSelectionEnabled()) {
if (isSelected()) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
} else {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
}
gc.drawLine(getBounds().x, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y);
gc.drawLine(getBounds().x, getBounds().y, getBounds().x, getBounds().y + getBounds().height - 1);
if (!isSelected()) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
gc.drawLine(getBounds().x + 1, getBounds().y + 1, getBounds().x + getBounds().width - 2, getBounds().y + 1);
gc.drawLine(getBounds().x + 1, getBounds().y + 1, getBounds().x + 1, getBounds().y + getBounds().height - 2);
}
if (isSelected()) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
} else {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
}
gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height - 1);
gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height - 1);
if (!isSelected()) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
gc.drawLine(getBounds().x + getBounds().width - 2, getBounds().y + 1, getBounds().x + getBounds().width - 2, getBounds().y + getBounds().height - 2);
gc.drawLine(getBounds().x + 1, getBounds().y + getBounds().height - 2, getBounds().x + getBounds().width - 2, getBounds().y + getBounds().height - 2);
}
} else {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height - 1);
gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height - 1);
}
int x = leftMargin;
Image image = getHeaderImage(item);
if (image != null) {
if (isSelected() && !item.getParent().getCellSelectionEnabled()) {
gc.drawImage(image, x + 1, getBounds().y + 1 + (getBounds().height - image.getBounds().height) / 2);
x += 1;
} else {
gc.drawImage(image, x, getBounds().y + (getBounds().height - image.getBounds().height) / 2);
}
x += image.getBounds().width + 5;
}
int width = getBounds().width - x;
width -= rightMargin;
Color foreground = getHeaderForeground(item);
if (foreground == null) {
foreground = getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
}
gc.setForeground(foreground);
int y = getBounds().y;
int selectionOffset = 0;
if (isSelected() && !item.getParent().getCellSelectionEnabled()) {
selectionOffset = 1;
}
if (!item.getParent().isWordWrapHeader()) {
y += (getBounds().height - gc.stringExtent(text).y) / 2;
gc.drawString(TextUtils.getShortString(gc, text, width), getBounds().x + x + selectionOffset, y + selectionOffset, true);
} else {
getTextLayout(gc, item);
textLayout.setWidth(width < 1 ? 1 : width);
textLayout.setText(text);
if (item.getParent().isAutoHeight()) {
// Look through all columns to get the max height needed for this item
int columnCount = item.getParent().getColumnCount();
int maxHeight = textLayout.getBounds().height + topMargin + bottomMargin;
for (int i = 0; i < columnCount; i++) {
GridColumn column = item.getParent().getColumn(i);
if (column.getWordWrap()) {
int height = column.getCellRenderer().computeSize(gc, column.getWidth(), SWT.DEFAULT, item).y;
maxHeight = Math.max(maxHeight, height);
}
}
if (maxHeight != item.getHeight()) {
item.setHeight(maxHeight);
}
}
textLayout.draw(gc, getBounds().x + x + selectionOffset, y + selectionOffset);
}
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultCellRenderer method paint.
/**
* {@inheritDoc}
*/
public void paint(GC gc, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
boolean drawAsSelected = isSelected();
boolean drawBackground = true;
if (isCellSelected()) {
// (!isCellFocus());
drawAsSelected = true;
}
if (drawAsSelected) {
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
} else {
if (item.getParent().isEnabled()) {
Color back = item.getBackground(getColumn());
if (back != null) {
gc.setBackground(back);
} else {
drawBackground = false;
}
} else {
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
}
gc.setForeground(item.getForeground(getColumn()));
}
if (drawBackground)
gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height);
int x = leftMargin;
if (isTree()) {
boolean renderBranches = item.getParent().getTreeLinesVisible();
if (renderBranches) {
branchRenderer.setBranches(getBranches(item));
branchRenderer.setIndent(treeIndent);
branchRenderer.setBounds(getBounds().x + x, getBounds().y, getToggleIndent(item), // Take into account border
getBounds().height + 1);
}
x += getToggleIndent(item);
toggleRenderer.setExpanded(item.isExpanded());
toggleRenderer.setHover(getHoverDetail().equals("toggle"));
toggleRenderer.setLocation(getBounds().x + x, (getBounds().height - toggleRenderer.getBounds().height) / 2 + getBounds().y);
if (item.hasChildren())
toggleRenderer.paint(gc, null);
if (renderBranches) {
branchRenderer.setToggleBounds(toggleRenderer.getBounds());
branchRenderer.paint(gc, null);
}
x += toggleRenderer.getBounds().width + insideMargin;
}
if (isCheck()) {
checkRenderer.setChecked(item.getChecked(getColumn()));
checkRenderer.setGrayed(item.getGrayed(getColumn()));
if (!item.getParent().isEnabled()) {
checkRenderer.setGrayed(true);
}
checkRenderer.setHover(getHoverDetail().equals("check"));
if (isCenteredCheckBoxOnly(item)) {
// Special logic if this column only has a checkbox and is centered
checkRenderer.setBounds(getBounds().x + ((getBounds().width - checkRenderer.getBounds().width) / 2), (getBounds().height - checkRenderer.getBounds().height) / 2 + getBounds().y, checkRenderer.getBounds().width, checkRenderer.getBounds().height);
} else {
checkRenderer.setBounds(getBounds().x + x, (getBounds().height - checkRenderer.getBounds().height) / 2 + getBounds().y, checkRenderer.getBounds().width, checkRenderer.getBounds().height);
x += checkRenderer.getBounds().width + insideMargin;
}
checkRenderer.paint(gc, null);
}
Image image = item.getImage(getColumn());
if (image != null) {
int y = getBounds().y;
y += (getBounds().height - image.getBounds().height) / 2;
gc.drawImage(image, getBounds().x + x, y);
x += image.getBounds().width + insideMargin;
}
int width = getBounds().width - x - rightMargin;
if (drawAsSelected) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
} else {
gc.setForeground(item.getForeground(getColumn()));
}
if (!isWordWrap()) {
String text = TextUtils.getShortString(gc, item.getText(getColumn()), width);
if (getAlignment() == SWT.RIGHT) {
int len = gc.stringExtent(text).x;
if (len < width) {
x += width - len;
}
} else if (getAlignment() == SWT.CENTER) {
int len = gc.stringExtent(text).x;
if (len < width) {
x += (width - len) / 2;
}
}
gc.drawString(text, getBounds().x + x, getBounds().y + textTopMargin + topMargin, true);
} else {
if (textLayout == null) {
textLayout = new TextLayout(gc.getDevice());
item.getParent().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
textLayout.dispose();
}
});
}
textLayout.setFont(gc.getFont());
textLayout.setText(item.getText(getColumn()));
textLayout.setAlignment(getAlignment());
textLayout.setWidth(width < 1 ? 1 : width);
if (item.getParent().isAutoHeight()) {
// Look through all columns (except this one) to get the max height needed for this item
int columnCount = item.getParent().getColumnCount();
int maxHeight = textLayout.getBounds().height + textTopMargin + textBottomMargin;
for (int i = 0; i < columnCount; i++) {
GridColumn column = item.getParent().getColumn(i);
if (i != getColumn() && column.getWordWrap()) {
int height = column.getCellRenderer().computeSize(gc, column.getWidth(), SWT.DEFAULT, item).y;
maxHeight = Math.max(maxHeight, height);
}
}
// Also look at the row header if necessary
if (item.getParent().isWordWrapHeader()) {
int height = item.getParent().getRowHeaderRenderer().computeSize(gc, SWT.DEFAULT, SWT.DEFAULT, item).y;
maxHeight = Math.max(maxHeight, height);
}
if (maxHeight != item.getHeight()) {
item.setHeight(maxHeight);
}
}
textLayout.draw(gc, getBounds().x + x, getBounds().y + textTopMargin + topMargin);
}
if (item.getParent().getLinesVisible()) {
if (isCellSelected()) {
// XXX: should be user definable?
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
} else {
gc.setForeground(item.getParent().getLineColor());
}
gc.drawLine(getBounds().x, getBounds().y + getBounds().height, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height);
gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height);
}
if (isCellFocus()) {
Rectangle focusRect = new Rectangle(getBounds().x, getBounds().y, getBounds().width - 1, getBounds().height);
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
gc.drawRectangle(focusRect);
if (isFocus()) {
focusRect.x++;
focusRect.width -= 2;
focusRect.y++;
focusRect.height -= 2;
gc.drawRectangle(focusRect);
}
}
}
Aggregations