Ejemplo n.º 1
0
    /** {@inheritDoc} */
    public boolean equals(Object o) {
      if (o != null && o instanceof CachedTeXFormula) {
        CachedTeXFormula c = (CachedTeXFormula) o;
        boolean b =
            (c.f.equals(f)
                && c.style == style
                && c.type == type
                && c.size == size
                && c.inset == inset
                && c.fgcolor.equals(fgcolor));
        if (b) {
          if (c.width == -1) {
            c.width = width;
            c.height = height;
            c.depth = depth;
          } else if (width == -1) {
            width = c.width;
            height = c.height;
            depth = c.depth;
          }
        }

        return b;
      }

      return false;
    }
Ejemplo n.º 2
0
  private static SoftReference<CachedImage> makeImage(CachedTeXFormula cached)
      throws ParseException {
    TeXFormula formula = new TeXFormula(cached.f);
    TeXIcon icon = formula.createTeXIcon(cached.style, cached.size, cached.type, cached.fgcolor);
    icon.setInsets(new Insets(cached.inset, cached.inset, cached.inset, cached.inset));
    Image image =
        new Graphics().createImage(icon.getIconWidth(), icon.getIconHeight(), Image.TYPE_INT_ARGB);
    Graphics2DInterface g2 = image.createGraphics2D();
    icon.paintIcon(null, g2, 0, 0);
    g2.dispose();
    cached.setDimensions(icon.getIconWidth(), icon.getIconHeight(), icon.getIconDepth());
    SoftReference<CachedImage> img =
        new SoftReference<CachedImage>(new CachedImage(image, cached), queue);

    if (cache.size() >= max) {
      Reference soft;
      while ((soft = queue.poll()) != null) {
        CachedImage ci = (CachedImage) soft.get();
        if (ci != null) {
          cache.remove(ci.cachedTf);
        }
      }
      Iterator<CachedTeXFormula> iter = cache.keySet().iterator();
      if (iter.hasNext()) {
        CachedTeXFormula c = iter.next();
        SoftReference<CachedImage> cachedImage = cache.get(c);
        if (cachedImage != null) {
          cachedImage.clear();
        }
        cache.remove(c);
      }
    }
    cache.put(cached, img);

    return img;
  }