Statistics
| Revision:

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

History | View | Annotate | Download (3.56 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
        int code = 0;
26
        
27
        private boolean okPressed = false;
28
                
29
        public CRSSelectionDialogPanel(){
30
                super();                
31
                inicializate();
32
        }
33
        
34
        public void inicializate(){
35
                vp = new CRSViewPanel();
36
                this.add(getContentPanel(), null);
37
                
38
                ListSelectionModel rowSM = vp.ep.getJTable().getSelectionModel();
39
                rowSM.addListSelectionListener(this);
40
                
41
                vp.getButtonAccept().addActionListener(new java.awt.event.ActionListener() {
42
            public void actionPerformed(java.awt.event.ActionEvent e) {
43
                    lastProj = getProjection();
44
                    
45
                    if (lastProj != null){
46
                            PluginServices.getMDIManager().closeWindow(CRSSelectionDialogPanel.this);
47
                                    okPressed = true;
48
                            }
49
                    else {
50
                            okPressed = false;
51
                    }                                
52
            }
53
        });
54
        vp.getButtonCancel().addActionListener(new java.awt.event.ActionListener() {
55
            public void actionPerformed(java.awt.event.ActionEvent e) {
56
                setProjection(lastProj);
57
                PluginServices.getMDIManager().closeWindow(CRSSelectionDialogPanel.this);
58
                okPressed = false;
59
            }
60
        });
61
        }
62
        
63
        public boolean isOkPressed() { return okPressed; }
64
                        
65
    public CRSViewPanel getProjPanel() {
66
        return (CRSViewPanel) getContentPanel();
67
    }
68

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

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

    
120
        public void actionPerformed(ActionEvent arg0) {
121
                // TODO Auto-generated method stub
122
                
123
        }
124
        
125
        public WindowInfo getWindowInfo() {
126
                WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
127
                   m_viewinfo.setTitle(PluginServices.getText(this, "Nuevo CRS"));
128
                return m_viewinfo;
129
        }
130
}