Search in sources :

Example 1 with GestureListener

use of org.eclipse.swt.events.GestureListener 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);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) FontData(org.eclipse.swt.graphics.FontData) GestureListener(org.eclipse.swt.events.GestureListener) GestureEvent(org.eclipse.swt.events.GestureEvent) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)1 GestureEvent (org.eclipse.swt.events.GestureEvent)1 GestureListener (org.eclipse.swt.events.GestureListener)1 Font (org.eclipse.swt.graphics.Font)1 FontData (org.eclipse.swt.graphics.FontData)1 Point (org.eclipse.swt.graphics.Point)1