Search in sources :

Example 1 with ITextualFigure

use of org.whole.lang.ui.figures.ITextualFigure in project whole by wholeplatform.

the class CaretUtils method getAbsoluteCaretBounds.

// end of multiline positioning methods
// FIXME alternative methods  added for backward compatibility
public static org.eclipse.draw2d.geometry.Rectangle getAbsoluteCaretBounds(IEntityPartViewer viewer, ITextualEntityPart targetPart) {
    ITextualFigure textualFigure = targetPart.getTextualFigure();
    Viewport viewport = ((FigureCanvas) viewer.getControl()).getViewport();
    org.eclipse.draw2d.geometry.Rectangle caretBounds = textualFigure.getCaretBounds().getCopy();
    viewport.getContents().translateToRelative(caretBounds);
    return caretBounds;
}
Also used : FigureCanvas(org.eclipse.draw2d.FigureCanvas) Viewport(org.eclipse.draw2d.Viewport) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure)

Example 2 with ITextualFigure

use of org.whole.lang.ui.figures.ITextualFigure in project whole by wholeplatform.

the class E4NavigationKeyHandler method navigateNextSibling.

/**
 * Traverses to the closest EditPart in the given list that is also in the given direction.
 *
 * @param	event		the KeyEvent for the keys that were pressed to trigger this traversal
 * @param	direction	PositionConstants.* indicating the direction in which to traverse
 */
boolean navigateNextSibling(KeyEvent event, int direction, List<?> list) {
    IEntityPart epStart = getFocusEntityPart();
    if (epStart instanceof ITextualEntityPart) {
        ITextualEntityPart textualEntityPart = (ITextualEntityPart) epStart;
        ITextualFigure textualFigure = textualEntityPart.getTextualFigure();
        String text = textualFigure.getText();
        int line = CaretUtils.getLineFromPosition(text, textualEntityPart.getCaretPosition());
        int lines = CaretUtils.getCaretLines(text);
        if ((direction == PositionConstants.WEST && textualEntityPart.getCaretPosition() > 0) || (direction == PositionConstants.EAST && textualEntityPart.getCaretPosition() < textualEntityPart.getCaretPositions())) {
            int position = textualEntityPart.getCaretPosition() + (direction == PositionConstants.WEST ? -1 : 1);
            CaretUpdater.sheduleSyncUpdate(getViewer(), textualEntityPart.getModelEntity(), position, true);
            return true;
        } else if ((direction == PositionConstants.NORTH && line > 0) || (direction == PositionConstants.SOUTH && line < lines)) {
            int dy = FigureUtilities.getFontMetrics(textualFigure.getFont()).getHeight() * (direction == PositionConstants.NORTH ? -1 : 1);
            Point location = textualFigure.getCaretBounds().getCenter().translate(0, dy);
            CaretUpdater.sheduleSyncUpdate(getViewer(), textualEntityPart.getModelEntity(), location, true);
            textualEntityPart.updateCaret(location);
            return true;
        }
    }
    if (!(epStart instanceof IGraphicalEntityPart))
        return false;
    IFigure figure = ((IGraphicalEntityPart) epStart).getFigure();
    Point pStart = getNavigationPoint(figure);
    figure.translateToAbsolute(pStart);
    // parent.findSibling(pStart, direction, epStart);
    EditPart next = findSibling(list, pStart, direction, epStart);
    while (next == null) {
        if (!(epStart.getParent() instanceof IGraphicalEntityPart))
            return false;
        epStart = (IGraphicalEntityPart) epStart.getParent();
        if (epStart == getViewer().getContents() || epStart.getParent() == getViewer().getContents() || epStart.getParent() == null)
            return false;
        list = epStart.getParent().getChildren();
        next = findSibling(list, pStart, direction, epStart);
    }
    // next = next.enter(pStart, direction, epStart);1+2
    navigateTo(next, event);
    return true;
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IGraphicalEntityPart(org.whole.lang.ui.editparts.IGraphicalEntityPart) ConnectionEditPart(org.eclipse.gef.ConnectionEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure) IEntityPart(org.whole.lang.ui.editparts.IEntityPart) Point(org.eclipse.draw2d.geometry.Point) EditPoint(org.whole.lang.ui.tools.EditPoint) IFigure(org.eclipse.draw2d.IFigure)

Example 3 with ITextualFigure

use of org.whole.lang.ui.figures.ITextualFigure in project whole by wholeplatform.

the class TextualHilightEditPolicy method moveCaretVertically.

public boolean moveCaretVertically(int lines) {
    ITextualEntityPart textualHost = getTextualHost();
    if (!textualHost.hasFocus())
        return false;
    ITextualFigure textualFigure = textualHost.getTextualFigure();
    int position = textualHost.getCaretPosition();
    int newLine = textualFigure.getLineFromPosition(position) + lines;
    if (newLine < 0 || newLine >= textualFigure.getCaretLines())
        return false;
    int dy = lines / Math.abs(lines);
    Rectangle translatedCaret = textualFigure.getCaretBounds().getCopy().translate(0, dy);
    Point newLocation = dy > 0 ? translatedCaret.getBottomLeft() : translatedCaret.getTopLeft();
    CaretUpdater.sheduleSyncUpdate(textualHost.getViewer(), textualHost.getModelEntity(), newLocation, true);
    return true;
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure) Point(org.eclipse.draw2d.geometry.Point)

Example 4 with ITextualFigure

use of org.whole.lang.ui.figures.ITextualFigure in project whole by wholeplatform.

the class CaretUtils method calculateCaretPosition.

public static int calculateCaretPosition(ITextualEntityPart targetPart, int horizontalLocation) {
    ITextualFigure textualFigure = targetPart.getTextualFigure();
    Point.SINGLETON.x = horizontalLocation;
    textualFigure.translateToRelative(Point.SINGLETON);
    horizontalLocation = Point.SINGLETON.x;
    Label label = textualFigure.getEmbeddedLabel();
    String text = textualFigure.getText();
    Font font = textualFigure.getEmbeddedLabelFont();
    int availableWidth = horizontalLocation - textualFigure.getTextBounds().x;
    int length = label.getTextUtilities().getLargestSubstringConfinedTo(text, font, availableWidth + 3);
    return CaretUtils.getStartingLinePosition(text, getCaretLines(text) - 1) + length;
}
Also used : Label(org.eclipse.draw2d.Label) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.draw2d.geometry.Point)

Example 5 with ITextualFigure

use of org.whole.lang.ui.figures.ITextualFigure in project whole by wholeplatform.

the class TextualDragTracker method handleDragInProgress.

@Override
protected boolean handleDragInProgress() {
    EditPartViewer viewer = getCurrentViewer();
    ITextualEntityPart textualEntityPart = getTextualEntityPart();
    if (textualEntityPart == null)
        return false;
    EditPart overPart = viewer.findObjectAt(getLocation());
    if (overPart == endPart) {
        end = textualEntityPart.getCaretPosition();
        if (start <= end)
            performSelectionUpdate(new SelectionRange(textualEntityPart, start, end), false);
        else {
            performSelectionUpdate(new SelectionRange(textualEntityPart, end, start), false);
        }
    } else {
        ITextualFigure textualFigure = textualEntityPart.getTextualFigure();
        Rectangle textBounds = textualFigure.getTextBounds();
        textualFigure.translateToAbsolute(textBounds);
        Point mouseLocation = getLocation();
        mouseLocation.x = Math.max(mouseLocation.x, textBounds.x);
        mouseLocation.x = Math.min(mouseLocation.x, textBounds.right() - 1);
        mouseLocation.y = Math.max(mouseLocation.y, textBounds.y);
        mouseLocation.y = Math.min(mouseLocation.y, textBounds.bottom() - 1);
        textualEntityPart.updateCaret(mouseLocation);
        end = textualEntityPart.getCaretPosition();
        if (start <= end)
            performSelectionUpdate(new SelectionRange(textualEntityPart, start, end), mouseLocation, false);
        else {
            performSelectionUpdate(new SelectionRange(textualEntityPart, end, start), mouseLocation, false);
        }
    }
    return super.handleDragInProgress();
}
Also used : ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) EditPart(org.eclipse.gef.EditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) EditPartViewer(org.eclipse.gef.EditPartViewer) Point(org.eclipse.draw2d.geometry.Point) ITextualFigure(org.whole.lang.ui.figures.ITextualFigure)

Aggregations

ITextualFigure (org.whole.lang.ui.figures.ITextualFigure)5 Point (org.eclipse.draw2d.geometry.Point)4 ITextualEntityPart (org.whole.lang.ui.editparts.ITextualEntityPart)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 EditPart (org.eclipse.gef.EditPart)2 FigureCanvas (org.eclipse.draw2d.FigureCanvas)1 IFigure (org.eclipse.draw2d.IFigure)1 Label (org.eclipse.draw2d.Label)1 Viewport (org.eclipse.draw2d.Viewport)1 ConnectionEditPart (org.eclipse.gef.ConnectionEditPart)1 EditPartViewer (org.eclipse.gef.EditPartViewer)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 Font (org.eclipse.swt.graphics.Font)1 IEntityPart (org.whole.lang.ui.editparts.IEntityPart)1 IGraphicalEntityPart (org.whole.lang.ui.editparts.IGraphicalEntityPart)1 EditPoint (org.whole.lang.ui.tools.EditPoint)1