Statistics
| Revision:

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 / TypeSelectorPanel.java @ 40560

History | View | Annotate | Download (3.42 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.newlayer.impl;
25

    
26
import java.awt.BorderLayout;
27

    
28
import javax.swing.DefaultListSelectionModel;
29
import javax.swing.JList;
30
import javax.swing.JPanel;
31
import javax.swing.JScrollPane;
32
import javax.swing.ListModel;
33
import javax.swing.event.ListSelectionEvent;
34
import javax.swing.event.ListSelectionListener;
35

    
36
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
37
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
38
import org.gvsig.newlayer.NewLayerProviderFactory;
39
import org.gvsig.newlayer.NewLayerService;
40
import org.gvsig.newlayer.NewLayerWizard;
41

    
42
public class TypeSelectorPanel extends JPanel implements OptionPanel{
43
        
44
        /**
45
         * 
46
         */
47
        private static final long serialVersionUID = 419873365484240927L;
48
        private NewLayerWizard wizard;
49
    private NewLayerProviderFactory currentType;
50

    
51
        public TypeSelectorPanel(NewLayerWizard wizard){
52
                this.wizard = wizard;
53
                initializeComponents();
54
        }
55

    
56
        public String getPanelTitle() {
57
                return "Type selector panel";
58
        }
59

    
60
        public void nextPanel() throws NotContinueWizardException {
61
                if (currentType!=null){
62
                        this.wizard.setType(currentType);
63
                        return;
64
                }
65
                throw new NotContinueWizardException("", null, false);
66
        }
67

    
68
        public void lastPanel() {
69
                // do nothing
70
                
71
        }
72

    
73
        public void updatePanel() {
74
                initializeComponents();
75
        }
76

    
77
        public JPanel getJPanel() {
78
                return this;
79
        }
80

    
81
    private void initializeComponents() {
82
        this.setLayout(new BorderLayout());
83

    
84
        JList types = new JList();     
85
        ListModel model =
86
            new org.gvsig.utils.DefaultListModel(this.getService()
87
                .getProviderFactories());
88
       
89
        types.setModel(model);
90
        types.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
91
        
92
        types.addListSelectionListener(new ListSelectionListener() {
93
                        public void valueChanged(ListSelectionEvent e) {
94
                                if (e.getValueIsAdjusting() == false) {
95
                                        JList list = (JList) e.getSource();
96
                                        
97
                                if (list.getSelectedIndex() > -1) {
98
                        currentType =
99
                            (NewLayerProviderFactory) list.getSelectedValue();
100
                        
101
                        wizard.setNextButtonEnabled(true);
102
                                } else {
103
                                    wizard.setNextButtonEnabled(false);
104
                                }
105
                            }
106
                        }
107
                });
108
        
109
        JScrollPane scrollPane = new JScrollPane();
110
        scrollPane.setViewportView(types);
111
        this.add(scrollPane, BorderLayout.CENTER);        
112
    }
113

    
114
        private NewLayerService getService() {
115
                return this.wizard.getService();
116
        } 
117
}