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 java.util.Vector;
20
21public abstract class FilterPointRepresentation extends FilterRepresentation {
22    private static final String LOGTAG = "FilterPointRepresentation";
23    private Vector<FilterPoint> mCandidates = new Vector<FilterPoint>();
24
25    public FilterPointRepresentation(String type, int textid, int editorID) {
26        super(type);
27        setFilterClass(ImageFilterRedEye.class);
28        setFilterType(FilterRepresentation.TYPE_NORMAL);
29        setTextId(textid);
30        setEditorId(editorID);
31    }
32
33    @Override
34    public abstract FilterRepresentation copy();
35
36    @Override
37    protected void copyAllParameters(FilterRepresentation representation) {
38        super.copyAllParameters(representation);
39        representation.useParametersFrom(this);
40    }
41
42    public boolean hasCandidates() {
43        return mCandidates != null;
44    }
45
46    public Vector<FilterPoint> getCandidates() {
47        return mCandidates;
48    }
49
50    @Override
51    public boolean isNil() {
52        if (getCandidates() != null && getCandidates().size() > 0) {
53            return false;
54        }
55        return true;
56    }
57
58    public Object getCandidate(int index) {
59        return this.mCandidates.get(index);
60    }
61
62    public void addCandidate(FilterPoint c) {
63        this.mCandidates.add(c);
64    }
65
66    @Override
67    public void useParametersFrom(FilterRepresentation a) {
68        if (a instanceof FilterPointRepresentation) {
69            FilterPointRepresentation representation = (FilterPointRepresentation) a;
70            mCandidates.clear();
71            for (FilterPoint redEyeCandidate : representation.mCandidates) {
72                mCandidates.add(redEyeCandidate);
73            }
74        }
75    }
76
77    public void removeCandidate(RedEyeCandidate c) {
78        this.mCandidates.remove(c);
79    }
80
81    public void clearCandidates() {
82        this.mCandidates.clear();
83    }
84
85    public int getNumberOfCandidates() {
86        return mCandidates.size();
87    }
88}
89