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
17package com.android.gallery3d.filtershow.filters;
18
19import com.android.gallery3d.app.Log;
20import com.android.gallery3d.filtershow.editors.BasicEditor;
21
22public class FilterRepresentation implements Cloneable {
23    private static final String LOGTAG = "FilterRepresentation";
24    private static final boolean DEBUG = false;
25    private String mName;
26    private int mPriority = TYPE_NORMAL;
27    private Class mFilterClass;
28    private boolean mSupportsPartialRendering = false;
29    private int mTextId = 0;
30    private int mEditorId = BasicEditor.ID;
31    private int mButtonId = 0;
32    private int mOverlayId = 0;
33    private boolean mOverlayOnly = false;
34    private boolean mShowEditingControls = true;
35    private boolean mShowParameterValue = true;
36    private boolean mShowUtilityPanel = true;
37
38    public static final byte TYPE_BORDER = 1;
39    public static final byte TYPE_FX = 2;
40    public static final byte TYPE_WBALANCE = 3;
41    public static final byte TYPE_VIGNETTE = 4;
42    public static final byte TYPE_NORMAL = 5;
43    public static final byte TYPE_TINYPLANET = 6;
44
45    private FilterRepresentation mTempRepresentation = null;
46
47    public FilterRepresentation(String name) {
48        mName = name;
49    }
50
51    @Override
52    public FilterRepresentation clone() throws CloneNotSupportedException {
53        FilterRepresentation representation = (FilterRepresentation) super.clone();
54        representation.setName(getName());
55        representation.setPriority(getPriority());
56        representation.setFilterClass(getFilterClass());
57        representation.setSupportsPartialRendering(supportsPartialRendering());
58        representation.setTextId(getTextId());
59        representation.setEditorId(getEditorId());
60        representation.setButtonId(getButtonId());
61        representation.setOverlayId(getOverlayId());
62        representation.setOverlayOnly(getOverlayOnly());
63        representation.setShowEditingControls(showEditingControls());
64        representation.setShowParameterValue(showParameterValue());
65        representation.setShowUtilityPanel(showUtilityPanel());
66        representation.mTempRepresentation =
67                mTempRepresentation != null ? mTempRepresentation.clone() : null;
68        if (DEBUG) {
69            Log.v(LOGTAG, "cloning from <" + this + "> to <" + representation + ">");
70        }
71        return representation;
72    }
73
74    public boolean equals(FilterRepresentation representation) {
75        if (representation == null) {
76            return false;
77        }
78        if (representation.mFilterClass == representation.mFilterClass
79                && representation.mName.equalsIgnoreCase(mName)
80                && representation.mPriority == mPriority
81                && representation.mSupportsPartialRendering == mSupportsPartialRendering
82                && representation.mTextId == mTextId
83                && representation.mEditorId == mEditorId
84                && representation.mButtonId == mButtonId
85                && representation.mOverlayId == mOverlayId
86                && representation.mOverlayOnly == mOverlayOnly
87                && representation.mShowEditingControls == mShowEditingControls
88                && representation.mShowParameterValue == mShowParameterValue
89                && representation.mShowUtilityPanel == mShowUtilityPanel) {
90            return true;
91        }
92        return false;
93    }
94
95    public String toString() {
96        return mName;
97    }
98
99    public void setName(String name) {
100        mName = name;
101    }
102
103    public String getName() {
104        return mName;
105    }
106
107    public void setPriority(int priority) {
108        mPriority = priority;
109    }
110
111    public int getPriority() {
112        return mPriority;
113    }
114
115    public boolean isNil() {
116        return false;
117    }
118
119    public boolean supportsPartialRendering() {
120        return false && mSupportsPartialRendering; // disable for now
121    }
122
123    public void setSupportsPartialRendering(boolean value) {
124        mSupportsPartialRendering = value;
125    }
126
127    public void useParametersFrom(FilterRepresentation a) {
128    }
129
130    public void clearTempRepresentation() {
131        mTempRepresentation = null;
132    }
133
134    public synchronized void updateTempParametersFrom(FilterRepresentation representation) {
135        if (mTempRepresentation == null) {
136            try {
137                mTempRepresentation = representation.clone();
138            } catch (CloneNotSupportedException e) {
139                e.printStackTrace();
140            }
141        } else {
142            mTempRepresentation.useParametersFrom(representation);
143        }
144    }
145
146    public synchronized void synchronizeRepresentation() {
147        if (mTempRepresentation != null) {
148            useParametersFrom(mTempRepresentation);
149        }
150    }
151
152    public boolean allowsMultipleInstances() {
153        return false;
154    }
155
156    public Class getFilterClass() {
157        return mFilterClass;
158    }
159
160    public void setFilterClass(Class filterClass) {
161        mFilterClass = filterClass;
162    }
163
164    public boolean same(FilterRepresentation b) {
165        if (b == null) {
166            return false;
167        }
168        return getFilterClass() == b.getFilterClass();
169    }
170
171    public int getTextId() {
172        return mTextId;
173    }
174
175    public void setTextId(int textId) {
176        mTextId = textId;
177    }
178
179    public int getButtonId() {
180        return mButtonId;
181    }
182
183    public void setButtonId(int buttonId) {
184        mButtonId = buttonId;
185    }
186
187    public int getOverlayId() {
188        return mOverlayId;
189    }
190
191    public void setOverlayId(int overlayId) {
192        mOverlayId = overlayId;
193    }
194
195    public boolean getOverlayOnly() {
196        return mOverlayOnly;
197    }
198
199    public void setOverlayOnly(boolean value) {
200        mOverlayOnly = value;
201    }
202
203    final public int getEditorId() {
204        return mEditorId;
205    }
206
207    public int[] getEditorIds() {
208        return new int[] {
209        mEditorId };
210    }
211
212    public void setEditorId(int editorId) {
213        mEditorId = editorId;
214    }
215
216    public boolean showEditingControls() {
217        return mShowEditingControls;
218    }
219
220    public void setShowEditingControls(boolean showEditingControls) {
221        mShowEditingControls = showEditingControls;
222    }
223
224    public boolean showParameterValue() {
225        return mShowParameterValue;
226    }
227
228    public void setShowParameterValue(boolean showParameterValue) {
229        mShowParameterValue = showParameterValue;
230    }
231
232    public boolean showUtilityPanel() {
233        return mShowUtilityPanel;
234    }
235
236    public void setShowUtilityPanel(boolean showUtilityPanel) {
237        mShowUtilityPanel = showUtilityPanel;
238    }
239
240    public String getStateRepresentation() {
241        return "";
242    }
243
244}
245