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

Quick Search    Search Deep

Source code: com/arranger/jarl/filter/base/Twirl.java


1   package com.arranger.jarl.filter.base;
2   
3   import com.arranger.jarl.base.IContext;
4   import com.arranger.jarl.base.IJarlObjectInfo;
5   import com.arranger.jarl.filter.BaseSegmentFilter;
6   import com.arranger.jarl.util.*;
7   import com.jhlabs.image.TwirlFilter;
8   import org.w3c.dom.Element;
9   
10  /**
11   * Twirl twirls the image
12   *
13   * @filterAttribute angle ## xs:float ## the angle to rotate in degrees
14   * @filterAttribute startAngle ## xs:float ## the angle to start rotate in degrees
15   * @filterAttribute endAngle ## xs:float ## the angle to end rotate in degrees
16   */
17  public class Twirl extends BaseSegmentFilter {
18  
19      protected float m_angle = Float.NEGATIVE_INFINITY;
20      protected float m_startAngle = Float.NEGATIVE_INFINITY;
21      protected float m_endAngle = Float.NEGATIVE_INFINITY;
22  
23      /**
24       * Prepare the filter with any changes as necessary
25       * @param context the current context
26       */
27      protected void prepareFilter(IContext context) {
28          float angle;
29          if (m_angle != Float.NEGATIVE_INFINITY) {
30              angle = m_angle;
31          } else if (m_startAngle != Float.NEGATIVE_INFINITY && m_endAngle != Float.NEGATIVE_INFINITY) {
32              angle = (float) InterpolateUtil.interpolate(getStartTime(),
33                      getEndTime(),
34                      m_startAngle,
35                      m_endAngle,
36                      context.getTime());
37          } else {
38              TwirlConfigSegment twirlConfigSegment = (TwirlConfigSegment) getCurrentSegment(context);
39              double currentTimePct = getCurrentSegmentTimePct(context, twirlConfigSegment);
40  
41              angle = (float) InterpolateUtil.interpolate(0,
42                      1,
43                      twirlConfigSegment.getStartAngle(),
44                      twirlConfigSegment.getEndAngle(),
45                      currentTimePct);
46          }
47          ((TwirlFilter) getImageFilter()).setAngle((float) Math.toRadians(angle));
48      }
49  
50      /**
51       * @return the name of the underlying filter class
52       */
53      protected String getImageFilterClassName() {
54          return TwirlFilter.class.getName();
55      }
56  
57      /**
58       * Always remember some attrs might not be there
59       * @param context
60       */
61      protected void initAttributes(IContext context) {
62          super.initAttributes(context);
63  
64          ObjectUtil.initializeField("angle", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
65          ObjectUtil.initializeField("startAngle", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
66          ObjectUtil.initializeField("endAngle", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
67      }
68  
69      protected void addJarlObjectInfo(IJarlObjectInfo jarlObjectInfo) {
70          super.addJarlObjectInfo(jarlObjectInfo);
71          populateInfo(jarlObjectInfo, "angle", "Angle (degrees)", JarlInfoUtil.PRIMITIVE_DISPLAY);
72          populateInfo(jarlObjectInfo, "startAngle", "Start Angle (degrees)", JarlInfoUtil.PRIMITIVE_DISPLAY);
73          populateInfo(jarlObjectInfo, "endAngle", "End Angle (degrees)", JarlInfoUtil.PRIMITIVE_DISPLAY);
74      }
75  
76      /**
77       * Create a concrete {@link com.arranger.jarl.util.WidgetConfigSegment} based on this element
78       * @param element
79       * @return a specific {@link com.arranger.jarl.util.WidgetConfigSegment}
80       */
81      public WidgetConfigSegment createSegment(Element element) {
82          return new TwirlConfigSegment(element);
83      }
84  
85      protected static class TwirlConfigSegment extends WidgetConfigSegment {
86  
87          protected float m_startAngle = Float.NEGATIVE_INFINITY;
88          protected float m_endAngle = Float.NEGATIVE_INFINITY;
89  
90          public TwirlConfigSegment(Element element) {
91              super(element);
92  
93              ObjectUtil.initializeFieldStrict("startAngle", element, this, ObjectUtil.PRIMITIVE_CONVERSION);
94              ObjectUtil.initializeFieldStrict("endAngle", element, this, ObjectUtil.PRIMITIVE_CONVERSION);
95          }
96  
97  
98          protected void addJarlObjectInfo(IJarlObjectInfo jarlObjectInfo) {
99              super.addJarlObjectInfo(jarlObjectInfo);
100             populateInfo(jarlObjectInfo, "startAngle", "Start Angle (degrees)", JarlInfoUtil.PRIMITIVE_DISPLAY);
101             populateInfo(jarlObjectInfo, "endAngle", "End Angle (degrees)", JarlInfoUtil.PRIMITIVE_DISPLAY);
102         }
103 
104         public float getStartAngle() {
105             return m_startAngle;
106         }
107 
108         public float getEndAngle() {
109             return m_endAngle;
110         }
111     }
112 }