use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultColumnFooterRenderer 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.getFooterFont());
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;
}
bounds.width = width;
}
gc.dispose();
return bounds;
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultColumnHeaderRenderer method computeSize.
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridColumn column = (GridColumn) value;
gc.setFont(column.getHeaderFont());
int x = leftMargin;
int y = topMargin + gc.getFontMetrics().getHeight() + bottomMargin;
if (column.getImage() != null) {
x += column.getImage().getBounds().width + imageSpacing;
y = Math.max(y, topMargin + column.getImage().getBounds().height + bottomMargin);
}
if (!isWordWrap()) {
x += gc.stringExtent(column.getText()).x + rightMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
getTextLayout(gc, column);
textLayout.setText(column.getText());
textLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
int textHeight = topMargin;
textHeight += textLayout.getBounds().height;
textHeight += bottomMargin;
y = Math.max(y, textHeight);
}
y += computeControlSize(column).y;
return new Point(x, y);
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultColumnHeaderRenderer 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.getHeaderFont());
boolean flat = (column.getParent().getCellSelectionEnabled() && !column.getMoveable());
boolean drawSelected = ((isMouseDown() && isHover()));
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
if (flat && isSelected()) {
gc.setBackground(column.getParent().getCellHeaderSelectionBackground());
}
gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height);
int pushedDrawingOffset = 0;
if (drawSelected) {
pushedDrawingOffset = 1;
}
int x = leftMargin;
if (column.getImage() != null) {
int y = bottomMargin;
if (column.getHeaderControl() == null) {
y = getBounds().y + pushedDrawingOffset + getBounds().height - bottomMargin - column.getImage().getBounds().height;
}
gc.drawImage(column.getImage(), getBounds().x + x + pushedDrawingOffset, y);
x += column.getImage().getBounds().width + imageSpacing;
}
int width = getBounds().width - x;
if (column.getSort() == SWT.NONE) {
width -= rightMargin;
} else {
width -= arrowMargin + arrowRenderer.getSize().x + arrowMargin;
}
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
int y = bottomMargin;
if (column.getHeaderControl() == null) {
y = getBounds().y + getBounds().height - bottomMargin - gc.getFontMetrics().getHeight();
} else {
y = getBounds().y + getBounds().height - bottomMargin - gc.getFontMetrics().getHeight() - computeControlSize(column).y;
}
String text = column.getText();
if (!isWordWrap()) {
text = TextUtils.getShortString(gc, text, width);
// y -= gc.getFontMetrics().getHeight();
}
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;
}
}
if (!isWordWrap()) {
gc.drawString(text, getBounds().x + x + pushedDrawingOffset, y + pushedDrawingOffset, true);
} else {
getTextLayout(gc, column);
textLayout.setWidth(width < 1 ? 1 : width);
textLayout.setText(text);
y -= textLayout.getBounds().height;
// remove the first line shift
y += gc.getFontMetrics().getHeight();
if (column.getParent().isAutoHeight()) {
column.getParent().recalculateHeader();
}
textLayout.draw(gc, getBounds().x + x + pushedDrawingOffset, y + pushedDrawingOffset);
}
if (column.getSort() != SWT.NONE) {
if (column.getHeaderControl() == null) {
y = getBounds().y + ((getBounds().height - arrowRenderer.getBounds().height) / 2) + 1;
} else {
y = getBounds().y + ((getBounds().height - computeControlSize(column).y - arrowRenderer.getBounds().height) / 2) + 1;
}
arrowRenderer.setSelected(column.getSort() == SWT.UP);
if (drawSelected) {
arrowRenderer.setLocation(getBounds().x + getBounds().width - arrowMargin - arrowRenderer.getBounds().width + 1, y);
} else {
if (column.getHeaderControl() == null) {
y = getBounds().y + ((getBounds().height - arrowRenderer.getBounds().height) / 2);
} else {
y = getBounds().y + ((getBounds().height - computeControlSize(column).y - arrowRenderer.getBounds().height) / 2);
}
arrowRenderer.setLocation(getBounds().x + getBounds().width - arrowMargin - arrowRenderer.getBounds().width, y);
}
arrowRenderer.paint(gc, null);
}
if (!flat) {
if (drawSelected) {
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 (!drawSelected) {
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 (drawSelected) {
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 (!drawSelected) {
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);
}
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class DefaultColumnHeaderRenderer method getControlBounds.
/**
* @return the bounds reserved for the control
*/
protected Rectangle getControlBounds(Object value, boolean preferred) {
Rectangle bounds = getBounds();
GridColumn column = (GridColumn) value;
Point controlSize = computeControlSize(column);
int y = getBounds().y + getBounds().height - bottomMargin - controlSize.y;
return new Rectangle(bounds.x + 3, y, bounds.width - 6, controlSize.y);
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project tdq-studio-se by Talend.
the class IndicatorSelectGrid method notifyhandleColumnHighlight.
@Override
protected void notifyhandleColumnHighlight(MouseEvent e) {
if (observers == null) {
return;
}
for (TDQObserver<ObserverEvent> observer : observers) {
ObserverEvent observerEvent = new ObserverEvent(ObserverEventEnum.ColumnHighlight);
GridColumn currentColumn = this.getColumn(new Point(e.x, e.y));
if (currentColumn != null) {
observerEvent.putData(ObserverEvent.COLUMN_HIGH_LIGHT, this.indexOf(currentColumn));
observer.update(observerEvent);
}
}
}
Aggregations