svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / preferences / DefaultNewLayerPreferencesComponent.java @ 40560
History | View | Annotate | Download (4.59 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.newlayer.impl.preferences; |
||
25 | |||
26 | import java.awt.GridBagConstraints; |
||
27 | import java.awt.GridBagLayout; |
||
28 | import java.awt.Insets; |
||
29 | import java.util.ArrayList; |
||
30 | import java.util.HashSet; |
||
31 | import java.util.List; |
||
32 | import java.util.Set; |
||
33 | |||
34 | import javax.swing.JCheckBox; |
||
35 | import javax.swing.JComponent; |
||
36 | import javax.swing.JPanel; |
||
37 | import javax.swing.event.ChangeEvent; |
||
38 | import javax.swing.event.ChangeListener; |
||
39 | |||
40 | import org.gvsig.newlayer.NewLayerLocator; |
||
41 | import org.gvsig.newlayer.NewLayerProviderFactory; |
||
42 | import org.gvsig.newlayer.preferences.NewLayerPreferencesComponent; |
||
43 | |||
44 | /**
|
||
45 | * Default implementation for the {@link NewLayerPreferencesComponent}.
|
||
46 | *
|
||
47 | * @author gvSIG Team
|
||
48 | * @version $Id$
|
||
49 | */
|
||
50 | public class DefaultNewLayerPreferencesComponent extends JPanel implements |
||
51 | NewLayerPreferencesComponent, ChangeListener {
|
||
52 | |||
53 | private static final long serialVersionUID = -4392838062470171181L; |
||
54 | |||
55 | private JCheckBox[] providerChecks; |
||
56 | private List<NewLayerProviderFactory> providers; |
||
57 | private boolean valueChanged = false; |
||
58 | |||
59 | /**
|
||
60 | * Creates a new DefaultNewLayerPreferencesComponent.
|
||
61 | *
|
||
62 | * @see JPanel#JPanel()
|
||
63 | */
|
||
64 | public DefaultNewLayerPreferencesComponent() {
|
||
65 | this(true); |
||
66 | } |
||
67 | |||
68 | /**
|
||
69 | * Creates a new DefaultNewLayerPreferencesComponent.
|
||
70 | *
|
||
71 | * @param isDoubleBuffered
|
||
72 | * a boolean, true for double-buffering, which
|
||
73 | * uses additional memory space to achieve fast, flicker-free
|
||
74 | * updates
|
||
75 | * @see JPanel#JPanel(boolean)
|
||
76 | */
|
||
77 | public DefaultNewLayerPreferencesComponent(boolean isDoubleBuffered) { |
||
78 | super(isDoubleBuffered);
|
||
79 | initialize(); |
||
80 | } |
||
81 | |||
82 | private void initialize() { |
||
83 | this.setLayout(new GridBagLayout()); |
||
84 | |||
85 | Insets insets = new Insets(1, 0, 1, 0); |
||
86 | |||
87 | GridBagConstraints gbc = new GridBagConstraints(); |
||
88 | gbc.gridx = 0;
|
||
89 | gbc.gridy = 1;
|
||
90 | gbc.gridheight = 1;
|
||
91 | gbc.gridwidth = GridBagConstraints.REMAINDER;
|
||
92 | gbc.fill = GridBagConstraints.NONE;
|
||
93 | gbc.anchor = GridBagConstraints.WEST;
|
||
94 | gbc.weightx = 1.0f;
|
||
95 | gbc.insets = insets; |
||
96 | |||
97 | providers = |
||
98 | new ArrayList<NewLayerProviderFactory>(NewLayerLocator.getManager() |
||
99 | .getProviders()); |
||
100 | providerChecks = new JCheckBox[providers.size()]; |
||
101 | for (int i = 0; i < providers.size(); i++) { |
||
102 | NewLayerProviderFactory factory = providers.get(i); |
||
103 | providerChecks[i] = |
||
104 | new JCheckBox(factory.getLabel(), factory.isEnabled()); |
||
105 | providerChecks[i].addChangeListener(this);
|
||
106 | providerChecks[i].setToolTipText(factory.getDescription()); |
||
107 | add(providerChecks[i], gbc); |
||
108 | gbc.gridy++; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | public JComponent asJComponent() { |
||
113 | return this; |
||
114 | } |
||
115 | |||
116 | public void initializeDefaults() { |
||
117 | for (int i = 0; i < providers.size(); i++) { |
||
118 | NewLayerProviderFactory factory = providers.get(i); |
||
119 | providerChecks[i].setSelected(factory.isEnabled()); |
||
120 | } |
||
121 | valueChanged = false;
|
||
122 | validate(); |
||
123 | } |
||
124 | |||
125 | public Set<NewLayerProviderFactory> getDisabledProviders() { |
||
126 | Set<NewLayerProviderFactory> disabledFactories =
|
||
127 | new HashSet<NewLayerProviderFactory>(); |
||
128 | |||
129 | for (int i = 0; i < providerChecks.length; i++) { |
||
130 | if (!providerChecks[i].isSelected()) {
|
||
131 | disabledFactories.add(providers.get(i)); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | return disabledFactories;
|
||
136 | } |
||
137 | |||
138 | public boolean isValueChanged() { |
||
139 | return valueChanged;
|
||
140 | } |
||
141 | |||
142 | public void setChangesApplied() { |
||
143 | valueChanged = false;
|
||
144 | } |
||
145 | |||
146 | public void stateChanged(ChangeEvent e) { |
||
147 | valueChanged = true;
|
||
148 | } |
||
149 | } |