Пример #1
0
 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();
 }
Пример #2
0
  /**
   * Inputs in the view the selected PO whose pretty code is recorded in the Goal class
   *
   * @throws IOException
   */
  public void inputPO() throws IOException {

    // we want to see a context, not the goal
    if (!POMode) {
      return;
    }

    if (ttext > 0) // if we've a title text
    setPartName(IConstants.PO_VIEW_TITLE + " : po " + ttext); // put it in the view
    else setPartName(IConstants.PO_VIEW_TITLE); // else, put the view title only

    // gets the PO pretty text
    String container = "";
    container = Goal.getGoal();

    // if the Goal is empty, we can return
    if (container.equals("")) {
      text.setText(container);
      return;
    }

    // get the style ranges
    Vector<StyleRange> range = Goal.getStyleRanges();
    int w = range.size() - 1;
    // keep the ranges which can be applied in the text area
    while (((StyleRange) range.get(w)).start >= container.length()) {
      w--;
    }

    // put the bar between the goal and the arrow result excerpted from this same goal
    container += "\n_______________________________________________\n\n";
    container += Goal.getResult();
    text.setText(container);

    // apply style ranges to the first part of the goal (before the bar)
    for (int e = 0; e <= w; e++) {
      text.setStyleRange((StyleRange) range.get(e));
    }

    // puts a style range to color the bar in black
    StyleRange srg = new StyleRange();
    srg.start += Goal.getGoal().length();
    srg.length = 50;
    srg.foreground = new Color(null, 0, 0, 0);
    text.setStyleRange(srg);

    // puts a style range to color the end of the goal in blue
    srg = new StyleRange();
    srg.start += Goal.getGoal().length() + 50;
    srg.length = Goal.getResult().length();
    srg.foreground = new Color(null, 0, 0, 255);
    text.setStyleRange(srg);

    // sets the cursor at the end of the code
    text.setSelection(text.getText().length(), text.getText().length());
  }
  private void formatHostName(int start, int end) {
    StyleRange style = new StyleRange();
    style.start = start;
    style.length = end - start;
    style.font = new Font(sShell.getDisplay(), "Courier New", 9, SWT.BOLD);
    style.foreground = sShell.getDisplay().getSystemColor(SWT.COLOR_BLUE);

    activeHostsFileStyledText.setStyleRange(style);
  }
  private void formatIpAddress(int start, int end) {
    StyleRange style = new StyleRange();
    style.start = start;
    style.length = end - start;
    style.font = new Font(sShell.getDisplay(), "Courier New", 9, SWT.BOLD);
    style.foreground = new Color(sShell.getDisplay(), 255, 127, 0); // Orange	

    activeHostsFileStyledText.setStyleRange(style);
  }
  private void formatRemark(int start, int end) {
    StyleRange style = new StyleRange();
    style.start = start;
    style.length = end - start;
    style.font = new Font(sShell.getDisplay(), "Courier New", 9, SWT.NORMAL);
    style.foreground = new Color(sShell.getDisplay(), 0, 128, 0); // Green	

    activeHostsFileStyledText.setStyleRange(style);
  }
Пример #6
0
  private void appendText(
      String line, final Color foreground, final Color background, final int textStyle) {

    int start = terminalText.getCharCount();
    terminalText.append(line);
    int len = terminalText.getCharCount() - start;
    terminalText.setStyleRange(new StyleRange(start, len, foreground, background, textStyle));

    scrollToEnd();
  }
Пример #7
0
 public static void lightenStyledTextColors(StyledText st, double pct) {
   StyleRange[] srs = st.getStyleRanges();
   Color defaultFGColor = CCWPlugin.getColor(RGBUtil.lighten(st.getForeground().getRGB(), pct));
   for (int i = 0; i < srs.length; i++) {
     StyleRange oldSR = srs[i];
     StyleRange newSR = newStyleRange(oldSR);
     Color lightForeground =
         (oldSR.foreground == null)
             ? defaultFGColor
             : CCWPlugin.getColor(RGBUtil.lighten(oldSR.foreground.getRGB(), pct));
     newSR.foreground = lightForeground;
     st.setStyleRange(newSR);
   }
   st.setForeground(defaultFGColor);
 }
Пример #8
0
 private void updateInput() {
   if (fInfoText == null || !fInputChanged) {
     return;
   }
   if (fLabelProvider == null) {
     fLabelProvider =
         new RLabelProvider(
             RLabelProvider.LONG | RLabelProvider.HEADER | RLabelProvider.NAMESPACE);
   }
   if (fInput != null) {
     final Image image = fLabelProvider.getImage(fInput.element);
     fTitleImage.setImage(
         (image != null)
             ? image
             : SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID));
     final StyledString styleString =
         fLabelProvider.getStyledText(
             fInput.element, fInput.element.getElementName(), fInput.elementAttr);
     fTitleText.setText(styleString.getString());
     fTitleText.setStyleRanges(styleString.getStyleRanges());
     if (fInput.detailTitle != null) {
       fInfoText.setText(
           fInput.detailTitle
               + '\n'
               + ((fInput.detailInfo != null) ? fInput.detailInfo : "")); // $NON-NLS-1$
       final StyleRange title = new StyleRange(0, fInput.detailTitle.length(), null, null);
       title.underline = true;
       fInfoText.setStyleRange(title);
     } else {
       fInfoText.setText(""); // $NON-NLS-1$
     }
   } else {
     fTitleImage.setImage(
         SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID));
     fTitleText.setText(""); // $NON-NLS-1$
     fInfoText.setText(""); // $NON-NLS-1$
   }
   if (fMode == MODE_SIMPLE) {
     setStatusText(
         (fInput.control != null && fInput.control.isFocusControl())
             ? InformationDispatchHandler.getTooltipAffordanceString()
             : ""); //$NON-NLS-1$
   }
   fInputChanged = false;
 }
Пример #9
0
 private void removeHighlightingCategory(
     org.eclipse.jface.text.IDocument document, String category) {
   org.eclipse.jface.text.Position[] positions = positionHelper.getPositions(document, category);
   if (category.equals(
       bento.language.bentocomp.resource.bento.ui.BentoPositionCategory.BRACKET.toString())) {
     org.eclipse.swt.custom.StyleRange styleRange;
     for (org.eclipse.jface.text.Position position : positions) {
       org.eclipse.jface.text.Position tmpPosition = convertToWidgetPosition(position);
       if (tmpPosition != null) {
         styleRange = getStyleRangeAtPosition(tmpPosition);
         styleRange.borderStyle = org.eclipse.swt.SWT.NONE;
         styleRange.borderColor = null;
         styleRange.background = null;
         textWidget.setStyleRange(styleRange);
       }
     }
   }
   positionHelper.removePositions(document, category);
 }
Пример #10
0
  private void setBracketHighlighting(org.eclipse.jface.text.IDocument document) {
    org.eclipse.swt.custom.StyleRange styleRange = null;
    org.eclipse.jface.text.Position[] positions =
        positionHelper.getPositions(
            document,
            bento.language.bentocomp.resource.bento.ui.BentoPositionCategory.BRACKET.toString());

    for (org.eclipse.jface.text.Position position : positions) {
      org.eclipse.jface.text.Position tmpPosition = convertToWidgetPosition(position);
      if (tmpPosition != null) {
        styleRange = getStyleRangeAtPosition(tmpPosition);
        styleRange.borderStyle = org.eclipse.swt.SWT.BORDER_SOLID;
        styleRange.borderColor = bracketColor;
        if (styleRange.foreground == null) {
          styleRange.foreground = black;
        }
        textWidget.setStyleRange(styleRange);
      }
    }
  }
  private void updateStyle(ITextViewer viewer) {
    StyledText text = viewer.getTextWidget();
    int widgetOffset = getWidgetOffset(viewer, fRememberedStyleRange.start);
    StyleRange range = new StyleRange(fRememberedStyleRange);
    range.start = widgetOffset;
    range.length = fRememberedStyleRange.length;
    StyleRange currentRange = text.getStyleRangeAtOffset(widgetOffset);
    if (currentRange != null) {
      range.strikeout = currentRange.strikeout;
      range.underline = currentRange.underline;
      range.fontStyle = currentRange.fontStyle;
    }

    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
    try {
      text.setStyleRange(range);
    } catch (IllegalArgumentException x) {
      // catching exception as offset + length might be outside of the text widget
      fRememberedStyleRange = null;
    }
  }
Пример #12
0
  /**
   * Inputs in the view the context file whose pretty code is recorded in the Context class
   *
   * @throws IOException
   */
  public void inputCTX() throws IOException {

    // we want to see a goal, not the context
    if (POMode) {
      return;
    }

    // no tooltip text and no goal number to show in the title
    setTitleToolTip(null);
    setPartName(IConstants.PO_VIEW_TITLE);

    // shows the context text
    text.setText(Context.getContext());

    // with style ranges
    Vector<StyleRange> range = Context.getStyleRanges();
    if (range != null) {
      for (int e = 0; e < range.size(); e++) {
        text.setStyleRange((StyleRange) range.get(e));
      }
    }
  }
Пример #13
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);
  }
Пример #14
0
 private void highlight(int start, String search) {
   stylerange.start = start;
   stylerange.length = search.length();
   text.setStyleRange(stylerange);
 }