use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class TBSearchCellRenderer method paint.
/**
* (non-Javadoc)
* @see org.eclipse.nebula.widgets.grid.IRenderer#paint(org.eclipse.swt.graphics.GC, java.lang.Object)
*/
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;
}
if (drawAsSelected) {
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
} else {
gc.setForeground(item.getForeground(getColumn()));
}
int width = getBounds().width - x - rightMargin;
int height = getBounds().height - bottomMargin;
int y = getBounds().y + textTopMargin + topMargin;
if (textLayout == null) {
textLayout = new TextLayout(gc.getDevice());
item.getParent().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
textLayout.dispose();
}
});
}
textLayout.setOrientation(item.getParent().getOrientation());
textLayout.setFont(gc.getFont());
String itemText = item.getText(getColumn());
textLayout.setText(item.getText(getColumn()));
textLayout.setAlignment(getAlignment());
textLayout.setWidth(width < 1 ? 1 : width);
if (styleColumn != -1 && getColumn() == styleColumn) {
if (style == null) {
final Font font = new Font(gc.getDevice(), gc.getFont().getFontData()[0].getName(), gc.getFont().getFontData()[0].getHeight(), SWT.BOLD);
style = new TextStyle(font, null, null);
item.getParent().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
font.dispose();
}
});
}
if (strText != null) {
if (blnIsApplyRegular) {
Pattern pattern = null;
if (blnIsCaseSensitive) {
pattern = Pattern.compile(strText);
} else {
pattern = Pattern.compile(strText, Pattern.CASE_INSENSITIVE);
}
Matcher matcher = pattern.matcher(itemText);
while (matcher.find()) {
textLayout.setStyle(style, matcher.start(), matcher.end() - 1);
}
} else {
int index;
if (blnIsCaseSensitive) {
index = itemText.indexOf(strText);
} else {
index = itemText.toUpperCase().indexOf(strText.toUpperCase());
}
if (index != -1) {
textLayout.setStyle(null, 0, itemText.length() - 1);
for (int i = 1; i < strText.length(); i++) {
int j = TextUtil.indexOf(itemText, strText, i, blnIsCaseSensitive);
if (j != -1) {
textLayout.setStyle(style, j, j + strText.length() - 1);
} else {
break;
}
}
}
}
}
}
if (item.getParent().isAutoHeight()) {
int textHeight = topMargin + textTopMargin;
for (int cnt = 0; cnt < textLayout.getLineCount(); cnt++) textHeight += textLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
Object obj = item.getData("itemHeight");
if (getColumn() != item.getParent().getColumnCount() - 1) {
if (obj != null) {
int heigth = (Integer) obj;
textHeight = Math.max(textHeight, heigth);
}
item.setData("itemHeight", textHeight);
} else {
int heigth = (Integer) obj;
textHeight = Math.max(textHeight, heigth);
if (textHeight != item.getHeight()) {
item.setHeight(textHeight);
}
item.setData("itemHeight", null);
}
}
y += getVerticalAlignmentAdjustment(textLayout.getBounds().height, height);
textLayout.draw(gc, getBounds().x + x, y);
if (item.getParent().getLinesVisible()) {
if (isCellSelected()) {
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);
}
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
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);
}
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class DefaultCellRenderer method notify.
/**
* {@inheritDoc}
*/
public boolean notify(int event, Point point, Object value) {
GridItem item = (GridItem) value;
if (isCheck()) {
if (event == IInternalWidget.MouseMove) {
if (overCheck(item, point)) {
setHoverDetail("check");
return true;
}
}
if (event == IInternalWidget.LeftMouseButtonDown) {
if (overCheck(item, point)) {
if (!item.getCheckable(getColumn())) {
return false;
}
item.setChecked(getColumn(), !item.getChecked(getColumn()));
item.getParent().redraw();
item.fireCheckEvent(getColumn());
return true;
}
}
}
if (isTree() && item.hasChildren()) {
if (event == IInternalWidget.MouseMove) {
if (overToggle(item, point)) {
setHoverDetail("toggle");
return true;
}
}
if (event == IInternalWidget.LeftMouseButtonDown) {
if (overToggle(item, point)) {
item.setExpanded(!item.isExpanded());
item.getParent().redraw();
if (item.isExpanded()) {
item.fireEvent(SWT.Expand);
} else {
item.fireEvent(SWT.Collapse);
}
return true;
}
}
}
return false;
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class DefaultCellRenderer method getBranches.
/**
* Calculates the sequence of branch lines which should be rendered for the provided item
* @param item
* @return an array of integers composed using the constants in {@link BranchRenderer}
*/
private int[] getBranches(GridItem item) {
int[] branches = new int[item.getLevel() + 1];
GridItem[] roots = item.getParent().getRootItems();
// Is this a node or a leaf?
if (item.getParentItem() == null) {
// Add descender if not last item
if (!item.isExpanded() && roots[roots.length - 1].equals(item)) {
if (item.hasChildren())
branches[item.getLevel()] = BranchRenderer.LAST_ROOT;
else
branches[item.getLevel()] = BranchRenderer.SMALL_L;
} else {
if (item.hasChildren())
branches[item.getLevel()] = BranchRenderer.ROOT;
else
branches[item.getLevel()] = BranchRenderer.SMALL_T;
}
} else if (item.hasChildren())
if (item.isExpanded())
branches[item.getLevel()] = BranchRenderer.NODE;
else
branches[item.getLevel()] = BranchRenderer.NONE;
else
branches[item.getLevel()] = BranchRenderer.LEAF;
// Branch for current item
GridItem parent = item.getParentItem();
if (parent == null)
return branches;
// Are there siblings below this item?
if (parent.indexOf(item) < parent.getItemCount() - 1)
branches[item.getLevel() - 1] = BranchRenderer.T;
else // Is the next node a root?
if (parent.getParentItem() == null && !parent.equals(roots[roots.length - 1]))
branches[item.getLevel() - 1] = BranchRenderer.T;
else
// This must be the last element at this level
branches[item.getLevel() - 1] = BranchRenderer.L;
Grid grid = item.getParent();
item = parent;
parent = item.getParentItem();
// Branches for parent items
while (item.getLevel() > 0) {
if (parent.indexOf(item) == parent.getItemCount() - 1) {
if (parent.getParentItem() == null && !grid.getRootItem(grid.getRootItemCount() - 1).equals(parent))
branches[item.getLevel() - 1] = BranchRenderer.I;
else
branches[item.getLevel() - 1] = BranchRenderer.NONE;
} else
branches[item.getLevel() - 1] = BranchRenderer.I;
item = parent;
parent = item.getParentItem();
}
// item should be null at this point
return branches;
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class DefaultEmptyCellRenderer method paint.
/**
* {@inheritDoc}
*/
public void paint(GC gc, Object value) {
Grid table = null;
if (value instanceof Grid)
table = (Grid) value;
GridItem item;
if (value instanceof GridItem) {
item = (GridItem) value;
table = item.getParent();
}
boolean drawBackground = true;
if (isSelected()) {
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
} else {
if (table.isEnabled()) {
drawBackground = false;
} else {
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
}
gc.setForeground(table.getForeground());
}
if (drawBackground)
gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width + 1, getBounds().height);
if (table.getLinesVisible()) {
gc.setForeground(table.getLineColor());
gc.drawLine(getBounds().x, getBounds().y + getBounds().height, getBounds().x + getBounds().width, getBounds().y + getBounds().height);
gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x + getBounds().width - 1, getBounds().y + getBounds().height);
}
}
Aggregations