root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / CrsRecentsPanel.java @ 8151
History | View | Annotate | Download (4.69 KB)
1 | 8103 | dguerrero | package org.gvsig.crs.gui.panels; |
---|---|---|---|
2 | |||
3 | import java.awt.Dimension; |
||
4 | import java.awt.FlowLayout; |
||
5 | import java.awt.GridLayout; |
||
6 | |||
7 | import javax.swing.BorderFactory; |
||
8 | import javax.swing.JLabel; |
||
9 | import javax.swing.JPanel; |
||
10 | import javax.swing.JScrollPane; |
||
11 | import javax.swing.JTable; |
||
12 | import javax.swing.ListSelectionModel; |
||
13 | 8146 | jlgomez | import javax.swing.event.TableModelListener; |
14 | 8103 | dguerrero | import javax.swing.table.DefaultTableModel; |
15 | import javax.swing.table.TableColumn; |
||
16 | |||
17 | 8113 | jlgomez | import org.cresques.cts.IProjection; |
18 | import org.gvsig.crs.CrsException; |
||
19 | import org.gvsig.crs.CrsFactory; |
||
20 | import org.gvsig.crs.ICrs; |
||
21 | 8103 | dguerrero | import org.gvsig.crs.persistence.CrsData; |
22 | import org.gvsig.crs.persistence.RecentCRSsPersistence; |
||
23 | |||
24 | import com.iver.andami.PluginServices; |
||
25 | import com.iver.cit.gvsig.gui.TableSorter; |
||
26 | |||
27 | public class CrsRecentsPanel extends JPanel { |
||
28 | |||
29 | /**
|
||
30 | *
|
||
31 | */
|
||
32 | private static final long serialVersionUID = 1L; |
||
33 | |||
34 | public JTable jTable = null; |
||
35 | private JScrollPane jScrollPane = null; |
||
36 | 8113 | jlgomez | public DefaultTableModel dtm = null; |
37 | 8146 | jlgomez | public TableSorter sorter = null; |
38 | 8103 | dguerrero | private CrsData crsDataArray[] = null; |
39 | |||
40 | 8113 | jlgomez | public int selectedRowTable = -1; |
41 | private int codeCRS = -1; |
||
42 | String cadWKT = ""; |
||
43 | |||
44 | 8103 | dguerrero | public CrsRecentsPanel() {
|
45 | super();
|
||
46 | initialize(); |
||
47 | } |
||
48 | |||
49 | private void initialize(){ |
||
50 | this.setLayout(new GridLayout(1,2)); |
||
51 | this.setLayout(new FlowLayout(FlowLayout.LEFT,10,10)); |
||
52 | this.add(getJLabel(), null); |
||
53 | this.add(getJScrollPane(), null); |
||
54 | } |
||
55 | |||
56 | private JLabel getJLabel(){ |
||
57 | JLabel label = new JLabel(); |
||
58 | label.setPreferredSize(new Dimension(500, 30)); |
||
59 | label.setText(PluginServices.getText(this, "?ltimos CRS utilizados:")); |
||
60 | return label;
|
||
61 | } |
||
62 | |||
63 | private JScrollPane getJScrollPane() { |
||
64 | if (jScrollPane == null) { |
||
65 | jScrollPane = new JScrollPane(); |
||
66 | jScrollPane.setPreferredSize(new Dimension(500,150)); |
||
67 | jScrollPane.setBorder( |
||
68 | BorderFactory.createCompoundBorder(
|
||
69 | BorderFactory.createCompoundBorder(
|
||
70 | BorderFactory.createTitledBorder(PluginServices.getText(this,"Coordinate Reference Systems")), |
||
71 | BorderFactory.createEmptyBorder(5,5,5,5)), |
||
72 | jScrollPane.getBorder())); |
||
73 | jScrollPane.setViewportView(getJTable()); |
||
74 | } |
||
75 | return jScrollPane;
|
||
76 | } |
||
77 | |||
78 | public JTable getJTable() { |
||
79 | if (jTable == null) { |
||
80 | String[] columnNames= {"Fuente","C?digo","Nombre"}; |
||
81 | Object[][]data = {}; |
||
82 | dtm = new DefaultTableModel(data, columnNames) |
||
83 | { |
||
84 | public boolean isCellEditable(int row, int column) { |
||
85 | return false; |
||
86 | } |
||
87 | 8146 | jlgomez | /*
|
88 | * metodo necesario para cuando utilizamos tablas ordenadas
|
||
89 | * ya que sino al ordenar por algun campo no se queda con el orden
|
||
90 | * actual al seleccionar una fila (non-Javadoc)
|
||
91 | * @see javax.swing.table.TableModel#getColumnClass(int)
|
||
92 | */
|
||
93 | public Class getColumnClass(int column) |
||
94 | { |
||
95 | return getValueAt(0, column).getClass(); |
||
96 | } |
||
97 | 8103 | dguerrero | }; |
98 | 8146 | jlgomez | sorter = new TableSorter(dtm);
|
99 | 8103 | dguerrero | |
100 | jTable = new JTable(sorter); |
||
101 | 8146 | jlgomez | sorter.setTableHeader(jTable.getTableHeader()); |
102 | 8103 | dguerrero | jTable.setCellSelectionEnabled(false);
|
103 | jTable.setRowSelectionAllowed(true);
|
||
104 | jTable.setColumnSelectionAllowed(false);
|
||
105 | jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||
106 | TableColumn column = null; |
||
107 | for (int i = 0; i < 3; i++) { |
||
108 | column = jTable.getColumnModel().getColumn(i); |
||
109 | if (i == 0) { |
||
110 | column.setPreferredWidth(60); //code column is shorter |
||
111 | }else if (i == 2) { |
||
112 | column.setPreferredWidth(275);
|
||
113 | } |
||
114 | else {
|
||
115 | column.setPreferredWidth(160);
|
||
116 | } |
||
117 | } |
||
118 | 8146 | jlgomez | } |
119 | 8113 | jlgomez | return jTable;
|
120 | } |
||
121 | |||
122 | public ICrs getProjection() {
|
||
123 | try {
|
||
124 | String txt = getWKT();
|
||
125 | ICrs crs = new CrsFactory().getCRS(getCodeCRS(), txt);
|
||
126 | return crs ;
|
||
127 | } catch (CrsException e) {
|
||
128 | e.printStackTrace(); |
||
129 | } |
||
130 | return null; |
||
131 | } |
||
132 | |||
133 | public void setWKT(String authority){ |
||
134 | int cod = getCodeCRS();
|
||
135 | for (int i = 0; i < crsDataArray.length; i++){ |
||
136 | if (crsDataArray[i].getCode() == cod && authority.equals(crsDataArray[i].getAuthority())){
|
||
137 | cadWKT = crsDataArray[i].getWkt(); |
||
138 | break;
|
||
139 | } |
||
140 | } |
||
141 | |||
142 | } |
||
143 | 8103 | dguerrero | |
144 | 8113 | jlgomez | public String getWKT(){ |
145 | return cadWKT;
|
||
146 | 8103 | dguerrero | } |
147 | 8113 | jlgomez | |
148 | public void setCodeCRS(int code) { |
||
149 | codeCRS = code; |
||
150 | } |
||
151 | |||
152 | public int getCodeCRS() { |
||
153 | return codeCRS;
|
||
154 | } |
||
155 | |||
156 | public void setProjection(IProjection crs) { |
||
157 | //setCrs((ICrs) crs);
|
||
158 | } |
||
159 | 8151 | dguerrero | |
160 | /**
|
||
161 | * Carga en la tabla los CRSs leidos del sistema de persistencia.
|
||
162 | */
|
||
163 | public void loadRecents(){ |
||
164 | RecentCRSsPersistence persistence = new RecentCRSsPersistence();
|
||
165 | crsDataArray = persistence.getArrayOfCrsData(); |
||
166 | |||
167 | for (int iRow = crsDataArray.length-1;iRow>=0;iRow--){ |
||
168 | Object row[] ={crsDataArray[iRow].getAuthority(),Integer.toString(crsDataArray[iRow].getCode()),crsDataArray[iRow].getName()}; |
||
169 | dtm.addRow(row); |
||
170 | } |
||
171 | |||
172 | /*
|
||
173 | /*Seleccionar el primer registro.
|
||
174 | */
|
||
175 | int numr = dtm.getRowCount();
|
||
176 | if (numr != 0 ) |
||
177 | this.getJTable().setRowSelectionInterval(0,0); |
||
178 | } |
||
179 | 8103 | dguerrero | |
180 | } |