Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / exportto / swing / impl / preferences / DefaultExporttoPreferencesComponent.java @ 37887

History | View | Annotate | Download (4.66 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.exportto.swing.impl.preferences;
23

    
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.util.ArrayList;
28
import java.util.HashSet;
29
import java.util.List;
30
import java.util.Set;
31

    
32
import javax.swing.JCheckBox;
33
import javax.swing.JComponent;
34
import javax.swing.JPanel;
35
import javax.swing.event.ChangeEvent;
36
import javax.swing.event.ChangeListener;
37

    
38
import org.gvsig.exportto.swing.preferences.ExporttoSwingPreferencesComponent;
39
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderFactory;
40
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderLocator;
41

    
42
/**
43
 * Default implementation for the {@link ExporttoSwingPreferencesComponent}.
44
 * 
45
 * @author gvSIG Team
46
 * @version $Id$
47
 */
48
public class DefaultExporttoPreferencesComponent extends JPanel implements
49
    ExporttoSwingPreferencesComponent, ChangeListener {
50

    
51
    private static final long serialVersionUID = -4392838062470171181L;
52

    
53
    private JCheckBox[] providerChecks;
54
    private List<ExporttoSwingProviderFactory> providers;
55
    private boolean valueChanged = false;
56

    
57
    /**
58
     * Creates a new DefaultExporttoPreferencesComponent.
59
     * 
60
     * @see JPanel#JPanel()
61
     */
62
    public DefaultExporttoPreferencesComponent() {
63
        this(true);
64
    }
65

    
66
    /**
67
     * Creates a new DefaultExporttoPreferencesComponent.
68
     * 
69
     * @param isDoubleBuffered
70
     *            a boolean, true for double-buffering, which
71
     *            uses additional memory space to achieve fast, flicker-free
72
     *            updates
73
     * @see JPanel#JPanel(boolean)
74
     */
75
    public DefaultExporttoPreferencesComponent(boolean isDoubleBuffered) {
76
        super(isDoubleBuffered);
77
        initialize();
78
    }
79

    
80
    private void initialize() {
81
        this.setLayout(new GridBagLayout());
82

    
83
        Insets insets = new Insets(1, 0, 1, 0);
84

    
85
        GridBagConstraints gbc = new GridBagConstraints();
86
        gbc.gridx = 0;
87
        gbc.gridy = 1;
88
        gbc.gridheight = 1;
89
        gbc.gridwidth = GridBagConstraints.REMAINDER;
90
        gbc.fill = GridBagConstraints.NONE;
91
        gbc.anchor = GridBagConstraints.WEST;
92
        gbc.weightx = 1.0f;
93
        gbc.insets = insets;
94

    
95
        providers =
96
            new ArrayList<ExporttoSwingProviderFactory>(
97
                ExporttoSwingProviderLocator.getManager()
98
                    .getProviderFactories());
99
        providerChecks = new JCheckBox[providers.size()];
100
        for (int i = 0; i < providers.size(); i++) {
101
            ExporttoSwingProviderFactory factory = providers.get(i);
102
            providerChecks[i] =
103
                new JCheckBox(factory.getLabel(), factory.isEnabled());
104
            providerChecks[i].addChangeListener(this);
105
            providerChecks[i].setToolTipText(factory.getDescription());
106
            add(providerChecks[i], gbc);
107
            gbc.gridy++;
108
        }
109
    }
110

    
111
    public JComponent asJComponent() {
112
        return this;
113
    }
114

    
115
    public void initializeDefaults() {
116
        for (int i = 0; i < providers.size(); i++) {
117
            ExporttoSwingProviderFactory factory = providers.get(i);
118
            providerChecks[i].setSelected(factory.isEnabled());
119
        }
120
        valueChanged = false;
121
        validate();
122
    }
123

    
124
    public Set<?> getDisabledProviders() {
125
        Set<ExporttoSwingProviderFactory> disabledFactories =
126
            new HashSet<ExporttoSwingProviderFactory>();
127

    
128
        for (int i = 0; i < providerChecks.length; i++) {
129
            if (!providerChecks[i].isSelected()) {
130
                disabledFactories.add(providers.get(i));
131
            }
132
        }
133

    
134
        return disabledFactories;
135
    }
136

    
137
    public boolean isValueChanged() {
138
        return valueChanged;
139
    }
140

    
141
    public void setChangesApplied() {
142
        valueChanged = false;
143
    }
144

    
145
    public void stateChanged(ChangeEvent e) {
146
        valueChanged = true;
147
    }
148
}