use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
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.GridItem in project translationstudio8 by heartsome.
the class DefaultRowHeaderRenderer method computeSize.
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
String text = getHeaderText(item);
Image image = getHeaderImage(item);
int x = 0;
x += leftMargin;
if (image != null) {
x += image.getBounds().width + 5;
}
x += gc.stringExtent(text).x + rightMargin;
int y = 0;
y += topMargin;
if (image != null) {
y += Math.max(gc.getFontMetrics().getHeight(), image.getBounds().height);
} else {
y += gc.getFontMetrics().getHeight();
}
y += bottomMargin;
return new Point(x, y);
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class MatchViewPart method createPartControl.
@Override
public void createPartControl(Composite parent) {
GridLayout parentGl = new GridLayout(1, false);
parentGl.marginWidth = 0;
parentGl.marginHeight = 0;
parent.setLayout(parentGl);
final Composite composite = new Composite(parent, SWT.NONE);
GridLayout compositeGl = new GridLayout(1, false);
compositeGl.marginBottom = -1;
compositeGl.marginLeft = -1;
compositeGl.marginRight = -1;
compositeGl.marginTop = 0;
compositeGl.marginWidth = 0;
compositeGl.marginHeight = 0;
compositeGl.verticalSpacing = 0;
composite.setLayout(compositeGl);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
// sourceText = new StyledText(composite, SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY);
// GridData sTextGd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
// Font f = JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT);
// sourceText.setFont(f);
// int lineH = sourceText.getLineHeight() * 3;
// sTextGd.heightHint = lineH;
// sTextGd.minimumHeight = lineH;
// sourceText.setLayoutData(sTextGd);
SashForm sashForm = new SashForm(composite, SWT.VERTICAL);
sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
sourceText = new SegmentViewer(sashForm, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL, null);
StyledText srcTextControl = sourceText.getTextWidget();
srcTextControl.setLineSpacing(net.heartsome.cat.ts.ui.Constants.SEGMENT_LINE_SPACING);
srcTextControl.setLeftMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_LEFT_MARGIN);
srcTextControl.setRightMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_RIGHT_MARGIN);
srcTextControl.setTopMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_TOP_MARGIN);
srcTextControl.setBottomMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_TOP_MARGIN);
srcTextControl.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
sourceText.setSource("");
sourceColunmCellRenderer.setSegmentViewer(sourceText);
GridData sTextGd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
Font f = JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT);
srcTextControl.setFont(f);
int lineH = srcTextControl.getLineHeight() * 2;
sTextGd.heightHint = lineH;
sTextGd.minimumHeight = lineH;
srcTextControl.setLayoutData(sTextGd);
net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(sourceText);
gridTable = new Grid(sashForm, SWT.BORDER | SWT.V_SCROLL);
gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
gridTable.setHeaderVisible(false);
gridTable.setAutoHeight(true);
gridTable.setRowsResizeable(true);
gridTable.setData("selectedBgColor", selectedBgColor);
final GridColumn sourceCln = new GridColumn(gridTable, SWT.NONE);
sourceColunmCellRenderer.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
sourceCln.setCellRenderer(sourceColunmCellRenderer);
sourceCln.setText(Messages.getString("view.MatchViewPart.sourceCln"));
sourceCln.setWordWrap(true);
sourceCln.setAlignment(SWT.CENTER);
sourceCln.setResizeable(false);
final GridColumn typeCln = new GridColumn(gridTable, SWT.NONE);
typeColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
typeCln.setCellRenderer(typeColumnCellRenderer);
typeCln.setText(Messages.getString("view.MatchViewPart.typeCln"));
typeCln.setWordWrap(true);
typeCln.setAlignment(SWT.CENTER);
typeCln.setResizeable(false);
final GridColumn targetCln = new GridColumn(gridTable, SWT.NONE);
targetColumnCellRenderer.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
targetCln.setCellRenderer(targetColumnCellRenderer);
targetCln.setText(Messages.getString("view.MatchViewPart.targetCln"));
targetCln.setWordWrap(true);
targetCln.setAlignment(SWT.CENTER);
targetCln.setResizeable(false);
// 设置可复制功能
copyEnable = new GridCopyEnable(gridTable);
sourceColunmCellRenderer.setCopyEnable(copyEnable);
targetColumnCellRenderer.setCopyEnable(copyEnable);
Composite statusComposite = new Composite(composite, SWT.NONE);
GridLayout statusComptGridLayout = new GridLayout(2, false);
statusComptGridLayout.marginBottom = -1;
statusComptGridLayout.marginLeft = -1;
statusComptGridLayout.marginRight = -1;
statusComptGridLayout.marginTop = -1;
statusComptGridLayout.marginWidth = 0;
statusComptGridLayout.marginHeight = 0;
statusComposite.setLayout(statusComptGridLayout);
statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
tipLabel = new CLabel(statusComposite, SWT.NONE);
tipLabel.setAlignment(SWT.LEFT);
infoLabel = new CLabel(statusComposite, SWT.NONE);
GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd.heightHint = 20;
infoLabel.setLayoutData(gd);
infoLabel.setAlignment(SWT.RIGHT);
// 设置列宽按比例4.5:1:4.5
composite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle area = composite.getClientArea();
Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
// - 2 * gridTable.getBorderWidth();
int width = area.width;
if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
Point vBarSize = gridTable.getVerticalBar().getSize();
width -= vBarSize.x;
}
gridTable.setSize(area.width, area.height);
width = width - 42;
sourceCln.setWidth((int) (width * 0.5));
typeCln.setWidth(42);
targetCln.setWidth((int) (width * 0.5));
}
});
gridTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
StyledText text = sourceText.getTextWidget();
text.setText(text.getText());
updateActionState();
GridItem[] selItems = gridTable.getSelection();
if (selItems.length != 1) {
return;
}
GridItem item = selItems[0];
setMatchMessage(infoLabelImage, item.getData("info").toString(), item.getData("infoTooltip").toString());
composite.layout();
}
});
gridTable.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
menuMgr.acceptMatchAction.run();
}
});
createActions();
sashForm.setWeights(new int[] { 3, 8 });
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class MatchViewPart method loadData.
private synchronized void loadData(List<AltTransBean> matches) {
if (matches == null) {
return;
}
IEditorReference[] editorReferences = getSite().getPage().getEditorReferences();
if (editorReferences.length == 0) {
return;
}
for (AltTransBean altTransBean : matches) {
String type = altTransBean.getMatchProps().get("hs:matchType");
if (type == null || type.equals("")) {
type = "others";
}
String orgin = altTransBean.getMatchOrigin();
if (orgin == null) {
// Fixed bug 2258 by Jason 翻译匹配面板不支持非 HS 工具匹配信息的显示
orgin = "";
}
String srcContent = altTransBean.getSrcContent();
if (srcContent == null || srcContent.equals("")) {
continue;
}
String tgtContent = altTransBean.getTgtContent();
if (tgtContent == null || tgtContent.equals("")) {
continue;
}
String quality = altTransBean.getMatchProps().get("match-quality").trim();
if (quality == null) {
quality = "";
} else {
if (!quality.endsWith("%")) {
quality += "%";
}
}
String changeDate = null;
String changeid = null;
String creationDate = null;
String creationid = null;
Vector<PropGroupBean> propGroups = altTransBean.getPropGroups();
StringBuffer toolTipBfTemp = new StringBuffer();
if (propGroups != null) {
for (PropGroupBean propGroupBean : propGroups) {
List<PropBean> propBeans = propGroupBean.getProps();
for (PropBean bean : propBeans) {
String ptype = bean.getProptype();
String pVal = bean.getValue();
if (ptype.equals("changeDate")) {
if (pVal != null && !pVal.equals("")) {
changeDate = DateUtils.formatDateFromUTC(pVal);
}
} else if (ptype.equals("changeId")) {
changeid = pVal;
} else if (ptype.equals("creationId")) {
creationid = pVal;
} else if (ptype.equals("creationDate")) {
if (pVal != null && !pVal.equals("")) {
creationDate = DateUtils.formatDateFromUTC(pVal);
}
} else {
toolTipBfTemp.append(ptype).append(" : ").append(pVal).append("\n");
}
}
}
}
StringBuffer toolTipBf = new StringBuffer();
if (creationid != null && !creationid.equals("")) {
toolTipBf.append(Messages.getString("view.MatchViewPart.info.tooltip.creationId")).append(creationid).append("\n");
}
if (creationDate != null && !creationDate.equals("")) {
toolTipBf.append(Messages.getString("view.MatchViewPart.info.tooltip.creationDate")).append(creationDate).append("\n");
}
toolTipBf.append(toolTipBfTemp);
StringBuffer msgBf = new StringBuffer();
if (changeDate != null && !changeDate.equals("")) {
msgBf.append(changeDate);
}
if (changeid != null && !changeid.equals("")) {
if (msgBf.length() != 0) {
msgBf.append(" | ");
}
msgBf.append(changeid);
}
if (orgin != null && !orgin.equals("")) {
if (msgBf.length() != 0) {
msgBf.append(" | ");
}
msgBf.append(orgin);
}
if (gridTable.isDisposed()) {
return;
}
String toolId = altTransBean.getMatchProps().get("tool-id");
GridItem gridItem = new GridItem(gridTable, SWT.NONE);
gridItem.setText(0, srcContent);
gridItem.setText(1, quality);
gridItem.setText(2, tgtContent);
gridItem.setToolTipText(0, toolId);
gridItem.setToolTipText(1, toolId);
gridItem.setToolTipText(2, toolId);
// 保存信息
gridItem.setData("info", resetSpecialString(msgBf.toString()));
gridItem.setData("infoTooltip", resetSpecialString(toolTipBf.toString()));
// 保存目标纯文本
gridItem.setData("tgtText", altTransBean.getTgtText());
// 保存目标纯文本
gridItem.setData("tgtContent", tgtContent);
gridItem.setData("matchType", type);
gridItem.setData("quality", quality.substring(0, quality.lastIndexOf('%')));
gridItem.setData("typeImage", getImageByType(type));
gridItem.setData("tmFuzzyInfo", altTransBean.getFuzzyResult());
}
}
use of org.eclipse.nebula.widgets.grid.GridItem in project translationstudio8 by heartsome.
the class SourceColunmCellRenderer method computeSize.
/**
* {@inheritDoc}
*/
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
GridItem item = (GridItem) value;
gc.setFont(item.getFont(getColumn()));
int x = 0;
x += leftMargin;
int y = 0;
Image image = item.getImage(getColumn());
if (image != null) {
y = topMargin + image.getBounds().height + bottomMargin;
}
// MOPR-DND
// MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns)
//
// x += gc.stringExtent(item.getText(column)).x + rightMargin;
//
// y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin);
//
// with this code:
int textHeight = 0;
if (!isWordWrap()) {
x += gc.textExtent(item.getText(getColumn())).x + rightMargin;
textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin;
} else {
int plainTextWidth;
if (wHint == SWT.DEFAULT)
plainTextWidth = getBounds().width - x - rightMargin;
else
plainTextWidth = wHint - x - rightMargin;
TextLayout currTextLayout = new TextLayout(gc.getDevice());
currTextLayout.setFont(gc.getFont());
currTextLayout.setText(item.getText(getColumn()));
currTextLayout.setAlignment(getAlignment());
currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
x += plainTextWidth + rightMargin;
textHeight += topMargin + textTopMargin;
for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++) textHeight += currTextLayout.getLineBounds(cnt).height;
textHeight += textBottomMargin + bottomMargin;
currTextLayout.dispose();
}
y = Math.max(y, textHeight);
return new Point(x, y);
}
Aggregations