Java Code Examples for javax.swing.text.MutableAttributeSet

The following examples show how to use javax.swing.text.MutableAttributeSet. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: wpcleaner   Source File: MWPaneSelectionManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Select previous occurrence of text. 
 */
public void selectPreviousOccurrence() {
  StyledDocument doc = textPane.getStyledDocument();
  int lastStart = Integer.MIN_VALUE;
  for (int pos = textPane.getSelectionStart(); pos > 0; pos = lastStart) {
    Element run = doc.getCharacterElement(pos - 1);
    lastStart = run.getStartOffset();
    MutableAttributeSet attr = (MutableAttributeSet) run.getAttributes();
    if ((attr != null) &&
        (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_TYPE) != null) &&
        (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_OCCURRENCE) != Boolean.FALSE)) {
      select(run);
      return;
    }
  }
  selectLastOccurrence();
}
 
Example 2
Source Project: MeteoInfo   Source File: JConsole.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private AttributeSet setStyle(
        String fontFamilyName,
        int size,
        Color color,
        boolean bold,
        boolean italic,
        boolean underline
) {
    MutableAttributeSet attr = new SimpleAttributeSet();
    if (color != null) {
        StyleConstants.setForeground(attr, color);
    }
    if (fontFamilyName != null) {
        StyleConstants.setFontFamily(attr, fontFamilyName);
    }
    if (size != -1) {
        StyleConstants.setFontSize(attr, size);
    }
    StyleConstants.setBold(attr, bold);
    StyleConstants.setItalic(attr, italic);
    StyleConstants.setUnderline(attr, underline);

    setStyle(attr);

    return getStyle();
}
 
Example 3
Source Project: uima-uimaj   Source File: CasAnnotationViewer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Do bold face by spans.
 */
private void doBoldFaceBySpans() {
  if (this.boldFaceSpans == null || this.boldFaceSpans.length == 0) {
    return;
  }
  int docLength = this.cas.getDocumentText().length();
  int spanLength = this.boldFaceSpans.length - (this.boldFaceSpans.length % 2);
  int i = 0;
  while (i < spanLength) {
    int begin = this.boldFaceSpans[i];
    int end = this.boldFaceSpans[i + 1];
    if (begin >= 0 && begin <= docLength && end >= 0 && end <= docLength && begin < end) {
      MutableAttributeSet attrs = new SimpleAttributeSet();
      StyleConstants.setBold(attrs, true);
      StyledDocument doc = (StyledDocument) this.textPane.getDocument();
      doc.setCharacterAttributes(begin, end - begin, attrs, false);
    }
    i += 2;
  }
}
 
Example 4
Source Project: howsun-javaee-framework   Source File: AnalizeWebParse.java    License: Apache License 2.0 5 votes vote down vote up
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
	if (t == HTML.Tag.IMG) {
		// get a src
		String src = (String) a.getAttribute(HTML.Attribute.SRC);
		if (src == null) {
			return;
		}

		if (Pattern.matches(regex, src)) {
			imgs.add(src);
		}
	}
}
 
Example 5
public boolean set(MutableAttributeSet target, int parameter)
{
    /* See above note in the case that parameter==1 */
    Boolean value = ( parameter != 0 ? True : False );

    target.addAttribute(swingName, value);

    return true; /* true indicates we were successful */
}
 
Example 6
Source Project: openjdk-8   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target)
{
    /* TODO: There's some ambiguity about whether this should
       *set* or *toggle* the attribute. */
    target.addAttribute(swingName, True);

    return true;  /* true indicates we were successful */
}
 
Example 7
public boolean set(MutableAttributeSet target, int parameter)
{
    Number swingValue;

    if (scale == 1f)
        swingValue = Integer.valueOf(parameter);
    else
        swingValue = new Float(parameter / scale);
    target.addAttribute(swingName, swingValue);
    return true;
}
 
Example 8
Source Project: MobyDroid   Source File: JTermDocument.java    License: Apache License 2.0 5 votes vote down vote up
public void write(String text, MutableAttributeSet attrs) {
    try {
        insertString(getLength(), text, attrs);
        limit = getLength();
        caret.setDot(limit);
    } catch (BadLocationException e) {
    }
}
 
Example 9
Source Project: Bytecoder   Source File: RTFAttributes.java    License: Apache License 2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target)
{
    if (swingValue == null)
        target.removeAttribute(swingName);
    else
        target.addAttribute(swingName, swingValue);

    return true;
}
 
Example 10
public
void setFontSize(int size) {
  Enumeration e = attributes.elements();
  while (e.hasMoreElements()) {
    StyleConstants.setFontSize((MutableAttributeSet)e.nextElement(),size);
  }
  return;
}
 
Example 11
Source Project: jdk1.8-source-analysis   Source File: RTFAttributes.java    License: Apache License 2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target, int parameter)
{
    Number swingValue;

    if (scale == 1f)
        swingValue = Integer.valueOf(parameter);
    else
        swingValue = new Float(parameter / scale);
    target.addAttribute(swingName, swingValue);
    return true;
}
 
Example 12
Source Project: openjdk-jdk9   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target)
{
    /* TODO: There's some ambiguity about whether this should
       *set* or *toggle* the attribute. */
    target.addAttribute(swingName, True);

    return true;  /* true indicates we were successful */
}
 
Example 13
Source Project: ObjectLogger   Source File: Html2Text.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    if (stringBuilder.length() != 0
            && t.isBlock()
            && !stringBuilder.toString().endsWith(lineBreak)) {
        stringBuilder.append(lineBreak);
    }
}
 
Example 14
Source Project: netbeans   Source File: JavadocRegistry.java    License: Apache License 2.0 5 votes vote down vote up
public @Override void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    if (t == HTML.Tag.BODY) {
        try {
            this.in.close ();
        } catch (IOException ioe) {/*Ignore it*/}
    }
}
 
Example 15
public boolean set(MutableAttributeSet target, int parameter)
{
    /* See above note in the case that parameter==1 */
    Boolean value = ( parameter != 0 ? True : False );

    target.addAttribute(swingName, value);

    return true; /* true indicates we were successful */
}
 
Example 16
public boolean setDefault(MutableAttributeSet target)
{
    if (swingDefault != rtfDefault ||
        ( target.getAttribute(swingName) != null ) )
      target.addAttribute(swingName, Boolean.valueOf(rtfDefault));
    return true;
}
 
Example 17
public boolean set(MutableAttributeSet target)
{
    /* TODO: There's some ambiguity about whether this should
       *set* or *toggle* the attribute. */
    target.addAttribute(swingName, True);

    return true;  /* true indicates we were successful */
}
 
Example 18
Source Project: jdk8u-jdk   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target)
{
    if (swingValue == null)
        target.removeAttribute(swingName);
    else
        target.addAttribute(swingName, swingValue);

    return true;
}
 
Example 19
public boolean set(MutableAttributeSet target, int parameter)
{
    Number swingValue;

    if (scale == 1f)
        swingValue = Integer.valueOf(parameter);
    else
        swingValue = new Float(parameter / scale);
    target.addAttribute(swingName, swingValue);
    return true;
}
 
Example 20
Source Project: jdk8u-jdk   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean setDefault(MutableAttributeSet target)
{
    if (swingDefault != rtfDefault ||
        ( target.getAttribute(swingName) != null ) )
      target.addAttribute(swingName, Boolean.valueOf(rtfDefault));
    return true;
}
 
Example 21
Source Project: Java8CN   Source File: RTFAttributes.java    License: Apache License 2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target, int parameter)
{
    /* See above note in the case that parameter==1 */
    Boolean value = ( parameter != 0 ? True : False );

    target.addAttribute(swingName, value);

    return true; /* true indicates we were successful */
}
 
Example 22
private static void toggleStyleInSelection(JTextPane textPane, Object style) {
    MutableAttributeSet attrSet = new SimpleAttributeSet();
    // Add or remove the style on the entire selection
    attrSet.addAttribute(style, !hasStyleInSelection(textPane, style));
    textPane.getStyledDocument().setCharacterAttributes(textPane.getSelectionStart(),
            textPane.getSelectionEnd() - textPane.getSelectionStart(),
            attrSet, false);
}
 
Example 23
Source Project: jdk8u-jdk   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target, int parameter)
{
    Number swingValue;

    if (scale == 1f)
        swingValue = Integer.valueOf(parameter);
    else
        swingValue = new Float(parameter / scale);
    target.addAttribute(swingName, swingValue);
    return true;
}
 
Example 24
Source Project: openjdk-jdk8u   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target, int parameter)
{
    Number swingValue;

    if (scale == 1f)
        swingValue = Integer.valueOf(parameter);
    else
        swingValue = new Float(parameter / scale);
    target.addAttribute(swingName, swingValue);
    return true;
}
 
Example 25
Source Project: hottub   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean setDefault(MutableAttributeSet target)
{
    Number old = (Number)target.getAttribute(swingName);
    if (old == null)
        old = swingDefault;
    if (old != null && (
            (scale == 1f && old.intValue() == rtfDefault) ||
            (Math.round(old.floatValue() * scale) == rtfDefault)
       ))
        return true;
    set(target, rtfDefault);
    return true;
}
 
Example 26
Source Project: PolyGlot   Source File: PGrammarPane.java    License: MIT License 5 votes vote down vote up
public void addImage(ImageNode image) {
    try {
        MutableAttributeSet inputAttributes = getInputAttributes();
        inputAttributes.removeAttributes(inputAttributes);
        StyleConstants.setIcon(inputAttributes, new ImageIcon(image.getImagePath()));
        inputAttributes.addAttribute(PGTUtil.IMAGE_ID_ATTRIBUTE, image.getId());
        imageReplaceSelection(" ");
        inputAttributes.removeAttributes(inputAttributes);
    } catch (IOException e) {
        IOHandler.writeErrorLog(e);
        InfoBox.error("Image Insertion Error", "Unable to insert image: "
                + e.getLocalizedMessage(), core.getRootWindow());
    }
}
 
Example 27
Source Project: TencentKona-8   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target, int parameter)
{
    Number swingValue;

    if (scale == 1f)
        swingValue = Integer.valueOf(parameter);
    else
        swingValue = new Float(parameter / scale);
    target.addAttribute(swingName, swingValue);
    return true;
}
 
Example 28
Source Project: Java8CN   Source File: RTFAttributes.java    License: Apache License 2.0 5 votes vote down vote up
public boolean setDefault(MutableAttributeSet target)
{
    if (swingDefault != rtfDefault ||
        ( target.getAttribute(swingName) != null ) )
      target.addAttribute(swingName, Boolean.valueOf(rtfDefault));
    return true;
}
 
Example 29
Source Project: jdk8u-jdk   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target, int parameter)
{
    Number swingValue;

    if (scale == 1f)
        swingValue = Integer.valueOf(parameter);
    else
        swingValue = new Float(parameter / scale);
    target.addAttribute(swingName, swingValue);
    return true;
}
 
Example 30
Source Project: jdk8u_jdk   Source File: RTFAttributes.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean set(MutableAttributeSet target, int parameter)
{
    /* See above note in the case that parameter==1 */
    Boolean value = ( parameter != 0 ? True : False );

    target.addAttribute(swingName, value);

    return true; /* true indicates we were successful */
}