/*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.jface.fieldassist.IControlContentAdapter#setControlContents(org.eclipse
   * .swt.widgets.Control, java.lang.String, int)
   */
  @Override
  public void setControlContents(Control control, String term, int cursorPosition) {

    String text = ((StyledText) control).getText();

    final String after = text.substring(((StyledText) control).getCaretOffset(), text.length());
    text = text.substring(0, ((StyledText) control).getCaretOffset());

    // We just add the maximum ammount matched from the term
    for (int i = term.length(); i > 0; i--) {
      final String subterm = term.substring(0, i);
      if (text.endsWith(subterm)) {
        term = term.substring(i, term.length());
        break;
      }
    }

    final StringBuffer buf = new StringBuffer();
    buf.append(text);
    buf.append(term);
    final int len = buf.length();
    buf.append(after);
    ((StyledText) control).setText(buf.toString());
    ((StyledText) control).setCaretOffset(len);
  }
  /**
   * This method is used to set the cell editors text
   *
   * @param toEdit String to be set in the cell editor
   */
  public void setEditText(String toEdit) {

    // Get the cell editor
    CellEditor cellEditor = getCellEditor();

    // IF the cell editor doesn't exist yet...
    if (cellEditor == null) {
      // Do nothing
      return;
    }

    // Get the Text Compartment Edit Part
    IXtextAwareEditPart textEP = (IXtextAwareEditPart) getEditPart();

    // Get the Text control
    StyledText textControl = (StyledText) cellEditor.getControl();

    // Set the Figures text
    textEP.setLabelText(toEdit);

    // See RATLC00522324
    if (cellEditor instanceof TextCellEditorEx) {
      ((TextCellEditorEx) cellEditor).setValueAndProcessEditOccured(toEdit);
    } else {
      cellEditor.setValue(toEdit);
    }

    // Set the controls text and position the caret at the end of the text
    textControl.setSelection(toEdit.length());
  }
 public void focusOnLines(ILocation range) {
   if (range instanceof ILineLocation) {
     ILineLocation lineLocation = (ILineLocation) range;
     // editors count lines from 0, Crucible counts from 1
     final int startLine = lineLocation.getRangeMin() - 1;
     final int endLine = lineLocation.getRangeMax() - 1;
     if (sourceViewer != null) {
       IDocument document = sourceViewer.getDocument();
       if (document != null) {
         try {
           int offset = document.getLineOffset(startLine);
           int length = document.getLineOffset(endLine) - offset;
           StyledText widget = sourceViewer.getTextWidget();
           try {
             widget.setRedraw(false);
             // sourceViewer.revealRange(offset, length);
             // sourceViewer.setSelectedRange(offset, 0);
             sourceViewer.setSelection(new TextSelection(offset, length), true);
           } finally {
             widget.setRedraw(true);
           }
         } catch (BadLocationException e) {
           StatusHandler.log(
               new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, e.getMessage(), e));
         }
       }
     }
   }
 }
  /*
   * @see IPainter#paint(int)
   */
  public void paint(int reason) {
    if (fViewer == null) {
      return;
    }
    if (fViewer.getDocument() == null) {
      deactivate(false);
      return;
    }

    // initialization
    if (!fIsActive) {
      StyledText textWidget = fViewer.getTextWidget();
      textWidget.addLineBackgroundListener(this);
      textWidget.addPaintListener(this);
      fPositionManager.managePosition(fCurrentLine);
      fIsActive = true;
    }

    // This forces redraw of the line highlight
    if (updateHighlightLine()) {
      // clear last line
      // Fix the background colors for tokens that didn't have the same as line!
      if (isOpaque() && !fLastLine.isDeleted() && fViewer instanceof ITextViewerExtension2) {
        ITextViewerExtension2 ext = (ITextViewerExtension2) fViewer;
        try {
          ext.invalidateTextPresentation(fLastLine.getOffset(), fLastLine.getLength());
        } catch (Exception e) {
          IdeLog.logError(CommonEditorPlugin.getDefault(), e);
        }
      }
      drawHighlightLine(fLastLine);
      // draw new line
      drawHighlightLine(fCurrentLine);
    }
  }
 public void resetLineBackground() {
   StyledText t = getSourceViewer().getTextWidget();
   if (t != null && !t.isDisposed()) {
     int lines = getLineCount();
     t.setLineBackground(0, lines, null);
   }
 }
 /*
  * @see AbstractInfoView#setInput(Object)
  */
 protected void setInput(Object input) {
   String javadocHtml = (String) input;
   if (fIsUsingBrowserWidget) {
     if (javadocHtml != null && javadocHtml.length() > 0) {
       boolean RTL = (getSite().getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0;
       if (RTL) {
         StringBuffer buffer = new StringBuffer(javadocHtml);
         HTMLPrinter.insertStyles(buffer, new String[] {"direction:rtl"}); // $NON-NLS-1$
         javadocHtml = buffer.toString();
       }
     }
     fBrowser.setText(javadocHtml);
   } else {
     fPresentation.clear();
     Rectangle size = fText.getClientArea();
     try {
       javadocHtml =
           ((DefaultInformationControl.IInformationPresenterExtension) fPresenter)
               .updatePresentation(
                   getSite().getShell(), javadocHtml, fPresentation, size.width, size.height);
     } catch (IllegalArgumentException ex) {
       // the javadoc might no longer be valid
       return;
     }
     fText.setText(javadocHtml);
     TextPresentation.applyTextPresentation(fPresentation, fText);
   }
 }
Example #7
0
 private void addListeners(bento.language.bentocomp.resource.bento.ui.BentoEditor editor) {
   UpdateHighlightingListener hl = new UpdateHighlightingListener();
   textWidget.addKeyListener(hl);
   textWidget.addVerifyListener(hl);
   textWidget.addMouseListener(hl);
   editor.addBackgroundParsingListener(hl);
 }
Example #8
0
  private void updateSizeAndLocations() {
    if (busyLabel == null || busyLabel.isDisposed()) {
      return;
    }

    Point leftToolBarSize = new Point(0, 0);
    if (leftToolBar != null && !leftToolBar.isDisposed()) {
      // bottom align tool bar in title region
      leftToolBarSize = leftToolBar.getSize();
      int y = leftToolBar.getParent().getSize().y - leftToolBarSize.y - 2;
      if (!hasLeftToolBar()) {
        // hide tool bar to avoid overlaying busyLabel on windows
        leftToolBarSize.x = 0;
      }
      leftToolBar.setBounds(busyLabel.getLocation().x, y, leftToolBarSize.x, leftToolBarSize.y);
    }
    if (titleLabel != null && !titleLabel.isDisposed()) {
      // center align title text in title region
      Point size = titleLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
      int y = (titleLabel.getParent().getSize().y - size.y) / 2;
      titleLabel.setBounds(
          busyLabel.getLocation().x + LEFT_TOOLBAR_HEADER_TOOLBAR_PADDING + leftToolBarSize.x,
          y,
          size.x,
          size.y);
    }
  }
Example #9
0
  public void initLogControl(StyledText log) {
    log.setFont(iniAppearance.getFontLog());
    log.setBackground(iniAppearance.getColorLogBackground());
    log.setForeground(iniAppearance.getColorLogBackground());

    logControls.add(log);
  }
  void executeCommand(String cmdLine) {
    clearStatus();

    IOSGiFrameworkConsole console =
        (IOSGiFrameworkConsole)
            getServer().getOriginal().loadAdapter(IOSGiFrameworkConsole.class, null);

    if (console == null) {
      IStatus status =
          EditorUIPlugin.newErrorStatus("Console editor part is not integrated with the runtime.");
      EditorUIPlugin.log(status);
      setStatus(status);
      return;
    }

    try {
      String result = console.executeCommand(cmdLine);
      manifestText.append("osgi> " + cmdLine + "\n");
      manifestText.append(result + "\n");
      forwardAction.setEnabled(history.canForward());
      backAction.setEnabled(history.canBack());
      toolBarManager.update(true);
      manifestText.setTopIndex(manifestText.getLineCount() - 1);
    } catch (CoreException e) {
      EditorUIPlugin.log(e);
      setStatus(
          EditorUIPlugin.newErrorStatus("Failed to execute command. See Error Log for details."));
    }

    commandText.setText("");
  }
  /**
   * 当文本处于正在编辑时,实时进行拼写检查,<div style='color:red'>该方法与{@link #tgtTextFirstRealTimeSpellCheck} 类似</div>
   */
  private static void tgtTextRealTimeSpellCheck(
      final String tgtLang, final HsMultiCellEditor targetEditor) {
    final StyledTextCellEditor tgtEditor = targetEditor.getCellEditor();
    final StyledText text = tgtEditor.getSegmentViewer().getTextWidget();
    if (tgtLang == null) {
      return;
    }
    text.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            String tgtText = text.getText();

            if (tgtText.isEmpty()) {
              return;
            }

            String endStr = tgtText.substring(tgtText.length() - 1, tgtText.length());
            if (endStr.matches(ENDREGEX)) {
              List<SingleWord> errorWordList = new LinkedList<SingleWord>();
              errorWordList = spellTrigger.getErrorWords(tgtText, tgtLang);
              if (errorWordList != null && errorWordList.size() > 0) {
                targetEditor.highLightedErrorWord(tgtText, errorWordList);
              } else {
                targetEditor.refreshErrorWordsStyle(null);
              }
            }
          }
        });
  }
  @Override
  protected Control createContents(Composite p) {
    Composite parent = (Composite) super.createContents(p);

    Label scriptLabel = new Label(parent, SWT.NONE);
    String headerMessages = getHeaderMessages();
    scriptLabel.setText(headerMessages);
    // FIXME, If the message can't be displayed complectly. try to set the tool tip
    if (headerMessages.length() > 50) { // simply first, just set the length greater than 50
      scriptLabel.setToolTipText(headerMessages);
    }

    int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL;
    if (isReadonly()) {
      style |= SWT.READ_ONLY;
    }
    scriptTxt = new StyledText(parent, style);
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 280;
    layoutData.minimumHeight = 280;
    layoutData.widthHint = 500;
    layoutData.minimumWidth = 500;
    scriptTxt.setLayoutData(layoutData);
    scriptTxt.setText(getScriptContent());

    return parent;
  }
 /**
  * Sets the visibility of the ascii text.
  *
  * @param visible the visibility of the ascii text
  * @see #getAsciiVisible()
  */
 public void setAsciiVisible(boolean visible) {
   ((GridData) asciiText.getLayoutData()).exclude = !visible;
   asciiText.setVisible(visible);
   ((GridLayout) composite.getLayout()).makeColumnsEqualWidth =
       visible && brailleText.getVisible();
   composite.layout();
 }
 /**
  * Creates a new instance of this class. Automatically starts listening to corresponding key and
  * modify events coming from the given <var>editor</var>.
  *
  * @param editor the text field to which the Undo-Redo functionality should be added
  */
 public UndoRedoStyledText(StyledText editor) {
   editor.addExtendedModifyListener(this);
   editor.addKeyListener(this);
   onMac = System.getProperty("os.name").startsWith("Mac OS X");
   this.editor = editor;
   stack = new UndoRedoStack<ExtendedModifyEvent>();
 }
Example #15
0
 /**
  * Hook to compute the menu location if the focus widget is a styled text widget.
  *
  * @param text the styled text widget that has the focus
  * @return a widget relative position of the menu to pop up or <code>null</code> if now position
  *     inside the widget can be computed
  */
 protected Point computeMenuLocation(StyledText text) {
   int offset = text.getCaretOffset();
   Point result = text.getLocationAtOffset(offset);
   result.y += text.getLineHeight(offset);
   if (!text.getClientArea().contains(result)) return null;
   return result;
 }
Example #16
0
  public void applyFont(FontType type, FontData data) {
    Font newFont = new Font(SwtUtils.DISPLAY, data);
    Font oldFont = null;

    switch (type) {
      case GLOBAL:
        {
          oldFont = iniAppearance.getFontGlobal();

          for (Control control : controls) {
            if (control.isDisposed()) continue;

            control.setFont(newFont);
          }

          for (Label label : labels) {
            if (label.isDisposed()) continue;

            label.setFont(newFont);
          }

          for (Button button : buttons) {
            if (button.isDisposed()) continue;

            button.setFont(newFont);
          }

          iniAppearance.setFontGlobal(newFont);
          break;
        }
      case LOG:
        {
          oldFont = iniAppearance.getFontLog();

          for (StyledText control : logControls) {
            if (control.isDisposed()) continue;

            control.setFont(newFont);
          }

          iniAppearance.setFontLog(newFont);
          break;
        }
      case CHAT:
        {
          oldFont = iniAppearance.getFontChat();

          for (Text control : chatControls) {
            if (control.isDisposed()) continue;

            control.setFont(newFont);
          }

          iniAppearance.setFontChat(newFont);
          break;
        }
    }

    if (oldFont != null) oldFont.dispose();
  }
Example #17
0
 protected void refreshCaret(StyledText text, int newOffset) {
   if (newOffset != -1) {
     Point newPos = text.getLocationAtOffset(newOffset);
     int newHeight = text.getLineHeight(newOffset);
     text.redraw(newPos.x, newPos.y, CARET_WIDTH, newHeight, false);
   }
 }
Example #18
0
  /**
   * triggers a repaint of the styled text of the containing editor whenever the text has changed.
   *
   * <p>The repaint will update the positions of all of the embedded controls.
   *
   * <p>XXX this method is being called too many times. It is being called more than once after each
   * cursor change. I need to take a good look at this and determine exactly when and where it
   * should be called
   */
  public void paint(int reason) {
    if (reason != TEXT_CHANGE && reason != ContainingEditor.EMBEDDED_REPAINT) {
      return;
    }
    List<ContainedEditorManager> toRemove = new LinkedList<ContainedEditorManager>();

    for (final ContainedEditorManager c : editorPositionMap.keySet()) {
      Position model = editorPositionMap.get(c);
      if (!model.isDeleted()) {
        // map from the model to the actual display (takes into account folding)
        Position projected = modelToProjected(model);
        if (projected == null) {
          // position is hidden behind folding
          c.getControl().setVisible(false);
        } else {
          try {
            Point location = styledText.getLocationAtOffset(projected.offset);
            location.x += ContainingEditor.MARGIN;
            location.y += ContainingEditor.MARGIN;
            c.getControl().setVisible(true);
            c.getControl().setLocation(location);
          } catch (IllegalArgumentException e) {
            EmbeddedCALPlugin.logError("Error repainting", e);
          }
        }
      } else {
        toRemove.add(c);
      }
    }
    for (final ContainedEditorManager c : toRemove) {
      removeControl(c, true);
    }
    styledText.getParent().getParent().redraw();
  }
Example #19
0
 /**
  * Eclipse hack. Disables/enabled all key bindings in specified site's part. Works only if host
  * editor is extender of AbstractTextEditor Uses reflection because setActionActivation is private
  * method TODO: find better way to disable key bindings or prioritize event handling to widgets
  *
  * @param partSite workbench part site
  * @param enable enable or disable
  */
 @Deprecated
 public static void enableHostEditorKeyBindings(IWorkbenchPartSite partSite, boolean enable) {
   IWorkbenchPart part = partSite.getPart();
   if (part instanceof AbstractTextEditor) {
     AbstractTextEditor hostEditor = (AbstractTextEditor) part;
     if (hostEditor instanceof BaseTextEditor) {
       StyledText textWidget = ((BaseTextEditor) hostEditor).getTextViewer().getTextWidget();
       if (textWidget == null || textWidget.isDisposed()) {
         return;
       }
     }
     try {
       Method activatorMethod =
           AbstractTextEditor.class.getDeclaredMethod("setActionActivation", Boolean.TYPE);
       activatorMethod.setAccessible(true);
       activatorMethod.invoke(hostEditor, enable);
     } catch (Throwable e) {
       if (e instanceof InvocationTargetException) {
         e = ((InvocationTargetException) e).getTargetException();
       }
       log.warn("Can't disable text editor action activations", e);
     }
     // hostEditor.getEditorSite().getActionBarContributor().setActiveEditor(hostEditor);
   }
 }
 @Override
 public void setMode(CommandLineMode mode) {
   if (mode == CommandLineMode.DEFAULT) {
     commandLineText.setEditable(true);
     if (registerModeSelection != null) {
       commandLineText.replaceTextRange(registerModeSelection.x, 1, "");
       commandLineText.setSelection(registerModeSelection);
       registerModeSelection = null;
     } else {
       // Reset any selection made in a readonly mode, otherwise we need to check if
       // cut/copy needs to be enabled.
       commandLineText.setSelection(commandLineText.getCaretOffset());
     }
     readOnly = false;
   } else if (mode == CommandLineMode.REGISTER) {
     if (registerModeSelection == null) {
       Point sel = commandLineText.getSelection();
       int leftOffset = Math.min(sel.x, sel.y);
       commandLineText.replaceTextRange(leftOffset, 0, "\"");
       registerModeSelection = sel;
       readOnly = true;
     }
   } else if (mode == CommandLineMode.MESSAGE || mode == CommandLineMode.MESSAGE_CLIPPED) {
     commandLineText.setEditable(false);
     setPosition(0);
     commandLineText.setTopIndex(0);
     readOnly = true;
     pasteItem.setEnabled(false);
     commandLineText.setWordWrap(mode == CommandLineMode.MESSAGE);
   }
 }
  /**
   * Creates a style range for the text viewer.
   *
   * @param viewer the text viewer
   * @return the new style range for the text viewer or <code>null</code>
   */
  private StyleRange createStyleRange(ITextViewer viewer) {
    StyledText text = viewer.getTextWidget();
    if (text == null || text.isDisposed()) {
      return null;
    }

    int widgetCaret = text.getCaretOffset();

    int modelCaret = 0;
    if (viewer instanceof ITextViewerExtension5) {
      ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
      modelCaret = extension.widgetOffset2ModelOffset(widgetCaret);
    } else {
      IRegion visibleRegion = viewer.getVisibleRegion();
      modelCaret = widgetCaret + visibleRegion.getOffset();
    }

    if (modelCaret >= getReplacementOffset() + getReplacementLength()) {
      return null;
    }

    int length = getReplacementOffset() + getReplacementLength() - modelCaret;

    Color foreground = getForegroundColor();
    Color background = getBackgroundColor();

    return new StyleRange(modelCaret, length, foreground, background);
  }
 protected void updateCaret() {
   if (commandLineText.getCaretOffset() == commandLineText.getCharCount()) {
     commandLineText.setCaret(endCharCaret);
   } else {
     commandLineText.setCaret(defaultCaret);
   }
 }
  public MergeSourceViewer(
      SourceViewer sourceViewer, ResourceBundle bundle, ICompareContainer container) {
    Assert.isNotNull(sourceViewer);
    fSourceViewer = sourceViewer;
    fResourceBundle = bundle;
    fContainer = container;

    MenuManager menu = new MenuManager();
    menu.setRemoveAllWhenShown(true);
    menu.addMenuListener(this);
    StyledText te = getSourceViewer().getTextWidget();
    te.setMenu(menu.createContextMenu(te));
    fContainer.registerContextMenu(menu, getSourceViewer());

    // for listening to editor show/hide line number preference value
    fPreferenceChangeListener =
        new IPropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            MergeSourceViewer.this.handlePropertyChangeEvent(event);
          }
        };
    EditorsUI.getPreferenceStore().addPropertyChangeListener(fPreferenceChangeListener);
    fShowLineNumber =
        EditorsUI.getPreferenceStore()
            .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
    if (fShowLineNumber) {
      updateLineNumberRuler();
    }

    IOperationHistory history = getHistory();
    if (history != null) history.addOperationHistoryListener(this);

    // don't add save when in a dialog, IWorkbenchPart is null in dialog containers
    fAddSaveAction = fContainer.getWorkbenchPart() != null;
  }
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setText("StyledText with underline and strike through");
   shell.setLayout(new FillLayout());
   StyledText text = new StyledText(shell, SWT.BORDER);
   text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
   // make 0123456789 appear underlined
   StyleRange style1 = new StyleRange();
   style1.start = 0;
   style1.length = 10;
   style1.underline = true;
   text.setStyleRange(style1);
   // make ABCDEFGHIJKLM have a strike through
   StyleRange style2 = new StyleRange();
   style2.start = 11;
   style2.length = 13;
   style2.strikeout = true;
   text.setStyleRange(style2);
   // make NOPQRSTUVWXYZ appear underlined and have a strike through
   StyleRange style3 = new StyleRange();
   style3.start = 25;
   style3.length = 13;
   style3.underline = true;
   style3.strikeout = true;
   text.setStyleRange(style3);
   shell.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
  protected void initCellEditor() {
    committed = false;

    // Get the Text Compartments Edit Part

    setEditText(getEditPart().getEditText());

    IFigure label = getEditPart().getFigure();
    Assert.isNotNull(label);
    StyledText text = (StyledText) getCellEditor().getControl();
    // scale the font accordingly to the zoom level
    text.setFont(getScaledFont(label));

    // Hook the cell editor's copy/paste actions to the actionBars so that
    // they can
    // be invoked via keyboard shortcuts.
    actionBars =
        PlatformUI.getWorkbench()
            .getActiveWorkbenchWindow()
            .getActivePage()
            .getActiveEditor()
            .getEditorSite()
            .getActionBars();
    saveCurrentActions(actionBars);
    actionHandler = new CellEditorActionHandler(actionBars);
    actionHandler.addCellEditor(getCellEditor());
    actionBars.updateActionBars();
  }
 public static void main(String[] args) {
   final Display display = new Display();
   final Shell shell = new Shell(display);
   shell.setLayout(new FillLayout());
   final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
   styledText.setText(text);
   FontData data = display.getSystemFont().getFontData()[0];
   Font font = new Font(display, data.getName(), 16, SWT.BOLD);
   styledText.setFont(font);
   styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
   styledText.addListener(
       SWT.Resize,
       new Listener() {
         public void handleEvent(Event event) {
           Rectangle rect = styledText.getClientArea();
           Image newImage = new Image(display, 1, Math.max(1, rect.height));
           GC gc = new GC(newImage);
           gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
           gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
           gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true);
           gc.dispose();
           styledText.setBackgroundImage(newImage);
           if (oldImage != null) oldImage.dispose();
           oldImage = newImage;
         }
       });
   shell.setSize(700, 400);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   if (oldImage != null) oldImage.dispose();
   font.dispose();
   display.dispose();
 }
 @Override
 public void setForegroundColor(final Color foreground) {
   super.setForegroundColor(foreground);
   fContentComposite.setForeground(foreground);
   fTitleText.setForeground(foreground);
   fInfoText.setForeground(foreground);
 }
Example #28
0
 private Point computeMenuLocation(Control focus, Menu menu) {
   Point cursorLocation = focus.getDisplay().getCursorLocation();
   Rectangle clientArea = null;
   Point result = null;
   if (focus instanceof StyledText) {
     StyledText styledText = (StyledText) focus;
     clientArea = styledText.getClientArea();
     result = computeMenuLocation(styledText);
   } else if (focus instanceof Tree) {
     Tree tree = (Tree) focus;
     clientArea = tree.getClientArea();
     result = computeMenuLocation(tree);
   } else if (focus instanceof Table) {
     Table table = (Table) focus;
     clientArea = table.getClientArea();
     result = computeMenuLocation(table);
   }
   if (result == null) {
     result = focus.toControl(cursorLocation);
   }
   if (clientArea != null && !clientArea.contains(result)) {
     result = new Point(clientArea.x + clientArea.width / 2, clientArea.y + clientArea.height / 2);
   }
   Rectangle shellArea = focus.getShell().getClientArea();
   if (!shellArea.contains(focus.getShell().toControl(focus.toDisplay(result)))) {
     result = new Point(shellArea.x + shellArea.width / 2, shellArea.y + shellArea.height / 2);
   }
   return focus.toDisplay(result);
 }
 private void createHighlighting(Class<SourceViewer> sourceViewerClazz)
     throws IllegalArgumentException, IllegalAccessException, SecurityException,
         NoSuchFieldException {
   // TODO this could use some performance tweaks
   final StyledText styledText = sourceViewer.getTextWidget();
   styledText.addLineBackgroundListener(new ColoringLineBackgroundListener(styledText));
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.jface.fieldassist.IControlContentAdapter#insertControlContents(org.eclipse
  * .swt.widgets.Control, java.lang.String, int)
  */
 @Override
 public void insertControlContents(Control control, String contents, int cursorPosition) {
   StyledText text = ((StyledText) control);
   text.insert(contents);
   cursorPosition = Math.min(cursorPosition, contents.length());
   text.setCaretOffset(text.getCaretOffset() + cursorPosition);
 }