~keheliya-gallaba/gephi/maven-build

« back to all changes in this revision

Viewing changes to ExportPluginUI/src/main/java/org/gephi/ui/exporter/plugin/UIExporterCSV.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.ui.exporter.plugin;
 
22
 
 
23
import javax.swing.JPanel;
 
24
import org.gephi.io.exporter.plugin.ExporterCSV;
 
25
import org.gephi.io.exporter.spi.Exporter;
 
26
import org.gephi.io.exporter.spi.ExporterUI;
 
27
import org.openide.util.NbBundle;
 
28
import org.openide.util.lookup.ServiceProvider;
 
29
 
 
30
/**
 
31
 *
 
32
 * @author Mathieu Bastian
 
33
 */
 
34
@ServiceProvider(service = ExporterUI.class)
 
35
public class UIExporterCSV implements ExporterUI {
 
36
 
 
37
    private UIExporterCSVPanel panel;
 
38
    private ExporterCSV exporterCSV;
 
39
    private ExporterCSVSettings settings = new ExporterCSVSettings();
 
40
 
 
41
    public void setup(Exporter exporter) {
 
42
        exporterCSV = (ExporterCSV) exporter;
 
43
        settings.load(exporterCSV);
 
44
        panel.setup(exporterCSV);
 
45
    }
 
46
 
 
47
    public void unsetup(boolean update) {
 
48
        if (update) {
 
49
            panel.unsetup(exporterCSV);
 
50
            settings.save(exporterCSV);
 
51
        }
 
52
        panel = null;
 
53
        exporterCSV = null;
 
54
    }
 
55
 
 
56
    public JPanel getPanel() {
 
57
        panel = new UIExporterCSVPanel();
 
58
        return panel;
 
59
    }
 
60
 
 
61
    public boolean isUIForExporter(Exporter exporter) {
 
62
        return exporter instanceof ExporterCSV;
 
63
    }
 
64
 
 
65
    public String getDisplayName() {
 
66
        return NbBundle.getMessage(UIExporterCSV.class, "UIExporterCSV.name");
 
67
    }
 
68
 
 
69
    private static class ExporterCSVSettings {
 
70
 
 
71
        private boolean edgeWeight = true;
 
72
        private boolean writeZero = true;
 
73
        private boolean header = true;
 
74
        private boolean list = false;
 
75
 
 
76
        private void save(ExporterCSV exporterCSV) {
 
77
            this.edgeWeight = exporterCSV.isEdgeWeight();
 
78
            this.writeZero = exporterCSV.isWriteZero();
 
79
            this.header = exporterCSV.isHeader();
 
80
            this.list = exporterCSV.isList();
 
81
        }
 
82
 
 
83
        private void load(ExporterCSV exporterCSV) {
 
84
            exporterCSV.setEdgeWeight(edgeWeight);
 
85
            exporterCSV.setWriteZero(writeZero);
 
86
            exporterCSV.setHeader(header);
 
87
            exporterCSV.setList(list);
 
88
        }
 
89
    }
 
90
}