Exemple #1
0
  /** Creates the "Example" widgets. */
  void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (horizontalButton.getSelection()) style |= SWT.H_SCROLL;
    if (verticalButton.getSelection()) style |= SWT.V_SCROLL;
    if (borderButton.getSelection()) style |= SWT.BORDER;
    if (noBackgroundButton.getSelection()) style |= SWT.NO_BACKGROUND;
    if (noFocusButton.getSelection()) style |= SWT.NO_FOCUS;
    if (noMergePaintsButton.getSelection()) style |= SWT.NO_MERGE_PAINTS;
    if (noRedrawResizeButton.getSelection()) style |= SWT.NO_REDRAW_RESIZE;

    /* Create the example widgets */
    paintCount = 0;
    cx = 0;
    cy = 0;
    canvas = new Canvas(canvasGroup, style);
    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            paintCount++;
            GC gc = e.gc;
            if (fillDamageButton.getSelection()) {
              Color color = e.display.getSystemColor(colors[paintCount % colors.length]);
              gc.setBackground(color);
              gc.fillRectangle(e.x, e.y, e.width, e.height);
            }
            Point size = canvas.getSize();
            gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360);
            gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10);
          }
        });
    canvas.addControlListener(
        new ControlAdapter() {
          public void controlResized(ControlEvent event) {
            Point size = canvas.getSize();
            maxX = size.x * 3 / 2;
            maxY = size.y * 3 / 2;
            resizeScrollBars();
          }
        });
    ScrollBar bar = canvas.getHorizontalBar();
    if (bar != null) {
      bar.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              scrollHorizontal((ScrollBar) event.widget);
            }
          });
    }
    bar = canvas.getVerticalBar();
    if (bar != null) {
      bar.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              scrollVertical((ScrollBar) event.widget);
            }
          });
    }
  }
  /**
   * 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();
  }