/**
   * Returns the package of the specified completion.
   *
   * @param c The completion.
   * @param desc The description text being parsed. Used for errors if we cannot determine the
   *     package.
   * @return The package.
   */
  private String getPackage(Completion c, String desc) {

    String pkg = null;

    if (c instanceof JSClassCompletion) {
      pkg = ((JSClassCompletion) c).getPackageName();
    }
    if (c instanceof JSCompletion) {
      String definedIn = ((JSCompletion) c).getEnclosingClassName(true);
      if (definedIn != null) {
        int lastDot = definedIn.lastIndexOf('.');
        if (lastDot > -1) {
          pkg = definedIn.substring(0, lastDot);
        }
      }
    } else {
      Logger.logError(
          "Can't determine package from completion type: "
              + c.getClass()
              + " ("
              + c.toString()
              + ") - href: "
              + desc);
    }

    return pkg;
  }
  protected void paintComponent(Graphics g) {

    // Set up rendering hints to look as close to native as possible
    Graphics2D g2d = (Graphics2D) g;
    Object old = null;

    // First, try to use the rendering hint set that is "native".
    Map hints = (Map) getToolkit().getDesktopProperty("awt.font.desktophints");
    if (hints != null) {
      old = g2d.getRenderingHints();
      g2d.addRenderingHints(hints);
    }
    // If a "native" set isn't found, just turn on standard text AA.
    else {
      old = g2d.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
      g2d.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }

    //		if (jsc!=null) {
    //			setText(null); // Stop "Foobar" from being painted
    //		}

    // We never paint "selection" around the icon, to imitate Eclipse
    final int iconW = 18;
    int h = getHeight();
    if (!selected) {
      g.setColor(getBackground());
      g.fillRect(0, 0, getWidth(), h);
    } else {
      g.setColor(altBG != null && evenRow ? altBG : list.getBackground());
      g.fillRect(0, 0, iconW, h);
      g.setColor(getBackground()); // Selection color
      g.fillRect(iconW, 0, getWidth() - iconW, h);
    }
    if (getIcon() != null) {
      int y = (h - getIcon().getIconHeight()) / 2;
      getIcon().paintIcon(this, g, 0, y);
    }

    int x = getX() + iconW + 2;
    g.setColor(selected ? list.getSelectionForeground() : list.getForeground());
    if (jsc != null && !simpleText) {
      jsc.rendererText(g, x, g.getFontMetrics().getHeight(), selected);
    } else {
      Completion c = jsc != null ? (Completion) jsc : nonJavaCompletion;
      if (c != null) {
        g.drawString(c.toString(), x, g.getFontMetrics().getHeight());
      }
    }

    // Restore rendering hints appropriately.
    if (hints != null) {
      g2d.addRenderingHints((Map) old);
    } else {
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, old);
    }
  }
  /**
   * Returns the class for a completion (class completions return the class itself, member
   * completions return the enclosing class).
   */
  private String getClass(Completion c, String desc) {

    String clazz = null;

    if (c instanceof JSClassCompletion) {
      clazz = ((JSClassCompletion) c).getClassName(true);
    } else if (c instanceof JSCompletion) {
      JSCompletion jsc = (JSCompletion) c;
      clazz = jsc.getEnclosingClassName(true);
    } else {
      Logger.logError(
          "Can't determine class from completion type: "
              + c.getClass()
              + " ("
              + c.toString()
              + ") - href: "
              + desc);
    }

    return clazz;
  }