use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.
the class GridCopyEnable method doMouseLocationChange.
void doMouseLocationChange(int x, int y, boolean select) {
if (gridTable.getItems().length == 0) {
defaultCaret.setVisible(false);
return;
}
Point eventP = new Point(x, y);
GridItem _focusItem = gridTable.getItem(eventP);
GridColumn col = gridTable.getColumn(eventP);
if (_focusItem == null) {
return;
}
GridCellRenderer gcr = col.getCellRenderer();
int colIndex = gcr.getColumn();
if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
return;
}
XGridCellRenderer cellRender = (XGridCellRenderer) gcr;
Rectangle cellBounds = _focusItem.getBounds(colIndex);
GC gc = new GC(Display.getDefault());
layout = cellRender.getTextLayout(gc, _focusItem, colIndex, true, false);
if (layout == null) {
gc.dispose();
return;
}
focusContent = layout.getText();
coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
if (!select) {
focusCellRect.x = cellBounds.x;
focusCellRect.y = cellBounds.y;
focusCellRect.height = cellBounds.height;
focusCellRect.width = cellBounds.width;
focusColIndex = colIndex;
focusItemIndex = gridTable.getIndexOfItem(_focusItem);
}
int[] trailing = new int[1];
int newCaretOffset = layout.getOffset(x - coordinateOffsetX, y - coordinateOffsetY, trailing);
int newCaretLine = layout.getLineIndex(newCaretOffset + trailing[0]);
int lineStart = layout.getLineOffsets()[newCaretLine];
Point point = null;
if (newCaretOffset + trailing[0] == lineStart && trailing[0] != 0) {
newCaretOffset += trailing[0];
newCaretOffset = layout.getPreviousOffset(newCaretOffset, SWT.MOVEMENT_CLUSTER);
point = layout.getLocation(newCaretOffset, true);
} else {
newCaretOffset += trailing[0];
point = layout.getLocation(newCaretOffset, false);
}
// check area, only in cell area effective
boolean vchange = focusCellRect.y <= y && y < focusCellRect.y + focusCellRect.height;
boolean hchange = focusCellRect.x <= x && x < focusCellRect.x + focusCellRect.width;
if (vchange && hchange && newCaretOffset != caretOffset) {
focusItem = _focusItem;
caretOffset = newCaretOffset;
if (select) {
doMouseSelection();
}
defaultCaret.setVisible(true);
Rectangle rc = layout.getLineBounds(newCaretLine);
defaultCaret.setBounds(point.x + coordinateOffsetX, point.y + coordinateOffsetY, 0, rc.height);
}
if (!select) {
caretOffset = newCaretOffset;
clearSelection();
}
layout.dispose();
layout = null;
gc.dispose();
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method initLanguageMenu.
/**
* 初始化语言菜单 ;
*/
private void initLanguageMenu() {
Set<String> set = new HashSet<String>();
for (DatabaseModelBean model : lstDatabase) {
MetaData metaData = model.toDbMetaData();
DBOperator dbop = DatabaseService.getDBOperator(metaData);
if (null == dbop) {
continue;
}
try {
dbop.start();
set.addAll(dbop.getLanguages());
} catch (SQLException e) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger1"), e);
} catch (ClassNotFoundException e) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger1"), e);
} finally {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
set.remove(strSrcLang);
set.remove(strTgtLang);
lstLangs = new ArrayList<String>(set);
Collections.sort(lstLangs);
// cmbLang.setItems((String[]) langs.toArray(new String[langs.size()]));
menu = new Menu(getShell(), SWT.POP_UP);
// }
if (strTgtLang != null) {
MenuItem itemTgt = new MenuItem(menu, SWT.CHECK);
itemTgt.setText(strTgtLang);
itemTgt.setSelection(true);
itemTgt.setEnabled(false);
}
for (final String lang : lstLangs) {
final MenuItem itemLang = new MenuItem(menu, SWT.CHECK);
itemLang.setText(lang);
itemLang.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
ArrayList<GridColumn> lstShowColumn = new ArrayList<GridColumn>();
// 每增加一列,除标记列外的其他列的和加100,然后平均分配给各个语言列,删除一列则做相反的操作
if (itemLang.getSelection()) {
int totalWidth = 0;
boolean blnIsResetWidth = false;
for (int index = 0; index < grid.getColumnCount(); index++) {
GridColumn column = grid.getColumn(index);
if (column.getText().equals(lang) && column.getWidth() == 0) {
lstShowColumn.add(column);
blnIsResetWidth = true;
} else if (column.getWidth() > 0) {
totalWidth += column.getWidth();
lstShowColumn.add(column);
}
}
if (blnIsResetWidth) {
int width = (totalWidth + 100) / lstShowColumn.size();
for (GridColumn column : lstShowColumn) {
column.setWidth(width);
}
}
// if (grid.getItemCount() > 0) {
// search();
// }
} else {
GridColumn deleteColumn = null;
for (int index = 0; index < grid.getColumnCount(); index++) {
GridColumn column = grid.getColumn(index);
if (column.getWidth() > 0) {
lstShowColumn.add(column);
}
if (column.getText().equals(lang)) {
deleteColumn = column;
// 将删除列中的数据清空,以保证行高正常调整
for (GridItem item : grid.getItems()) {
item.setText(index, "");
}
}
}
int width = (deleteColumn.getWidth() * lstShowColumn.size() - 100) / (lstShowColumn.size() - 1);
deleteColumn.setWidth(0);
lstShowColumn.remove(deleteColumn);
for (GridColumn column : lstShowColumn) {
column.setWidth(width);
}
// search();
}
}
});
}
}
use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.
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 translationstudio8 by heartsome.
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 translationstudio8 by heartsome.
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;
}
Aggregations