Revision 10508

View differences:

trunk/extensions/extWFS2/src/com/iver/cit/gvsig/gui/panels/WFSAreaPanel.java
11 11
import java.awt.event.FocusListener;
12 12
import java.awt.event.ItemEvent;
13 13
import java.awt.event.ItemListener;
14
import java.awt.event.KeyEvent;
15
import java.awt.event.KeyListener;
14 16
import java.awt.event.MouseAdapter;
15 17
import java.awt.event.MouseEvent;
16 18
import java.awt.event.MouseListener;
......
108 110
 *
109 111
 * $Id$
110 112
 * $Log$
111
 * Revision 1.21  2007-02-22 13:17:57  ppiqueras
113
 * Revision 1.22  2007-02-26 12:58:09  ppiqueras
114
 * En caso de escribir una coordenada con formato incorrecto, avisa al usuario y restaura el valor anterior.
115
 *
116
 * Revision 1.21  2007/02/22 13:17:57  ppiqueras
112 117
 * Mejor documentado el c?digo.
113 118
 *
114 119
 * Revision 1.20  2007/02/22 12:23:32  ppiqueras
......
313 318
				 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
314 319
				 */
315 320
				public void actionPerformed(ActionEvent e) {
316
					 JComboBox cb = (JComboBox)e.getSource();
317
					 switch(((ItemOperation)cb.getSelectedItem()).getOperation()) {
318
					 	case DISABLED_OPERATION:
321
					JComboBox cb = (JComboBox)e.getSource();
322
					switch(((ItemOperation)cb.getSelectedItem()).getOperation()) {
323
						case DISABLED_OPERATION:
319 324
					 		disableCoorderatesRegionOperation();
320 325
					 		disableAreaRegionOperation();
321 326
					 		break;
......
338 343
					 		}
339 344

  
340 345
					 		break;
341
					 	}
346
					}
342 347
				}				
343 348
			});
344 349
		}
......
820 825
		private final String JTEXTFIELD_V1Y_NAME = "V1Y";
821 826
		private final String JTEXTFIELD_V2X_NAME = "V2X";
822 827
		private final String JTEXTFIELD_V2Y_NAME = "V2Y";
828
		
829
		private final short JTEXTFIELD_V1X = 1;
830
		private final short JTEXTFIELD_V1Y = 2;
831
		private final short JTEXTFIELD_V2X = 3;
832
		private final short JTEXTFIELD_V2Y = 4;
823 833

  
824 834
		private JPanel jPanelVertex1 = null;
825 835
		private JPanel jPanelVertex2 = null;
......
844 854
		private boolean hasChanged_v1Y;
845 855
		private boolean hasChanged_v2X;
846 856
		private boolean hasChanged_v2Y;
847

  
857
		private short last_Coordinate_that_Loose_the_Focus; // 0 -> any; 1 -> V1X; 2 -> V1Y; 3 -> V2X; 4 -> V2Y
858
		private String previous_Coordinate_Value[];
859
		
860
		private short current_coordinate_with_focus;
861
		
848 862
		private FocusListener focusListenerForCoordinateValidation = null;
863
		private KeyListener keyListenerForCoordinateValidation = null;
849 864

  
850 865
		/**
851 866
		 * This is the default constructor
......
871 886
			this.last_Coordinates[1] = "";
872 887
			this.last_Coordinates[2] = "";
873 888
			this.last_Coordinates[3] = "";
889
			this.last_Coordinate_that_Loose_the_Focus = 0;
890
			this.previous_Coordinate_Value = new String[4];
874 891

  
875 892
			// By default no coordinates have changed
876 893
			this.resetCoordinatesFlags();
......
908 925
			hasChanged_v2Y = false;
909 926
		}
910 927
		
911
		/**
928
		/**last_Coordinated_that_Changed
912 929
		 * This method initializes jPanelVertex1
913 930
		 * 
914 931
		 * @return javax.swing.JPanel
......
1131 1148
		 */
1132 1149
		private FocusListener getFocusListenerForCoordinateValidation() {
1133 1150
			if (focusListenerForCoordinateValidation == null) {
1134
				focusListenerForCoordinateValidation = new FocusAdapter() {
1151
				focusListenerForCoordinateValidation = new FocusListener() {
1152

  
1135 1153
					/*
1136 1154
					 *  (non-Javadoc)
1155
					 * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
1156
					 */
1157
					public void focusGained(FocusEvent e) {
1158
						JTextField jTF = (JTextField)e.getSource();
1159

  
1160
						// Stores which coordinate has gotten the focus
1161
						if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1162
							current_coordinate_with_focus = JTEXTFIELD_V1X;
1163

  
1164
							return;
1165
						}
1166

  
1167
						if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1168
							current_coordinate_with_focus = JTEXTFIELD_V1Y;
1169

  
1170
							return;
1171
						}
1172
	
1173
						if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1174
							current_coordinate_with_focus = JTEXTFIELD_V2X;
1175

  
1176
							return;
1177
						}
1178
	
1179
						if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1180
							current_coordinate_with_focus = JTEXTFIELD_V2Y;
1181

  
1182
							return;
1183
						}
1184

  
1185
					}
1186
					
1187
					/*
1188
					 *  (non-Javadoc)
1137 1189
					 * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
1138 1190
					 */
1139 1191
					public void focusLost(FocusEvent e) {
1140 1192
						JTextField jTF = (JTextField)e.getSource();
1141 1193

  
1142 1194
						// If a coordinate has lost focus, is valid and has changed -> store the new value and set its related 'hasChanged' flag to true
1143
						if (validateCoordinate(jTF)) {
1144
							String text = jTF.getText();
1195
						String text = jTF.getText();
1145 1196

  
1146
							if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1147
								if (text.compareTo(last_Coordinates[0]) != 0) {
1148
									hasChanged_v1X = true;
1149
								}
1150
								
1151
								return;
1197
						if (jTF.getName().compareTo(JTEXTFIELD_V1X_NAME) == 0) {
1198

  
1199
							if (text.compareTo(last_Coordinates[0]) != 0) {
1200
								hasChanged_v1X = true;
1152 1201
							}
1153
							if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1154
								if (text.compareTo(last_Coordinates[1]) != 0) {
1155
									hasChanged_v1Y = true;
1156
								}
1157
								
1158
								return;
1202

  
1203
							return;
1204
						}
1205

  
1206
						if (jTF.getName().compareTo(JTEXTFIELD_V1Y_NAME) == 0) {
1207
							if (text.compareTo(last_Coordinates[1]) != 0) {
1208
								hasChanged_v1Y = true;
1159 1209
							}
1160
							if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1161
								if (text.compareTo(last_Coordinates[2]) != 0) {
1162
									hasChanged_v2X = true;
1163
								}
1164 1210
								
1165
								return;
1211
							return;
1212
						}
1213

  
1214
						if (jTF.getName().compareTo(JTEXTFIELD_V2X_NAME) == 0) {
1215
							if (text.compareTo(last_Coordinates[2]) != 0) {
1216
								hasChanged_v2X = true;
1166 1217
							}
1167
							if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1168
								if (text.compareTo(last_Coordinates[3]) != 0) {
1169
									hasChanged_v2Y = true;
1170
								}
1218

  
1219
							return;
1220
						}
1221

  
1222
						if (jTF.getName().compareTo(JTEXTFIELD_V2Y_NAME) == 0) {
1223
							if (text.compareTo(last_Coordinates[3]) != 0) {
1224
								hasChanged_v2Y = true;
1225
							}
1171 1226
								
1172
								return;
1173
							}
1227
							return;
1174 1228
						}
1175
					}				
1229
					}
1176 1230
				};
1177 1231
			}
1178 1232
			
1179 1233
			return focusListenerForCoordinateValidation;
1180 1234
		}
1235
		
1236
		private KeyListener getKeyListenerForCoordinateValidation() {
1237
			if (keyListenerForCoordinateValidation == null) {
1238
				keyListenerForCoordinateValidation = new KeyListener() {
1239
					
1240
					public void keyPressed(KeyEvent e) {
1241
					}
1181 1242

  
1243
					public void keyReleased(KeyEvent e) {
1244
						validateCoordinate(current_coordinate_with_focus);
1245
					}
1246

  
1247
					public void keyTyped(KeyEvent e) {
1248
					}
1249
				};
1250
			}
1251
			
1252
			return keyListenerForCoordinateValidation;
1253
		}
1254

  
1182 1255
		/**
1183 1256
		 * This method initializes jTextFieldVertex1X	
1184 1257
		 * 	
......
1186 1259
		 */
1187 1260
		private JTextFieldWithSpecificCaretPosition getJTextFieldVertex1X() {
1188 1261
			if (jTextFieldVertex1X == null) {
1189
				jTextFieldVertex1X = new JTextFieldWithSpecificCaretPosition();
1262
				jTextFieldVertex1X = new JTextFieldWithSpecificCaretPosition("");
1190 1263
				jTextFieldVertex1X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1191 1264
				jTextFieldVertex1X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_right_up_vertex"));
1192 1265
				jTextFieldVertex1X.addFocusListener(getFocusListenerForCoordinateValidation());
1266
				jTextFieldVertex1X.addKeyListener(getKeyListenerForCoordinateValidation());
1193 1267
				jTextFieldVertex1X.setName(JTEXTFIELD_V1X_NAME);
1194 1268
			}
1195 1269
			return jTextFieldVertex1X;
......
1202 1276
		 */
1203 1277
		private JTextFieldWithSpecificCaretPosition getJTextFieldVertex1Y() {
1204 1278
			if (jTextFieldVertex1Y == null) {
1205
				jTextFieldVertex1Y = new JTextFieldWithSpecificCaretPosition();
1279
				jTextFieldVertex1Y = new JTextFieldWithSpecificCaretPosition("");
1206 1280
				jTextFieldVertex1Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1207 1281
				jTextFieldVertex1Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_right_up_vertex"));
1208 1282
				jTextFieldVertex1Y.addFocusListener(getFocusListenerForCoordinateValidation());
1283
				jTextFieldVertex1Y.addKeyListener(getKeyListenerForCoordinateValidation());
1209 1284
				jTextFieldVertex1Y.setName(JTEXTFIELD_V1Y_NAME);
1210 1285
			}
1211 1286
			return jTextFieldVertex1Y;
......
1218 1293
		 */
1219 1294
		private JTextFieldWithSpecificCaretPosition getJTextFieldVertex2X() {
1220 1295
			if (jTextFieldVertex2X == null) {
1221
				jTextFieldVertex2X = new JTextFieldWithSpecificCaretPosition();
1296
				jTextFieldVertex2X = new JTextFieldWithSpecificCaretPosition("");
1222 1297
				jTextFieldVertex2X.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));
1223 1298
				jTextFieldVertex2X.setToolTipText(PluginServices.getText(this, "x_coordinate_from_area_left_bottom_vertex"));
1224 1299
				jTextFieldVertex2X.addFocusListener(getFocusListenerForCoordinateValidation());
1300
				jTextFieldVertex2X.addKeyListener(getKeyListenerForCoordinateValidation());
1225 1301
				jTextFieldVertex2X.setName(JTEXTFIELD_V2X_NAME);
1226 1302
			}
1227 1303
			return jTextFieldVertex2X;
......
1234 1310
		 */
1235 1311
		private JTextFieldWithSpecificCaretPosition getJTextFieldVertex2Y() {
1236 1312
			if (jTextFieldVertex2Y == null) {
1237
				jTextFieldVertex2Y = new JTextFieldWithSpecificCaretPosition();
1313
				jTextFieldVertex2Y = new JTextFieldWithSpecificCaretPosition("");
1238 1314
				jTextFieldVertex2Y.setPreferredSize(new Dimension(DEFAULT_TEXT_FIELDS_WIDTH, DEFAULT_LABELS_AND_TEXT_FIELDS_HEIGHT));			
1239 1315
				jTextFieldVertex2Y.setToolTipText(PluginServices.getText(this, "y_coordinate_from_area_left_bottom_vertex"));
1240 1316
				jTextFieldVertex2Y.addFocusListener(getFocusListenerForCoordinateValidation());
1317
				jTextFieldVertex2Y.addKeyListener(getKeyListenerForCoordinateValidation());
1241 1318
				jTextFieldVertex2Y.setName(JTEXTFIELD_V2Y_NAME);
1242 1319
			}
1243 1320
			return jTextFieldVertex2Y;
......
1324 1401
		private boolean validateCoordinate(JTextField coordinate) {
1325 1402
			if (coordinate != null) {
1326 1403
				// If the format of the coordinate is incorrect, shows a message warning the user that problem and resets the coordinate text 
1327
				if ((coordinate.getText().compareTo("") != 0) && (! StringNumberUtilities.isExponentialRealNumber(coordinate.getText()))) {
1328
					JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1329
					coordinate.setText(""); // Reset text
1404
				if ((coordinate.getText().compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(coordinate.getText()))) {
1405
//					JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1406
//					switch (last_Coordinate_that_Loose_the_Focus) {
1407
//						case 1:
1408
//							coordinate.setText(previous_Coordinate_Value[0]); // Set last value
1409
//							break;
1410
//						case 2:
1411
//							coordinate.setText(previous_Coordinate_Value[1]); // Set last value
1412
//							break;
1413
//						case 3:
1414
//							coordinate.setText(previous_Coordinate_Value[2]); // Set last value
1415
//							break;
1416
//						case 4:
1417
//							coordinate.setText(previous_Coordinate_Value[3]); // Set last value
1418
//							break;
1419
//						default:
1420
//							// Do nothing
1421
//					}
1422
					
1330 1423
					return false;
1331 1424
				}
1332
				else
1425
				else {
1333 1426
					return true;
1427
				}
1334 1428
			}
1335 1429

  
1336 1430
			return false; // If coordinate is null
1337 1431
		}
1432
		
1433
		/**
1434
		 * Validates the coordinate of a JTextField: returns true if it's valid; else returns false
1435
		 * 
1436
		 * @param coordinate javax.swing.JTextField
1437
		 * @return A boolean value
1438
		 */
1439
		private boolean validateCoordinate(int coordinate_ID) {
1440
			JTextField coordinate = null;
1441
			String text;
1442
			
1443
			switch (coordinate_ID) {
1444
				case JTEXTFIELD_V1X:
1445
					coordinate = getJTextFieldVertex1X();
1446
					text = coordinate.getText();
1447
					
1448
					if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1449
						JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1450
						coordinate.setText(previous_Coordinate_Value[0]); // Set last value
1451
						return false;
1452
					}
1453
					else {
1454
						previous_Coordinate_Value[0] = text;
1455
						return true;
1456
					}
1338 1457

  
1458
//					break;
1459
				case JTEXTFIELD_V1Y:
1460
					coordinate = getJTextFieldVertex1Y();
1461
					text = coordinate.getText();
1462
					
1463
					if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1464
						JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1465
						coordinate.setText(previous_Coordinate_Value[1]); // Set last value
1466
						return false;
1467
					}
1468
					else {
1469
						previous_Coordinate_Value[1] = text;
1470
						return true;
1471
					}
1472

  
1473
//					break;
1474
				case JTEXTFIELD_V2X:
1475
					coordinate = getJTextFieldVertex2X();
1476
					text = coordinate.getText();
1477
					
1478
					if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1479
						JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1480
						coordinate.setText(previous_Coordinate_Value[2]); // Set last value
1481
						return false;
1482
					}
1483
					else {
1484
						previous_Coordinate_Value[2] = text;
1485
						return true;
1486
					}
1487

  
1488
//					break;
1489
				case JTEXTFIELD_V2Y:
1490
					coordinate = getJTextFieldVertex2Y();
1491
					text = coordinate.getText();
1492
					
1493
					if ((text.compareTo("") != 0) && (! StringNumberUtilities.isRealNumberWithIntegerExponent(text))) {
1494
						JOptionPane.showMessageDialog(this, PluginServices.getText(null, "incorrect_coordinate_format"), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE);
1495
						coordinate.setText(previous_Coordinate_Value[3]); // Set last value
1496
						return false;
1497
					}
1498
					else {
1499
						previous_Coordinate_Value[3] = text;
1500
						return true;
1501
					}
1502

  
1503
//					break;
1504
				default:
1505
					return true; // Avoid problems
1506
			}
1507
			
1508
//			if (coordinate != null) {
1509
//				// If the format of the coordinate is incorrect, shows a message warning the user that problem and resets the coordinate text 
1510
//					switch (coordinate_ID) {
1511
//						case 1:
1512
//							coordinate.setText(previous_Coordinate_Value[0]); // Set last value
1513
//							break;
1514
//						case 2:
1515
//							coordinate.setText(previous_Coordinate_Value[1]); // Set last value
1516
//							break;
1517
//						case 3:
1518
//							coordinate.setText(previous_Coordinate_Value[2]); // Set last value
1519
//							break;
1520
//						case 4:
1521
//							coordinate.setText(previous_Coordinate_Value[3]); // Set last value
1522
//							break;
1523
//						default:
1524
//							// Do nothing
1525
//					}
1526
					
1527
//					return false;
1528
//				}
1529
//				else
1530
//					return true;
1531
////			}
1532
//
1533
//			return false; // If coordinate is null
1534
		}
1535

  
1339 1536
		/**
1340 1537
		 * This method initializes jRadioButtonPreviewArea
1341 1538
		 * 
......
1706 1903
		public void updateCoordinates(Rectangle2D extent){
1707 1904
			getJTextFieldVertex1X().setText(String.valueOf(extent.getMaxX()));
1708 1905
			last_Coordinates[0] = getJTextFieldVertex1X().getText();
1906
			previous_Coordinate_Value[0] = last_Coordinates[0];
1907
			
1709 1908
			getJTextFieldVertex1Y().setText(String.valueOf(extent.getMaxY()));
1710 1909
			last_Coordinates[1] = getJTextFieldVertex1Y().getText();
1910
			previous_Coordinate_Value[1] = last_Coordinates[1];
1911
			
1711 1912
			getJTextFieldVertex2X().setText(String.valueOf(extent.getMinX()));
1712 1913
			last_Coordinates[2] = getJTextFieldVertex2X().getText();
1914
			previous_Coordinate_Value[2] = last_Coordinates[2];
1915
			
1713 1916
			getJTextFieldVertex2Y().setText(String.valueOf(extent.getMinY()));
1714 1917
			last_Coordinates[3] = getJTextFieldVertex2Y().getText();
1918
			previous_Coordinate_Value[3] = last_Coordinates[3];
1715 1919
			
1716 1920
			resetCoordinatesFlags();
1717 1921

  
......
1808 2012
				else {
1809 2013
					return true;
1810 2014
				}
1811
					
1812 2015
			}
1813 2016
		}
1814 2017
		
......
1818 2021
		 * @return java.awt.geom.Rectangle2D
1819 2022
		 */
1820 2023
		public Rectangle2D getExtent() {
1821
			double v1x = getDoubleValueOfJTextFieldV1X();//Double.parseDouble(getJTextFieldVertex1X().getText());
1822
			double v1y = getDoubleValueOfJTextFieldV1Y();//Double.parseDouble(getJTextFieldVertex1Y().getText());
1823
			double v2x = getDoubleValueOfJTextFieldV2X();//Double.parseDouble(getJTextFieldVertex2X().getText());
1824
			double v2y = getDoubleValueOfJTextFieldV2Y();//Double.parseDouble(getJTextFieldVertex2Y().getText());
2024
			double v1x = getDoubleValueOfJTextFieldV1X();
2025
			double v1y = getDoubleValueOfJTextFieldV1Y();
2026
			double v2x = getDoubleValueOfJTextFieldV2X();
2027
			double v2y = getDoubleValueOfJTextFieldV2Y();
1825 2028
			
1826 2029
			return new Rectangle2D.Double(v2x, v1y, (v1x - v2x), (v1y  - v2y));
1827 2030
		}

Also available in: Unified diff