Search in sources :

Example 1 with IStyle

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));
    }
}
Also used : IStyle(net.sourceforge.nattable.style.IStyle) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image)

Example 2 with IStyle

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;
}
Also used : IStyle(net.sourceforge.nattable.style.IStyle) BorderStyle(net.sourceforge.nattable.style.BorderStyle)

Example 3 with IStyle

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;
}
Also used : IDataValidator(net.sourceforge.nattable.data.validate.IDataValidator) ICellEditHandler(net.sourceforge.nattable.edit.ICellEditHandler) ILayer(net.sourceforge.nattable.layer.ILayer) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter) IStyle(net.sourceforge.nattable.style.IStyle) NatTable(net.sourceforge.nattable.NatTable) CellStyleProxy(net.sourceforge.nattable.style.CellStyleProxy)

Example 4 with IStyle

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);
}
Also used : IStyle(net.sourceforge.nattable.style.IStyle) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 5 with IStyle

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));
                }
            }
        }
    }
}
Also used : IStyle(net.sourceforge.nattable.style.IStyle) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) Map(java.util.Map) Font(org.eclipse.swt.graphics.Font)

Aggregations

IStyle (net.sourceforge.nattable.style.IStyle)10 Rectangle (org.eclipse.swt.graphics.Rectangle)6 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)3 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)3 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)3 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)3 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)2 ILayer (net.sourceforge.nattable.layer.ILayer)2 Color (org.eclipse.swt.graphics.Color)2 Image (org.eclipse.swt.graphics.Image)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)1 XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)1 ISegmentViewer (net.heartsome.cat.ts.ui.innertag.ISegmentViewer)1 SegmentViewer (net.heartsome.cat.ts.ui.innertag.SegmentViewer)1 NatTable (net.sourceforge.nattable.NatTable)1 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)1 ICellEditHandler (net.sourceforge.nattable.edit.ICellEditHandler)1