use of org.eclipse.swt.events.GestureEvent in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method initializeZoomGestures.
private void initializeZoomGestures(Control rulerControl, final ISourceViewer sourceViewer) {
final StyledText styledText = sourceViewer.getTextWidget();
GestureListener gestureListener = new GestureListener() {
private Font fMagnificationStartFont;
private int fLastHeight = -1;
@Override
public void gesture(GestureEvent e) {
if (e.detail == SWT.GESTURE_BEGIN) {
fMagnificationStartFont = styledText.getFont();
} else if (e.detail == SWT.GESTURE_END) {
fMagnificationStartFont = null;
updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION);
} else if (e.detail == SWT.GESTURE_ROTATE) {
if (Math.abs(e.rotation) > 45) {
// don't observe magnify events after reset
fMagnificationStartFont = null;
initializeViewerFont(fSourceViewer);
updateCaret();
IStatusField statusField = getStatusField(ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION);
if (statusField != null) {
int newHeight = styledText.getFont().getFontData()[0].getHeight();
statusField.setText(NLSUtility.format(EditorMessages.Editor_font_reset_message, Integer.valueOf(newHeight)));
}
}
} else if (e.detail == SWT.GESTURE_MAGNIFY && fMagnificationStartFont != null) {
FontData fontData = fMagnificationStartFont.getFontData()[0];
int startHeight = fontData.getHeight();
int newHeight = Math.max(1, (int) (startHeight * e.magnification));
if (newHeight != fLastHeight) {
fLastHeight = newHeight;
fontData.setHeight(newHeight);
Font newFont = new Font(fMagnificationStartFont.getDevice(), fontData);
setFont(sourceViewer, newFont);
disposeFont();
updateCaret();
IStatusField statusField = getStatusField(ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION);
if (statusField != null) {
statusField.setText(NLSUtility.format(EditorMessages.Editor_font_zoom_message, new Object[] { Integer.valueOf(startHeight), Integer.valueOf(newHeight) }));
}
}
}
}
};
styledText.addGestureListener(gestureListener);
rulerControl.addGestureListener(gestureListener);
}
Aggregations