Java Code Examples for javax.swing.text.MutableAttributeSet#getAttribute()

The following examples show how to use javax.swing.text.MutableAttributeSet#getAttribute() . 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 File: MWPaneSelectionManager.java    From wpcleaner with Apache License 2.0 6 votes vote down vote up
/**
 * Select last occurrence of text. 
 */
public void selectLastOccurrence() {
  StyledDocument doc = textPane.getStyledDocument();
  int lastStart = Integer.MIN_VALUE;
  for (int pos = doc.getLength(); 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;
    }
  }
}
 
Example 2
Source File: JavadocRegistry.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    if (t == HTML.Tag.META) {
        String value = (String) a.getAttribute(HTML.Attribute.CONTENT);
        if (value != null) {
            StringTokenizer tk = new StringTokenizer(value,";"); // NOI18N
            while (tk.hasMoreTokens()) {
                String str = tk.nextToken().trim();
                if (str.startsWith("charset")) {        //NOI18N
                    str = str.substring(7).trim();
                    if (str.charAt(0)=='=') {
                        this.encoding = str.substring(1).trim();
                        try {
                            this.in.close();
                        } catch (IOException ioe) {/*Ignore it*/}
                        return;                                
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: SearchThreadJdk12_japan.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {

            if ( t == HTML.Tag.DT ) {
                where = IN_DT;
                currentDii = null;
            }
            else if ( t == HTML.Tag.A && where == IN_DT ) {
                where = IN_AREF;
                Object val = a.getAttribute( HTML.Attribute.HREF );
                if ( val != null ) {
                    hrefVal = val.toString();
                    currentDii = new DocIndexItem( null, null, contextURL, hrefVal );
                }
            }
            else if ( t == HTML.Tag.A && (where == IN_DESCRIPTION_SUFFIX || where == IN_DESCRIPTION) ) {
                // Just ignore
            }
            else if ( (t == HTML.Tag.B || t == HTML.Tag.SPAN) && where == IN_AREF ) {
                where = IN_AREF;
            }
            else {
                where = IN_BALAST;
            }
        }
 
Example 4
Source File: AnalizeWebParse.java    From howsun-javaee-framework with Apache License 2.0 6 votes vote down vote up
public void handleStartTag(HTML.Tag tag, MutableAttributeSet attribs, int pos) {

		if (finished == true) {
			return;
		}

		if (start == false) {
			if (tag == HTML.Tag.DIV) {
				String cla = (String) attribs.getAttribute(HTML.Attribute.CLASS);
				if (cla == null) {
					return;
				}

				if (cla.indexOf("body") != -1) {
					// Start
					start = true;
				}
			}
		}
	}
 
Example 5
Source File: Results.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public void handleStartTag(HTML.Tag tag, MutableAttributeSet attrs, int pos) {
  if (allResults.hasNext() && HTML.Tag.TR.equals(tag)) {
    Object rawAttr = attrs.getAttribute(HTML.Attribute.CLASS);
    if (rawAttr != null) {
      String classes = String.valueOf(rawAttr);
      if (classes.contains(toSubstitute)) {
        String result = allResults.next();
        originals.add(classes);
        substitutions.add(classes.replace(toSubstitute, result));
        tagPositions.add(pos);
      }
    }
  }
}
 
Example 6
Source File: RTFAttributes.java    From jdk1.8-source-analysis with 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 7
Source File: RTFAttributes.java    From openjdk-jdk8u-backup with 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 8
Source File: RTFAttributes.java    From jdk8u-jdk with 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 9
Source File: RTFAttributes.java    From openjdk-jdk8u with 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 10
Source File: RTFAttributes.java    From jdk8u-dev-jdk with 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 11
Source File: RTFAttributes.java    From JDKSourceCode1.8 with MIT License 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 12
Source File: RTFAttributes.java    From JDKSourceCode1.8 with MIT License 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 13
Source File: RTFAttributes.java    From jdk8u60 with 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 14
Source File: HTMLSuiteResult.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public void handleStartTag(Tag tag, MutableAttributeSet attributes, int pos) {
  if (Tag.A.equals(tag)) {
    String href = (String) attributes.getAttribute(HTML.Attribute.HREF);
    hrefList.add(href.replace('\\', '/'));
    tagPositions.add(pos);
  }
}
 
Example 15
Source File: RTFAttributes.java    From openjdk-8 with 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 16
Source File: RTFAttributes.java    From TencentKona-8 with 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 17
Source File: RTFAttributes.java    From Java8CN with 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 18
Source File: RTFAttributes.java    From openjdk-8 with 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 19
Source File: RTFAttributes.java    From openjdk-jdk9 with 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 20
Source File: MWPaneReplaceAllAction.java    From wpcleaner with Apache License 2.0 4 votes vote down vote up
/**
 * @param e Event.
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
@Override
public void actionPerformed(ActionEvent e) {
  MWPane textPane = getMWPane(e);
  if (textPane == null) {
    return;
  }
  StyledDocument doc = textPane.getStyledDocument();
  if (doc == null) {
    return;
  }
  int length = doc.getLength();
  int lastEnd = Integer.MAX_VALUE;
  for (int pos = 0; pos < length; pos = lastEnd) {
    try {
      Element run = doc.getCharacterElement(pos);
      lastEnd = run.getEndOffset();
      if (pos == lastEnd) {
        // offset + length beyond length of document, bail.
        break;
      }
      MutableAttributeSet attr = (MutableAttributeSet) run.getAttributes();
      if ((attr != null) &&
          (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_TYPE) != null) &&
          (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_INFO) != null)) {
        Object attrInfo = attr.getAttribute(MWPaneFormatter.ATTRIBUTE_INFO);
        if (attrInfo instanceof CheckErrorResult) {
          int startOffset = MWPaneFormatter.getUUIDStartOffset(textPane, run);
          int endOffset = MWPaneFormatter.getUUIDEndOffet(textPane, run);
          if (originalText.equals(textPane.getText(startOffset, endOffset - startOffset))) {
            boolean possible = false;
            CheckErrorResult info = (CheckErrorResult) attrInfo;
            List<Actionnable> actionnables = info.getPossibleActions();
            if (actionnables != null) {
              for (Actionnable actionnable : actionnables) {
                possible |= actionnable.isPossibleReplacement(newText);
              }
            }
            if (possible) {
              doc.remove(startOffset, endOffset - startOffset);
              doc.insertString(startOffset, newText, attr);
              lastEnd = startOffset + newText.length();
            }
          }
        }
      }
    } catch (BadLocationException exception) {
      // Nothing to do
    }
  }
}