Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/arranger/jarl/filter/paint/BasePaintFilter.java


1   package com.arranger.jarl.filter.paint;
2   
3   import com.arranger.jarl.base.IContext;
4   import com.arranger.jarl.filter.BaseSegmentFilter;
5   import com.arranger.jarl.util.ImageUtil;
6   import com.arranger.jarl.widget.IWidget;
7   
8   import java.awt.*;
9   import java.awt.image.FilteredImageSource;
10  
11  /**
12   * BasePaintFilter created on Apr 4, 2003 
13   */
14  public abstract class BasePaintFilter extends BaseSegmentFilter {
15  
16      /**
17       * Instead of being a global filter, this is a local filter
18       *
19       * Post filter applying the transparent overlay as well as returning the stored graphics
20       * @param widget
21       * @param context
22       * @param graphics
23       * @return the restored graphics
24       */
25      public Graphics2D postFilterWidget(IWidget widget, IContext context, Graphics2D graphics) {
26          //perform the actual filter
27          m_image = filterImage(context, m_image);
28  
29          //long ms = System.currentTimeMillis();
30  
31          Shape shape = (Shape) context.getAttributes().get(Shape.class);
32          //rifle through the image masking and setting transparent
33          m_image = Toolkit.getDefaultToolkit().createImage(
34                  new FilteredImageSource(
35                          new FilteredImageSource(m_image.getSource(), new ImageUtil.ShapeImageMaskFilter(shape)),
36                          new ImageUtil.TransparentImageFilter(Color.black)
37                  )
38          );
39  
40          Composite composite = (Composite) context.getAttributes().get(Composite.class);
41          if (composite != null && composite instanceof AlphaComposite) {
42              float alpha = ((AlphaComposite)composite).getAlpha();
43              ImageUtil.overlayTransparentImage(m_graphics, m_image, alpha);
44          } else {
45              ImageUtil.overlayTransparentImage(m_graphics, m_image);
46          }
47  
48          //context.onStatus("postFilterWidget took: " + ((System.currentTimeMillis() - ms) / 1000f) + "s");
49  
50          //dispose old graphics
51          graphics.dispose();
52          m_image = null;
53  
54          //restore times
55          m_startTime = null;
56          m_endTime = null;
57  
58          //return graphics
59          return m_graphics;
60      }
61  }