Search in sources :

Example 6 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)

Example 7 with IStyle

use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.

the class TextCellEditor method createTextControl.

protected Text createTextControl(Composite parent) {
    IStyle cellStyle = getCellStyle();
    final Text textControl = new Text(parent, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
    textControl.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    textControl.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    textControl.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    textControl.addKeyListener(new KeyAdapter() {

        private final Color originalColor = textControl.getForeground();

        @Override
        public void keyReleased(KeyEvent e) {
            if (!validateCanonicalValue()) {
                textControl.setForeground(GUIHelper.COLOR_RED);
            } else {
                textControl.setForeground(originalColor);
            }
        }

        ;
    });
    return textControl;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) IStyle(net.sourceforge.nattable.style.IStyle) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Color(org.eclipse.swt.graphics.Color) Text(org.eclipse.swt.widgets.Text)

Example 8 with IStyle

use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.

the class InlineCellEditController method editCellInline.

public static boolean editCellInline(LayerCell cell, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
    try {
        ActiveCellEditor.commit();
        final List<String> configLabels = cell.getConfigLabels().getLabels();
        Rectangle cellBounds = cell.getBounds();
        ILayer layer = cell.getLayer();
        int columnPosition = layer.getColumnPositionByX(cellBounds.x);
        int columnIndex = layer.getColumnIndexByPosition(columnPosition);
        int rowPosition = layer.getRowPositionByY(cellBounds.y);
        int rowIndex = layer.getRowIndexByPosition(rowPosition);
        boolean editable = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, configLabels).isEditable(columnIndex, rowIndex);
        if (!editable) {
            return false;
        }
        ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
        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);
        ICellEditHandler editHandler = new SingleEditHandler(cellEditor, layer, columnPosition, rowPosition);
        final Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));
        Object originalCanonicalValue = cell.getDataValue();
        ActiveCellEditor.activate(cellEditor, parent, originalCanonicalValue, initialEditValue, displayConverter, cellStyle, dataValidator, editHandler, columnPosition, rowPosition, columnIndex, rowIndex);
        Control editorControl = ActiveCellEditor.getControl();
        if (editorControl != null) {
            editorControl.setBounds(editorBounds);
            ILayerListener layerListener = layerListenerMap.get(layer);
            if (layerListener == null) {
                layerListener = new InlineCellEditLayerListener(layer);
                layerListenerMap.put(layer, layerListener);
                layer.addLayerListener(layerListener);
            }
        }
    } catch (Exception e) {
        if (cell == null) {
            System.err.println("Cell being edited is no longer available. " + "Character: " + initialEditValue);
        } else {
            System.err.println("Error while editing cell (inline): " + "Cell: " + cell + "; Character: " + initialEditValue);
            e.printStackTrace(System.err);
        }
    }
    return true;
}
Also used : IDataValidator(net.sourceforge.nattable.data.validate.IDataValidator) ILayer(net.sourceforge.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerListener(net.sourceforge.nattable.layer.ILayerListener) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter) IStyle(net.sourceforge.nattable.style.IStyle) Control(org.eclipse.swt.widgets.Control) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor) CellStyleProxy(net.sourceforge.nattable.style.CellStyleProxy)

Example 9 with IStyle

use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.

the class MultiCellEditController method editSelectedCells.

public static boolean editSelectedCells(SelectionLayer selectionLayer, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
    LayerCell lastSelectedCell = EditUtils.getLastSelectedCell(selectionLayer);
    // IF cell is selected
    if (lastSelectedCell != null) {
        final List<String> lastSelectedCellLabelsArray = lastSelectedCell.getConfigLabels().getLabels();
        PositionCoordinate[] selectedCells = selectionLayer.getSelectedCells();
        // AND selected cell count > 1
        if (selectedCells.length > 1) {
            ICellEditor lastSelectedCellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
            // AND all selected cells are editable
            if (EditUtils.isEditorSame(selectionLayer, configRegistry, lastSelectedCellEditor) && EditUtils.allCellsEditable(selectionLayer, configRegistry)) {
                // THEN use multi commit handler and populate editor in popup
                ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                IDisplayConverter dataTypeConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                Object originalCanonicalValue = lastSelectedCell.getDataValue();
                for (PositionCoordinate selectedCell : selectedCells) {
                    Object cellValue = selectionLayer.getCellByPosition(selectedCell.columnPosition, selectedCell.rowPosition).getDataValue();
                    if (!cellValue.equals(originalCanonicalValue)) {
                        originalCanonicalValue = null;
                        break;
                    }
                }
                ITickUpdateHandler tickUpdateHandler = configRegistry.getConfigAttribute(TickUpdateConfigAttributes.UPDATE_HANDLER, DisplayMode.EDIT, lastSelectedCellLabelsArray);
                boolean allowIncrementDecrement = tickUpdateHandler != null && tickUpdateHandler.isApplicableFor(originalCanonicalValue);
                MultiCellEditDialog dialog = new MultiCellEditDialog(parent.getShell(), cellEditor, dataTypeConverter, cellStyle, dataValidator, originalCanonicalValue, initialEditValue, allowIncrementDecrement);
                int returnValue = dialog.open();
                ActiveCellEditor.close();
                if (returnValue == Dialog.OK) {
                    Object editorValue = dialog.getEditorValue();
                    Object newValue = editorValue;
                    if (allowIncrementDecrement) {
                        switch(dialog.getEditType()) {
                            case INCREASE:
                                newValue = tickUpdateHandler.getIncrementedValue(originalCanonicalValue);
                                break;
                            case DECREASE:
                                newValue = tickUpdateHandler.getDecrementedValue(originalCanonicalValue);
                                break;
                        }
                    }
                    for (PositionCoordinate selectedCell : selectedCells) {
                        selectionLayer.doCommand(new UpdateDataCommand(selectionLayer, selectedCell.columnPosition, selectedCell.rowPosition, newValue));
                    }
                }
            }
        } else {
            // ELSE use single commit handler and populate editor inline in cell rectangle
            selectionLayer.fireLayerEvent(new InlineCellEditEvent(selectionLayer, new PositionCoordinate(selectionLayer, lastSelectedCell.getColumnPosition(), lastSelectedCell.getRowPosition()), parent, configRegistry, initialEditValue));
        }
        return true;
    }
    return false;
}
Also used : IDataValidator(net.sourceforge.nattable.data.validate.IDataValidator) MultiCellEditDialog(net.sourceforge.nattable.edit.gui.MultiCellEditDialog) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) UpdateDataCommand(net.sourceforge.nattable.edit.command.UpdateDataCommand) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter) ITickUpdateHandler(net.sourceforge.nattable.tickupdate.ITickUpdateHandler) IStyle(net.sourceforge.nattable.style.IStyle) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor) InlineCellEditEvent(net.sourceforge.nattable.edit.event.InlineCellEditEvent) CellStyleProxy(net.sourceforge.nattable.style.CellStyleProxy)

Example 10 with IStyle

use of net.sourceforge.nattable.style.IStyle in project translationstudio8 by heartsome.

the class StyledTextCellEditor method createTextControl.

protected StyledText createTextControl(Composite parent) {
    TagStyleManager tagStyleManager = xliffEditor.getTagStyleManager();
    IStyle cellStyle = this.hsCellEditor.getCellStyle();
    int styled = HorizontalAlignmentEnum.getSWTStyle(cellStyle);
    styled |= SWT.MULTI | SWT.WRAP;
    viewer = new SegmentViewer(parent, styled, tagStyleManager.getTagStyle());
    // 添加标记样式改变监听
    // addTagStyleChangeListener();
    // 注册标记样式调节器
    net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(viewer);
    // TagStyleConfigurator.configure(viewer);
    // 将原来直接创建StyledText的方式改为由TextViewer提供
    final StyledText textControl = viewer.getTextWidget();
    initStyle(textControl, cellStyle);
    textControl.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent e) {
        }

        public void focusGained(FocusEvent e) {
            getActionHandler().updateGlobalActionHandler();
        }
    });
    viewer.getDocument().addDocumentListener(new IDocumentListener() {

        public void documentChanged(DocumentEvent e) {
            // 自动行高
            autoResize();
        }

        public void documentAboutToBeChanged(DocumentEvent event) {
        }
    });
    // 实现编辑模式下添加右键菜单
    // dispose textControl前应去掉右键menu,因为右键menu是和nattable共享的,不能在这儿dispose,说见close()方法
    final Menu menu = (Menu) xliffEditor.getTable().getData(Menu.class.getName());
    textControl.setMenu(menu);
    return textControl;
}
Also used : IStyle(net.sourceforge.nattable.style.IStyle) ISegmentViewer(net.heartsome.cat.ts.ui.innertag.ISegmentViewer) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) StyledText(org.eclipse.swt.custom.StyledText) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Menu(org.eclipse.swt.widgets.Menu) DocumentEvent(org.eclipse.jface.text.DocumentEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

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