OSDN Git Service

am fef58a0f: change edit icon
[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         setPriority(FilterRepresentation.TYPE_VIGNETTE);
35         setTextId(R.string.vignette);
36         setButtonId(R.id.vignetteEditor);
37         setEditorId(EditorVignette.ID);
38         setName("Vignette");
39         setFilterClass(ImageFilterVignette.class);
40
41         setMinimum(-100);
42         setMaximum(100);
43         setDefaultValue(0);
44     }
45
46     @Override
47     public void useParametersFrom(FilterRepresentation a) {
48         super.useParametersFrom(a);
49         mCenterX = ((FilterVignetteRepresentation) a).mCenterX;
50         mCenterY = ((FilterVignetteRepresentation) a).mCenterY;
51         mRadiusX = ((FilterVignetteRepresentation) a).mRadiusX;
52         mRadiusY = ((FilterVignetteRepresentation) a).mRadiusY;
53     }
54
55     @Override
56     public FilterRepresentation clone() throws CloneNotSupportedException {
57         FilterVignetteRepresentation representation = (FilterVignetteRepresentation) super
58                 .clone();
59         representation.mCenterX = mCenterX;
60         representation.mCenterY = mCenterY;
61
62         return representation;
63     }
64
65     @Override
66     public void setCenter(float centerX, float centerY) {
67         mCenterX = centerX;
68         mCenterY = centerY;
69     }
70
71     @Override
72     public float getCenterX() {
73         return mCenterX;
74     }
75
76     @Override
77     public float getCenterY() {
78         return mCenterY;
79     }
80
81     @Override
82     public void setRadius(float radiusX, float radiusY) {
83         mRadiusX = radiusX;
84         mRadiusY = radiusY;
85     }
86
87     @Override
88     public void setRadiusX(float radiusX) {
89         mRadiusX = radiusX;
90     }
91
92     @Override
93     public void setRadiusY(float radiusY) {
94         mRadiusY = radiusY;
95     }
96
97     @Override
98     public float getRadiusX() {
99         return mRadiusX;
100     }
101
102     @Override
103     public float getRadiusY() {
104         return mRadiusY;
105     }
106
107     public boolean isCenterSet() {
108         return mCenterX != Float.NaN;
109     }
110
111     @Override
112     public boolean isNil() {
113         return getValue() == 0;
114     }
115
116     private static final String[] sParams = {
117             "Name", "value", "mCenterX", "mCenterY", "mRadiusX",
118             "mRadiusY"
119     };
120
121     @Override
122     public String[][] serializeRepresentation() {
123         String[][] ret = {
124                 { sParams[0], getName() },
125                 { sParams[1], Integer.toString(getValue()) },
126                 { sParams[2], Float.toString(mCenterX) },
127                 { sParams[3], Float.toString(mCenterY) },
128                 { sParams[4], Float.toString(mRadiusX) },
129                 { sParams[5], Float.toString(mRadiusY) }
130         };
131         return ret;
132     }
133
134     @Override
135     public void deSerializeRepresentation(String[][] rep) {
136         super.deSerializeRepresentation(rep);
137         for (int i = 0; i < rep.length; i++) {
138             String key = rep[i][0];
139             String value = rep[i][1];
140             if (sParams[0].equals(key)) {
141                 setName(value);
142             } else if (sParams[1].equals(key)) {
143                setValue(Integer.parseInt(value));
144             } else if (sParams[2].equals(key)) {
145                 mCenterX = Float.parseFloat(value);
146             } else if (sParams[3].equals(key)) {
147                 mCenterY = Float.parseFloat(value);
148             } else if (sParams[4].equals(key)) {
149                 mRadiusX = Float.parseFloat(value);
150             } else if (sParams[5].equals(key)) {
151                 mRadiusY = Float.parseFloat(value);
152             }
153         }
154     }
155 }