Ejemplo n.º 1
0
  /**
   * Installs this highlighter into the specified StyledText object. Client can manually call
   * detach() method, then wants to destroy this object.
   */
  public void attach(StyledText parent) {
    detach();

    text = parent;
    text.addDisposeListener(ml);
    text.addLineStyleListener(ml);
    text.addLineBackgroundListener(ml);
    text.addPaintListener(ml);
    text.addVerifyListener(ml);
    text.addExtendedModifyListener(ml);
    text.addControlListener(ml);
    text.addKeyListener(ml);
    text.addTraverseListener(ml);
    text.addMouseListener(ml);
    text.addSelectionListener(ml);
    text.getContent().addTextChangeListener(ml);
    ScrollBar sb = text.getVerticalBar();
    if (sb != null) sb.addSelectionListener(ml);
    updateViewport();

    new Thread() {
      public void run() {
        // setPriority(Thread.NORM_PRIORITY-1);
        while (true) {
          try {
            sleep(300);
          } catch (InterruptedException e) {
          }
          if (baseEditor == null || text == null) break;
          if (backParserDelay) {
            backParserDelay = false;
            try {
              sleep(1500);
            } catch (InterruptedException e) {
            }
            continue;
          }
          ;
          Display.getDefault()
              .syncExec(
                  new Runnable() {
                    public void run() {
                      if (baseEditor == null || text == null) return;
                      if (text.isDisposed()) return;
                      // System.out.println(System.currentTimeMillis());
                      baseEditor.idleJob(80);
                      // redrawFrom(text.getLineAtOffset(text.getCaretOffset()));
                    }
                  });
        }
        ;
      };
    }.start();
  }
Ejemplo n.º 2
0
 /**
  * Removes this object from the corresponding StyledText widget. Object can't be used after this
  * call, until another attach. This method is called automatically, when StyledText widget is
  * disposed
  */
 public void detach() {
   if (text == null) return;
   text.removeDisposeListener(ml);
   text.removeLineStyleListener(ml);
   text.removeLineBackgroundListener(ml);
   text.removePaintListener(ml);
   text.removeVerifyListener(ml);
   text.removeExtendedModifyListener(ml);
   text.removeControlListener(ml);
   text.removeKeyListener(ml);
   text.removeTraverseListener(ml);
   text.removeMouseListener(ml);
   text.removeSelectionListener(ml);
   ScrollBar sb = text.getVerticalBar();
   if (sb != null) sb.removeSelectionListener(ml);
   baseEditor = null;
 }