Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / preferences / DefaultNewLayerPreferencesComponent.java @ 37891

History | View | Annotate | Download (4.54 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.newlayer.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.newlayer.NewLayerLocator;
39
import org.gvsig.newlayer.NewLayerProviderFactory;
40
import org.gvsig.newlayer.preferences.NewLayerPreferencesComponent;
41

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

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

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

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

    
66
    /**
67
     * Creates a new DefaultNewLayerPreferencesComponent.
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 DefaultNewLayerPreferencesComponent(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<NewLayerProviderFactory>(NewLayerLocator.getManager()
97
                .getProviders());
98
        providerChecks = new JCheckBox[providers.size()];
99
        for (int i = 0; i < providers.size(); i++) {
100
            NewLayerProviderFactory factory = providers.get(i);
101
            providerChecks[i] =
102
                new JCheckBox(factory.getLabel(), factory.isEnabled());
103
            providerChecks[i].addChangeListener(this);
104
            providerChecks[i].setToolTipText(factory.getDescription());
105
            add(providerChecks[i], gbc);
106
            gbc.gridy++;
107
        }
108
    }
109

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

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

    
123
    public Set<NewLayerProviderFactory> getDisabledProviders() {
124
        Set<NewLayerProviderFactory> disabledFactories =
125
            new HashSet<NewLayerProviderFactory>();
126

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

    
133
        return disabledFactories;
134
    }
135

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

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

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