Search in sources :

Example 6 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.

the class DefaultColumnHeaderRenderer method computeSize.

/**
     * {@inheritDoc}
     */
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
    GridColumn column = (GridColumn) value;
    gc.setFont(column.getHeaderFont());
    int x = leftMargin;
    int y = topMargin + gc.getFontMetrics().getHeight() + bottomMargin;
    if (column.getImage() != null) {
        x += column.getImage().getBounds().width + imageSpacing;
        y = Math.max(y, topMargin + column.getImage().getBounds().height + bottomMargin);
    }
    if (!isWordWrap()) {
        x += gc.stringExtent(column.getText()).x + rightMargin;
    } else {
        int plainTextWidth;
        if (wHint == SWT.DEFAULT)
            plainTextWidth = getBounds().width - x - rightMargin;
        else
            plainTextWidth = wHint - x - rightMargin;
        getTextLayout(gc, column);
        textLayout.setText(column.getText());
        textLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth);
        x += plainTextWidth + rightMargin;
        int textHeight = topMargin;
        textHeight += textLayout.getBounds().height;
        textHeight += bottomMargin;
        y = Math.max(y, textHeight);
    }
    y += computeControlSize(column).y;
    return new Point(x, y);
}
Also used : GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 7 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn 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);
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) Color(org.eclipse.swt.graphics.Color) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 8 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn 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 });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) StyledText(org.eclipse.swt.custom.StyledText) ISelectionListener(org.eclipse.ui.ISelectionListener) Listener(org.eclipse.swt.widgets.Listener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Grid(org.eclipse.nebula.widgets.grid.Grid) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GridCopyEnable(net.heartsome.cat.ts.ui.grid.GridCopyEnable) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 9 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.

the class GridCopyEnable method clearSelection.

void clearSelection() {
    int start = selection.x;
    int end = selection.y;
    selection.x = selection.y = caretOffset;
    selectionAnchor = -1;
    // redraw old selection, if any
    if (end - start > 0 && gridTable.getItems().length != 0) {
        if (layout == null && focusItemIndex != -1 && focusItemIndex != -1) {
            GridItem item = gridTable.getItem(focusItemIndex);
            GridColumn col = gridTable.getColumn(focusColIndex);
            GridCellRenderer gcr = col.getCellRenderer();
            if (gcr != null && gcr instanceof XGridCellRenderer) {
                GC gc = new GC(gcr.getDisplay());
                layout = ((XGridCellRenderer) gcr).getTextLayout(gc, item, focusColIndex, true, false);
                gc.dispose();
            }
            if (layout == null) {
                return;
            }
        }
        Rectangle rect = layout.getBounds(start, end);
        gridTable.redraw(rect.x + coordinateOffsetX, rect.y + coordinateOffsetY, rect.width, rect.height, false);
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) Rectangle(org.eclipse.swt.graphics.Rectangle) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 10 with GridColumn

use of org.eclipse.nebula.widgets.grid.GridColumn in project translationstudio8 by heartsome.

the class GridCopyEnable method handleVerticalScroll.

void handleVerticalScroll(Event event) {
    GridVisibleRange visibleR = gridTable.getVisibleRange();
    GridItem[] items = visibleR.getItems();
    boolean itemFlg = false;
    for (GridItem item : items) {
        if (focusItem == item) {
            itemFlg = true;
        }
    }
    boolean columnFlg = false;
    GridColumn[] columns = visibleR.getColumns();
    if (columns.length - 1 >= focusColIndex) {
        columnFlg = true;
    }
    if (!itemFlg || !columnFlg) {
        defaultCaret.setVisible(false);
        return;
    }
    defaultCaret.setVisible(true);
    GridColumn col = gridTable.getColumn(focusColIndex);
    GridCellRenderer gcr = col.getCellRenderer();
    int colIndex = gcr.getColumn();
    if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
        return;
    }
    XGridCellRenderer cellRender = (XGridCellRenderer) gcr;
    Rectangle cellBounds = focusItem.getBounds(colIndex);
    GC gc = new GC(Display.getDefault());
    TextLayout layout = null;
    try {
        layout = cellRender.getTextLayout(gc, focusItem, colIndex, true, false);
        if (layout == null) {
            gc.dispose();
            return;
        }
        Point point = layout.getLocation(caretOffset, false);
        coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
        coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
        defaultCaret.setLocation(point.x + coordinateOffsetX, point.y + coordinateOffsetY);
    } finally {
        if (layout != null) {
            layout.dispose();
        }
        if (gc != null) {
            gc.dispose();
        }
    }
}
Also used : GridVisibleRange(org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout) GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GC(org.eclipse.swt.graphics.GC)

Aggregations

GridColumn (org.eclipse.nebula.widgets.grid.GridColumn)45 Point (org.eclipse.swt.graphics.Point)38 GridItem (org.eclipse.nebula.widgets.grid.GridItem)16 Rectangle (org.eclipse.swt.graphics.Rectangle)14 TalendGridColumn (org.eclipse.nebula.widgets.grid.TalendGridColumn)7 GC (org.eclipse.swt.graphics.GC)7 TalendGridItem (org.eclipse.nebula.widgets.grid.TalendGridItem)6 GridData (org.eclipse.swt.layout.GridData)6 Color (org.eclipse.swt.graphics.Color)5 Image (org.eclipse.swt.graphics.Image)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Grid (org.eclipse.nebula.widgets.grid.Grid)4 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 TextLayout (org.eclipse.swt.graphics.TextLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 Event (org.eclipse.swt.widgets.Event)4 Listener (org.eclipse.swt.widgets.Listener)4 GridCellRenderer (org.eclipse.nebula.widgets.grid.GridCellRenderer)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3