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

History | View | Annotate | Download (2.04 KB)

1
package org.gvsig.newlayer.impl;
2

    
3
import java.awt.BorderLayout;
4

    
5
import javax.swing.JList;
6
import javax.swing.JPanel;
7
import javax.swing.JScrollPane;
8
import javax.swing.ListModel;
9
import javax.swing.event.ListSelectionEvent;
10
import javax.swing.event.ListSelectionListener;
11

    
12
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
13
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
14
import org.gvsig.newlayer.NewLayerService;
15
import org.gvsig.newlayer.NewLayerWizard;
16

    
17
public class TypeSelectorPanel extends JPanel implements OptionPanel{
18
        
19
        /**
20
         * 
21
         */
22
        private static final long serialVersionUID = 419873365484240927L;
23
        private NewLayerWizard wizard;
24
        private String currentType;
25

    
26
        public TypeSelectorPanel(NewLayerWizard wizard){
27
                this.wizard = wizard;
28
                initializeComponents();
29
        }
30

    
31
        public String getPanelTitle() {
32
                return "Type selector panel";
33
        }
34

    
35
        public void nextPanel() throws NotContinueWizardException {
36
                if (currentType!=null){
37
                        this.wizard.setType(currentType);
38
                        return;
39
                }
40
                throw new NotContinueWizardException("", null, false);
41
        }
42

    
43
        public void lastPanel() {
44
                // do nothing
45
                
46
        }
47

    
48
        public void updatePanel() {
49
                initializeComponents();
50
        }
51

    
52
        public JPanel getJPanel() {
53
                return this;
54
        }
55

    
56
    private void initializeComponents() {
57
        this.setLayout(new BorderLayout());
58

    
59
        JList types = new JList();     
60
        ListModel model = new org.gvsig.utils.DefaultListModel(this.getService().getTypes());
61
        types.setModel(model);
62
        
63
        types.addListSelectionListener(new ListSelectionListener() {
64
                        public void valueChanged(ListSelectionEvent e) {
65
                                if (e.getValueIsAdjusting() == false) {
66
                                        JList list = (JList) e.getSource();
67
                                        
68
                                if (list.getSelectedIndex() > -1) {
69
                                        currentType = (String) list.getSelectedValue();
70
                                }
71
                            }
72
                        }
73
                });
74
        
75
        JScrollPane scrollPane = new JScrollPane();
76
        scrollPane.setViewportView(types);
77
        this.add(scrollPane, BorderLayout.CENTER);        
78
    }
79

    
80
        private NewLayerService getService() {
81
                return this.wizard.getService();
82
        } 
83
}