Statistics
| Revision:

root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / CRSSelectionDialogPanel.java @ 7732

History | View | Annotate | Download (3.4 KB)

1
package org.gvsig.crs.gui;
2

    
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5

    
6
import javax.swing.JPanel;
7
import javax.swing.ListSelectionModel;
8
import javax.swing.event.ListSelectionEvent;
9
import javax.swing.event.ListSelectionListener;
10

    
11
import org.cresques.cts.IProjection;
12

    
13
import com.iver.andami.PluginServices;
14
import com.iver.andami.ui.mdiManager.IWindow;
15
import com.iver.andami.ui.mdiManager.WindowInfo;
16
import com.iver.cit.gvsig.gui.dialogs.CSSelectionDialog;
17

    
18
public class CRSSelectionDialogPanel extends JPanel implements  IWindow, ListSelectionListener, ActionListener {
19
        
20
        private static final long serialVersionUID = 1L;        
21
        
22
        JPanel contentPane = null;
23
        public CRSViewPanel vp = null;
24
        private IProjection lastProj = null;
25
        
26
        private boolean okPressed = false;
27
                
28
        public CRSSelectionDialogPanel(){
29
                super();                
30
                inicializate();
31
        }
32
        
33
        public void inicializate(){
34
                vp = new CRSViewPanel();
35
                this.add(getContentPanel(), null);
36
                
37
                ListSelectionModel rowSM = vp.ep.getJTable().getSelectionModel();
38
                rowSM.addListSelectionListener(this);
39
                
40
                vp.getButtonAccept().addActionListener(new java.awt.event.ActionListener() {
41
            public void actionPerformed(java.awt.event.ActionEvent e) {
42
                    lastProj = getProjection();
43
                    
44
                    if (lastProj != null){
45
                            PluginServices.getMDIManager().closeWindow(CRSSelectionDialogPanel.this);
46
                                    okPressed = true;
47
                            }
48
                    else {
49
                            okPressed = false;
50
                    }                                
51
            }
52
        });
53
        vp.getButtonCancel().addActionListener(new java.awt.event.ActionListener() {
54
            public void actionPerformed(java.awt.event.ActionEvent e) {
55
                setProjection(lastProj);
56
                PluginServices.getMDIManager().closeWindow(CRSSelectionDialogPanel.this);
57
                okPressed = false;
58
            }
59
        });
60
        }
61
        
62
        public boolean isOkPressed() { return okPressed; }
63
                        
64
    public CRSViewPanel getProjPanel() {
65
        return (CRSViewPanel) getContentPanel();
66
    }
67

    
68
        public JPanel getContentPanel() {
69
            if (contentPane == null) {
70
                contentPane = vp;
71
                
72
       }
73
      return contentPane;
74
    }        
75

    
76
        public void valueChanged(ListSelectionEvent e) {
77
                ListSelectionModel lsm = (ListSelectionModel)e.getSource();
78
        if (lsm.isSelectionEmpty()) {
79
                vp.ep.selectedRowTable = -1;
80
                vp.ep.setCodeCRS(-1);
81
                vp.getButtonAccept().setEnabled(false);
82
                vp.ep.getInfoCrs().setEnabled(false);  
83
        } 
84
        else {                
85
                vp.ep.selectedRowTable = lsm.getMinSelectionIndex();
86
                vp.ep.setCodeCRS(Integer.parseInt((String)vp.ep.dtm.getValueAt(vp.ep.selectedRowTable,0)));
87
                vp.ep.setWKT();
88
                vp.getButtonAccept().setEnabled(true);
89
                vp.ep.getInfoCrs().setEnabled(true);  
90
        }
91
              
92
        }        
93
        
94
        public IProjection getProjection() {
95
                return (IProjection) getProjPanel().getProjection();
96
        }
97
        /**
98
         * @param proj
99
         */
100
        public void setProjection(IProjection proj) {
101
                lastProj = proj;
102
                getProjPanel().setProjection(proj);
103
        }
104
        
105
        public String getProjectionAbrev(){
106
                return  (String) getProjPanel().getProjection().getAbrev();
107
        }
108

    
109
        public void actionPerformed(ActionEvent arg0) {
110
                // TODO Auto-generated method stub
111
                
112
        }
113
        
114
        public WindowInfo getWindowInfo() {
115
                WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
116
                   m_viewinfo.setTitle(PluginServices.getText(this, "Nuevo CRS"));
117
                return m_viewinfo;
118
        }
119
}