use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.
the class ImagePainter method paintCell.
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
if (paintBg) {
super.paintCell(cell, gc, bounds, configRegistry);
}
Image image = getImage(cell, configRegistry);
if (image != null) {
Rectangle imageBounds = image.getBounds();
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height));
}
}
use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.
the class LineBorderDecorator method getBorderStyle.
private BorderStyle getBorderStyle(LayerCell cell, IConfigRegistry configRegistry) {
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
BorderStyle borderStyle = cellStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE);
if (borderStyle == null) {
borderStyle = defaultBorderStyle;
}
return borderStyle;
}
use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.
the class HsMultiCellEditorControl method activeCell.
private static HsMultiCellEditor activeCell(ViewportLayer vLayer, XLIFFEditorImplWithNatTable xliffEditor, IConfigRegistry configRegistry, int columnIndex, int rowIndex, int rowPosition, String cellType) {
NatTable natTable = xliffEditor.getTable();
int columnPosition = vLayer.getColumnPositionByIndex(columnIndex);
LayerCell cell = natTable.getCellByPosition(columnPosition, rowPosition);
if (cell == null) {
return null;
}
Rectangle cellBounds = cell.getBounds();
List<String> configLabels = cell.getConfigLabels().getLabels();
if (!xliffEditor.isHorizontalLayout()) {
if (cellType.equals(NatTableConstant.SOURCE)) {
configLabels.remove(XLIFFEditorImplWithNatTable.TARGET_EDIT_CELL_LABEL);
} else if (cellType.equals(NatTableConstant.TARGET)) {
configLabels.remove(XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
}
}
ILayer layer = cell.getLayer();
Object originalCanonicalValue = cell.getDataValue();
IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels);
IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels);
IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels);
Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));
int cellStartY = cellBounds.y;
int cellEndY = cellStartY + cellBounds.height;
Rectangle clientArea = natTable.getClientAreaProvider().getClientArea();
int clientAreaEndY = clientArea.y + clientArea.height;
if (cellEndY > clientAreaEndY) {
editorBounds.height = clientAreaEndY - cellStartY;
}
StyledTextCellEditor cellEditor = (StyledTextCellEditor) configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
ICellEditHandler editHandler = new HsMultiCellEditorHandler(cellEditor, layer);
HsMultiCellEditor hsCellEditor = new HsMultiCellEditor(cellType, cellEditor, editHandler, columnPosition, rowPosition, columnIndex, rowIndex, dataValidator, originalCanonicalValue, displayConverter, cellStyle, editorBounds);
return hsCellEditor;
}
use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.
the class TextPainter method paintCell.
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
String text = convertDataType(cell, configRegistry);
// Draw Text
String originalText = text;
int originalTextWidth = getWidthFromCache(gc, originalText);
text = getAvailableTextToDisplay(gc, rectangle, text);
int contentWidth = Math.min(originalTextWidth, rectangle.width);
int fontHeight = gc.getFontMetrics().getHeight();
int contentHeight = fontHeight * getNumberOfNewLines(text);
gc.drawText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth), rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight), true);
gc.setClipping(originalClipping);
}
use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.
the class StatusPainter method paintCell.
/**
* 重绘操作
*/
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
List<Map<Integer, Image>> images = getImages(cell, configRegistry);
Rectangle cellBounds = cell.getBounds();
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
if (paintBg) {
Color originalBackground = gc.getBackground();
Color originalForeground = gc.getForeground();
Color backgroundColor = CellStyleUtil.getCellStyle(cell, configRegistry).getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
if (backgroundColor != null) {
gc.setBackground(backgroundColor);
gc.fillRectangle(bounds);
}
super.paintCell(cell, gc, bounds, configRegistry);
if (machQuality != null) {
Font oldFont = gc.getFont();
Font font = cellStyle.getAttributeValue(CellStyleAttributes.FONT);
gc.setFont(font);
if (cellBackground != null) {
gc.setBackground(cellBackground);
gc.setForeground(GUIHelper.COLOR_BLACK);
}
gc.drawText(machQuality, cellBounds.x + 15 + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, 15), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, 15));
gc.setFont(oldFont);
}
gc.setForeground(originalForeground);
gc.setBackground(originalBackground);
cellBackground = null;
}
if (images != null) {
int x = 0;
for (Map<Integer, Image> imageMap : images) {
Iterator<Integer> ps = imageMap.keySet().iterator();
if (ps.hasNext()) {
int p = ps.next();
Image image = imageMap.get(p);
if (image == null) {
continue;
}
if (x == 0) {
// 第一张图片的水平位置以cell的水平位置为准
x = cellBounds.x;
} else {
// 累加显示过图片的宽度以确定下一张图片的水平位置
x = cellBounds.x + 20;
x += 16 * (p - 1);
}
// TODO 没有考虑对齐方式
if (p - 1 == 0) {
// 第一张图片的水平位置要加上HorizontalAligmentPadding的宽度和VerticalAlignmentPadding的高度
gc.drawImage(image, x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, 16), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, 16));
} else {
gc.drawImage(image, x, bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, 16));
}
}
}
}
}
Aggregations