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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations