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/Marble.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.InterpolateUtil;
7   import com.arranger.jarl.util.ObjectUtil;
8   import com.arranger.jarl.util.WidgetConfigSegment;
9   import com.arranger.jarl.util.JarlInfoUtil;
10  import com.jhlabs.image.MarbleFilter;
11  import org.w3c.dom.Element;
12  
13  /**
14   * Marble marbelizes the image
15   *
16   * @filterAttribute xscale ## xs:float ## the x scale of the marbelization (between 1 & 32)
17   * @filterAttribute yscale ## xs:float ## the y scale of the marbelization (between 1 & 32)
18   * @filterAttribute turbulence ## xs:float ## the turbulence of the marbelization (between 1 & 15)
19   *
20   * @filterAttribute startXscale ## xs:float ## the starting x scale of the marbelization (between 1 & 32)
21   * @filterAttribute startYscale ## xs:float ## the starting y scale of the marbelization (between 1 & 32)
22   * @filterAttribute startTurbulence ## xs:float ## the starting turbulence of the marbelization (between 1 & 15)
23   * @filterAttribute endXscale ## xs:float ## the ending x scale of the marbelization (between 1 & 32)
24   * @filterAttribute endYscale ## xs:float ## the ending y scale of the marbelization (between 1 & 32)
25   * @filterAttribute endTurbulence ## xs:float ## the ending turbulence of the marbelization (between 1 & 15)
26   */
27  public class Marble extends BaseSegmentFilter {
28  
29      protected float m_xscale = Float.NEGATIVE_INFINITY;
30      protected float m_yscale = Float.NEGATIVE_INFINITY;
31      protected float m_turbulence = Float.NEGATIVE_INFINITY;
32  
33      protected float m_startXscale = Float.NEGATIVE_INFINITY;
34      protected float m_startYscale = Float.NEGATIVE_INFINITY;
35      protected float m_startTurbulence = Float.NEGATIVE_INFINITY;
36      protected float m_endXscale = Float.NEGATIVE_INFINITY;
37      protected float m_endYscale = Float.NEGATIVE_INFINITY;
38      protected float m_endTurbulence = Float.NEGATIVE_INFINITY;
39  
40      /**
41       * Prepare the filter with any changes as necessary
42       * @param context the current context
43       */
44      protected void prepareFilter(IContext context) {
45          float xscale, yscale, turbulence;
46  
47          if (m_xscale != Float.NEGATIVE_INFINITY) {
48              xscale = m_xscale;
49              yscale = m_yscale;
50              turbulence = m_turbulence;
51          } else if (m_startXscale != Float.NEGATIVE_INFINITY && m_endXscale != Float.NEGATIVE_INFINITY) {
52              xscale = (float) InterpolateUtil.interpolate(getStartTime(),
53                      getEndTime(),
54                      m_startXscale,
55                      m_endXscale,
56                      context.getTime());
57  
58              yscale = (float) InterpolateUtil.interpolate(getStartTime(),
59                      getEndTime(),
60                      m_startYscale,
61                      m_endYscale,
62                      context.getTime());
63  
64              turbulence = (float) InterpolateUtil.interpolate(getStartTime(),
65                      getEndTime(),
66                      m_startTurbulence,
67                      m_endTurbulence,
68                      context.getTime());
69          } else {
70              MarbleConfigSegment marbleConfigSegment = (MarbleConfigSegment) getCurrentSegment(context);
71              double currentTimePct = getCurrentSegmentTimePct(context, marbleConfigSegment);
72  
73              xscale = (float) InterpolateUtil.interpolate(0,
74                      1,
75                      marbleConfigSegment.getStartXscale(),
76                      marbleConfigSegment.getEndXscale(),
77                      currentTimePct);
78  
79              yscale = (float) InterpolateUtil.interpolate(0,
80                      1,
81                      marbleConfigSegment.getStartYscale(),
82                      marbleConfigSegment.getEndYscale(),
83                      currentTimePct);
84  
85              turbulence = (float) InterpolateUtil.interpolate(0,
86                      1,
87                      marbleConfigSegment.getStartTurbulence(),
88                      marbleConfigSegment.getEndTurbulence(),
89                      currentTimePct);
90          }
91  
92          MarbleFilter marbleFilter = (MarbleFilter) getImageFilter();
93          marbleFilter.setXScale(xscale);
94          marbleFilter.setYScale(yscale);
95          marbleFilter.setTurbulence(turbulence);
96      }
97  
98      /**
99       * @return the name of the underlying filter class
100      */
101     protected String getImageFilterClassName() {
102         return MarbleFilter.class.getName();
103     }
104 
105     /**
106      * Always remember some attrs might not be there
107      * @param context
108      */
109     protected void initAttributes(IContext context) {
110         super.initAttributes(context);
111 
112         ObjectUtil.initializeField("xscale", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
113         ObjectUtil.initializeField("yscale", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
114         ObjectUtil.initializeField("turbulence", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
115 
116         ObjectUtil.initializeField("startXscale", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
117         ObjectUtil.initializeField("startYscale", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
118         ObjectUtil.initializeField("startTurbulence", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
119         ObjectUtil.initializeField("endXscale", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
120         ObjectUtil.initializeField("endYscale", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
121         ObjectUtil.initializeField("endTurbulence", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
122     }
123 
124     protected void addJarlObjectInfo(IJarlObjectInfo jarlObjectInfo) {
125         super.addJarlObjectInfo(jarlObjectInfo);
126         populateInfo(jarlObjectInfo, "xscale", "X-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
127         populateInfo(jarlObjectInfo, "yscale", "Y-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
128         populateInfo(jarlObjectInfo, "turbulence", "Turbulence", JarlInfoUtil.PRIMITIVE_DISPLAY);
129 
130         populateInfo(jarlObjectInfo, "startXscale", "Start X-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
131         populateInfo(jarlObjectInfo, "endXscale", "End X-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
132         populateInfo(jarlObjectInfo, "startXscale", "Start Y-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
133         populateInfo(jarlObjectInfo, "endYscale", "End Y-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
134         populateInfo(jarlObjectInfo, "startTurbulence", "Start Turbulence", JarlInfoUtil.PRIMITIVE_DISPLAY);
135         populateInfo(jarlObjectInfo, "endTurbulence", "End Turbulence", JarlInfoUtil.PRIMITIVE_DISPLAY);
136     }
137 
138     /**
139      * Create a concrete {@link WidgetConfigSegment} based on this element
140      * @param element
141      * @return a specific {@link WidgetConfigSegment}
142      */
143     public WidgetConfigSegment createSegment(Element element) {
144         return new MarbleConfigSegment(element);
145     }
146 
147     protected static class MarbleConfigSegment extends WidgetConfigSegment {
148 
149         protected float m_startXscale = Float.NEGATIVE_INFINITY;
150         protected float m_startYscale = Float.NEGATIVE_INFINITY;
151         protected float m_startTurbulence = Float.NEGATIVE_INFINITY;
152         protected float m_endXscale = Float.NEGATIVE_INFINITY;
153         protected float m_endYscale = Float.NEGATIVE_INFINITY;
154         protected float m_endTurbulence = Float.NEGATIVE_INFINITY;
155 
156         public MarbleConfigSegment(Element element) {
157             super(element);
158 
159             ObjectUtil.initializeFieldStrict("startXscale", element, this, ObjectUtil.PRIMITIVE_CONVERSION);
160             ObjectUtil.initializeFieldStrict("startYscale", element, this, ObjectUtil.PRIMITIVE_CONVERSION);
161             ObjectUtil.initializeFieldStrict("startTurbulence", element, this, ObjectUtil.PRIMITIVE_CONVERSION);
162             ObjectUtil.initializeFieldStrict("endXscale", element, this, ObjectUtil.PRIMITIVE_CONVERSION);
163             ObjectUtil.initializeFieldStrict("endYscale", element, this, ObjectUtil.PRIMITIVE_CONVERSION);
164             ObjectUtil.initializeFieldStrict("endTurbulence", element, this, ObjectUtil.PRIMITIVE_CONVERSION);
165         }
166 
167         protected void addJarlObjectInfo(IJarlObjectInfo jarlObjectInfo) {
168             super.addJarlObjectInfo(jarlObjectInfo);
169             populateInfo(jarlObjectInfo, "startXscale", "Start X-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
170             populateInfo(jarlObjectInfo, "endXscale", "End X-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
171             populateInfo(jarlObjectInfo, "startXscale", "Start Y-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
172             populateInfo(jarlObjectInfo, "endYscale", "End Y-Scale", JarlInfoUtil.PRIMITIVE_DISPLAY);
173             populateInfo(jarlObjectInfo, "startTurbulence", "Start Turbulence", JarlInfoUtil.PRIMITIVE_DISPLAY);
174             populateInfo(jarlObjectInfo, "endTurbulence", "End Turbulence", JarlInfoUtil.PRIMITIVE_DISPLAY);
175         }
176 
177         public float getStartXscale() {
178             return m_startXscale;
179         }
180 
181         public float getStartYscale() {
182             return m_startYscale;
183         }
184 
185         public float getStartTurbulence() {
186             return m_startTurbulence;
187         }
188 
189         public float getEndXscale() {
190             return m_endXscale;
191         }
192 
193         public float getEndYscale() {
194             return m_endYscale;
195         }
196 
197         public float getEndTurbulence() {
198             return m_endTurbulence;
199         }
200     }
201 }