public BulletsState(final StyledText inWidget) {
   inWidget.getLineCount();
   for (int i = 0; i < inWidget.getLineCount(); i++) {
     final Bullet lBullet = inWidget.getLineBullet(i);
     if (lBullet != null) {
       bullets.add(new LineBulletState(i, lBullet.type, lBullet.style.metrics.width));
     }
   }
 }
 void drawLine(int lno) {
   if (lno < 0 || lno >= text.getLineCount()) return;
   int y = text.getLocationAtOffset(text.getOffsetAtLine(lno)).y;
   int height = 0;
   if (text.getLineCount() > lno + 1)
     height = text.getLocationAtOffset(text.getOffsetAtLine(lno + 1)).y - y;
   else height = text.getLocationAtOffset(text.getCharCount()).y + text.getLineHeight();
   int width = text.getClientArea().width + text.getHorizontalPixel();
   text.redraw(0, y, width, height, false);
 }
 void pairsDraw(GC gc, PairMatch pm) {
   if (pm == null) return;
   if (pm.start != null) {
     if (pm.sline >= text.getLineCount()) return;
     int lineOffset = text.getOffsetAtLine(pm.sline);
     pairDraw(
         gc, (StyledRegion) pm.start.rdef, pm.start.start + lineOffset, pm.start.end + lineOffset);
   }
   if (pm.end != null) {
     if (pm.eline >= text.getLineCount()) return;
     int lineOffset = text.getOffsetAtLine(pm.eline);
     pairDraw(gc, (StyledRegion) pm.end.rdef, pm.end.start + lineOffset, pm.end.end + lineOffset);
   }
 }
 void redrawFrom(int lno) {
   if (lno < 0 || lno >= text.getLineCount()) return;
   int y = text.getLocationAtOffset(text.getOffsetAtLine(lno)).y;
   int height = text.getClientArea().height - y;
   int width = text.getClientArea().width + text.getHorizontalPixel();
   text.redraw(0, y, width, height, false);
 }
  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("");
  }
 /**
  * Draw the given line range.
  *
  * @param gc
  * @param startLine first line number
  * @param endLine last line number (inclusive)
  * @param x the X-coordinate of the drawing range
  * @param w the width of the drawing range
  */
 private void drawLineRange(GC gc, int startLine, int endLine, int x, int w) {
   final int viewPortWidth = fTextWidget.getClientArea().width;
   for (int line = startLine; line <= endLine; line++) {
     int lineOffset = fTextWidget.getOffsetAtLine(line);
     // line end offset including line delimiter
     int lineEndOffset;
     if (line < fTextWidget.getLineCount() - 1) {
       lineEndOffset = fTextWidget.getOffsetAtLine(line + 1);
     } else {
       lineEndOffset = fTextWidget.getCharCount();
     }
     // line length excluding line delimiter
     int lineLength = lineEndOffset - lineOffset;
     while (lineLength > 0) {
       char c = fTextWidget.getTextRange(lineOffset + lineLength - 1, 1).charAt(0);
       if (c != '\r' && c != '\n') {
         break;
       }
       --lineLength;
     }
     // compute coordinates of last character on line
     Point endOfLine = fTextWidget.getLocationAtOffset(lineOffset + lineLength);
     if (x - endOfLine.x > viewPortWidth) {
       // line is not visible
       continue;
     }
     // Y-coordinate of line
     int y = fTextWidget.getLinePixel(line);
     // compute first visible char offset
     int startOffset;
     try {
       startOffset = fTextWidget.getOffsetAtLocation(new Point(x, y)) - 1;
       if (startOffset - 2 <= lineOffset) {
         startOffset = lineOffset;
       }
     } catch (IllegalArgumentException iae) {
       startOffset = lineOffset;
     }
     // compute last visible char offset
     int endOffset;
     if (x + w >= endOfLine.x) {
       // line end is visible
       endOffset = lineEndOffset;
     } else {
       try {
         endOffset = fTextWidget.getOffsetAtLocation(new Point(x + w - 1, y)) + 1;
         if (endOffset + 2 >= lineEndOffset) {
           endOffset = lineEndOffset;
         }
       } catch (IllegalArgumentException iae) {
         endOffset = lineEndOffset;
       }
     }
     // draw character range
     if (endOffset > startOffset) {
       drawCharRange(gc, startOffset, endOffset);
     }
   }
 }
 void updateViewport() {
   baseEditor.lineCountEvent(text.getLineCount());
   int start = 0;
   try {
     start = text.getTopIndex() - 1;
   } catch (Exception e) {
     e.printStackTrace(System.out);
   }
   if (start < 0) start = 0;
   int end = start + text.getClientArea().height / text.getLineHeight();
   baseEditor.visibleTextEvent(start, end - start + 2);
 }
 /**
  * Draw characters in view range.
  *
  * @param gc
  * @param x
  * @param y
  * @param w
  * @param h
  */
 private void handleDrawRequest(GC gc, int x, int y, int w, int h) {
   int startLine = fTextWidget.getLineIndex(y);
   int endLine = fTextWidget.getLineIndex(y + h - 1);
   if (startLine <= endLine && startLine < fTextWidget.getLineCount()) {
     if (fIsAdvancedGraphicsPresent) {
       int alpha = gc.getAlpha();
       gc.setAlpha(100);
       drawLineRange(gc, startLine, endLine, x, w);
       gc.setAlpha(alpha);
     } else drawLineRange(gc, startLine, endLine, x, w);
   }
 }
    private synchronized void adjustOther(StyledText source, StyledText other) {
      if (source == null) source = this.source;
      if (other == null) other = this.other;

      if (source == null) {
        logWriter.println("WARNING:  attempting to adjust source but no source StyledText");
        return;
      }
      if (other == null) {
        logWriter.println("WARNING:  attempting to adjust other but no other StyledText");
        return;
      }

      int caretOffset = source.getCaretOffset();
      int lineIndex = source.getLineAtOffset(caretOffset);
      int otherLineHeight = other.getLineHeight();
      int otherLineRealPixel = lineIndex * otherLineHeight;
      int sourceLinePixel = source.getLinePixel(lineIndex);
      int otherTopPixel = otherLineRealPixel - sourceLinePixel;

      int otherHeight = other.getClientArea().height;
      int otherLineBelow = otherHeight - (sourceLinePixel + otherLineHeight);

      int otherLineCount = other.getLineCount();
      int otherLinesBelow = otherLineCount - lineIndex;
      int otherLinesBelowHeight = otherLinesBelow * otherLineHeight;
      int otherBottomGap = otherHeight - (sourceLinePixel + otherLinesBelowHeight);

      //   other would have to scroll before first line
      if (otherTopPixel < 0) {
        int sourceTopPixel = source.getTopPixel() - otherTopPixel;
        otherTopPixel = 0;
        source.setTopPixel(sourceTopPixel);
      }

      //   other line would be partially past the bottom of view
      else if (otherLineBelow < 0) {
        int sourceTopPixel = source.getTopPixel() - otherLineBelow;
        otherTopPixel -= otherLineBelow;
        source.setTopPixel(sourceTopPixel);
      }

      //   other would have to scroll past last line
      else if (otherBottomGap > 0) {
        int sourceTopPixel = source.getTopPixel() - otherBottomGap;
        otherTopPixel -= otherBottomGap;
        source.setTopPixel(sourceTopPixel);
      }

      other.setTopPixel(otherTopPixel);
      redraw();
    }
    @Override
    public void modifyText(ExtendedModifyEvent event) {
      // TODO:  is this ever not true?
      if (source != currentText) return;

      if (undoing) changes.add(changeIndex, event);
      else if (redoing) changes.add(changeIndex++, event);
      else {
        if (changeIndex < changes.size()) changes.subList(changeIndex, changes.size()).clear();
        changes.add(changeIndex++, event);
      }
      undoing = redoing = false;

      //   need to redraw page lines
      int lineCount = source.getLineCount();
      if (lineCount != prevLineCount) redraw();
      prevLineCount = lineCount;
    }
    @Override
    public void paintControl(PaintEvent event) {
      /*   Using event.gc.getFontMetrics().getAverageCharWidth()) was not
          enough on low resolutions, as the rounding to an int seemed
          enough to screw up the right margin, even when using a
          monospaced font (this is the current theory).
      */
      if (charsPerLine != getCharsPerLine()) {
        charsPerLine = getCharsPerLine();
        char buffer[] = new char[charsPerLine];
        for (int i = 0; i < charsPerLine; i++) buffer[i] = 'm';
        rightMargin = event.gc.stringExtent(new String(buffer)).x;
      }

      int lineHeight = source.getLineHeight();
      int drawHeight = source.getClientArea().height;
      int drawWidth = source.getClientArea().width;

      event.gc.setForeground(color);
      event.gc.setBackground(color);

      //   draw right margin
      event.gc.drawLine(rightMargin, 0, rightMargin, drawHeight);

      for (int i = source.getTopIndex(); i < source.getLineCount(); i++) {
        //   draw page lines
        int at = source.getLinePixel(i);
        if (isFirstLineOnPage(i)) event.gc.drawLine(0, at, drawWidth, at);

        //   draw paragraph end markers
        String line = source.getLine(i);
        if (line.length() > 0 && line.charAt(line.length() - 1) == PARAGRAPH_END) {
          Point point = event.gc.stringExtent(line);
          int span = point.y / 2;
          event.gc.fillOval(point.x + span / 2, at + span / 2, span, span);
        }

        //   check if line still visible
        if (at + lineHeight > drawHeight) break;
      }

      adjustOtherThread.notifyPainted(source);
    }
Beispiel #12
0
  public void _setWhatsNew() {

    if (sWhatsNew.indexOf("<html") >= 0 || sWhatsNew.indexOf("<HTML") >= 0) {
      BrowserWrapper browser = Utils.createSafeBrowser(cWhatsNew, SWT.NONE);
      if (browser != null) {
        browser.setText(sWhatsNew);
      } else {
        try {
          File tempFile = File.createTempFile("AZU", ".html");
          tempFile.deleteOnExit();
          FileUtil.writeBytesAsFile(tempFile.getAbsolutePath(), sWhatsNew.getBytes("utf8"));
          Utils.launch(tempFile.getAbsolutePath());
          shell.dispose();
          return;
        } catch (IOException e) {
        }
      }
    } else {

      StyledText helpPanel = new StyledText(cWhatsNew, SWT.VERTICAL | SWT.HORIZONTAL);

      helpPanel.setEditable(false);
      try {
        helpPanel.setRedraw(false);
        helpPanel.setWordWrap(false);
        helpPanel.setFont(monospace);

        black = ColorCache.getColor(display, 0, 0, 0);
        white = ColorCache.getColor(display, 255, 255, 255);
        light = ColorCache.getColor(display, 200, 200, 200);
        grey = ColorCache.getColor(display, 50, 50, 50);
        green = ColorCache.getColor(display, 30, 80, 30);
        blue = ColorCache.getColor(display, 20, 20, 80);
        int style;
        boolean setStyle;

        helpPanel.setForeground(grey);

        String[] lines = sWhatsNew.split("\\r?\\n");
        for (int i = 0; i < lines.length; i++) {
          String line = lines[i];

          setStyle = false;
          fg = grey;
          bg = white;
          style = SWT.NORMAL;

          char styleChar;
          String text;

          if (line.length() < 2) {
            styleChar = ' ';
            text = " " + lineSeparator;
          } else {
            styleChar = line.charAt(0);
            text = line.substring(1) + lineSeparator;
          }

          switch (styleChar) {
            case '*':
              text = "  * " + text;
              fg = green;
              setStyle = true;
              break;
            case '+':
              text = "     " + text;
              fg = black;
              bg = light;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '!':
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '@':
              fg = blue;
              setStyle = true;
              break;
            case '$':
              bg = blue;
              fg = white;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case ' ':
              text = "  " + text;
              break;

            default:
              text = styleChar + text;
          }

          helpPanel.append(text);

          if (setStyle) {
            int lineCount = helpPanel.getLineCount() - 1;
            int charCount = helpPanel.getCharCount();
            //          System.out.println("Got Linecount " + lineCount + ", Charcount " +
            // charCount);

            int lineOfs = helpPanel.getOffsetAtLine(lineCount - 1);
            int lineLen = charCount - lineOfs;
            //          System.out.println("Setting Style : " + lineOfs + ", " + lineLen);
            helpPanel.setStyleRange(new StyleRange(lineOfs, lineLen, fg, bg, style));
            helpPanel.setLineBackground(lineCount - 1, 1, bg);
          }
        }

        helpPanel.setRedraw(true);
      } catch (Exception e) {
        System.out.println("Unable to load help contents because:" + e);
        // e.printStackTrace();
      }
    }

    if (labelLoading != null && !labelLoading.isDisposed()) {
      labelLoading.dispose();
    }
    shell.layout(true, true);
  }
 public boolean isLastLineShown() {
   int bottomLine = commandLineText.getLineIndex(commandLineText.getBounds().y);
   // -1: getLineIndex will always return 0 to getLineCount() - 1.
   return bottomLine >= commandLineText.getLineCount() - 1;
 }
Beispiel #14
0
  private void scrollToEnd() {

    terminalText.setTopIndex(terminalText.getLineCount() - 1);
  }