OSDN Git Service

9d103d590163af482dc76e78b90c99272e6e36df
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / filters / FilterRepresentation.java
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.gallery3d.filtershow.filters;
18
19 import android.util.Log;
20
21 import com.android.gallery3d.filtershow.editors.BasicEditor;
22
23 public class FilterRepresentation implements Cloneable {
24     private static final String LOGTAG = "FilterRepresentation";
25     private static final boolean DEBUG = false;
26     private String mName;
27     private int mPriority = TYPE_NORMAL;
28     private Class<?> mFilterClass;
29     private boolean mSupportsPartialRendering = false;
30     private int mTextId = 0;
31     private int mEditorId = BasicEditor.ID;
32     private int mButtonId = 0;
33     private int mOverlayId = 0;
34     private boolean mOverlayOnly = false;
35     private boolean mShowParameterValue = true;
36     private String mSerializationName;
37     public static final byte TYPE_BORDER = 1;
38     public static final byte TYPE_FX = 2;
39     public static final byte TYPE_WBALANCE = 3;
40     public static final byte TYPE_VIGNETTE = 4;
41     public static final byte TYPE_NORMAL = 5;
42     public static final byte TYPE_TINYPLANET = 6;
43
44     private FilterRepresentation mTempRepresentation = null;
45
46     public FilterRepresentation(String name) {
47         mName = name;
48     }
49
50     @Override
51     public FilterRepresentation clone() throws CloneNotSupportedException {
52         FilterRepresentation representation = (FilterRepresentation) super.clone();
53         representation.setName(getName());
54         representation.setFilterClass(getFilterClass());
55         representation.setFilterType(getFilterType());
56         representation.setSupportsPartialRendering(supportsPartialRendering());
57         representation.setTextId(getTextId());
58         representation.setEditorId(getEditorId());
59         representation.setOverlayId(getOverlayId());
60         representation.setOverlayOnly(getOverlayOnly());
61         representation.setShowParameterValue(showParameterValue());
62         representation.mSerializationName = mSerializationName;
63
64         representation.mTempRepresentation =
65                 mTempRepresentation != null ? mTempRepresentation.clone() : null;
66         if (DEBUG) {
67             Log.v(LOGTAG, "cloning from <" + this + "> to <" + representation + ">");
68         }
69         return representation;
70     }
71
72     public boolean equals(FilterRepresentation representation) {
73         if (representation == null) {
74             return false;
75         }
76         if (representation.mFilterClass == representation.mFilterClass
77                 && representation.mName.equalsIgnoreCase(mName)
78                 && representation.mPriority == mPriority
79                 && representation.mSupportsPartialRendering == mSupportsPartialRendering
80                 && representation.mTextId == mTextId
81                 && representation.mEditorId == mEditorId
82                 && representation.mButtonId == mButtonId
83                 && representation.mOverlayId == mOverlayId
84                 && representation.mOverlayOnly == mOverlayOnly
85                 && representation.mShowParameterValue == mShowParameterValue) {
86             return true;
87         }
88         return false;
89     }
90
91     @Override
92     public String toString() {
93         return mName;
94     }
95
96     public void setName(String name) {
97         mName = name;
98     }
99
100     public String getName() {
101         return mName;
102     }
103
104     public void setSerializationName(String sname) {
105         mSerializationName = sname;
106     }
107
108     public String getSerializationName() {
109         return mSerializationName;
110     }
111
112     public void setFilterType(int priority) {
113         mPriority = priority;
114     }
115
116     public int getFilterType() {
117         return mPriority;
118     }
119
120     public boolean isNil() {
121         return false;
122     }
123
124     public boolean supportsPartialRendering() {
125         return false && mSupportsPartialRendering; // disable for now
126     }
127
128     public void setSupportsPartialRendering(boolean value) {
129         mSupportsPartialRendering = value;
130     }
131
132     public void useParametersFrom(FilterRepresentation a) {
133     }
134
135     public void clearTempRepresentation() {
136         mTempRepresentation = null;
137     }
138
139     public synchronized void updateTempParametersFrom(FilterRepresentation representation) {
140         if (mTempRepresentation == null) {
141             try {
142                 mTempRepresentation = representation.clone();
143             } catch (CloneNotSupportedException e) {
144                 e.printStackTrace();
145             }
146         } else {
147             mTempRepresentation.useParametersFrom(representation);
148         }
149     }
150
151     public synchronized void synchronizeRepresentation() {
152         if (mTempRepresentation != null) {
153             useParametersFrom(mTempRepresentation);
154         }
155     }
156
157     public boolean allowsMultipleInstances() {
158         return false;
159     }
160
161     public Class<?> getFilterClass() {
162         return mFilterClass;
163     }
164
165     public void setFilterClass(Class<?> filterClass) {
166         mFilterClass = filterClass;
167     }
168
169     public boolean same(FilterRepresentation b) {
170         if (b == null) {
171             return false;
172         }
173         return getFilterClass() == b.getFilterClass();
174     }
175
176     public int getTextId() {
177         return mTextId;
178     }
179
180     public void setTextId(int textId) {
181         mTextId = textId;
182     }
183
184     public int getOverlayId() {
185         return mOverlayId;
186     }
187
188     public void setOverlayId(int overlayId) {
189         mOverlayId = overlayId;
190     }
191
192     public boolean getOverlayOnly() {
193         return mOverlayOnly;
194     }
195
196     public void setOverlayOnly(boolean value) {
197         mOverlayOnly = value;
198     }
199
200     final public int getEditorId() {
201         return mEditorId;
202     }
203
204     public int[] getEditorIds() {
205         return new int[] {
206         mEditorId };
207     }
208
209     public void setEditorId(int editorId) {
210         mEditorId = editorId;
211     }
212
213     public boolean showParameterValue() {
214         return mShowParameterValue;
215     }
216
217     public void setShowParameterValue(boolean showParameterValue) {
218         mShowParameterValue = showParameterValue;
219     }
220
221     public String getStateRepresentation() {
222         return "";
223     }
224
225     public String[][] serializeRepresentation() {
226         String[][] ret = { { "Name" , getName() }};
227         return ret;
228     }
229
230     public void deSerializeRepresentation(String[][] rep) {
231         for (int i = 0; i < rep.length; i++) {
232             if ("Name".equals(rep[i][0])) {
233                 mName = rep[i][1];
234                 break;
235             }
236         }
237     }
238
239     // Override this in subclasses
240     public int getStyle() {
241         return -1;
242     }
243 }