private void updateTemplateFromEditor(PrintfTemplate template) {
    ArrayList params = new ArrayList();
    String format = null;
    int text_length = editorPane.getDocument().getLength();
    try {
      format = editorPane.getDocument().getText(0, text_length);
    } catch (BadLocationException ex1) {
    }
    Element section_el = editorPane.getDocument().getDefaultRootElement();
    // Get number of paragraphs.
    int num_para = section_el.getElementCount();
    for (int p_count = 0; p_count < num_para; p_count++) {
      Element para_el = section_el.getElement(p_count);
      // Enumerate the content elements
      int num_cont = para_el.getElementCount();
      for (int c_count = 0; c_count < num_cont; c_count++) {
        Element content_el = para_el.getElement(c_count);
        AttributeSet attr = content_el.getAttributes();
        // Get the name of the style applied to this content element; may be null
        String sn = (String) attr.getAttribute(StyleConstants.NameAttribute);
        // Check if style name match
        if (sn != null && sn.startsWith("Parameter")) {
          // we extract the label.
          JLabel l = (JLabel) StyleConstants.getComponent(attr);
          if (l != null) {
            params.add(l.getName());
          }
        }
      }
    }

    template.setFormat(format);
    template.setTokens(params);
  }
 @Override
 public void mouseClicked(MouseEvent me) {
   Element el = doc.getCharacterElement(viewToModel(me.getPoint()));
   if (el == null) return;
   AttributeSet as = el.getAttributes();
   if (as.isDefined("ip")) {
     String ip = (String) as.getAttribute("ip");
     ScriptException se = (ScriptException) as.getAttribute("exception");
     Node node = net.getAtIP(ip);
     if (node == null) {
       Utility.displayError("Error", "Computer does not exist");
       return;
     }
     String errorString =
         "--ERROR--\n"
             + "Error at line number "
             + se.getLineNumber()
             + " and column number "
             + se.getColumnNumber()
             + "\n"
             + se.getMessage();
     new ScriptDialog(
             parentFrame,
             str -> {
               if (str != null) {
                 node.setScript(str);
               }
             },
             node.getScript(),
             errorString)
         .setVisible(true);
   }
 }
  /**
   * Performs layout for the minor axis of the box (i.e. the axis orthogonal to the axis that it
   * represents). The results of the layout (the offset and span for each children) are placed in
   * the given arrays which represent the allocations to the children along the minor axis.
   *
   * @param targetSpan the total span given to the view, which would be used to layout the children.
   * @param axis the axis being layed out
   * @param offsets the offsets from the origin of the view for each of the child views; this is a
   *     return value and is filled in by the implementation of this method
   * @param spans the span of each child view; this is a return value and is filled in by the
   *     implementation of this method
   */
  protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
    int n = getViewCount();
    Object key = (axis == X_AXIS) ? CSS.Attribute.WIDTH : CSS.Attribute.HEIGHT;
    for (int i = 0; i < n; i++) {
      View v = getView(i);
      int min = (int) v.getMinimumSpan(axis);
      int max;

      // check for percentage span
      AttributeSet a = v.getAttributes();
      CSS.LengthValue lv = (CSS.LengthValue) a.getAttribute(key);
      if ((lv != null) && lv.isPercentage()) {
        // bound the span to the percentage specified
        min = Math.max((int) lv.getValue(targetSpan), min);
        max = min;
      } else {
        max = (int) v.getMaximumSpan(axis);
      }

      // assign the offset and span for the child
      if (max < targetSpan) {
        // can't make the child this wide, align it
        float align = v.getAlignment(axis);
        offsets[i] = (int) ((targetSpan - max) * align);
        spans[i] = max;
      } else {
        // make it the target width, or as small as it can get.
        offsets[i] = 0;
        spans[i] = Math.max(min, targetSpan);
      }
    }
  }
  /**
   * Highlight lines to start or end delimiter.
   *
   * @param content the content to parse
   * @param line the line number
   * @throws BadLocationException if offsets are wrong
   */
  protected void highlightLinesAfter(String content, int line) throws BadLocationException {
    int offset = m_RootElement.getElement(line).getEndOffset();

    // Start/End delimiter not found, nothing to do

    int startDelimiter = -1;
    int endDelimiter = -1;
    if (getMultiLineComment()) {
      startDelimiter = indexOf(content, getMultiLineCommentStart(), offset);
      endDelimiter = indexOf(content, getMultiLineCommentEnd(), offset);
    }

    if (startDelimiter < 0) startDelimiter = content.length();

    if (endDelimiter < 0) endDelimiter = content.length();

    int delimiter = Math.min(startDelimiter, endDelimiter);

    if (delimiter < offset) return;

    // Start/End delimiter found, reapply highlighting

    int endLine = m_RootElement.getElementIndex(delimiter);

    for (int i = line + 1; i < endLine; i++) {
      Element branch = m_RootElement.getElement(i);
      Element leaf = m_Self.getCharacterElement(branch.getStartOffset());
      AttributeSet as = leaf.getAttributes();

      if (as.isEqual(DEFAULT_COMMENT)) applyHighlighting(content, i);
    }
  }
 /*    */ public void translate(ClassGenerator classGen, MethodGenerator methodGen) /*    */ {
   /* 88 */ ConstantPoolGen cpg = classGen.getConstantPool();
   /* 89 */ InstructionList il = methodGen.getInstructionList();
   /* 90 */ SymbolTable symbolTable = getParser().getSymbolTable();
   /*    */
   /* 93 */ for (int i = 0; i < this._sets.size(); i++)
   /*    */ {
     /* 95 */ QName name = (QName) this._sets.elementAt(i);
     /*    */
     /* 97 */ AttributeSet attrs = symbolTable.lookupAttributeSet(name);
     /*    */
     /* 99 */ if (attrs != null) {
       /* 100 */ String methodName = attrs.getMethodName();
       /* 101 */ il.append(classGen.loadTranslet());
       /* 102 */ il.append(methodGen.loadDOM());
       /* 103 */ il.append(methodGen.loadIterator());
       /* 104 */ il.append(methodGen.loadHandler());
       /* 105 */ il.append(methodGen.loadCurrentNode());
       /* 106 */ int method =
           cpg.addMethodref(
               classGen.getClassName(),
               methodName,
               "(Lcom/sun/org/apache/xalan/internal/xsltc/DOM;Lcom/sun/org/apache/xml/internal/dtm/DTMAxisIterator;Lcom/sun/org/apache/xml/internal/serializer/SerializationHandler;I)V");
       /*    */
       /* 108 */ il.append(new INVOKESPECIAL(method));
       /*    */ }
     /*    */ else
     /*    */ {
       /* 112 */ Parser parser = getParser();
       /* 113 */ String atrs = name.toString();
       /* 114 */ reportError(this, parser, "ATTRIBSET_UNDEF_ERR", atrs);
       /*    */ }
     /*    */ }
   /*    */ }
  /*
    Iterates through the element tree and prints
    out each element and its attributes.
  */
  private void dumpTree() {

    Element elem;
    while (true) {
      if ((elem = next()) != null) {
        System.out.println("elem: " + elem.getName());
        AttributeSet attr = elem.getAttributes();
        String s = "";
        Enumeration names = attr.getAttributeNames();
        while (names.hasMoreElements()) {
          Object key = names.nextElement();
          Object value = attr.getAttribute(key);
          if (value instanceof AttributeSet) {
            // don't go recursive
            s = s + key + "=**AttributeSet** ";
          } else {
            s = s + key + "=" + value + " ";
          }
        }
        System.out.println("attributes: " + s);
      } else {
        break;
      }
    }
  }
  /**
   * Searches for embedded tags in the AttributeSet and writes them out. It also stores these tags
   * in a vector so that when appropriate the corresponding end tags can be written out.
   *
   * @exception IOException on any I/O error
   */
  protected void writeEmbeddedTags(AttributeSet attr) throws IOException {

    // translate css attributes to html
    attr = convertToHTML(attr, oConvAttr);

    Enumeration names = attr.getAttributeNames();
    while (names.hasMoreElements()) {
      Object name = names.nextElement();
      if (name instanceof HTML.Tag) {
        HTML.Tag tag = (HTML.Tag) name;
        if (tag == HTML.Tag.FORM || tags.contains(tag)) {
          continue;
        }
        write('<');
        write(tag.toString());
        Object o = attr.getAttribute(tag);
        if (o != null && o instanceof AttributeSet) {
          writeAttributes((AttributeSet) o);
        }
        write('>');
        tags.addElement(tag);
        tagValues.addElement(o);
      }
    }
  }
Exemple #8
0
  private void getAttributes(final Node node) {
    final AttributeSet attributeSet = new AttributeSet(node);

    // None as yet.

    attributeSet.validate(); // look for any unsupported attributes
  }
 /** Is this image within a link? */
 boolean isLink() {
   // ! It would be nice to cache this but in an editor it can change
   // See if I have an HREF attribute courtesy of the enclosing A tag:
   AttributeSet anchorAttr = (AttributeSet) fElement.getAttributes().getAttribute(HTML.Tag.A);
   if (anchorAttr != null) {
     return anchorAttr.isDefined(HTML.Attribute.HREF);
   }
   return false;
 }
 /** Print the given AttributeSet as a sequence of assignment-like strings, e.g. "key=value". */
 protected void writeAttributes(AttributeSet attrs) throws IOException {
   Enumeration e = attrs.getAttributeNames();
   while (e.hasMoreElements()) {
     Object name = e.nextElement();
     Object val = attrs.getAttribute(name);
     write(name + "=" + val);
     writeLineSeparator();
   }
 }
 /**
  * Writes out comments.
  *
  * @param elem an Element
  * @exception IOException on any I/O error
  * @exception BadLocationException if pos represents an invalid location within the document.
  */
 protected void comment(Element elem) throws BadLocationException, IOException {
   AttributeSet as = elem.getAttributes();
   if (matchNameAttribute(as, HTML.Tag.COMMENT)) {
     Object comment = as.getAttribute(HTML.Attribute.COMMENT);
     if (comment instanceof String) {
       writeComment((String) comment);
     } else {
       writeComment(null);
     }
   }
 }
 @Override
 public void mouseMoved(MouseEvent me) {
   Element el = doc.getCharacterElement(viewToModel(me.getPoint()));
   if (el == null) return;
   AttributeSet as = el.getAttributes();
   if (as.isDefined("ip")) {
     setCursor(handCursor);
   } else {
     setCursor(defaultCursor);
   }
 }
Exemple #13
0
 /**
  * Checks whether the hyperlink event originated on a <a ...> element with a relative href
  * consisting of a URL fragment only, i.e. <a href="#thisIsALocalFragment">. If so, replies the
  * fragment, i.e. "thisIsALocalFragment".
  *
  * <p>Otherwise, replies null
  *
  * @param e the hyperlink event
  * @return the local fragment
  */
 protected String getUrlFragment(HyperlinkEvent e) {
   AttributeSet set = e.getSourceElement().getAttributes();
   Object value = set.getAttribute(Tag.A);
   if (value == null || !(value instanceof SimpleAttributeSet)) return null;
   SimpleAttributeSet atts = (SimpleAttributeSet) value;
   value = atts.getAttribute(javax.swing.text.html.HTML.Attribute.HREF);
   if (value == null) return null;
   String s = (String) value;
   if (s.matches("#.*")) return s.substring(1);
   return null;
 }
  /**
   * Searches the attribute set for a tag, both of which are passed in as a parameter. Returns true
   * if no match is found and false otherwise.
   */
  private boolean noMatchForTagInAttributes(AttributeSet attr, HTML.Tag t, Object tagValue) {
    if (attr != null && attr.isDefined(t)) {
      Object newValue = attr.getAttribute(t);

      if ((tagValue == null)
          ? (newValue == null)
          : (newValue != null && tagValue.equals(newValue))) {
        return false;
      }
    }
    return true;
  }
 /**
  * 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);
   }
 }
 /** Look up an integer-valued attribute. <b>Not</b> recursive. */
 private int getIntAttr(HTML.Attribute name, int deflt) {
   AttributeSet attr = fElement.getAttributes();
   if (attr.isDefined(name)) { // does not check parents!
     int i;
     String val = (String) attr.getAttribute(name);
     if (val == null) i = deflt;
     else
       try {
         i = Math.max(0, Integer.parseInt(val));
       } catch (NumberFormatException x) {
         i = deflt;
       }
     return i;
   } else return deflt;
 }
 /**
  * Determines if the HTML.Tag associated with the element is a block tag.
  *
  * @param attr an AttributeSet
  * @return true if tag is block tag, false otherwise.
  */
 protected boolean isBlockTag(AttributeSet attr) {
   Object o = attr.getAttribute(StyleConstants.NameAttribute);
   if (o instanceof HTML.Tag) {
     HTML.Tag name = (HTML.Tag) o;
     return name.isBlock();
   }
   return false;
 }
 void editorPane_keyPressed(KeyEvent e) {
   StyledDocument doc = editorPane.getStyledDocument();
   int pos = editorPane.getCaretPosition();
   int code = e.getKeyCode();
   Element el;
   switch (code) {
     case KeyEvent.VK_BACK_SPACE:
     case KeyEvent.VK_DELETE:
     case KeyEvent.VK_LEFT:
     case KeyEvent.VK_KP_LEFT:
       if (pos == 0) return;
       // we want to get the element to the left of position.
       el = doc.getCharacterElement(pos - 1);
       break;
     case KeyEvent.VK_RIGHT:
     case KeyEvent.VK_KP_RIGHT:
       // we want to get the element to the right of position.
       el = doc.getCharacterElement(pos + 1);
       break;
     default:
       return; // bail we don't handle it.
   }
   AttributeSet attr = el.getAttributes();
   String el_name = (String) attr.getAttribute(StyleConstants.NameAttribute);
   int el_range = el.getEndOffset() - el.getStartOffset() - 1;
   if (el_name.startsWith("Parameter") && StyleConstants.getComponent(attr) != null) {
     try {
       switch (code) {
         case KeyEvent.VK_BACK_SPACE:
         case KeyEvent.VK_DELETE:
           doc.remove(el.getStartOffset(), el_range);
           break;
         case KeyEvent.VK_LEFT:
         case KeyEvent.VK_KP_LEFT:
           editorPane.setCaretPosition(pos - el_range);
           break;
         case KeyEvent.VK_RIGHT:
         case KeyEvent.VK_KP_RIGHT:
           editorPane.setCaretPosition(pos + (el_range));
           break;
       }
     } catch (BadLocationException ex) {
     }
   }
 }
 protected HashAttributeSet(AttributeSet attributeSet, Class<?> interfaceName) {
   attributeInterfaceName = interfaceName;
   if (attributeSet != null) {
     Attribute[] attributes = attributeSet.toArray();
     for (Attribute element : attributes) {
       add(element);
     }
   }
 }
Exemple #20
0
  /*
   *  Determine the Y offset for the current row
   */
  private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics) throws BadLocationException {
    //  Get the bounding rectangle of the row

    Rectangle r = component.modelToView(rowStartOffset);
    int lineHeight = fontMetrics.getHeight();
    int y = r.y + r.height;
    int descent = 0;

    //  The text needs to be positioned above the bottom of the bounding
    //  rectangle based on the descent of the font(s) contained on the row.
    if (r.height == lineHeight) {
      // default font is being used
      descent = fontMetrics.getDescent();
    } else {
      // We need to check all the attributes for font changes
      if (fonts == null) {
        fonts = new HashMap<String, FontMetrics>();
      }

      Element root = component.getDocument().getDefaultRootElement();
      int index = root.getElementIndex(rowStartOffset);
      Element line = root.getElement(index);

      for (int i = 0; i < line.getElementCount(); i++) {
        Element child = line.getElement(i);
        AttributeSet as = child.getAttributes();
        String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily);
        Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize);
        String key = fontFamily + fontSize;

        FontMetrics fm = fonts.get(key);

        if (fm == null) {
          Font font = new Font(fontFamily, Font.PLAIN, fontSize);
          fm = component.getFontMetrics(font);
          fonts.put(key, fm);
        }

        descent = Math.max(descent, fm.getDescent());
      }
    }

    return y - descent;
  }
 public boolean addAll(AttributeSet attributeSet) {
   boolean outcome = true;
   Attribute[] attributes = attributeSet.toArray();
   for (Attribute element : attributes) {
     if (!add(element)) {
       outcome = false;
     }
   }
   return outcome;
 }
 /**
  * Returns true if the StyleConstants.NameAttribute is equal to the tag that is passed in as a
  * parameter.
  */
 protected boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag) {
   Object o = attr.getAttribute(StyleConstants.NameAttribute);
   if (o instanceof HTML.Tag) {
     HTML.Tag name = (HTML.Tag) o;
     if (name == tag) {
       return true;
     }
   }
   return false;
 }
 /*     */ protected void setPropertiesFromAttributes() /*     */ {
   /* 140 */ AttributeSet localAttributeSet = getAttributes();
   /* 141 */ if (localAttributeSet != null) {
     /* 142 */ Document localDocument = getDocument();
     /* 143 */ if ((localDocument instanceof StyledDocument)) {
       /* 144 */ StyledDocument localStyledDocument = (StyledDocument) localDocument;
       /* 145 */ this.font = localStyledDocument.getFont(localAttributeSet);
       /* 146 */ this.fg = localStyledDocument.getForeground(localAttributeSet);
       /* 147 */ if (localAttributeSet.isDefined(StyleConstants.Background))
         /* 148 */ this.bg = localStyledDocument.getBackground(localAttributeSet);
       /*     */ else {
         /* 150 */ this.bg = null;
         /*     */ }
       /* 152 */ setUnderline(StyleConstants.isUnderline(localAttributeSet));
       /* 153 */ setStrikeThrough(StyleConstants.isStrikeThrough(localAttributeSet));
       /* 154 */ setSuperscript(StyleConstants.isSuperscript(localAttributeSet));
       /* 155 */ setSubscript(StyleConstants.isSubscript(localAttributeSet));
       /*     */ } else {
       /* 157 */ throw new StateInvariantError("LabelView needs StyledDocument");
       /*     */ }
     /*     */ }
   /*     */ }
  /** Translate the stylesheet into JVM bytecodes. */
  public void translate() {
    _className = getXSLTC().getClassName();

    // Define a new class by extending TRANSLET_CLASS
    final ClassGenerator classGen =
        new ClassGenerator(
            _className, TRANSLET_CLASS, Constants.EMPTYSTRING, ACC_PUBLIC | ACC_SUPER, null, this);

    addDOMField(classGen);

    // Compile transform() to initialize parameters, globals & output
    // and run the transformation
    compileTransform(classGen);

    // Translate all non-template elements and filter out all templates
    final Enumeration elements = elements();
    while (elements.hasMoreElements()) {
      Object element = elements.nextElement();
      // xsl:template
      if (element instanceof Template) {
        // Separate templates by modes
        final Template template = (Template) element;
        // _templates.addElement(template);
        getMode(template.getModeName()).addTemplate(template);
      }
      // xsl:attribute-set
      else if (element instanceof AttributeSet) {
        ((AttributeSet) element).translate(classGen, null);
      } else if (element instanceof Output) {
        // save the element for later to pass to compileConstructor
        Output output = (Output) element;
        if (output.enabled()) _lastOutputElement = output;
      } else {
        // Global variables and parameters are handled elsewhere.
        // Other top-level non-template elements are ignored. Literal
        // elements outside of templates will never be output.
      }
    }

    checkOutputMethod();
    processModes();
    compileModes(classGen);
    compileStaticInitializer(classGen);
    compileConstructor(classGen, _lastOutputElement);

    if (!getParser().errorsFound()) {
      getXSLTC().dumpClass(classGen.getJavaClass());
    }
  }
  @SuppressWarnings("unchecked")
  public List<Long> groups(
      String username,
      LdapConfig config,
      LdapOperations ldap,
      RoleProvider provider,
      AttributeSet attrSet) {

    Set<String> groupNames = attrSet.getAll(grpAttribute);
    if (groupNames == null) {
      throw new ValidationException(username + " has no attributes " + grpAttribute);
    }

    final GroupAttributeMapper mapper = new GroupAttributeMapper(config);

    // If filtered is activated, then load all group names as mapped
    // via the name field.
    //
    // TODO: this should likely be done via either paged queries
    // or once for each target.
    List<String> filteredNames = null;
    if (filtered) {
      String filter = config.getGroupFilter().encode();
      filteredNames = (List<String>) ldap.search("", filter, mapper);
    }

    List<Long> groups = new ArrayList<Long>();
    for (String grpName : groupNames) {
      // If DN is true, then we need to map from the attribute value
      // to the actual group name before comparing.
      if (dn) {
        DistinguishedName relative = config.relativeDN(grpName);
        String nameAttr = config.getGroupAttribute("name");
        grpName = relative.getValue(nameAttr);
      }

      // Apply filter if necessary.
      if (filtered && !filteredNames.contains(grpName)) {
        log.debug("Group not found by filter: " + grpName);
        continue;
      }

      // Finally, add the grou
      groups.add(provider.createGroup(grpName, null, false, true));
    }
    return groups;
  }
 /**
  * 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);
   }
 }
 /**
  * Writes out the content of the SELECT form element.
  *
  * @param attr the AttributeSet associated with the form element
  * @exception IOException on any I/O error
  */
 protected void selectContent(AttributeSet attr) throws IOException {
   Object model = attr.getAttribute(StyleConstants.ModelAttribute);
   incrIndent();
   if (model instanceof OptionListModel) {
     OptionListModel listModel = (OptionListModel) model;
     int size = listModel.getSize();
     for (int i = 0; i < size; i++) {
       Option option = (Option) listModel.getElementAt(i);
       writeOption(option);
     }
   } else if (model instanceof OptionComboBoxModel) {
     OptionComboBoxModel comboBoxModel = (OptionComboBoxModel) model;
     int size = comboBoxModel.getSize();
     for (int i = 0; i < size; i++) {
       Option option = (Option) comboBoxModel.getElementAt(i);
       writeOption(option);
     }
   }
   decrIndent();
 }
 /**
  * Writes out text that is contained in a TEXTAREA form element.
  *
  * @param attr an AttributeSet
  * @exception IOException on any I/O error
  * @exception BadLocationException if pos represents an invalid location within the document.
  */
 protected void textAreaContent(AttributeSet attr) throws BadLocationException, IOException {
   Document doc = (Document) attr.getAttribute(StyleConstants.ModelAttribute);
   if (doc != null && doc.getLength() > 0) {
     if (segment == null) {
       segment = new Segment();
     }
     doc.getText(0, doc.getLength(), segment);
     if (segment.count > 0) {
       inTextArea = true;
       incrIndent();
       indent();
       setCanWrapLines(true);
       replaceEntities = true;
       write(segment.array, segment.offset, segment.count);
       replaceEntities = false;
       setCanWrapLines(false);
       writeLineSeparator();
       inTextArea = false;
       decrIndent();
     }
   }
 }
 @Override
 public final AttributeSet resolve(ResolverContext context) throws Exception {
   checkArgument(context.getDescriptor().getId().equals(descriptor.getId()));
   if (log.isDebugEnabled()) {
     log.debug(
         "Retrieving attributes via resolver id=\"{}\" name=\"{}\"",
         descriptor.getId(),
         descriptor.getName());
   }
   Timer.Context timerCtx = timer.time();
   try {
     return AttributeSet.builder(descriptor)
         .attributes(doResolve(context))
         .ticker(context.getTicker())
         .build();
   } catch (Exception e) {
     if (log.isDebugEnabled()) {
       log.debug(e.getMessage(), e);
     }
     throw e;
   } finally {
     histogram.update(timerCtx.stop());
   }
 }
  @Override
  protected int drawUnselectedText(java.awt.Graphics g, int x, int y, int p0, int p1)
      throws BadLocationException {
    Document doc = getDocument();
    Segment segment = new Segment();
    Segment token = getLineBuffer();

    doc.getText(p0, p1 - p0, segment);

    int count = p1 - p0;
    int left = 0;

    int state = TEXT;

    int elementIndex = doc.getDefaultRootElement().getElementIndex(p0);

    AttributeSet lineAttributes =
        doc.getDefaultRootElement().getElement(elementIndex).getAttributes();

    if (lineAttributes.isDefined("inComment")) {
      state = MULTILINECOMMENT;
    }

    for (int i = 0; i < count; i++) {
      // Starting in default text state.
      if (state == TEXT) {
        if (Character.isLetter(segment.array[i + segment.offset])
            && Character.isLowerCase(segment.array[i + segment.offset])) {
          // flush now
          g.setColor(textColor);
          doc.getText(p0 + left, i - left, token);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i;
          state = KEYWORD;
        } // Do nothing
        else {
          if (segment.array[i + segment.offset] == '/') {
            // flush now
            g.setColor(textColor);
            doc.getText(p0 + left, i - left, token);
            x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
            left = i;
            state = COMMENT;
          } else if (segment.array[i + segment.offset] == '"') {
            // flush now
            g.setColor(textColor);
            doc.getText(p0 + left, i - left, token);
            x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
            left = i;
            state = STRING;
          }
        }
      } else if (state == KEYWORD) {
        // Still
        if (Character.isLetter(
            segment
                .array[
                i
                    + segment
                        .offset])) { // && Character.isLowerCase(segment.array[i+segment.offset]))
        } else {
          // flush now
          doc.getText(p0 + left, i - left, token);
          if (Keywords.isKeyword(token)) {
            g.setColor(keywordColor);
          } else {
            g.setColor(textColor);
          }
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i;
          state = TEXT;
          if (segment.array[i + segment.offset] == '/') {
            state = COMMENT;
          } else if (segment.array[i + segment.offset] == '"') {
            state = STRING;
          }
        }
      } else if (state == COMMENT) {
        if (segment.array[i + segment.offset] == '/') {
          break;
        } else if (segment.array[i + segment.offset] == '*') {
          state = MULTILINECOMMENT;
        } else {
          state = TEXT;
        }
      } else if (state == MULTILINECOMMENT) {
        if (i > 0
            && segment.array[i + segment.offset] == '/'
            && segment.array[i + segment.offset - 1] == '*') {
          // flush now
          doc.getText(p0 + left, i + 1 - left, token);
          g.setColor(commentColor);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i + 1;
          state = TEXT;
        }
      } else if (state == STRING) {
        if (segment.array[i + segment.offset] == '"') {
          // flush now
          doc.getText(p0 + left, i + 1 - left, token);
          g.setColor(stringColor);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i + 1;
          state = TEXT;
        }
      }
      // Starting not in token
    } // end loop
    // Flush last
    doc.getText(p0 + left, p1 - p0 - left, token);
    if (state == KEYWORD) {
      if (Keywords.isKeyword(token)) {
        g.setColor(keywordColor);
      } else {
        g.setColor(textColor);
      }
    } else if (state == STRING) {
      g.setColor(stringColor);
    } else if (state == COMMENT && ((p1 - p0 - left) > 1)) {
      g.setColor(commentColor);
    } else if (state == MULTILINECOMMENT) {
      g.setColor(commentColor);
    } else {
      g.setColor(textColor);
    }
    x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);

    return x;
  }