Java 类javax.swing.text.MutableAttributeSet 实例源码

项目:Neukoelln_SER316    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:incubator-netbeans    文件:AttrSetTesting.java   
public static AttrSet add(Context context, Object... keyValuePairs) throws Exception {
    @SuppressWarnings("unchecked")
    List<Item> list = (List<Item>) context.getInstance(List.class);
    MutableAttributeSet expected = new SimpleAttributeSet();
    for (int i = keyValuePairs.length; i > 0;) {
        Object value = keyValuePairs[--i];
        Object key = keyValuePairs[--i];
        expected.addAttribute(key, value);
    }
    AttrSet attrSet = AttrSet.get(keyValuePairs);
    Item item = new Item(expected, attrSet);
    list.add(item);
    StringBuilder sb = context.logOpBuilder();
    if (sb != null) {
        sb.append("Add[").append(list.size() - 1).append("]: ").append(expected);
        context.logOp(sb);
    }
    return attrSet;
}
项目:incubator-netbeans    文件:ButtonsHTMLParser.java   
@Override
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    String tag = t.toString();
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "StartTag <{0}> with attributes: {1}",
                   new Object[]{ tag, Collections.list(a.getAttributeNames()).toString() });
    }
    if (TAG_TITLE.equalsIgnoreCase(tag)) {
        readingTitle = true;
        return ;
    } else {
        readingTitle = false;
    }
    if (TAG_FORM.equalsIgnoreCase(tag)) {
        readingForm = true;
        inputs.clear();
        inputs.add(new SimpleAttributeSet(a));
        return ;
    }
    if (readingForm) {
        if (TAG_INPUT.equalsIgnoreCase(tag)) {
            inputs.add(new SimpleAttributeSet(a));
        }
    }
}
项目:incubator-netbeans    文件:SearchThreadJdk12.java   
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;*/
                // Ignore formatting
            }
            else {
                where = IN_BALAST;
            }
        }
项目:incubator-netbeans    文件:SearchThreadJdk12_japan.java   
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;
            }
        }
项目:incubator-netbeans    文件:JavadocRegistry.java   
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;                                
                    }
                }
            }
        }
    }
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:SER316-Munich    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:SER316-Ingolstadt    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:Tarski    文件:OurSyntaxDocument.java   
/** Changes the font and tabsize for the document. */
public final void do_setFont(String fontName, int fontSize, int tabSize) {
   if (tabSize < 1) tabSize = 1; else if (tabSize > 100) tabSize = 100;
   if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize) return;
   this.font = fontName;
   this.fontSize = fontSize;
   this.tabSize = tabSize;
   for(MutableAttributeSet s: all) { StyleConstants.setFontFamily(s, fontName);  StyleConstants.setFontSize(s, fontSize); }
   do_reapplyAll();
   BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); // this is used to derive the tab width
   int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
   TabStop[] pos = new TabStop[100];
   for(int i=0; i<100; i++) { pos[i] = new TabStop(i*gap + gap); }
   StyleConstants.setTabSet(tabset, new TabSet(pos));
   setParagraphAttributes(0, getLength(), tabset, false);
}
项目:Wilmersdorf_SER316    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:Reinickendorf_SER316    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:Dahlem_SER316    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:SER316-Aachen    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:spring16project-Modula-2    文件:AltHTMLWriter.java   
/**
 * Create/update an HTML &lt;font&gt; tag attribute.  The
 * value of the attribute should be a MutableAttributeSet so
 * that the attributes can be updated as they are discovered.
 */
private static void createFontAttribute(CSS.Attribute a, AttributeSet from, MutableAttributeSet to) {
    MutableAttributeSet fontAttr = (MutableAttributeSet) to.getAttribute(HTML.Tag.FONT);
    if (fontAttr == null) {
        fontAttr = new SimpleAttributeSet();
        to.addAttribute(HTML.Tag.FONT, fontAttr);
    }
    // edit the parameters to the font tag
    String htmlValue = from.getAttribute(a).toString();
    if (a == CSS.Attribute.FONT_FAMILY) {
        fontAttr.addAttribute(HTML.Attribute.FACE, htmlValue);
    }
    else if (a == CSS.Attribute.FONT_SIZE) {
        fontAttr.addAttribute(HTML.Attribute.SIZE, htmlValue);
    }
    else if (a == CSS.Attribute.COLOR) {
        fontAttr.addAttribute(HTML.Attribute.COLOR, htmlValue);
    }
}
项目:javify    文件:HTMLDocument.java   
public void start(HTML.Tag tag, MutableAttributeSet atts)
{
  pushCharacterStyle();
  charAttr.addAttribute(tag, atts.copyAttributes());
  StyleSheet styleSheet = getStyleSheet();
  // TODO: Add other tags here.
  if (tag == HTML.Tag.FONT)
    {
      String color = (String) atts.getAttribute(HTML.Attribute.COLOR);
      if (color != null)
        styleSheet.addCSSAttribute(charAttr, CSS.Attribute.COLOR, color);
      String face = (String) atts.getAttribute(HTML.Attribute.FACE);
      if (face != null)
        styleSheet.addCSSAttribute(charAttr, CSS.Attribute.FONT_FAMILY,
                                   face);
      String size = (String) atts.getAttribute(HTML.Attribute.SIZE);
      if (size != null)
        styleSheet.addCSSAttribute(charAttr, CSS.Attribute.FONT_SIZE,
                                   size);
    }
}
项目:javify    文件:HTMLDocument.java   
/**
 * Adds content that is specified in the attribute set.
 *
 * @param t the HTML.Tag
 * @param a the attribute set specifying the special content
 */
protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
{
  if (t != HTML.Tag.FRAME && ! inParagraph())
    {
      blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
    }

  a.addAttribute(StyleConstants.NameAttribute, t);

  // The two spaces are required because some special elements like HR
  // must be broken. At least two characters are needed to break into the
  // two parts.
  DefaultStyledDocument.ElementSpec spec =
    new DefaultStyledDocument.ElementSpec(a.copyAttributes(),
      DefaultStyledDocument.ElementSpec.ContentType,
      new char[] {' '}, 0, 1 );
  parseBuffer.add(spec);
}
项目:javify    文件:HTMLDocument.java   
/**
 * This is a callback from the parser that should be routed to the
 * appropriate handler for the tag.
 *
 * @param t the HTML.Tag that was encountered
 * @param a the attribute set
 * @param pos the position at which the tag was encountered
 */
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos)
{
  if (t == insertTag)
    insertTagEncountered = true;

  if (shouldInsert())
    {
      TagAction action = (TagAction) tagToAction.get(t);
      if (action != null)
        {
          action.start(t, a);
          action.end(t);
        }
    }
}
项目:javify    文件:HTMLDocument.java   
/**
 * Adds the given text that was encountered in a <PRE> element.
 * This adds synthesized lines to hold the text runs.
 *
 * @param data the text
 */
protected void preContent(char[] data)
{
  int start = 0;
  for (int i = 0; i < data.length; i++)
    {
      if (data[i] == '\n')
        {
          addContent(data, start, i - start + 1);
          blockClose(HTML.Tag.IMPLIED);
          MutableAttributeSet atts = new SimpleAttributeSet();
          atts.addAttribute(CSS.Attribute.WHITE_SPACE, "pre");
          blockOpen(HTML.Tag.IMPLIED, atts);
          start = i + 1;
        }
    }
  if (start < data.length)
    {
      // Add remaining last line.
      addContent(data, start, data.length - start);
    }
}
项目:spring16project-Fortran    文件:AltHTMLWriter.java   
/**
 * Create/update an HTML &lt;font&gt; tag attribute. The value of the
 * attribute should be a MutableAttributeSet so that the attributes can be
 * updated as they are discovered.
 */
private static void createFontAttribute(CSS.Attribute a, AttributeSet from, MutableAttributeSet to) {
    MutableAttributeSet fontAttr = (MutableAttributeSet) to.getAttribute(HTML.Tag.FONT);
    if (fontAttr == null) {
        fontAttr = new SimpleAttributeSet();
        to.addAttribute(HTML.Tag.FONT, fontAttr);
    }
    // edit the parameters to the font tag
    String htmlValue = from.getAttribute(a).toString();
    if (a == CSS.Attribute.FONT_FAMILY) {
        fontAttr.addAttribute(HTML.Attribute.FACE, htmlValue);
    } else if (a == CSS.Attribute.FONT_SIZE) {
        fontAttr.addAttribute(HTML.Attribute.SIZE, htmlValue);
    } else if (a == CSS.Attribute.COLOR) {
        fontAttr.addAttribute(HTML.Attribute.COLOR, htmlValue);
    }
}
项目:spring16project-Fortran    文件:AltHTMLWriter.java   
/**
 * Copies the given AttributeSet to a new set, converting any CSS attributes
 * found to arguments of an HTML style attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        } else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
项目:SweetHome3D    文件:HelpController.java   
@Override
public void handleStartTag(HTML.Tag tag, MutableAttributeSet att, int pos)
{
    if (tag.equals(HTML.Tag.A))
    { // <a href=...> tag
        String attribute = (String) att.getAttribute(HTML.Attribute.HREF);
        if (attribute != null)
        {
            addReferencedDocument(attribute);
        }
    }
    else if (tag.equals(HTML.Tag.TITLE))
    {
        this.inTitle = true;
    }
}
项目:crawler-java    文件:Crawler.java   
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    String href = (String) a.getAttribute(HTML.Attribute.HREF);

    if ((href == null) && (t == HTML.Tag.FRAME))
        href = (String) a.getAttribute(HTML.Attribute.SRC);

    if (href == null)
        return;

    int i = href.indexOf('#');
    if (i != -1)
        href = href.substring(0, i);

    if (href.toLowerCase().startsWith("mailto:"))
        return;

    handleLink(base, href);
}
项目:javify    文件:JTextPane.java   
/**
 * Sets text attributes for the current selection. If there is no selection
 * the text attributes are applied to newly inserted text
 *
 * @param attribute the text attributes to set
 * @param replace if <code>true</code>, the attributes of the current
 *     selection are overridden, otherwise they are merged
 *
 * @see #getInputAttributes
 */
public void setCharacterAttributes(AttributeSet attribute,
                                   boolean replace)
{
  int dot = getCaret().getDot();
  int start = getSelectionStart();
  int end = getSelectionEnd();
  if (start == dot && end == dot)
    // There is no selection, update insertAttributes instead
    {
      MutableAttributeSet inputAttributes =
        getStyledEditorKit().getInputAttributes();
      if (replace)
        inputAttributes.removeAttributes(inputAttributes);
      inputAttributes.addAttributes(attribute);
    }
  else
    getStyledDocument().setCharacterAttributes(start, end - start, attribute,
                                               replace);
}
项目:javify    文件:HTMLDocument.java   
/**
 * Updates the frame that is represented by the specified element to
 * refer to the specified URL.
 *
 * @param el the element
 * @param url the new url
 */
private void updateFrame(Element el, URL url)
{
  try
    {
      writeLock();
      DefaultDocumentEvent ev =
        new DefaultDocumentEvent(el.getStartOffset(), 1,
                                 DocumentEvent.EventType.CHANGE);
      AttributeSet elAtts = el.getAttributes();
      AttributeSet copy = elAtts.copyAttributes();
      MutableAttributeSet matts = (MutableAttributeSet) elAtts;
      ev.addEdit(new AttributeUndoableEdit(el, copy, false));
      matts.removeAttribute(HTML.Attribute.SRC);
      matts.addAttribute(HTML.Attribute.SRC, url.toString());
      ev.end();
      fireChangedUpdate(ev);
      fireUndoableEditUpdate(new UndoableEditEvent(this, ev));
    }
  finally
    {
      writeUnlock();
    }
}
项目:Neukoelln_SER316    文件:AltHTMLWriter.java   
/**
 * Convert the give set of attributes to be html for
 * the purpose of writing them out.  Any keys that
 * have been converted will not appear in the resultant
 * set.  Any keys not converted will appear in the
 * resultant set the same as the received set.<p>
 * This will put the converted values into <code>to</code>, unless
 * it is null in which case a temporary AttributeSet will be returned.
 */
AttributeSet convertToHTML(AttributeSet from, MutableAttributeSet to) {
    if (to == null) {
        to = convAttr;
    }
    to.removeAttributes(to);
    if (writeCSS) {
        convertToHTML40(from, to);
    }
    else {
        convertToHTML32(from, to);
    }
    return to;
}
项目:incubator-netbeans    文件:AttrSetTesting.java   
public static void merge(Context context, int... indexes) throws Exception {
    @SuppressWarnings("unchecked")
    List<Item> list = (List<Item>) context.getInstance(List.class);
    StringBuilder sb = context.logOpBuilder();
    if (sb != null) {
        sb.append("Merge[");
    }
    MutableAttributeSet mutableAttributeSet = new SimpleAttributeSet();
    AttrSet[] attrSets = new AttrSet[indexes.length];
    for (int i = indexes.length - 1; i >= 0; i--) {
        int index = indexes[i];
        if (sb != null) {
            if (i > 0) {
                sb.append(',');
            }
            sb.append(index);
        }
        Item item = list.get(index);
        attrSets[i] = item.attrSet;
        mutableAttributeSet.addAttributes(item.expected);
    }
    AttrSet mergedAttrSet = AttrSet.merge(attrSets);
    Item mergedItem = new Item(mutableAttributeSet, mergedAttrSet);
    list.add(mergedItem);

    if (sb != null) {
        sb.append("]\n");
        context.logOp(sb);
    }
}
项目:incubator-netbeans    文件:ButtonsHTMLParser.java   
@Override
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    String tag = t.toString();
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "SimpleTag <{0}> with attributes: {1}",
                   new Object[]{tag, Collections.list(a.getAttributeNames()).toString()});
    }
    if (readingForm) {
        if (TAG_INPUT.equalsIgnoreCase(tag)) {
            inputs.add(new SimpleAttributeSet(a));
        }
    }
}
项目:incubator-netbeans    文件:JavadocRegistry.java   
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*/}
    }
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Convert the give set of attributes to be html for
 * the purpose of writing them out.  Any keys that
 * have been converted will not appear in the resultant
 * set.  Any keys not converted will appear in the
 * resultant set the same as the received set.<p>
 * This will put the converted values into <code>to</code>, unless
 * it is null in which case a temporary AttributeSet will be returned.
 */
AttributeSet convertToHTML(AttributeSet from, MutableAttributeSet to) {
    if (to == null) {
        to = convAttr;
    }
    to.removeAttributes(to);
    if (writeCSS) {
        convertToHTML40(from, to);
    }
    else {
        convertToHTML32(from, to);
    }
    return to;
}
项目:org.alloytools.alloy    文件:OurConsole.java   
/**
 * Helper method that construct a mutable style with the given font name,
 * font size, boldness, color, and left indentation.
 */
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, Color color, int leftIndent) {
    MutableAttributeSet s = new SimpleAttributeSet();
    StyleConstants.setFontFamily(s, fontName);
    StyleConstants.setFontSize(s, fontSize);
    StyleConstants.setBold(s, boldness);
    StyleConstants.setForeground(s, color);
    StyleConstants.setLeftIndent(s, leftIndent);
    return s;
}
项目:org.alloytools.alloy    文件:OurSyntaxDocument.java   
/** Changes the font and tabsize for the document. */
public final void do_setFont(String fontName, int fontSize, int tabSize) {
    if (tabSize < 1)
        tabSize = 1;
    else if (tabSize > 100)
        tabSize = 100;
    if (fontName.equals(this.font) && fontSize == this.fontSize && tabSize == this.tabSize)
        return;
    this.font = fontName;
    this.fontSize = fontSize;
    this.tabSize = tabSize;
    for (MutableAttributeSet s : all) {
        StyleConstants.setFontFamily(s, fontName);
        StyleConstants.setFontSize(s, fontSize);
    }
    do_reapplyAll();
    BufferedImage im = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); // this
                                                                                // is
                                                                                // used
                                                                                // to
                                                                                // derive
                                                                                // the
                                                                                // tab
                                                                                // width
    int gap = tabSize * im.createGraphics().getFontMetrics(new Font(fontName, Font.PLAIN, fontSize)).charWidth('X');
    TabStop[] pos = new TabStop[100];
    for (int i = 0; i < 100; i++) {
        pos[i] = new TabStop(i * gap + gap);
    }
    StyleConstants.setTabSet(tabset, new TabSet(pos));
    setParagraphAttributes(0, getLength(), tabset, false);
}
项目:gate-core    文件:HtmlDocumentHandler.java   
/** This method is called when the HTML parser encounts an empty tag
  */
@Override
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos){
  // fire the status listener if the elements processed exceded the rate
  if ((++elements % ELEMENTS_RATE) == 0)
    fireStatusChangedEvent("Processed elements : " + elements);

  // construct a feature map from the attributes list
  // these are empty elements
  FeatureMap fm = Factory.newFeatureMap();

  // take all the attributes an put them into the feature map
  if (0 != a.getAttributeCount ()){

     // Out.println("HAS  attributes = " + a.getAttributeCount ());
      Enumeration<?> enumeration = a.getAttributeNames ();
      while (enumeration.hasMoreElements ()){
        Object attribute = enumeration.nextElement ();
        fm.put ( attribute.toString(),(a.getAttribute(attribute)).toString());

      }//while

  }//if

  // create the start index of the annotation
  Long startIndex = new Long(tmpDocContent.length());

  // initialy the start index is equal with the End index
  CustomObject obj = new CustomObject(t.toString(),fm,startIndex,startIndex);

  // we add the object directly into the colector
  // we don't add it to the stack because this is an empty tag
  colector.add(obj);

  // Just analize the tag t and add some\n chars and spaces to the
  // tmpDocContent.The reason behind is that we need to have a readable form
  // for the final document.
  customizeAppearanceOfDocumentWithSimpleTag(t);

}
项目:SER316-Munich    文件:AltHTMLWriter.java   
/**
 * Convert the give set of attributes to be html for
 * the purpose of writing them out.  Any keys that
 * have been converted will not appear in the resultant
 * set.  Any keys not converted will appear in the
 * resultant set the same as the received set.<p>
 * This will put the converted values into <code>to</code>, unless
 * it is null in which case a temporary AttributeSet will be returned.
 */
AttributeSet convertToHTML(AttributeSet from, MutableAttributeSet to) {
    if (to == null) {
        to = convAttr;
    }
    to.removeAttributes(to);
    if (writeCSS) {
        convertToHTML40(from, to);
    }
    else {
        convertToHTML32(from, to);
    }
    return to;
}
项目:OpenJSharp    文件:RTFAttributes.java   
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 */
}
项目:OpenJSharp    文件:RTFAttributes.java   
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 */
}
项目:OpenJSharp    文件:RTFAttributes.java   
public boolean setDefault(MutableAttributeSet target)
{
    if (swingDefault != rtfDefault ||
        ( target.getAttribute(swingName) != null ) )
      target.addAttribute(swingName, Boolean.valueOf(rtfDefault));
    return true;
}
项目:OpenJSharp    文件:RTFAttributes.java   
public boolean set(MutableAttributeSet target)
{
    if (swingValue == null)
        target.removeAttribute(swingName);
    else
        target.addAttribute(swingName, swingValue);

    return true;
}
项目:OpenJSharp    文件:RTFAttributes.java   
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;
}
项目:OpenJSharp    文件:RTFAttributes.java   
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;
}