コード例 #1
0
  /*
   * (non-Javadoc)
   *
   * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
   * int, int)
   */
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    // check if loading
    if (this.delegate instanceof AsynchronousLoading) {
      AsynchronousLoading asyncDelegate = (AsynchronousLoading) this.delegate;
      // if the delegate is still loading - do nothing
      if (asyncDelegate.isLoading()) return;
    }

    SubstanceColorScheme scheme =
        SubstanceColorSchemeUtilities.getColorScheme(c, ComponentState.DISABLED_UNSELECTED);
    HashMapKey key =
        SubstanceCoreUtilities.getHashKey(
            this.getIconWidth(), this.getIconHeight(), scheme.getDisplayName());

    BufferedImage filtered = this.cachedImages.get(key);
    if (filtered == null) {
      BufferedImage offscreen =
          FlamingoUtilities.getBlankImage(this.getIconWidth(), this.getIconHeight());
      Graphics2D g2d = offscreen.createGraphics();
      this.delegate.paintIcon(c, g2d, 0, 0);
      g2d.dispose();
      filtered = SubstanceImageCreator.getColorSchemeImage(offscreen, scheme, 0.5f);
      this.cachedImages.put(key, filtered);
    }
    g.drawImage(filtered, x, y, null);
  }