Example usage for org.eclipse.jface.viewers ViewerCell getTextBounds

List of usage examples for org.eclipse.jface.viewers ViewerCell getTextBounds

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerCell getTextBounds.

Prototype

public Rectangle getTextBounds() 

Source Link

Document

The location and bounds of the area where the text is drawn depends on various things (image displayed, control with SWT.CHECK)

Usage

From source file:com.google.gapid.widgets.MeasuringViewLabelProvider.java

License:Apache License

public Object getFollow(Point point) {
    ViewerCell cell = viewer.getCell(point);
    if (cell == null || !isFollowable(cell.getElement())) {
        return null;
    }/*  w ww  .  ja  v a2s  . c  o  m*/

    LinkableStyledString string = format(cell.getItem(), cell.getElement(), LinkableStyledString.create(theme));
    string.endLink();
    string.append("dummy", string.defaultStyle());
    updateLayout(cell, string.getString());

    Rectangle bounds = cell.getTextBounds();
    int offset = layout.getOffset(point.x - bounds.x, point.y - bounds.y, null);
    return string.getLinkTarget(offset);
}

From source file:com.netxforge.screens.editing.base.tables.FocusBlockOwnerDrawHighlighterForMultiselection.java

License:Open Source License

private void markFocusedBlock(Event event, List<ViewerCell> block) {

    // iterate through the cell, and draw a rectangle.
    for (ViewerCell cell : block) {
        Color background = (cell.getControl().isFocusControl()) ? getSelectedCellBackgroundColor(cell)
                : getSelectedCellBackgroundColorNoFocus(cell);
        Color foreground = (cell.getControl().isFocusControl()) ? getSelectedCellForegroundColor(cell)
                : getSelectedCellForegroundColorNoFocus(cell);

        if (foreground != null || background != null || onlyTextHighlighting(cell)) {
            GC gc = event.gc;/*from w  w  w  .j a va  2s.  com*/

            if (background == null) {
                background = cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
            }

            if (foreground == null) {
                foreground = cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
            }

            gc.setBackground(background);
            gc.setForeground(foreground);

            if (onlyTextHighlighting(cell)) {
                Rectangle area = event.getBounds();
                Rectangle rect = cell.getTextBounds();
                if (rect != null) {
                    area.x = rect.x;
                }
                gc.fillRectangle(area);
            } else {
                gc.fillRectangle(event.getBounds());

            }

        }
    }
    drawBorder(event, block);
    event.detail &= ~SWT.SELECTED;
}

From source file:de.walware.ecommons.ui.util.ColumnHoverManager.java

License:Open Source License

@Override
protected void computeInformation() {
    //      if (!fProcessMouseHoverEvent) {
    //         setInformation(null, null);
    //         return;
    //      }/*from   ww  w  .  j a  v a  2  s . c o m*/

    final Point location = getHoverEventLocation();
    final ViewerCell cell = computeCellAtLocation(location);
    if (cell == null) {
        setInformation(null, null);
        return;
    }
    final Object element = prepareHoverInformation(cell);
    if (element == null) {
        setInformation(null, null);
        return;
    }
    final Rectangle textArea = cell.getTextBounds();
    final Rectangle imageArea = cell.getImageBounds();
    final Rectangle clientArea = fSubjectControl.getClientArea();
    final int x = Math.max(0, Math.min(textArea.x, imageArea.x));
    int x2 = (clientArea.width + location.x) / 2;
    x2 = Math.min(x2, location.x + 120);
    //      final int x2 = clientArea.width;
    final Rectangle area = new Rectangle(x, textArea.y, x2 - x, textArea.height);

    synchronized (fMutex) {
        if (fThread != null) {
            setInfo(null, null);
            return;
        }

        fThread = new Thread("Structured Viewer Hover Presenter") { //$NON-NLS-1$
            @Override
            public void run() {
                boolean ok = false;
                try {
                    if (fThread == null) {
                        return;
                    }
                    final Object information = getHoverInformation(element);

                    //               if (hover instanceof ITextHoverExtension)
                    //                  setCustomInformationControlCreator(((ITextHoverExtension) hover).getHoverControlCreator());
                    //               else
                    //                  setCustomInformationControlCreator(null);

                    synchronized (fMutex) {
                        if (fThread != null && information != null) {
                            setInfo(information, area);
                            fThread = null;
                            ok = true;
                        }
                    }
                } catch (final RuntimeException e) {
                    StatusManager.getManager().handle(new Status(IStatus.ERROR, SharedUIResources.PLUGIN_ID,
                            IStatus.OK, "Unexpected runtime error while computing a element hover", e)); //$NON-NLS-1$
                } finally {
                    if (!ok) {
                        synchronized (fMutex) {
                            setInfo(null, null);
                            fThread = null;
                        }
                    }
                }
            }
        };

        fThread.setDaemon(true);
        fThread.setPriority(Thread.MIN_PRIORITY);
        fThread.start();
    }
}

From source file:eu.esdihumboldt.hale.ui.templates.webtemplates.WebTemplatesDialog.java

License:Open Source License

@Override
protected void setupViewer(final TreeViewer viewer, WebTemplate initialSelection) {
    // this label provider is used for filtering (I guess)
    viewer.setLabelProvider(new LabelProvider() {

        @Override//w ww . j  a  va  2  s  .com
        public String getText(Object element) {
            if (element instanceof WebTemplate) {
                return ((WebTemplate) element).getName();
            }
            return super.getText(element);
        }

    });

    viewer.getTree().setHeaderVisible(true);
    //      viewer.getTree().setLinesVisible(true);

    // main column
    TreeViewerColumn mainColumn = new TreeViewerColumn(viewer, SWT.NONE);
    mainColumn.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();

            StyledString text = new StyledString();
            if (element instanceof WebTemplate) {
                WebTemplate template = (WebTemplate) element;

                text.append(template.getName());
            } else {
                text.append(element.toString());
            }

            cell.setText(text.getString());
            cell.setStyleRanges(text.getStyleRanges());

            super.update(cell);
        }
    });
    mainColumn.getColumn().setText("Template");
    layout.setColumnData(mainColumn.getColumn(), new ColumnWeightData(7));

    // link column
    if (Desktop.isDesktopSupported()) {
        TreeViewerColumn linkColumn = new TreeViewerColumn(viewer, SWT.CENTER);
        linkColumn.setLabelProvider(new LinkLabels());

        // listener that reacts on link cell clicks
        viewer.getTree().addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                if (e.button == 1) {
                    ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
                    if (cell != null && cell.getColumnIndex() == 1 && cell.getTextBounds().contains(e.x, e.y)) {
                        Object element = cell.getElement();
                        if (element instanceof WebTemplate) {
                            try {
                                Desktop.getDesktop().browse(((WebTemplate) element).getSite());
                            } catch (IOException e1) {
                                log.error("Could not launch browser", e1);
                            }
                        }
                    }
                }
            }
        });

        layout.setColumnData(linkColumn.getColumn(), new ColumnWeightData(1));
    }

    viewer.setComparator(new ViewerComparator());

    viewer.setContentProvider(new WebTemplatesContentProvider());
    viewer.setInput(templates);
}

From source file:org.eclipse.emf.examples.library.databinding.common.FocusCellOwnerDrawHighlighter.java

License:Open Source License

private void markFocusedCell(Event event, ViewerCell cell) {
    Color background = (cell.getControl().isFocusControl()) ? getSelectedCellBackgroundColor(cell)
            : getSelectedCellBackgroundColorNoFocus(cell);
    Color foreground = (cell.getControl().isFocusControl()) ? getSelectedCellForegroundColor(cell)
            : getSelectedCellForegroundColorNoFocus(cell);

    if (foreground != null || background != null || onlyTextHighlighting(cell)) {
        GC gc = event.gc;//from w ww  .  j a  va2  s  .  c o m

        if (background == null) {
            background = cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
        }

        if (foreground == null) {
            foreground = cell.getItem().getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
        }

        gc.setBackground(background);
        gc.setForeground(foreground);

        if (onlyTextHighlighting(cell)) {
            Rectangle area = event.getBounds();
            Rectangle rect = cell.getTextBounds();
            if (rect != null) {
                area.x = rect.x;
            }
            gc.fillRectangle(area);
        } else {
            gc.fillRectangle(event.getBounds());
        }

        event.detail &= ~SWT.SELECTED;
    }
}