2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.gallery3d.filtershow.filters;
19 import com.android.gallery3d.R;
20 import com.android.gallery3d.filtershow.editors.EditorVignette;
21 import com.android.gallery3d.filtershow.imageshow.Oval;
23 public class FilterVignetteRepresentation extends FilterBasicRepresentation implements Oval {
24 private static final String LOGTAG = "FilterVignetteRepresentation";
25 private float mCenterX = Float.NaN;
26 private float mCenterY;
27 private float mRadiusX = Float.NaN;
28 private float mRadiusY;
30 public FilterVignetteRepresentation() {
31 super("Vignette", -100, 50, 100);
32 setSerializationName("VIGNETTE");
33 setShowParameterValue(true);
34 setFilterType(FilterRepresentation.TYPE_VIGNETTE);
35 setTextId(R.string.vignette);
36 setEditorId(EditorVignette.ID);
38 setFilterClass(ImageFilterVignette.class);
45 public void useParametersFrom(FilterRepresentation a) {
46 super.useParametersFrom(a);
47 mCenterX = ((FilterVignetteRepresentation) a).mCenterX;
48 mCenterY = ((FilterVignetteRepresentation) a).mCenterY;
49 mRadiusX = ((FilterVignetteRepresentation) a).mRadiusX;
50 mRadiusY = ((FilterVignetteRepresentation) a).mRadiusY;
54 public FilterRepresentation copy() {
55 FilterVignetteRepresentation representation = new FilterVignetteRepresentation();
56 copyAllParameters(representation);
57 return representation;
61 protected void copyAllParameters(FilterRepresentation representation) {
62 super.copyAllParameters(representation);
63 representation.useParametersFrom(this);
67 public void setCenter(float centerX, float centerY) {
73 public float getCenterX() {
78 public float getCenterY() {
83 public void setRadius(float radiusX, float radiusY) {
89 public void setRadiusX(float radiusX) {
94 public void setRadiusY(float radiusY) {
99 public float getRadiusX() {
104 public float getRadiusY() {
108 public boolean isCenterSet() {
109 return mCenterX != Float.NaN;
113 public boolean isNil() {
114 return getValue() == 0;
118 public boolean equals(FilterRepresentation representation) {
119 if (!super.equals(representation)) {
122 if (representation instanceof FilterVignetteRepresentation) {
123 FilterVignetteRepresentation rep = (FilterVignetteRepresentation) representation;
124 if (rep.getCenterX() == getCenterX()
125 && rep.getCenterY() == getCenterY()
126 && rep.getRadiusX() == getRadiusX()
127 && rep.getRadiusY() == getRadiusY()) {
134 private static final String[] sParams = {
135 "Name", "value", "mCenterX", "mCenterY", "mRadiusX",
140 public String[][] serializeRepresentation() {
142 { sParams[0], getName() },
143 { sParams[1], Integer.toString(getValue()) },
144 { sParams[2], Float.toString(mCenterX) },
145 { sParams[3], Float.toString(mCenterY) },
146 { sParams[4], Float.toString(mRadiusX) },
147 { sParams[5], Float.toString(mRadiusY) }
153 public void deSerializeRepresentation(String[][] rep) {
154 super.deSerializeRepresentation(rep);
155 for (int i = 0; i < rep.length; i++) {
156 String key = rep[i][0];
157 String value = rep[i][1];
158 if (sParams[0].equals(key)) {
160 } else if (sParams[1].equals(key)) {
161 setValue(Integer.parseInt(value));
162 } else if (sParams[2].equals(key)) {
163 mCenterX = Float.parseFloat(value);
164 } else if (sParams[3].equals(key)) {
165 mCenterY = Float.parseFloat(value);
166 } else if (sParams[4].equals(key)) {
167 mRadiusX = Float.parseFloat(value);
168 } else if (sParams[5].equals(key)) {
169 mRadiusY = Float.parseFloat(value);