OSDN Git Service

Removing unused UI fields in FilterRepresentation.
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / filters / FilterVignetteRepresentation.java
1 /*
2  * Copyright (C) 2012 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 com.android.gallery3d.R;
20 import com.android.gallery3d.filtershow.editors.EditorVignette;
21 import com.android.gallery3d.filtershow.imageshow.Oval;
22
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;
29
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);
37         setName("Vignette");
38         setFilterClass(ImageFilterVignette.class);
39         setMinimum(-100);
40         setMaximum(100);
41         setDefaultValue(0);
42     }
43
44     @Override
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;
51     }
52
53     @Override
54     public FilterRepresentation clone() throws CloneNotSupportedException {
55         FilterVignetteRepresentation representation = (FilterVignetteRepresentation) super
56                 .clone();
57         representation.mCenterX = mCenterX;
58         representation.mCenterY = mCenterY;
59
60         return representation;
61     }
62
63     @Override
64     public void setCenter(float centerX, float centerY) {
65         mCenterX = centerX;
66         mCenterY = centerY;
67     }
68
69     @Override
70     public float getCenterX() {
71         return mCenterX;
72     }
73
74     @Override
75     public float getCenterY() {
76         return mCenterY;
77     }
78
79     @Override
80     public void setRadius(float radiusX, float radiusY) {
81         mRadiusX = radiusX;
82         mRadiusY = radiusY;
83     }
84
85     @Override
86     public void setRadiusX(float radiusX) {
87         mRadiusX = radiusX;
88     }
89
90     @Override
91     public void setRadiusY(float radiusY) {
92         mRadiusY = radiusY;
93     }
94
95     @Override
96     public float getRadiusX() {
97         return mRadiusX;
98     }
99
100     @Override
101     public float getRadiusY() {
102         return mRadiusY;
103     }
104
105     public boolean isCenterSet() {
106         return mCenterX != Float.NaN;
107     }
108
109     @Override
110     public boolean isNil() {
111         return getValue() == 0;
112     }
113
114     private static final String[] sParams = {
115             "Name", "value", "mCenterX", "mCenterY", "mRadiusX",
116             "mRadiusY"
117     };
118
119     @Override
120     public String[][] serializeRepresentation() {
121         String[][] ret = {
122                 { sParams[0], getName() },
123                 { sParams[1], Integer.toString(getValue()) },
124                 { sParams[2], Float.toString(mCenterX) },
125                 { sParams[3], Float.toString(mCenterY) },
126                 { sParams[4], Float.toString(mRadiusX) },
127                 { sParams[5], Float.toString(mRadiusY) }
128         };
129         return ret;
130     }
131
132     @Override
133     public void deSerializeRepresentation(String[][] rep) {
134         super.deSerializeRepresentation(rep);
135         for (int i = 0; i < rep.length; i++) {
136             String key = rep[i][0];
137             String value = rep[i][1];
138             if (sParams[0].equals(key)) {
139                 setName(value);
140             } else if (sParams[1].equals(key)) {
141                setValue(Integer.parseInt(value));
142             } else if (sParams[2].equals(key)) {
143                 mCenterX = Float.parseFloat(value);
144             } else if (sParams[3].equals(key)) {
145                 mCenterY = Float.parseFloat(value);
146             } else if (sParams[4].equals(key)) {
147                 mRadiusX = Float.parseFloat(value);
148             } else if (sParams[5].equals(key)) {
149                 mRadiusY = Float.parseFloat(value);
150             }
151         }
152     }
153 }