Index: org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.common/src/main/java/org/gvsig/crs/gui/panels/EPSGpanel.java =================================================================== --- org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.common/src/main/java/org/gvsig/crs/gui/panels/EPSGpanel.java (revisione 342) +++ org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.common/src/main/java/org/gvsig/crs/gui/panels/EPSGpanel.java (copia locale) @@ -111,15 +111,12 @@ public int epsg_code = 0; public int selectedRowTable = -1; private int codeCRS = -1; - int[] valid_method_code = { 1024, 9800, 9801, 9802, 9803, 9804, 9805, 9806, 9807, 9808, 9809, 9810, - 9811, 9812, 9813, 9814, 9815, 9816, 9817, 9602, 9659, 9818, 9819, 9820, 9822, - 9827}; + int[] valid_method_code = {1024, 9800, 9801, 9802, 9803, 9804, 9805, 9806, 9807, 9808, 9809, 9810, + 9811, 9812, 9813, 9814, 9815, 9816, 9817, 9602, 9659, 9818, 9819, 9820, 9822, 9827}; - boolean tecla_valida = false; boolean source_yn = false; - private JRadioButton codeRadioButton = null; private JRadioButton nameRadioButton = null; private JRadioButton areaRadioButton = null; @@ -253,7 +250,7 @@ if (searchTextField.getText().equals("")) { searchTextField.setBackground(new Color(255,204,204)); - JOptionPane.showMessageDialog(this, PluginServices.getText(this,"fill_name"), "Warning...", JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(this, PluginServices.getText(this,"fill_name"), PluginServices.getText(this,"warning"), JOptionPane.WARNING_MESSAGE); } else { @@ -264,155 +261,94 @@ dtm.removeRow(numRow); } - if (codeRadioButton.isSelected() && (searchTextField.getText().length()!=searchTextField.getText().replaceAll("[^0-9]", "").length())){ + key = searchTextField.getText(); + if (codeRadioButton.isSelected() && (key.length() != key.replaceAll("[^0-9]", "").length())){ not_numeric = true; } //Dependiendo de la opcion se realizada una busqueda ResultSet result = null; - ResultSet result2 = null; - /* - * variable que indicara si la busqueda se hace primero en epsg_coordinatereferencesystem - * o en epsg_area; esto es debido a que HSQLDB no soporta la bsqueda simultnea en ambas - * tablas, por lo cual hay que separar la bsqueda - */ - int bus = 2; + String sentence = null; + String select = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, " + + "area_of_use_code, source_geogcrs_code, projection_conv_code, deprecated, " + + "epsg_area.area_name, epsg_area.area_of_use " + + "FROM epsg_coordinatereferencesystem " + + "INNER JOIN epsg_area " + + "ON (epsg_coordinatereferencesystem.area_of_use_code = epsg_area.area_code) "; + String condition1 = null; + String condition2 = "AND (deprecated = 0) " + + "AND (coord_ref_sys_kind IN ('geographic 2D', 'projected')) " + + "ORDER BY coord_ref_sys_name"; + if (codeRadioButton.isSelected() && !not_numeric) { - bus=0; key = searchTextField.getText(); int code = Integer.parseInt(key); - String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " + - "source_geogcrs_code, projection_conv_code " + - "FROM epsg_coordinatereferencesystem " + - "WHERE coord_ref_sys_code = " + code; - - result = Query.select(sentence,connect.getConnection()); - + condition1 = "WHERE coord_ref_sys_code = " + code + " "; + sentence = select + condition1 + condition2; + result = Query.select(sentence, connect.getConnection()); } else if (nameRadioButton.isSelected()) { - bus=0; key = searchTextField.getText(); key = key.toLowerCase(); - String key2 = key.substring(0,1); - String key3 = key.substring(1,key.length()); - key2 = key2.toUpperCase(); - - String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, " + - "area_of_use_code, source_geogcrs_code, projection_conv_code " + - "FROM epsg_coordinatereferencesystem " + - "WHERE (coord_ref_sys_name LIKE '%" + key + "%') OR (coord_ref_sys_name LIKE '%"+ - key.toUpperCase() +"%') " + - "OR (coord_ref_sys_name LIKE '%" + key2+key3 +"%')"; - result = Query.select(sentence,connect.getConnection()); + condition1 = "WHERE (LCASE(coord_ref_sys_name) LIKE '%" + key + "%') "; + sentence = select + condition1 + condition2; + result = Query.select(sentence, connect.getConnection()); } else if (areaRadioButton.isSelected()) { - bus=1; key = searchTextField.getText(); - key = key.toLowerCase(); - String key2 = key.substring(0,1); - String key3 = key.substring(1,key.length()); - key2 = key2.toUpperCase(); - - String sentence = "SELECT area_name, area_of_use, area_code " + - "FROM epsg_area " + - "WHERE (area_name LIKE '%" + key + "%') OR (area_of_use LIKE '%" + key + "%') "+ - "OR (area_name LIKE '%" + key.toUpperCase() + "%') OR (area_of_use LIKE '%" + key.toUpperCase() + "%') "+ - "OR (area_name LIKE '%" + key2+key3 + "%') OR (area_of_use LIKE '%" + key2+key3 + "%') "; - result = Query.select(sentence,connect.getConnection()); + key = key.toLowerCase(); + condition1 = "WHERE ((LCASE(epsg_area.area_name) LIKE '%" + key + "%') " + + "OR (LCASE(epsg_area.area_of_use) LIKE '%" + key + "%')) "; + sentence = select + condition1 + condition2; + result = Query.select(sentence, connect.getConnection()); } - if (bus==0){ + if (result != null) { try { while(result.next()) { - Object[]data = new Object[5]; - data[0] = String.valueOf(result.getInt("coord_ref_sys_code")); + Object[] data = new Object[5]; + data[0] = result.getString("coord_ref_sys_code"); data[1] = result.getString("coord_ref_sys_name"); crs_kind = result.getString("coord_ref_sys_kind"); data[2] = crs_kind; projection_conv_code = result.getInt("projection_conv_code"); setProjectionCode(projection_conv_code); - - int area_of_use_code = Integer.parseInt(result.getString("area_of_use_code")); - - String sentence = "SELECT area_name, area_of_use FROM epsg_area " + - "WHERE area_code = "+ area_of_use_code ; - - result2 = Query.select(sentence,connect.getConnection()); - while(result2.next()){ - data[3] = result2.getString("area_name"); - data[4] = result2.getString("area_of_use"); - } - if (data[0]!=null /*&& validCRS(projection_conv_code)*/ && valid(crs_kind)){ + data[3] = result.getString("area_name"); + data[4] = result.getString("area_of_use"); + if (data[0] != null /*&& validCRS(projection_conv_code)*/ && valid(crs_kind)){ dtm.addRow(data); } } } - catch (SQLException e1) { logger.error("Can't get values from RecordSet.",e1); } } - else if (bus==1){ - try { - while(result.next()) { - Object[]data = new Object[5]; - data[3] = result.getString("area_name"); - data[4] = result.getString("area_of_use"); - - int area_of_use_code = Integer.parseInt(result.getString("area_code")); - - String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, " + - "coord_ref_sys_kind, source_geogcrs_code, projection_conv_code " + - "FROM epsg_coordinatereferencesystem " + - "WHERE area_of_use_code = "+ area_of_use_code ; - - result2 = Query.select(sentence,connect.getConnection()); - while(result2.next()){ - data[0] = String.valueOf(result2.getInt("coord_ref_sys_code")); - data[1] = result2.getString("coord_ref_sys_name"); - data[2] = result2.getString("coord_ref_sys_kind"); - crs_kind = (String)data[2]; - projection_conv_code = result2.getInt("projection_conv_code"); - setProjectionCode(projection_conv_code); - } - /* - * Buscaremos solo aquellos CRS cuyas proyecciones esten entre las - * 16 soportadas por proj4 para ello creamos un metodo para validar - * si esta entre estas proyecciones - */ - if (data[0]!=null /*&& validCRS(projection_conv_code)*/ && valid(crs_kind)){ - dtm.addRow(data); - } - if (notValid(crs_kind)){ - not_valid = true; - } - } - } - - catch (SQLException e1) { - logger.error("Can't get values from RecordSet.",e1); - - } - } + int numr = dtm.getRowCount(); if (not_valid){ - JOptionPane.showMessageDialog(this, PluginServices.getText(this,"crs_not_soported"), "Warning...", + JOptionPane.showMessageDialog(this, + PluginServices.getText(this,"crs_not_soported"), + PluginServices.getText(this,"warning"), JOptionPane.WARNING_MESSAGE); not_valid = false; } else if (not_numeric) { - JOptionPane.showMessageDialog(EPSGpanel.this, - PluginServices.getText(this,"numeric_format"), - "Warning...", JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(EPSGpanel.this, + PluginServices.getText(this,"numeric_format"), + PluginServices.getText(this,"warning"), + JOptionPane.WARNING_MESSAGE); searchTextField.setText(""); } - else if (numr == 0){ - JOptionPane.showMessageDialog(this, PluginServices.getText(this,"no_results"), "Warning...", - JOptionPane.WARNING_MESSAGE); + else if (numr == 0) { + JOptionPane.showMessageDialog(this, + PluginServices.getText(this,"no_results"), + PluginServices.getText(this,"warning"), + JOptionPane.WARNING_MESSAGE); } - else{ + else { this.getJTable().setRowSelectionInterval(0,0); } } @@ -546,7 +482,7 @@ else if (i == 2) { column.setPreferredWidth(80); } - else if (i==4){ + else if (i == 4){ column.setPreferredWidth(300); } else { @@ -634,8 +570,8 @@ */ String sentence = "SELECT source_geogcrs_code, projection_conv_code, " + "coord_ref_sys_kind, datum_code " + - "FROM epsg_coordinatereferencesystem " + - "WHERE coord_ref_sys_code = "+ epsg_code ; + "FROM epsg_coordinatereferencesystem " + + "WHERE coord_ref_sys_code = " + epsg_code; ResultSet result = Query.select(sentence,connect.getConnection()); try { @@ -674,7 +610,7 @@ else { JOptionPane.showMessageDialog(this, PluginServices.getText(this,"crs_no_selected."), - "Warning...", JOptionPane.WARNING_MESSAGE); + PluginServices.getText(this,"warning"), JOptionPane.WARNING_MESSAGE); } cadWKT = wkt.getWKT(); @@ -695,15 +631,15 @@ public void loadViewCRS(int code){ connection(); String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " + - "source_geogcrs_code, projection_conv_code " + + "source_geogcrs_code, projection_conv_code, deprecated " + "FROM epsg_coordinatereferencesystem " + - "WHERE coord_ref_sys_code = " + code; + "WHERE coord_ref_sys_code = " + code + " AND deprecated = 0"; ResultSet result = Query.select(sentence,connect.getConnection()); try { result.next(); Object[]data = new Object[5]; - data[0] = String.valueOf(result.getInt("coord_ref_sys_code")); + data[0] = result.getString("coord_ref_sys_code"); data[1] = result.getString("coord_ref_sys_name"); crs_kind = result.getString("coord_ref_sys_kind"); data[2] = crs_kind; @@ -774,7 +710,7 @@ searchTextField.setBackground(new Color(255,204,204)); JOptionPane.showMessageDialog(EPSGpanel.this, PluginServices.getText(this,"fill_name"), - "Warning...", JOptionPane.WARNING_MESSAGE); + PluginServices.getText(this,"warning"), JOptionPane.WARNING_MESSAGE); } else { searchButton(); @@ -820,7 +756,7 @@ String sentence = "SELECT projection_conv_code " + "FROM epsg_coordinatereferencesystem " + - "WHERE coord_ref_sys_code = " + code; + "WHERE coord_ref_sys_code = " + code; ResultSet result = Query.select(sentence,connect.getConnection()); int projCode = 0;