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 @ 38549

History | View | Annotate | Download (2.49 KB)

1 36022 fdiaz
package org.gvsig.newlayer.impl;
2
3
import java.awt.BorderLayout;
4
5 38549 jldominguez
import javax.swing.DefaultListSelectionModel;
6 36022 fdiaz
import javax.swing.JList;
7
import javax.swing.JPanel;
8
import javax.swing.JScrollPane;
9
import javax.swing.ListModel;
10
import javax.swing.event.ListSelectionEvent;
11
import javax.swing.event.ListSelectionListener;
12
13
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
14
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
15 37891 cordinyana
import org.gvsig.newlayer.NewLayerProviderFactory;
16 36022 fdiaz
import org.gvsig.newlayer.NewLayerService;
17
import org.gvsig.newlayer.NewLayerWizard;
18
19
public class TypeSelectorPanel extends JPanel implements OptionPanel{
20
21 36220 fdiaz
        /**
22
         *
23
         */
24
        private static final long serialVersionUID = 419873365484240927L;
25 36022 fdiaz
        private NewLayerWizard wizard;
26 37891 cordinyana
    private NewLayerProviderFactory currentType;
27 36022 fdiaz
28
        public TypeSelectorPanel(NewLayerWizard wizard){
29
                this.wizard = wizard;
30
                initializeComponents();
31
        }
32
33
        public String getPanelTitle() {
34
                return "Type selector panel";
35
        }
36
37
        public void nextPanel() throws NotContinueWizardException {
38 36220 fdiaz
                if (currentType!=null){
39
                        this.wizard.setType(currentType);
40
                        return;
41
                }
42
                throw new NotContinueWizardException("", null, false);
43 36022 fdiaz
        }
44
45
        public void lastPanel() {
46
                // do nothing
47
48
        }
49
50
        public void updatePanel() {
51
                initializeComponents();
52
        }
53
54
        public JPanel getJPanel() {
55
                return this;
56
        }
57
58
    private void initializeComponents() {
59
        this.setLayout(new BorderLayout());
60
61
        JList types = new JList();
62 37891 cordinyana
        ListModel model =
63
            new org.gvsig.utils.DefaultListModel(this.getService()
64
                .getProviderFactories());
65 38549 jldominguez
66 36022 fdiaz
        types.setModel(model);
67 38549 jldominguez
        types.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
68 36022 fdiaz
69
        types.addListSelectionListener(new ListSelectionListener() {
70
                        public void valueChanged(ListSelectionEvent e) {
71
                                if (e.getValueIsAdjusting() == false) {
72
                                        JList list = (JList) e.getSource();
73
74
                                if (list.getSelectedIndex() > -1) {
75 37891 cordinyana
                        currentType =
76
                            (NewLayerProviderFactory) list.getSelectedValue();
77 38549 jldominguez
78
                        wizard.setNextButtonEnabled(true);
79
                                } else {
80
                                    wizard.setNextButtonEnabled(false);
81 36022 fdiaz
                                }
82
                            }
83
                        }
84
                });
85
86
        JScrollPane scrollPane = new JScrollPane();
87
        scrollPane.setViewportView(types);
88
        this.add(scrollPane, BorderLayout.CENTER);
89
    }
90
91
        private NewLayerService getService() {
92
                return this.wizard.getService();
93
        }
94
}