~keheliya-gallaba/gephi/maven-build

« back to all changes in this revision

Viewing changes to filters/src/main/java/org/gephi/filters/RangePropertyEditor.java

  • Committer: Keheliya Gallaba
  • Date: 2011-08-01 13:01:30 UTC
  • Revision ID: keheliya.gallaba@gmail.com-20110801130130-0u2qgcufi8bvqwxv
Adding Export Plugin, Export Plugin UI, Filters Impl

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2008-2010 Gephi
 
3
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
 
4
Website : http://www.gephi.org
 
5
 
 
6
This file is part of Gephi.
 
7
 
 
8
Gephi is free software: you can redistribute it and/or modify
 
9
it under the terms of the GNU Affero General Public License as
 
10
published by the Free Software Foundation, either version 3 of the
 
11
License, or (at your option) any later version.
 
12
 
 
13
Gephi is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU Affero General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU Affero General Public License
 
19
along with Gephi.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
package org.gephi.filters;
 
22
 
 
23
import java.beans.PropertyEditorSupport;
 
24
import org.gephi.filters.api.Range;
 
25
 
 
26
/**
 
27
 *
 
28
 * @author Mathieu Bastian
 
29
 */
 
30
public class RangePropertyEditor extends PropertyEditorSupport {
 
31
 
 
32
    private Range range;
 
33
 
 
34
    @Override
 
35
    public void setValue(Object value) {
 
36
        this.range = (Range) value;
 
37
    }
 
38
 
 
39
    @Override
 
40
    public Object getValue() {
 
41
        return range;
 
42
    }
 
43
 
 
44
    @Override
 
45
    public String getAsText() {
 
46
        if (range != null) {
 
47
            return range.getRangeType().getSimpleName() + " - " + range.toString();
 
48
        } else {
 
49
            return "null";
 
50
        }
 
51
    }
 
52
 
 
53
    @Override
 
54
    public void setAsText(String text) throws IllegalArgumentException {
 
55
        if (!text.equals("null")) {
 
56
            String[] arr = text.split(" - ");
 
57
            if (arr[0].equals("Float")) {
 
58
                range = new Range(Float.parseFloat(arr[1]), Float.parseFloat(arr[2]));
 
59
            } else if (arr[0].equals("Double")) {
 
60
                range = new Range(Double.parseDouble(arr[1]), Double.parseDouble(arr[2]));
 
61
            } else if (arr[0].equals("Integer")) {
 
62
                range = new Range(Integer.parseInt(arr[1]), Integer.parseInt(arr[2]));
 
63
            } else if (arr[0].equals("Long")) {
 
64
                range = new Range(Long.parseLong(arr[1]), Long.parseLong(arr[2]));
 
65
            }
 
66
        }
 
67
    }
 
68
}