Java 类org.eclipse.swt.custom.StyleRange 实例源码

项目:n4js    文件:WizardPreviewProvider.java   
/**
 * Updates the syntax highlighting.
 *
 * Disables highlighting for inactive blocks, or for all blocks if the editor is disabled.
 */
private void updateHighlighting() {
    if (!getEnabled()) {
        unhighlightAll();
        return;
    }
    if (contentBlocks == null) {
        return;
    }

    int accumulatedOffset = 0;
    for (ContentBlock block : contentBlocks) {
        if (!block.highlighted) {
            StyleRange range = new StyleRange(accumulatedOffset, block.content.length(), inactiveColor, null);
            sourceViewer.getTextWidget().setStyleRange(range);
        }
        accumulatedOffset += block.content.length();
    }
}
项目:n4js    文件:SpecProcessPage.java   
private void asyncDisplayMessages() {
    Message m = null;
    synchronized (msgStack) {
        if (msgStack.isEmpty())
            return;

        m = msgStack.pop();
    }
    int offsetStart = errorText.getCharCount();
    errorText.append(m.msg + "\n");
    int offsetEnd = errorText.getCharCount();
    errorText.setTopIndex(errorText.getLineCount() - 1);

    if (m.color != null) {
        StyleRange range = new StyleRange(offsetStart, offsetEnd - offsetStart, m.color, null);
        errorText.setStyleRange(range);
    }
}
项目:pgcodekeeper    文件:UsageReportPreferencePage.java   
private void appendEvents(StringBuilder builder, List<StyleRange> styles) {
    UsageEventType[] events = EventRegister.getInstance().getRegisteredEventTypes();
    if (events.length > 0) {
        appendLabeledValue(Messages.UsageReportPreferencePage_Events, "", builder, styles);
        builder.append(UIConsts._NL);
        for (UsageEventType event : events) {
            appendLabeledValue(Messages.UsageReportPreferencePage_EventComponent, event.getComponentName(), builder, styles);
            appendLabeledValue(Messages.UsageReportPreferencePage_EventVersion, event.getComponentVersion(), builder, styles);
            appendLabeledValue(Messages.UsageReportPreferencePage_EventAction, event.getActionName(), builder, styles);
            if(event.getValueDescription() != null) {
                appendLabeledValue(Messages.UsageReportPreferencePage_EventValue, event.getValueDescription(), builder, styles);
            }

            builder.append(UIConsts._NL);
        }
    }
}
项目:vertigo-chroma-kspplugin    文件:KspOutlinePage.java   
private void setStyledText(ViewerCell cell, TreeObject obj) {
    /* Calcul du texte. */
    String mainText = obj.getMainText();
    if (mainText == null) {
        return;
    }
    String subText = obj.getSubText();
    String subTextFinal = subText == null ? "" : (" : " + subText);
    String fullText = mainText + subTextFinal;
    cell.setText(fullText);

    /* Calcul du style. */
    List<StyleRange> styles = new ArrayList<>();
    StyleRange styleMainText = new StyleRange(0, mainText.length(), null, null);
    styles.add(styleMainText);
    if (!subTextFinal.isEmpty()) {
        Display display = Display.getCurrent();
        Color blue = display.getSystemColor(SWT.COLOR_DARK_YELLOW);
        StyleRange styleSubText = new StyleRange(mainText.length(), subTextFinal.length(), blue, null);
        styles.add(styleSubText);
    }
    cell.setStyleRanges(styles.toArray(new StyleRange[0]));
}
项目:BiglyBT    文件:ProgressReporterPanel.java   
/**
 * Appends the given message to the detail panel; render the message in error color if specified
 * @param value
 * @param isError if <code>true</code> then render the message in the system error color; otherwise render in default color
 */
private void appendToDetail(String value, boolean isError) {

    if (null == value || value.length() < 1) {
        return;
    }

    if (null == detailListWidget || detailListWidget.isDisposed()) {
        return;
    }

    int charCount = detailListWidget.getCharCount();
    detailListWidget.append(value + "\n");
    if (isError) {
        StyleRange style2 = new StyleRange();
        style2.start = charCount;
        style2.length = value.length();
        style2.foreground = errorColor;
        detailListWidget.setStyleRange(style2);
    }
    detailSection.setEnabled(true);
    if ( isError ){
        detailSection.setCollapsed( false );
        detailListWidget.setSelection( detailListWidget.getCharCount(), detailListWidget.getCharCount());
    }
}
项目:avro-schema-editor    文件:SchemaViewerStyledCellLabelProvider.java   
@Override
  public void update(ViewerCell cell) {

      AvroNode node = nodeConverter.convertToAvroNode(cell.getElement());

String text = labelProvider.getText(node);
      Image image = labelProvider.getImage(node);
      StyleRange[] styleRanges = labelProvider.getStyleRanges(node);

      cell.setText(text);
cell.setImage(image);
      cell.setStyleRanges(styleRanges);

      Color backgroundColor = labelProvider.getBackgroundColor(node);
      if (backgroundColor != null) {
        cell.setBackground(backgroundColor);
      }

      super.update(cell);
  }
项目:egradle    文件:EGradleConsoleStyleListener.java   
private void parseByIndex(LineStyleEvent event, StyleRange startStyle, String currentText, List<StyleRange> ranges,
        ParseData data) {
    int fromIndex = 0;
    int pos = 0;
    int length = currentText.length();
    do {
        if (fromIndex >= length) {
            break;
        }
        pos = currentText.indexOf(data.subString, fromIndex);
        fromIndex = pos + 1;

        if (pos != -1) {
            addRange(ranges, event.lineOffset + pos, data.subString.length(), getColor(data.color), data.bold);
        }
    } while (pos != -1);
}
项目:DarwinSPL    文件:DwprofileHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, de.darwinspl.preferences.resource.dwprofile.ui.DwprofilePositionCategory.BRACKET.toString());

    for (Position position : positions) {
        Position tmpPosition = convertToWidgetPosition(position);
        if (tmpPosition != null) {
            styleRange = getStyleRangeAtPosition(tmpPosition);
            styleRange.borderStyle = SWT.BORDER_SOLID;
            styleRange.borderColor = bracketColor;
            if (styleRange.foreground == null) {
                styleRange.foreground = black;
            }
            textWidget.setStyleRange(styleRange);
        }
    }
}
项目:DarwinSPL    文件:DwprofileHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(de.darwinspl.preferences.resource.dwprofile.ui.DwprofilePositionCategory.BRACKET.toString())) {
        StyleRange styleRange;
        for (Position position : positions) {
            Position tmpPosition = convertToWidgetPosition(position);
            if (tmpPosition != null) {
                styleRange = getStyleRangeAtPosition(tmpPosition);
                styleRange.borderStyle = SWT.NONE;
                styleRange.borderColor = null;
                styleRange.background = null;
                textWidget.setStyleRange(styleRange);
            }
        }
    }
    positionHelper.removePositions(document, category);
}
项目:DarwinSPL    文件:HyexpressionHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionPositionCategory.BRACKET.toString());

    for (Position position : positions) {
        Position tmpPosition = convertToWidgetPosition(position);
        if (tmpPosition != null) {
            styleRange = getStyleRangeAtPosition(tmpPosition);
            styleRange.borderStyle = SWT.BORDER_SOLID;
            styleRange.borderColor = bracketColor;
            if (styleRange.foreground == null) {
                styleRange.foreground = black;
            }
            textWidget.setStyleRange(styleRange);
        }
    }
}
项目:DarwinSPL    文件:HyexpressionHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionPositionCategory.BRACKET.toString())) {
        StyleRange styleRange;
        for (Position position : positions) {
            Position tmpPosition = convertToWidgetPosition(position);
            if (tmpPosition != null) {
                styleRange = getStyleRangeAtPosition(tmpPosition);
                styleRange.borderStyle = SWT.NONE;
                styleRange.borderColor = null;
                styleRange.background = null;
                textWidget.setStyleRange(styleRange);
            }
        }
    }
    positionHelper.removePositions(document, category);
}
项目:DarwinSPL    文件:HyvalidityformulaHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaPositionCategory.BRACKET.toString());

    for (Position position : positions) {
        Position tmpPosition = convertToWidgetPosition(position);
        if (tmpPosition != null) {
            styleRange = getStyleRangeAtPosition(tmpPosition);
            styleRange.borderStyle = SWT.BORDER_SOLID;
            styleRange.borderColor = bracketColor;
            if (styleRange.foreground == null) {
                styleRange.foreground = black;
            }
            textWidget.setStyleRange(styleRange);
        }
    }
}
项目:DarwinSPL    文件:HyvalidityformulaHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaPositionCategory.BRACKET.toString())) {
        StyleRange styleRange;
        for (Position position : positions) {
            Position tmpPosition = convertToWidgetPosition(position);
            if (tmpPosition != null) {
                styleRange = getStyleRangeAtPosition(tmpPosition);
                styleRange.borderStyle = SWT.NONE;
                styleRange.borderColor = null;
                styleRange.background = null;
                textWidget.setStyleRange(styleRange);
            }
        }
    }
    positionHelper.removePositions(document, category);
}
项目:DarwinSPL    文件:HydatavalueHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavaluePositionCategory.BRACKET.toString());

    for (Position position : positions) {
        Position tmpPosition = convertToWidgetPosition(position);
        if (tmpPosition != null) {
            styleRange = getStyleRangeAtPosition(tmpPosition);
            styleRange.borderStyle = SWT.BORDER_SOLID;
            styleRange.borderColor = bracketColor;
            if (styleRange.foreground == null) {
                styleRange.foreground = black;
            }
            textWidget.setStyleRange(styleRange);
        }
    }
}
项目:DarwinSPL    文件:HydatavalueHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavaluePositionCategory.BRACKET.toString())) {
        StyleRange styleRange;
        for (Position position : positions) {
            Position tmpPosition = convertToWidgetPosition(position);
            if (tmpPosition != null) {
                styleRange = getStyleRangeAtPosition(tmpPosition);
                styleRange.borderStyle = SWT.NONE;
                styleRange.borderColor = null;
                styleRange.background = null;
                textWidget.setStyleRange(styleRange);
            }
        }
    }
    positionHelper.removePositions(document, category);
}
项目:DarwinSPL    文件:HymappingHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingPositionCategory.BRACKET.toString());

    for (Position position : positions) {
        Position tmpPosition = convertToWidgetPosition(position);
        if (tmpPosition != null) {
            styleRange = getStyleRangeAtPosition(tmpPosition);
            styleRange.borderStyle = SWT.BORDER_SOLID;
            styleRange.borderColor = bracketColor;
            if (styleRange.foreground == null) {
                styleRange.foreground = black;
            }
            textWidget.setStyleRange(styleRange);
        }
    }
}
项目:DarwinSPL    文件:HymappingHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingPositionCategory.BRACKET.toString())) {
        StyleRange styleRange;
        for (Position position : positions) {
            Position tmpPosition = convertToWidgetPosition(position);
            if (tmpPosition != null) {
                styleRange = getStyleRangeAtPosition(tmpPosition);
                styleRange.borderStyle = SWT.NONE;
                styleRange.borderColor = null;
                styleRange.background = null;
                textWidget.setStyleRange(styleRange);
            }
        }
    }
    positionHelper.removePositions(document, category);
}
项目:DarwinSPL    文件:HyconstraintsHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsPositionCategory.BRACKET.toString());

    for (Position position : positions) {
        Position tmpPosition = convertToWidgetPosition(position);
        if (tmpPosition != null) {
            styleRange = getStyleRangeAtPosition(tmpPosition);
            styleRange.borderStyle = SWT.BORDER_SOLID;
            styleRange.borderColor = bracketColor;
            if (styleRange.foreground == null) {
                styleRange.foreground = black;
            }
            textWidget.setStyleRange(styleRange);
        }
    }
}
项目:DarwinSPL    文件:HyconstraintsHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsPositionCategory.BRACKET.toString())) {
        StyleRange styleRange;
        for (Position position : positions) {
            Position tmpPosition = convertToWidgetPosition(position);
            if (tmpPosition != null) {
                styleRange = getStyleRangeAtPosition(tmpPosition);
                styleRange.borderStyle = SWT.NONE;
                styleRange.borderColor = null;
                styleRange.background = null;
                textWidget.setStyleRange(styleRange);
            }
        }
    }
    positionHelper.removePositions(document, category);
}
项目:DarwinSPL    文件:HymanifestHighlighting.java   
private void setBracketHighlighting(IDocument document) {
    StyleRange styleRange = null;
    Position[] positions = positionHelper.getPositions(document, eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestPositionCategory.BRACKET.toString());

    for (Position position : positions) {
        Position tmpPosition = convertToWidgetPosition(position);
        if (tmpPosition != null) {
            styleRange = getStyleRangeAtPosition(tmpPosition);
            styleRange.borderStyle = SWT.BORDER_SOLID;
            styleRange.borderColor = bracketColor;
            if (styleRange.foreground == null) {
                styleRange.foreground = black;
            }
            textWidget.setStyleRange(styleRange);
        }
    }
}
项目:DarwinSPL    文件:HymanifestHighlighting.java   
private void removeHighlightingCategory(IDocument document, String category) {
    Position[] positions = positionHelper.getPositions(document, category);
    if (category.equals(eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestPositionCategory.BRACKET.toString())) {
        StyleRange styleRange;
        for (Position position : positions) {
            Position tmpPosition = convertToWidgetPosition(position);
            if (tmpPosition != null) {
                styleRange = getStyleRangeAtPosition(tmpPosition);
                styleRange.borderStyle = SWT.NONE;
                styleRange.borderColor = null;
                styleRange.background = null;
                textWidget.setStyleRange(styleRange);
            }
        }
    }
    positionHelper.removePositions(document, category);
}
项目:team-explorer-everywhere    文件:TeamExplorerPendingChangesWorkItemsSection.java   
private void appendField(
    final TableTooltipStyledTextInfo info,
    final StringBuilder sb,
    final WorkItem workItem,
    final String fieldName) {
    final String displayName = map.get(fieldName);
    Check.notNull(displayName, "displayName"); //$NON-NLS-1$

    sb.append(displayName);
    sb.append("\t"); //$NON-NLS-1$

    final Object value = workItem.getFields().getField(fieldName).getValue();
    if (value != null) {
        final int rangeStart = sb.length();
        sb.append(value.toString());
        final int rangeLen = sb.length() - rangeStart;

        final StyleRange range = new StyleRange();
        range.start = rangeStart;
        range.length = rangeLen;
        range.fontStyle = SWT.BOLD;
        info.addStyleRange(range);
    }
    sb.append(NewlineUtils.PLATFORM_NEWLINE);
}
项目:subclipse    文件:SourceViewerInformationControl.java   
public void setInformation(String content) {
    if (content == null) {
        fViewer.setInput(null);
        return;
    }

    IDocument doc= new Document(content);
    fViewer.setInput(doc);

    // decorate text
    StyleRange styleRange = new StyleRange();
    styleRange.start = 0;
    styleRange.length = content.indexOf('\n');
    styleRange.fontStyle = SWT.BOLD;
   fViewer.getTextWidget().setStyleRange(styleRange);
}
项目:Notepad4e    文件:Note.java   
/**
 * Constructor. Sets properties of the editor window.
 * 
 * @param parent
 * @param text
 * @param editable
 * @param shortcutHandler
 */
public Note(Composite parent, String text, boolean editable) {
    // Enable multiple lines and scroll bars.
    super(parent, SWT.V_SCROLL | SWT.H_SCROLL);

    preferences = InstanceScope.INSTANCE.getNode(Notepad4e.PLUGIN_ID);

    undoRedoManager = new UndoRedoManager(this);
    bulletStyle = new StyleRange();
    bulletStyle.metrics = new GlyphMetrics(0, 0, 0);

    // Scroll bars only appear when the text extends beyond the note window.
    setAlwaysShowScrollBars(false);
    setParametersFromPreferences();
    setText(text);
    initialiseMenu();

    if (!editable) {
        toggleEditable();
    }
}
项目:Notepad4e    文件:Note.java   
/**
 * Creates a string giving a description of the styles in the current note.
 * 
 * @return CSV string containing a serialised representation of the styles
 */
public String serialiseStyle() {
    StringBuilder styleSerialisation = new StringBuilder();
    StyleRange[] currentStyles = getStyleRanges();
    // Append integers corresponding to various information of each style range object, separated by
    // STRING_SEPARATOR.
    for (int styleIndex = 0; styleIndex < currentStyles.length; ++styleIndex) {
        styleSerialisation.append(currentStyles[styleIndex].start);
        styleSerialisation.append(STRING_SEPARATOR);
        styleSerialisation.append(currentStyles[styleIndex].length);
        styleSerialisation.append(STRING_SEPARATOR);
        styleSerialisation.append(currentStyles[styleIndex].fontStyle);
        styleSerialisation.append(STRING_SEPARATOR);
        // If underlined, 1, else 0.
        styleSerialisation.append(currentStyles[styleIndex].underline ? 1 : 0);
        styleSerialisation.append(STRING_SEPARATOR);
        // If strikeout, 1, else 0.
        styleSerialisation.append(currentStyles[styleIndex].strikeout ? 1 : 0);
        styleSerialisation.append(STRING_SEPARATOR);
    }
    return styleSerialisation.toString();
}
项目:Notepad4e    文件:Note.java   
/**
 * Applies styles to the current note based on a styles' serialisation string.
 * 
 * @param serialisation
 */
public void deserialiseStyle(String serialisation) {
    String[] integers = serialisation.split(STRING_SEPARATOR);
    StyleRange[] styles = new StyleRange[integers.length / 5];
    // Do the parsing.
    for (int styleIndex = 0; styleIndex < styles.length; ++styleIndex) {
        // Each StyleRange object has 5 corresponding integers in the CSV string.
        int integerIndex = 5 * styleIndex;
        styles[styleIndex] = new StyleRange();
        styles[styleIndex].start = Integer.parseInt(integers[integerIndex]);
        styles[styleIndex].length = Integer.parseInt(integers[integerIndex + 1]);
        styles[styleIndex].fontStyle = Integer.parseInt(integers[integerIndex + 2]);
        styles[styleIndex].underline = (Integer.parseInt(integers[integerIndex + 3]) == 1) ? true : false;
        styles[styleIndex].strikeout = (Integer.parseInt(integers[integerIndex + 4]) == 1) ? true : false;
    }
    // Apply the parsed styles.
    setStyleRanges(styles);
}
项目:Notepad4e    文件:UndoRedoManager.java   
/**
 * Records history for undo/redo functions.
 * 
 * @param event
 * @param styles
 */
public void recordNoteModification(VerifyEvent event, StyleRange[] styles) {
    // Previous action cannot be an undo: empty redo deque and remove stylesBeforeUndo.
    redoDeque.clear();
    stylesBeforeUndo = null;

    // Construct modification record depending on whether the function was called by a style or a text
    // modification and push it on the deque.
    if (event != null) {
        undoDeque.push(new ModificationRecord(styles, event.start, event.text.length(),
                note.getText().substring(event.start, event.end), event.text));
    } else {
        undoDeque.push(new ModificationRecord(styles, 0, 0, null, null));
    }

    // Limit maximum size of deque by clearing oldest records.
    if (undoDeque.size() > MAX_DEQUE_SIZES) {
        undoDeque.pollLast();
    }
}
项目:JAADAS    文件:AbstractAttributesColorer.java   
protected void changeStyles(){
    final StyleRange [] srs = new StyleRange[styleList.size()];
    styleList.toArray(srs);

    getDisplay().asyncExec(new Runnable(){
        public void run(){
            for (int i = 0; i < srs.length; i++){
                try{
                    //System.out.println("Style Range: "+srs[i]);
                    getViewer().getTextWidget().setStyleRange(srs[i]);
                }
                catch(Exception e){
                    System.out.println("Seting Style Range Ex: "+e.getMessage());
                }
            }
        };
    });        
}
项目:EclipsePlugins    文件:RiologView.java   
@Override
public Message.StyledAppendable startStyle(int style) {
  if (style >= styles.length) {
    return this;
  }
  StyleRange styleRange = styles[style];
  if (styleRange == null) {
    return this;
  }
  styleRanges.add(styleRange);
  if (styleStart != -1) {
    endStyle();
  }
  styleStart = builder.length();  // start
  ranges.add(styleStart);
  return this;
}
项目:Black    文件:blackAction.java   
public void showFindResult(TreeItem ti) {
    if (ti != null) {
        File f = (File) ti.getData("file");
        if (f != null) {
            openFile(f, false);
            ArrayList<IRegion> al = (ArrayList<IRegion>) ti.getData("iregions");
            if (al != null) {
                Iterator<IRegion> it = al.iterator();
                while (it.hasNext()) {
                    IRegion ir = it.next();
                    b.blackTextArea.styles = new ArrayList<StyleRange[]>();
                    StyleRange sr = new StyleRange(ir.getOffset(), ir.getLength(), b.color_textBackground,
                            org.eclipse.wb.swt.SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN));
                    StyleRange[] s = b.getEditer().getStyleRanges(ir.getOffset(), ir.getLength());
                    if (s != null)
                        b.blackTextArea.styles.add(s);
                    b.getEditer().setStyleRange(sr);
                }
            }

        }
    }
}
项目:Black    文件:blackAction.java   
public void showUpdateinof() {
    bMessageBox bme = new bMessageBox(b, SWT.NONE, false) {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void saveAction() {
            // TODO Auto-generated method stub

        }
    };
    bme.setTextFontinfo(12, SWT.None);
    bme.setText(b.updateinfo);
    bme.setTitle("���°汾");
    // bme.text.setLineAlignment(0, 1, SWT.CENTER);
    StyleRange sr = new StyleRange();
    sr.start = 1;
    sr.length = bme.text.getLine(1).length();
    sr.font = SWTResourceManager.getFont("����", 20, SWT.NONE, false, true);
    bme.text.setStyleRange(sr);
    // bme.text.set
    bme.open();
}
项目:Black    文件:blackTextArea.java   
public void showMark() {
    int lineindex = st.getLineAtOffset(st.getCaretOffset());
    int lineoffset = st.getOffsetAtLine(lineindex);
    List<TextRegion> lis = new cheakDocument().splitString(st.getLine(st.getLineAtOffset(st.getCaretOffset())), ' ',
            false, null);
    Iterator<TextRegion> it = lis.iterator();
    StyleRange sr = new StyleRange();
    while (it.hasNext()) {
        TextRegion tr = it.next();
        sr.background = SWTResourceManager.getColor(SWT.COLOR_GREEN);
        sr.start = tr.start + lineoffset;
        sr.length = tr.end - tr.start;
        st.setStyleRange(sr);

    }
}
项目:tlaplus    文件:TLCUIHelper.java   
/**
 * Creates a hyperlink style range that begins at start and ends at end.
 * Sets the data field of the hyperlink to location.
 * 
 * The data field can be used to jump to the location when the link
 * is opened. Use {@link TLCUIHelper#openTLCLocationHyperlink(StyledText, MouseEvent, ILaunchConfiguration)}
 * to open such links.
 * 
 * @param location
 * @param start
 * @param end
 * @return
 */
public static StyleRange getHyperlinkStyleRange(Location location, int start, int end)
{
    /*
     * To create the link, we follow the instructions
     * found here:
     * 
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83408
     */
    // create the style for the link
    StyleRange style = new StyleRange(start, end - start, null, null);
    style.underlineStyle = SWT.UNDERLINE_LINK;
    style.underline = true;
    // set the data field of the style range to store the location
    // this can be used for jumping to the location when
    // the hyperlink is opened
    style.data = location;
    return style;
}
项目:tlaplus    文件:TLCUIHelperTest.java   
@Test
public void testSetTLCLocationHyperlinksString() {
    final String text = 
              "0. Line " + line + ", column " + beginColumn + " to line " + line + ", column " + endColumn + " in " + module + "\n"
            + "4. Line " + line + ", column " + beginColumn + " to line " + line + ", column " + endColumn + " in " + module;

    final List<StyleRange> ranges = TLCUIHelper.setTLCLocationHyperlinks(text);

    // check if we get expected amount of locations
    Assert.assertEquals(2, ranges.size());

    // check each location individually
    for (final StyleRange range : ranges) {
        if (range.data instanceof Location) {
            final Location location = (Location) range.data;
            Assert.assertEquals(module, location.source());
            Assert.assertEquals(line, location.beginLine());
            Assert.assertEquals(line, location.endLine());
            Assert.assertEquals(beginColumn, location.beginColumn());
            Assert.assertEquals(endColumn, location.endColumn());
        }
    }
}
项目:tlaplus    文件:TLCUIHelperTest.java   
@Test
public void testTLAandPCalLocations() {
    final String text =
            // PCal
            "Failure of assertion at line " + line  + ", column " + beginColumn + ".\n" +
            // TLA
            "4. Line " + line+ ", column " + beginColumn + " to line " + line + ", column " + endColumn + " in " + module;

    final List<StyleRange> ranges = TLCUIHelper.setTLCLocationHyperlinks(text);

    // check if we get expected amount of locations
    Assert.assertEquals(2, ranges.size());

    // check each location individually
    for (final StyleRange range : ranges) {
        if (range.data instanceof Location) {
            final Location location = (Location) range.data;
            Assert.assertEquals(module, location.source());
            Assert.assertEquals(line, location.beginLine());
            Assert.assertEquals(beginColumn, location.beginColumn());
            // ignore end line and endColumn here as the PCal matcher does
            // not know and hence set this information.
        }
    }
}
项目:typescript.java    文件:RenameInformationPopup.java   
private void createContent(Composite parent) {
    Display display= parent.getDisplay();
    Color foreground= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
    Color background= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
    addMoveSupport(fPopup, parent);

    StyledText hint= new StyledText(fPopup, SWT.READ_ONLY | SWT.SINGLE);
    hint.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
    String enterKeyName= getEnterBinding();
    String hintTemplate= RefactoringMessages.RenameInformationPopup_EnterNewName;
    hint.setText(NLS.bind(hintTemplate, enterKeyName));
    hint.setForeground(foreground);
    hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$
    hint.setEnabled(false); // text must not be selectable
    addMoveSupport(fPopup, hint);

    addLink(parent);
    addViewMenu(parent);

    recursiveSetBackgroundColor(parent, background);

}
项目:mytourbook    文件:DialogModifyColumns.java   
private void createUI_76_Hints(final Composite parent) {

        // use a bulleted list to display this info
        final StyleRange style = new StyleRange();
        style.metrics = new GlyphMetrics(0, 0, 10);
        final Bullet bullet = new Bullet(style);

        final String infoText = Messages.ColumnModifyDialog_Label_Hints;
        final int lineCount = Util.countCharacter(infoText, '\n');

        final StyledText styledText = new StyledText(parent, SWT.READ_ONLY | SWT.WRAP | SWT.MULTI);
        styledText.setText(infoText);
        styledText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        styledText.setLineBullet(1, lineCount, bullet);
        styledText.setLineWrapIndent(1, lineCount, 10);
        GridDataFactory.fillDefaults()//
                .grab(true, false)
                .span(2, 1)
                .applyTo(styledText);
    }
项目:statecharts    文件:SyntaxColoringLabel.java   
/**
 * Add bold font size to label dimension
 */
protected Dimension getTextExtentsInternal(String draw, Font f) {
    Dimension d = super.getTextExtents(draw, f).getCopy();
    int paintOffset = 0;
    int lineOffset = getText().indexOf(draw);
    for (StyleRange range : ranges) {
        int beginIndex = range.start - lineOffset;
        if (beginIndex > draw.length()) {
            break;
        }
        int endIndex = beginIndex + range.length;
        String substring = draw.substring(beginIndex > 0 ? beginIndex : 0,
                Math.min(endIndex > 0 ? endIndex : 0, draw.length()));
        Font font = SWT.BOLD == (range.fontStyle & SWT.BOLD) ? boldFont : getFont();
        int offset = getTextExtend(font, substring);
        paintOffset += offset;
    }
    d.width = Math.max(d.width, paintOffset);
    return d;

}
项目:statecharts    文件:StyleRanges.java   
public List<StyleRange> getRanges(String expression) {
    final List<StyleRange> ranges = Lists.newArrayList();
    DocumentEvent event = new DocumentEvent();
    event.fDocument = new DummyDocument(expression);
    DocumentTokenSource tokenSource = tokenSourceProvider.get();
    tokenSource.updateStructure(event);
    Iterator<ILexerTokenRegion> iterator = tokenSource.getTokenInfos().iterator();
    while (iterator.hasNext()) {
        ILexerTokenRegion next = iterator.next();
        TextAttribute attribute = attributeProvider.getAttribute(tokenTypeMapper.getId(next.getLexerTokenType()));
        StyleRange range = new StyleRange(next.getOffset(), next.getLength(), attribute.getForeground(),
                attribute.getBackground());
        range.font = attribute.getFont();
        range.fontStyle = attribute.getStyle();
        ranges.add(range);
    }
    return ranges;
}
项目:LogViewer    文件:DamageRepairer.java   
/**
 * Adds style information to the given text presentation.
 *
 * @param presentation the text presentation to be extended
 * @param offset the offset of the range to be styled
 * @param length the length of the range to be styled
 * @param attr the attribute describing the style of the range to be styled
 * @param wholeLine the boolean switch to declare that the whole line should be colored
 */
private void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr, boolean wholeLine) {
    if (attr != null) {
        int style= attr.getStyle();
        int fontStyle= style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL);
        if(wholeLine) {
            try {
                int line = document.getLineOfOffset(offset);
                int start = document.getLineOffset(line);
                length = document.getLineLength(line);
                offset = start;
            } catch (BadLocationException e) {
            }
        }
        StyleRange styleRange = new StyleRange(offset,length,attr.getForeground(),attr.getBackground(),fontStyle);
        styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0;
        styleRange.underline = (style & TextAttribute.UNDERLINE) != 0;
        presentation.addStyleRange(styleRange);
    }
}