Search in sources :

Example 11 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class SelectionLayerPainter method paintLayer.

@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
    Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
    columnPositionOffset = positionRectangle.x;
    rowPositionOffset = positionRectangle.y;
    cells = new HashMap<PositionCoordinate, LayerCell>();
    super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
    // Save gc settings
    int originalLineStyle = gc.getLineStyle();
    Color originalForeground = gc.getForeground();
    // Apply border settings
    gc.setLineStyle(SWT.LINE_CUSTOM);
    gc.setLineDash(new int[] { 1, 1 });
    gc.setForeground(GUIHelper.COLOR_BLACK);
    // Draw horizontal borders
    boolean selectedMode = false;
    for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++) {
        LayerCell cell = null;
        for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++) {
            cell = cells.get(new PositionCoordinate(natLayer, columnPosition, rowPosition));
            if (cell != null) {
                if (selectedMode != isSelected(cell)) {
                    selectedMode = !selectedMode;
                    Rectangle cellBounds = cell.getBounds();
                    // Draw top edge
                    gc.drawLine(cellBounds.x - 1, cellBounds.y - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y - 1);
                }
            }
        }
        if (selectedMode && cell != null) {
            // If last cell is selected, draw its bottom edge
            Rectangle cellBounds = cell.getBounds();
            gc.drawLine(cellBounds.x - 1, cellBounds.y + cellBounds.height - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y + cellBounds.height - 1);
        }
        selectedMode = false;
    }
    // Draw vertical borders
    for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++) {
        LayerCell cell = null;
        for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++) {
            cell = cells.get(new PositionCoordinate(natLayer, columnPosition, rowPosition));
            if (cell != null) {
                if (selectedMode != isSelected(cell)) {
                    selectedMode = !selectedMode;
                    Rectangle cellBounds = cell.getBounds();
                    // Draw left edge
                    gc.drawLine(cellBounds.x - 1, cellBounds.y - 1, cellBounds.x - 1, cellBounds.y + cellBounds.height - 1);
                }
            }
        }
        if (selectedMode && cell != null) {
            // If last cell is selected, draw its right edge
            Rectangle cellBounds = cell.getBounds();
            gc.drawLine(cellBounds.x + cellBounds.width - 1, cellBounds.y - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y + cellBounds.height - 1);
        }
        selectedMode = false;
    }
    // Restore original gc settings
    gc.setLineStyle(originalLineStyle);
    gc.setForeground(originalForeground);
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 12 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class TextPainterWithPadding method paintCell.

/**
	 * (non-Javadoc)
	 * @see net.sourceforge.nattable.painter.cell.BackgroundPainter#paintCell(net.sourceforge.nattable.layer.cell.LayerCell,
	 *      org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle,
	 *      net.sourceforge.nattable.config.IConfigRegistry)
	 */
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    super.paintCell(cell, gc, rectangle, configRegistry);
    IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
    setupGCFromConfig(gc, cellStyle);
    if (innerTagFactory == null) {
        innerTagFactory = new XliffInnerTagFactory(placeHolderBuilder);
    }
    innerTagFactory.reset();
    int rowIndex = cell.getLayer().getRowIndexByPosition(cell.getRowPosition());
    int columnIndex = cell.getLayer().getColumnIndexByPosition(cell.getColumnPosition());
    if (!editor.isHorizontalLayout()) {
        // 垂直
        if (rowIndex % 2 != 0) {
            LayerCell srcCell = cell.getLayer().getCellByPosition(cell.getColumnPosition(), cell.getRowPosition() - 1);
            if (srcCell != null) {
                String sourceVal = (String) srcCell.getDataValue();
                innerTagFactory.parseInnerTag(sourceVal);
            }
        }
    } else {
        // 水平
        if (columnIndex == editor.getTgtColumnIndex()) {
            LayerCell srcCell = cell.getLayer().getCellByPosition(1, cell.getRowPosition());
            if (srcCell != null) {
                String sourceVal = (String) srcCell.getDataValue();
                innerTagFactory.parseInnerTag(sourceVal);
            }
        }
    }
    TextLayout layout = getCellTextLayout(cell);
    int tempIndx = rowIndex;
    if (!editor.isHorizontalLayout()) {
        tempIndx = tempIndx / 2;
    }
    if (tempIndx == editor.getSelectedRows()[0] && (editor.isHorizontalLayout() ? columnIndex == editor.getSrcColumnIndex() : rowIndex % 2 == 0)) {
        List<String> terms = editor.getTermsCache().get(tempIndx);
        if (terms != null && terms.size() > 0) {
            List<StyleRange> ranges = new ArrayList<StyleRange>();
            TextStyle style = new TextStyle(getFont(), null, ColorConfigBean.getInstance().getHighlightedTermColor());
            char[] source = layout.getText().toCharArray();
            for (String term : terms) {
                if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
                    term = term.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
                    term = term.replaceAll("\\t", Constants.TAB_CHARACTER + "​");
                    term = term.replaceAll(" ", Constants.SPACE_CHARACTER + "​");
                }
                ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style));
            }
            for (StyleRange range : ranges) {
                layout.setStyle(range, range.start, range.start + range.length - 1);
            }
        }
    }
    try {
        String displayText = layout.getText();
        Rectangle bounds = cell.getBounds();
        if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
            appendNonprintingStyle(layout);
        }
        layout.draw(gc, bounds.x + leftPadding, bounds.y + topPadding);
        List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
        for (InnerTagBean innerTagBean : innerTagBeans) {
            String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
            int start = displayText.indexOf(placeHolder);
            if (start == -1) {
                continue;
            }
            Point p = layout.getLocation(start, false);
            int x = bounds.x + p.x + leftPadding;
            x += SEGMENT_LINE_SPACING;
            Point tagSize = tagRender.calculateTagSize(innerTagBean);
            int lineIdx = layout.getLineIndex(start);
            Rectangle r = layout.getLineBounds(lineIdx);
            // -
            int y = bounds.y + p.y + topPadding + r.height / 2 - tagSize.y / 2;
            // layout.getLineMetrics(0).getDescent();
            // if (y + r.height > tagSize.y) {
            // FontMetrics fm = layout.getLineMetrics(lineIdx);
            // y = y + r.height - tagSize.y - fm.getDescent();
            // }
            tagRender.draw(gc, innerTagBean, x, y);
        }
    } finally {
        layout.dispose();
    }
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) StyleRange(org.eclipse.swt.custom.StyleRange) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout) IStyle(net.sourceforge.nattable.style.IStyle) XliffInnerTagFactory(net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory) TextStyle(org.eclipse.swt.graphics.TextStyle)

Example 13 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class ColumnReorderDragMode method mouseMove.

public void mouseMove(NatTable natTable, MouseEvent event) {
    if (event.x > natTable.getWidth()) {
        return;
    }
    Point dragPt = new Point(event.x, event.y);
    int gridColumnPosition = natTable.getColumnPositionByX(event.x);
    if (gridColumnPosition >= 0) {
        int gridRowPosition = natTable.getRowPositionByY(event.y);
        LayerCell cell = natTable.getCellByPosition(gridColumnPosition, gridRowPosition);
        if (cell == null) {
            return;
        }
        Rectangle selectedColumnHeaderRect = cell.getBounds();
        int tmpDragToGridColumnPosition = 0;
        moveDirection = CellEdgeDetectUtil.getHorizontalCellEdge(selectedColumnHeaderRect, dragPt);
        switch(moveDirection) {
            case LEFT:
                tmpDragToGridColumnPosition = gridColumnPosition;
                if ((isValidCoordinate = isValidTargetColumnPosition(natTable, dragFromGridColumnPosition, tmpDragToGridColumnPosition, event))) {
                    dragToGridColumnPosition = tmpDragToGridColumnPosition;
                    dragToColumnHandleX = selectedColumnHeaderRect.x;
                } else {
                    dragToColumnHandleX = 0;
                }
                break;
            case RIGHT:
                tmpDragToGridColumnPosition = gridColumnPosition + 1;
                if ((isValidCoordinate = isValidTargetColumnPosition(natTable, dragFromGridColumnPosition, tmpDragToGridColumnPosition, event))) {
                    dragToGridColumnPosition = tmpDragToGridColumnPosition;
                    dragToColumnHandleX = selectedColumnHeaderRect.x + selectedColumnHeaderRect.width;
                } else {
                    dragToColumnHandleX = 0;
                }
                break;
        }
        natTable.redraw(0, 0, natTable.getWidth(), natTable.getHeight(), false);
    }
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 14 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class MaxCellBoundsHelper method getPreferredRowHeight.

public static int getPreferredRowHeight(ILayer layer, int rowPosition, IConfigRegistry configRegistry, GC gc) {
    int maxHeight = 0;
    ICellPainter painter;
    LayerCell cell;
    for (int columnPosition = 0; columnPosition < layer.getColumnCount(); columnPosition++) {
        cell = layer.getCellByPosition(columnPosition, rowPosition);
        if (cell != null) {
            painter = configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
            if (painter != null) {
                int preferedHeight = painter.getPreferredHeight(cell, gc, configRegistry);
                maxHeight = (preferedHeight > maxHeight) ? preferedHeight : maxHeight;
            }
        }
    }
    return maxHeight;
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) ICellPainter(net.sourceforge.nattable.painter.cell.ICellPainter)

Example 15 with LayerCell

use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.

the class AutoResizeCurrentRowsCommandHandler method getPreferredRowHeight.

private int getPreferredRowHeight(ILayer layer, int rowPosition, IConfigRegistry configRegistry, GC gc, int clientAreaHeight) {
    int maxHeight = 0;
    ICellPainter painter;
    LayerCell cell;
    for (int columnPosition = 0; columnPosition < layer.getColumnCount(); columnPosition++) {
        cell = layer.getCellByPosition(columnPosition, rowPosition);
        if (cell != null) {
            painter = configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
            if (painter != null) {
                int preferedHeight = painter.getPreferredHeight(cell, gc, configRegistry);
                maxHeight = (preferedHeight > maxHeight) ? preferedHeight : maxHeight;
            }
        }
    }
    if (maxHeight > clientAreaHeight) {
        return clientAreaHeight;
    }
    return maxHeight;
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) ICellPainter(net.sourceforge.nattable.painter.cell.ICellPainter)

Aggregations

LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)24 Rectangle (org.eclipse.swt.graphics.Rectangle)8 ICellPainter (net.sourceforge.nattable.painter.cell.ICellPainter)4 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)3 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)3 IStyle (net.sourceforge.nattable.style.IStyle)3 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)2 UpdateDataCommand (net.sourceforge.nattable.edit.command.UpdateDataCommand)2 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)2 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)2 Point (org.eclipse.swt.graphics.Point)2 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1 XPathParseException (com.ximpleware.XPathParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)1 XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)1 NoteBean (net.heartsome.cat.ts.core.bean.NoteBean)1