Changeset 35032 in osm for applications/editors
- Timestamp:
- 2019-06-13T01:20:11+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/gui/autocalibrate/CalibrationWindow.java
r35030 r35032 40 40 public class CalibrationWindow extends JFrame { 41 41 42 private static final long serialVersionUID = 1L; 43 private static final int FILES_ONLY = 0; 44 45 private JFileChooser fileChooser; 46 private String referenceFileName; 47 private List<Point2D> originPoints; 48 private List<Point2D> referencePoints; 49 private String dist1Value; 50 private String dist2Value; 51 52 private JPanel dialogPane; 53 private JPanel contentPanel; 54 private JPanel infoBar; 55 private JPanel buttonBar; 56 57 private JButton addRefPointsButton; 58 private JButton addEdgePointsButton; 59 private JButton helpButton; 60 private JButton openButton; 61 private JButton selectLayerButton; 62 private JButton runButton; 63 private JButton cancelButton; 64 65 private JLabel infoHeader; 66 private JLabel edgePointHeader; 67 private JLabel edgePointNames; 68 private JLabel edgePointValues; 69 private JLabel distanceHeader; 70 private JLabel distance1; 71 private JLabel distance2; 72 private JTextField distance1Field; 73 private JTextField distance2Field; 74 private JLabel distance1Value; 75 private JLabel distance2Value; 76 private JLabel refFileHeader; 77 private JLabel refFileName; 78 private JLabel refFileNameValue; 79 private JLabel refPointHeader; 80 private JLabel refPointNames; 81 private JLabel refPointValues; 82 83 private JLabel edgePointsChecked; 84 private JLabel distance1Checked; 85 private JLabel distance2Checked; 86 private JLabel fileChecked; 87 private JLabel refPointsChecked; 88 89 90 public CalibrationWindow() { 91 fileChooser = new JFileChooser(); 92 referenceFileName = null; 93 setFileChooser(); 94 95 originPoints = new ArrayList<>(); 96 referencePoints = new ArrayList<>(); 97 dist1Value = null; 98 dist2Value = null; 99 100 initComponents(); 101 updateState(); 102 } 103 104 /** 105 * initialize components 106 */ 107 private void initComponents() { 108 dialogPane = new JPanel(); 109 contentPanel = new JPanel(); 110 infoBar = new JPanel(); 111 buttonBar = new JPanel(); 112 113 addRefPointsButton = new JButton(); 114 addEdgePointsButton = new JButton(); 115 helpButton = new JButton(); 116 openButton = new JButton(); 117 selectLayerButton = new JButton(); 118 runButton = new JButton(); 119 cancelButton = new JButton(); 120 121 infoHeader = new JLabel(); 122 edgePointHeader = new JLabel(); 123 edgePointNames = new JLabel(); 124 edgePointValues = new JLabel(); 125 distanceHeader = new JLabel(); 126 distance1 = new JLabel(); 127 distance2 = new JLabel(); 128 distance1Field = new JTextField(); 129 distance2Field = new JTextField(); 130 distance1Value = new JLabel(); 131 distance2Value = new JLabel(); 132 refFileHeader = new JLabel(); 133 refFileName = new JLabel(); 134 refFileNameValue = new JLabel(); 135 refPointHeader = new JLabel(); 136 refPointNames = new JLabel(); 137 refPointValues = new JLabel(); 138 139 edgePointsChecked = new JLabel(); 140 distance1Checked = new JLabel(); 141 distance2Checked = new JLabel(); 142 fileChecked = new JLabel(); 143 refPointsChecked = new JLabel(); 144 145 // this 146 setTitle(tr("AutoCalibration")); 147 java.awt.Container contentPane = getContentPane(); 148 contentPane.setLayout(new BorderLayout()); 149 this.setMinimumSize(new Dimension(50,100)); 150 151 // dialog pane 152 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 153 dialogPane.setLayout(new BorderLayout()); 154 155 // info bar 156 setInfoBar(); 157 setInfoHeader(); 158 dialogPane.add(infoBar, BorderLayout.NORTH); 159 160 // content panel 161 setContentPanel(); 162 setPointHeader(); 163 setEdgePointNamesValues(); 164 setDistanceHeader(); 165 setDistance1(); 166 setDistance1Field(); 167 setDistance2(); 168 setDistance2Field(); 169 setRefFileHeader(); 170 setRefFileName(); 171 setOpenButton(); 172 setSelectLayerButton(); 173 setRefPointHeader(); 174 setRefPointNamesValues(); 175 dialogPane.add(contentPanel, BorderLayout.CENTER); 176 177 // button bar 178 setButtonBar(); 179 setOKButton(); 180 setCancelButton(); 181 dialogPane.add(buttonBar, BorderLayout.SOUTH); 182 183 // content Pane 184 contentPane.add(dialogPane, BorderLayout.CENTER); 185 pack(); 186 setLocationRelativeTo(getOwner()); 187 } 188 189 190 // COMPONENTS 191 192 private void setInfoBar() { 193 infoBar.setBorder(new EmptyBorder(0, 0, 12, 0)); 194 infoBar.setLayout(new GridBagLayout()); 195 ((GridBagLayout) infoBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 196 ((GridBagLayout) infoBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 197 } 198 199 private void setInfoHeader() { 200 infoHeader.setText(tr("<html>Please enter the required information.</html>")); 201 infoBar.add(infoHeader, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 202 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 203 new Insets(5, 5, 0, 0), 0, 0)); 204 205 String space = " "; 206 helpButton = new JButton(tr(space + "help" + space)); 207 infoBar.add(helpButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, 208 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 209 new Insets(0, 0, 0, 0), 0, 0)); 210 } 211 212 private void setContentPanel() { 213 contentPanel.setLayout(new GridBagLayout()); 214 contentPanel.setBackground(new Color(200, 200, 200)); 215 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; 216 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0}; 42 private static final long serialVersionUID = 1L; 43 private static final int FILES_ONLY = 0; 44 45 private JFileChooser fileChooser; 46 private String referenceFileName; 47 private List<Point2D> originPoints; 48 private List<Point2D> referencePoints; 49 private String dist1Value; 50 private String dist2Value; 51 52 private JPanel dialogPane; 53 private JPanel contentPanel; 54 private JPanel infoBar; 55 private JPanel buttonBar; 56 57 private JButton addRefPointsButton; 58 private JButton addEdgePointsButton; 59 private JButton helpButton; 60 private JButton openButton; 61 private JButton selectLayerButton; 62 private JButton runButton; 63 private JButton cancelButton; 64 65 private JLabel infoHeader; 66 private JLabel edgePointHeader; 67 private JLabel edgePointNames; 68 private JLabel edgePointValues; 69 private JLabel distanceHeader; 70 private JLabel distance1; 71 private JLabel distance2; 72 private JTextField distance1Field; 73 private JTextField distance2Field; 74 private JLabel distance1Value; 75 private JLabel distance2Value; 76 private JLabel refFileHeader; 77 private JLabel refFileName; 78 private JLabel refFileNameValue; 79 private JLabel refPointHeader; 80 private JLabel refPointNames; 81 private JLabel refPointValues; 82 83 private JLabel edgePointsChecked; 84 private JLabel distance1Checked; 85 private JLabel distance2Checked; 86 private JLabel fileChecked; 87 private JLabel refPointsChecked; 88 89 public CalibrationWindow() { 90 fileChooser = new JFileChooser(); 91 referenceFileName = null; 92 setFileChooser(); 93 94 originPoints = new ArrayList<>(); 95 referencePoints = new ArrayList<>(); 96 dist1Value = null; 97 dist2Value = null; 98 99 initComponents(); 100 updateState(); 101 } 102 103 /** 104 * initialize components 105 */ 106 private void initComponents() { 107 dialogPane = new JPanel(); 108 contentPanel = new JPanel(); 109 infoBar = new JPanel(); 110 buttonBar = new JPanel(); 111 112 addRefPointsButton = new JButton(); 113 addEdgePointsButton = new JButton(); 114 helpButton = new JButton(); 115 openButton = new JButton(); 116 selectLayerButton = new JButton(); 117 runButton = new JButton(); 118 cancelButton = new JButton(); 119 120 infoHeader = new JLabel(); 121 edgePointHeader = new JLabel(); 122 edgePointNames = new JLabel(); 123 edgePointValues = new JLabel(); 124 distanceHeader = new JLabel(); 125 distance1 = new JLabel(); 126 distance2 = new JLabel(); 127 distance1Field = new JTextField(); 128 distance2Field = new JTextField(); 129 distance1Value = new JLabel(); 130 distance2Value = new JLabel(); 131 refFileHeader = new JLabel(); 132 refFileName = new JLabel(); 133 refFileNameValue = new JLabel(); 134 refPointHeader = new JLabel(); 135 refPointNames = new JLabel(); 136 refPointValues = new JLabel(); 137 138 edgePointsChecked = new JLabel(); 139 distance1Checked = new JLabel(); 140 distance2Checked = new JLabel(); 141 fileChecked = new JLabel(); 142 refPointsChecked = new JLabel(); 143 144 // this 145 setTitle(tr("AutoCalibration")); 146 java.awt.Container contentPane = getContentPane(); 147 contentPane.setLayout(new BorderLayout()); 148 this.setMinimumSize(new Dimension(50, 100)); 149 150 // dialog pane 151 dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); 152 dialogPane.setLayout(new BorderLayout()); 153 154 // info bar 155 setInfoBar(); 156 setInfoHeader(); 157 dialogPane.add(infoBar, BorderLayout.NORTH); 158 159 // content panel 160 setContentPanel(); 161 setPointHeader(); 162 setEdgePointNamesValues(); 163 setDistanceHeader(); 164 setDistance1(); 165 setDistance1Field(); 166 setDistance2(); 167 setDistance2Field(); 168 setRefFileHeader(); 169 setRefFileName(); 170 setOpenButton(); 171 setSelectLayerButton(); 172 setRefPointHeader(); 173 setRefPointNamesValues(); 174 dialogPane.add(contentPanel, BorderLayout.CENTER); 175 176 // button bar 177 setButtonBar(); 178 setOKButton(); 179 setCancelButton(); 180 dialogPane.add(buttonBar, BorderLayout.SOUTH); 181 182 // content Pane 183 contentPane.add(dialogPane, BorderLayout.CENTER); 184 pack(); 185 setLocationRelativeTo(getOwner()); 186 } 187 188 189 // COMPONENTS 190 191 private void setInfoBar() { 192 infoBar.setBorder(new EmptyBorder(0, 0, 12, 0)); 193 infoBar.setLayout(new GridBagLayout()); 194 ((GridBagLayout) infoBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 195 ((GridBagLayout) infoBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 196 } 197 198 private void setInfoHeader() { 199 infoHeader.setText(tr("<html>Please enter the required information.</html>")); 200 infoBar.add(infoHeader, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 201 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 202 new Insets(5, 5, 0, 0), 0, 0)); 203 204 String space = " "; 205 helpButton = new JButton(tr(space + "help" + space)); 206 infoBar.add(helpButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, 207 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 208 new Insets(0, 0, 0, 0), 0, 0)); 209 } 210 211 private void setContentPanel() { 212 contentPanel.setLayout(new GridBagLayout()); 213 contentPanel.setBackground(new Color(200, 200, 200)); 214 ((GridBagLayout) contentPanel.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; 215 ((GridBagLayout) contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0}; 217 216 ((GridBagLayout) contentPanel.getLayout()).columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4}; 218 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 219 } 220 221 private void setPointHeader() { 222 edgePointHeader.setText(tr("<html><b><u>Local Edge Points</u></b></html>")); 223 contentPanel.add(edgePointHeader, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, 224 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 225 new Insets(5, 5, 5, 30), 0, 0)); 226 } 227 228 private void setEdgePointNamesValues() { 229 edgePointNames.setText(tr("<html>" 230 + "Point 1 (Lat,Lon):<br>" 231 + "Point 2 (Lat,Lon):<br>" 232 + "Point 3 (Lat,Lon):<br>" 233 + "</html>")); 234 contentPanel.add(edgePointNames, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, 235 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 236 new Insets(5, 5, 5, 30), 0, 0)); 237 238 if(!this.originPoints.isEmpty()) { 239 edgePointValuesEntered(); 240 } 241 else { 242 addEdgePointsButton = new JButton(tr("Add Points...")); 243 contentPanel.add(addEdgePointsButton, new GridBagConstraints(3, 1, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 244 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 245 new Insets(5, 50, 5, 5), 0, 0)); 246 } 247 } 248 249 private void setDistanceHeader() { 250 distanceHeader.setText(tr("<html><b><u>True Distances</u></b></html>")); 251 contentPanel.add(distanceHeader, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, 252 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 253 new Insets(5, 5, 5, 30), 0, 0)); 254 } 255 256 private void setDistance1Field() { 257 distance1Field.setText("Click here..."); 258 contentPanel.add(distance1Field, new GridBagConstraints(3, 3, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 259 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 260 new Insets(5, 50, 5, 5), 0, 0)); 261 } 262 263 private void setDistance2() { 264 distance2.setText(tr("Point 2 to Point 3 (meter):")); 265 contentPanel.add(distance2, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, 266 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 267 new Insets(5, 5, 5, 30), 0, 0)); 268 } 269 270 private void setDistance2Field() { 271 distance2Field.setText("Click here..."); 272 contentPanel.add(distance2Field, new GridBagConstraints(3, 4, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 273 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 274 new Insets(5, 50, 5, 5), 0, 0)); 275 } 276 277 private void setRefFileHeader() { 278 refFileHeader.setText(tr("<html><b><u>Reference File</u></b></html>")); 279 contentPanel.add(refFileHeader, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, 280 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 281 new Insets(5, 5, 5, 30), 0, 0)); 282 } 283 284 private void setRefFileName() { 285 refFileName.setText(tr("<html>Reference Name:" 286 + "<br>" 287 + "<br>" 288 + "<br>" 289 + "</html>")); 290 291 contentPanel.add(refFileName, new GridBagConstraints(0, 6, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 292 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 293 new Insets(5, 5, 5, 30), 0, 0)); 294 } 295 296 private void setSelectLayerButton() { 297 String imageName = "layerlist.png"; 298 Image image = null; 299 try { 300 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 301 } catch (Exception ex) { 302 System.out.println("Error: Could not load image " + imageName + "," + ex); 303 } 304 305 selectLayerButton.setToolTipText(tr("Select a layer as reference...")); 306 selectLayerButton.setIcon(new ImageIcon(image)); 307 contentPanel.add(selectLayerButton, new GridBagConstraints(3, 6, 2, 1, 1.0, 0.0, 308 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 309 new Insets(5, 50, 5, 5), 0, 0)); 310 } 311 312 private void setOpenButton() { 313 String imageName = "open.png"; 314 Image image = null; 315 try { 316 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 317 } catch (Exception ex) { 318 System.out.println("Error: Could not load image " + imageName + "," + ex); 319 } 320 321 openButton.setToolTipText(tr("Open a file as reference...")); 322 openButton.setIcon(new ImageIcon(image)); 323 contentPanel.add(openButton, new GridBagConstraints(6, 6, GridBagConstraints.REMAINDER, 1, 1.0, 0.0, 324 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 325 new Insets(5, 5, 5, 5), 0, 0)); 326 } 327 328 private void setRefPointHeader() { 329 refPointHeader.setText("<html><b><u>Reference Points</u></b></html>\""); 330 contentPanel.add(refPointHeader, new GridBagConstraints(0, 7, 3, 1, 0.0, 0.0, 331 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 332 new Insets(5, 5, 5, 30), 0, 0)); 333 } 334 335 private void setRefPointNamesValues() { 336 Point2D rp1 = null; 337 Point2D rp2 = null; 338 Point2D rp3 = null; 339 340 if(!this.referencePoints.isEmpty()) { 341 rp1 = referencePoints.get(0); 342 rp2 = referencePoints.get(1); 343 rp3 = referencePoints.get(2); 344 } 345 346 refPointNames.setText(tr("<html>" 347 + "Point 1 (Lat,Lon):<br>" 348 + "Point 2 (Lat,Lon):<br>" 349 + "Point 3 (Lat,Lon):<br>" 350 + "</html>")); 351 contentPanel.add(refPointNames, new GridBagConstraints(0, 8, 3, 1, 0.0, 0.0, 352 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 353 new Insets(5, 5, 5, 30), 0, 0)); 354 355 if(!this.referencePoints.isEmpty()) { 356 refPointValues.setText(tr("<html>" 357 + rp1.getY() + ", " + rp1.getX() + "<br>" 358 + rp2.getY() + ", " + rp2.getX() + "<br>" 359 + rp3.getY() + ", " + rp3.getX() + "<br>" 360 + "</html>")); 361 362 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 363 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 364 new Insets(5, 5, 5, 30), 0, 0)); 365 } 366 else { 367 addRefPointsButton = new JButton(tr("Add Points...")); 368 contentPanel.add(addRefPointsButton, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 369 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 370 new Insets(5, 50, 5, 5), 0, 0)); 371 } 372 } 373 374 private void setButtonBar() { 375 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 376 buttonBar.setLayout(new GridBagLayout()); 377 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 378 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 379 } 380 381 private void setOKButton() { 382 runButton.setText(tr("Run")); 383 buttonBar.add(runButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 384 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 385 new Insets(0, 0, 0, 5), 0, 0)); 386 } 387 388 private void setCancelButton() { 389 cancelButton.setText(tr("Cancel")); 390 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 391 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 392 new Insets(0, 0, 0, 0), 0, 0)); 393 } 394 395 396 // DYNAMIC FIELD CHANGES 397 398 private void edgePointValuesEntered() { 399 Point2D p1 = null; 400 Point2D p2 = null; 401 Point2D p3 = null; 402 DecimalFormat df = new DecimalFormat("###,###.###"); 403 404 if(this.originPoints.size() == 3) { 405 p1 = originPoints.get(0); 406 p2 = originPoints.get(1); 407 p3 = originPoints.get(2); 408 } 409 else return; 410 411 edgePointValues.setText(tr("<html>" 412 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>" 413 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>" 414 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>" 415 + "</html>")); 416 417 contentPanel.remove(addEdgePointsButton); 418 contentPanel.add(edgePointValues, new GridBagConstraints(3, 1, 3, 1, 0.0, 0.0, 419 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 420 new Insets(5, 5, 5, 30), 0, 0)); 421 422 edgePointsChecked.setIcon(getCheckedIcon()); 423 contentPanel.add(edgePointsChecked, new GridBagConstraints(6, 1, 3, 1, 0.0, 0.0, 424 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 425 new Insets(5, 5, 5, 5), 0, 0)); 426 } 427 428 private void distance1Entered() { 429 contentPanel.remove(distance1Field); 430 distance1Value.setText(dist1Value); 431 contentPanel.add(distance1Value, new GridBagConstraints(3, 3, 2, 1, 0.0, 0.0, 432 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 433 new Insets(5, 5, 5, 30), 0, 0)); 434 435 distance1Checked.setIcon(getCheckedIcon()); 436 contentPanel.add(distance1Checked, new GridBagConstraints(6, 3, 3, 1, 0.0, 0.0, 437 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 438 new Insets(5, 5, 5, 5), 0, 0)); 439 } 440 441 private void distance2Entered() { 442 contentPanel.remove(distance2Field); 443 distance2Value.setText(dist2Value); 444 contentPanel.add(distance2Value, new GridBagConstraints(3, 4, 2, 1, 0.0, 0.0, 445 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 446 new Insets(5, 5, 5, 30), 0, 0)); 447 448 distance2Checked.setIcon(getCheckedIcon()); 449 contentPanel.add(distance2Checked, new GridBagConstraints(6, 4, 3, 1, 0.0, 0.0, 450 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 451 new Insets(5, 5, 5, 5), 0, 0)); 452 } 453 454 private void refFileEntered() { 455 contentPanel.remove(selectLayerButton); 456 contentPanel.remove(openButton); 457 refFileName.setText(tr("<html>Reference Name:</html>")); 458 refFileNameValue.setText(referenceFileName); 459 contentPanel.add(refFileNameValue, new GridBagConstraints(3, 6, 2, 1, 0.0, 0.0, 460 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 461 new Insets(5, 5, 5, 30), 0, 0)); 462 463 fileChecked.setIcon(getCheckedIcon()); 464 contentPanel.add(fileChecked, new GridBagConstraints(6, 6, 3, 1, 0.0, 0.0, 465 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 466 new Insets(5, 5, 5, 5), 0, 0)); 467 } 468 469 private void refPointValuesEntered() { 470 Point2D p1 = null; 471 Point2D p2 = null; 472 Point2D p3 = null; 473 DecimalFormat df = new DecimalFormat("###,###.###"); 474 475 if(this.referencePoints.size() == 3) { 476 p1 = referencePoints.get(0); 477 p2 = referencePoints.get(1); 478 p3 = referencePoints.get(2); 479 } 480 else return; 481 482 refPointValues.setText(tr("<html>" 483 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>" 484 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>" 485 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>" 486 + "</html>")); 487 488 contentPanel.remove(addRefPointsButton); 489 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, 3, 1, 0.0, 0.0, 490 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 491 new Insets(5, 5, 5, 30), 0, 0)); 492 493 refPointsChecked.setIcon(getCheckedIcon()); 494 contentPanel.add(refPointsChecked, new GridBagConstraints(6, 8, 3, 1, 0.0, 0.0, 495 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 496 new Insets(5, 5, 5, 5), 0, 0)); 497 } 498 499 private void setDistance1() { 500 distance1.setText(tr("Point 1 to Point 2 (meter):")); 501 contentPanel.add(distance1, new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0, 502 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 503 new Insets(5, 5, 5, 30), 0, 0)); 504 } 505 506 507 // GETTER / SETTER 508 509 public JButton getOpenButton() { 510 return this.openButton; 511 } 512 513 public JTextField getDistance1Field() { 514 return this.distance1Field; 515 } 516 517 public JTextField getDistance2Field() { 518 return this.distance2Field; 519 } 520 521 public String getDistance1FieldText() { 522 return this.distance1Field.getText(); 523 } 524 525 public String getDistance2FieldText() { 526 return this.distance2Field.getText(); 527 } 528 529 public void setOriginPoints(List<Point2D> points) { 530 this.originPoints = points; 531 edgePointValuesEntered(); 532 updateState(); 533 } 534 535 public void setReferencePoints(List<Point2D> points) { 536 this.referencePoints = points; 537 refPointValuesEntered(); 538 updateState(); 539 } 540 541 public void setDistance1Field(String s) { 542 this.distance1Field.setText(s); 543 updateState(); 544 } 545 546 public void setDistance2Field(String s) { 547 this.distance2Field.setText(s); 548 updateState(); 549 } 550 551 public void setDistance1Value(String valueAsString) { 552 this.dist1Value = valueAsString; 553 if(!valueAsString.equals("")) distance1Entered(); 554 updateState(); 555 } 556 557 public void setDistance2Value(String valueAsString) { 558 this.dist2Value = valueAsString; 559 if(!valueAsString.equals("")) distance2Entered(); 560 updateState(); 561 } 562 563 public void setReferenceFileName(String name) { 564 this.referenceFileName = name; 565 } 566 567 private void setFileChooser() { 568 fileChooser.setFileSelectionMode(FILES_ONLY); 569 FileNameExtensionFilter filter = new FileNameExtensionFilter(".osm, .gpx","osm", "gpx"); 570 fileChooser.setFileFilter(filter); 571 } 572 573 public void setReferenceFileNameValue(String value) { 574 this.referenceFileName = value; 575 this.refFileNameValue.setText(value); 576 refFileEntered(); 577 updateState(); 578 } 579 580 public JFileChooser getFileChooser() { 581 return this.fileChooser; 582 } 583 584 public String getFileName() { 585 return this.referenceFileName; 586 } 587 588 // LISTENER 589 590 public void setOkButtonListener(ActionListener l) { 591 this.runButton.addActionListener(l); 592 } 593 594 public void setCancelButtonListener(ActionListener l) { 595 this.cancelButton.addActionListener(l); 596 } 597 598 public void setWindowListener(WindowListener l) { 599 this.addWindowListener(l); 600 } 601 602 public void addOpenFileButtonListener(ActionListener l) { 603 this.openButton.addActionListener(l); 604 } 605 606 public void addSelectLayerButtonListener(ActionListener l) { 607 this.selectLayerButton.addActionListener(l); 608 } 609 610 public void addCancelButtonListener(ActionListener l) { 611 this.cancelButton.addActionListener(l); 612 } 613 614 public void addRunButtonListener(ActionListener l) { 615 this.runButton.addActionListener(l); 616 } 617 618 public void addEdgePointButtonListener(ActionListener l) { 619 this.addEdgePointsButton.addActionListener(l); 620 } 621 622 public void addReferencePointButtonListener(ActionListener l) { 623 this.addRefPointsButton.addActionListener(l); 624 } 625 626 public void addFrameWindowListener(WindowAdapter wAdapter) { 627 this.addWindowListener(wAdapter); 628 } 629 630 public void addDistance1FieldListener(FocusListener l) { 631 this.distance1Field.addFocusListener(l); 632 } 633 634 public void addDistance2FieldListener(FocusListener l) { 635 this.distance2Field.addFocusListener(l); 636 } 637 638 public void addHelpButtonListener(ActionListener l) { 639 this.helpButton.addActionListener(l); 640 } 641 642 643 // HELPER 644 645 private ImageIcon getCheckedIcon() { 646 String imageName = "checked.png"; 647 Image image = null; 648 try { 649 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 650 } catch (Exception ex) { 651 System.out.println("Error: Could not load image " + imageName + "," + ex); 652 } 653 return new ImageIcon(image); 654 } 655 656 public void updateState() { 657 if(originPoints.isEmpty()) { 658 // button blink 659 distance1Field.setEnabled(false); 660 distance2Field.setEnabled(false); 661 openButton.setEnabled(false); 662 selectLayerButton.setEnabled(false); 663 addRefPointsButton.setEnabled(false); 664 runButton.setEnabled(false); 665 } 666 else { 667 if(dist1Value == null && dist2Value == null) { 668 distance1Field.setEnabled(true); 669 distance2Field.setEnabled(true); 670 } 671 if(dist1Value != null) { 672 openButton.setEnabled(true); 673 selectLayerButton.setEnabled(true); 674 } 675 if(referenceFileName != null) addRefPointsButton.setEnabled(true); 676 if(!referencePoints.isEmpty()) runButton.setEnabled(true); 677 } 678 } 679 680 public void refresh() { 681 this.setVisible(true); 682 } 217 ((GridBagLayout) contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4}; 218 } 219 220 private void setPointHeader() { 221 edgePointHeader.setText(tr("<html><b><u>Local Edge Points</u></b></html>")); 222 contentPanel.add(edgePointHeader, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, 223 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 224 new Insets(5, 5, 5, 30), 0, 0)); 225 } 226 227 private void setEdgePointNamesValues() { 228 edgePointNames.setText(tr("<html>" 229 + "Point 1 (Lat,Lon):<br>" 230 + "Point 2 (Lat,Lon):<br>" 231 + "Point 3 (Lat,Lon):<br>" 232 + "</html>")); 233 contentPanel.add(edgePointNames, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, 234 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 235 new Insets(5, 5, 5, 30), 0, 0)); 236 237 if (!originPoints.isEmpty()) { 238 edgePointValuesEntered(); 239 } else { 240 addEdgePointsButton = new JButton(tr("Add Points...")); 241 contentPanel.add(addEdgePointsButton, new GridBagConstraints(3, 1, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 242 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 243 new Insets(5, 50, 5, 5), 0, 0)); 244 } 245 } 246 247 private void setDistanceHeader() { 248 distanceHeader.setText(tr("<html><b><u>True Distances</u></b></html>")); 249 contentPanel.add(distanceHeader, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, 250 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 251 new Insets(5, 5, 5, 30), 0, 0)); 252 } 253 254 private void setDistance1Field() { 255 distance1Field.setText("Click here..."); 256 contentPanel.add(distance1Field, new GridBagConstraints(3, 3, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 257 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 258 new Insets(5, 50, 5, 5), 0, 0)); 259 } 260 261 private void setDistance2() { 262 distance2.setText(tr("Point 2 to Point 3 (meter):")); 263 contentPanel.add(distance2, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, 264 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 265 new Insets(5, 5, 5, 30), 0, 0)); 266 } 267 268 private void setDistance2Field() { 269 distance2Field.setText("Click here..."); 270 contentPanel.add(distance2Field, new GridBagConstraints(3, 4, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 271 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 272 new Insets(5, 50, 5, 5), 0, 0)); 273 } 274 275 private void setRefFileHeader() { 276 refFileHeader.setText(tr("<html><b><u>Reference File</u></b></html>")); 277 contentPanel.add(refFileHeader, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, 278 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 279 new Insets(5, 5, 5, 30), 0, 0)); 280 } 281 282 private void setRefFileName() { 283 refFileName.setText("<html>"+tr("Reference Name:") 284 + "<br>" 285 + "<br>" 286 + "<br>" 287 + "</html>"); 288 289 contentPanel.add(refFileName, new GridBagConstraints(0, 6, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 290 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 291 new Insets(5, 5, 5, 30), 0, 0)); 292 } 293 294 private void setSelectLayerButton() { 295 String imageName = "layerlist.png"; 296 Image image = null; 297 try { 298 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 299 } catch (Exception ex) { 300 System.out.println("Error: Could not load image " + imageName + "," + ex); 301 } 302 303 selectLayerButton.setToolTipText(tr("Select a layer as reference...")); 304 selectLayerButton.setIcon(new ImageIcon(image)); 305 contentPanel.add(selectLayerButton, new GridBagConstraints(3, 6, 2, 1, 1.0, 0.0, 306 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 307 new Insets(5, 50, 5, 5), 0, 0)); 308 } 309 310 private void setOpenButton() { 311 String imageName = "open.png"; 312 Image image = null; 313 try { 314 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 315 } catch (Exception ex) { 316 System.out.println("Error: Could not load image " + imageName + "," + ex); 317 } 318 319 openButton.setToolTipText(tr("Open a file as reference...")); 320 openButton.setIcon(new ImageIcon(image)); 321 contentPanel.add(openButton, new GridBagConstraints(6, 6, GridBagConstraints.REMAINDER, 1, 1.0, 0.0, 322 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 323 new Insets(5, 5, 5, 5), 0, 0)); 324 } 325 326 private void setRefPointHeader() { 327 refPointHeader.setText("<html><b><u>Reference Points</u></b></html>\""); 328 contentPanel.add(refPointHeader, new GridBagConstraints(0, 7, 3, 1, 0.0, 0.0, 329 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 330 new Insets(5, 5, 5, 30), 0, 0)); 331 } 332 333 private void setRefPointNamesValues() { 334 Point2D rp1 = null; 335 Point2D rp2 = null; 336 Point2D rp3 = null; 337 338 if (!referencePoints.isEmpty()) { 339 rp1 = referencePoints.get(0); 340 rp2 = referencePoints.get(1); 341 rp3 = referencePoints.get(2); 342 } 343 344 refPointNames.setText(tr("<html>" 345 + "Point 1 (Lat,Lon):<br>" 346 + "Point 2 (Lat,Lon):<br>" 347 + "Point 3 (Lat,Lon):<br>" 348 + "</html>")); 349 contentPanel.add(refPointNames, new GridBagConstraints(0, 8, 3, 1, 0.0, 0.0, 350 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 351 new Insets(5, 5, 5, 30), 0, 0)); 352 353 if (!referencePoints.isEmpty()) { 354 refPointValues.setText(tr("<html>" 355 + rp1.getY() + ", " + rp1.getX() + "<br>" 356 + rp2.getY() + ", " + rp2.getX() + "<br>" 357 + rp3.getY() + ", " + rp3.getX() + "<br>" 358 + "</html>")); 359 360 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 361 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 362 new Insets(5, 5, 5, 30), 0, 0)); 363 } else { 364 addRefPointsButton = new JButton(tr("Add Points...")); 365 contentPanel.add(addRefPointsButton, new GridBagConstraints(3, 8, GridBagConstraints.REMAINDER, 1, 0.0, 0.0, 366 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 367 new Insets(5, 50, 5, 5), 0, 0)); 368 } 369 } 370 371 private void setButtonBar() { 372 buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); 373 buttonBar.setLayout(new GridBagLayout()); 374 ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; 375 ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; 376 } 377 378 private void setOKButton() { 379 runButton.setText(tr("Run")); 380 buttonBar.add(runButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 381 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 382 new Insets(0, 0, 0, 5), 0, 0)); 383 } 384 385 private void setCancelButton() { 386 cancelButton.setText(tr("Cancel")); 387 buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 388 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 389 new Insets(0, 0, 0, 0), 0, 0)); 390 } 391 392 393 // DYNAMIC FIELD CHANGES 394 395 private void edgePointValuesEntered() { 396 Point2D p1 = null; 397 Point2D p2 = null; 398 Point2D p3 = null; 399 DecimalFormat df = new DecimalFormat("###,###.###"); 400 401 if (originPoints.size() == 3) { 402 p1 = originPoints.get(0); 403 p2 = originPoints.get(1); 404 p3 = originPoints.get(2); 405 } else return; 406 407 edgePointValues.setText(tr("<html>" 408 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>" 409 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>" 410 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>" 411 + "</html>")); 412 413 contentPanel.remove(addEdgePointsButton); 414 contentPanel.add(edgePointValues, new GridBagConstraints(3, 1, 3, 1, 0.0, 0.0, 415 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 416 new Insets(5, 5, 5, 30), 0, 0)); 417 418 edgePointsChecked.setIcon(getCheckedIcon()); 419 contentPanel.add(edgePointsChecked, new GridBagConstraints(6, 1, 3, 1, 0.0, 0.0, 420 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 421 new Insets(5, 5, 5, 5), 0, 0)); 422 } 423 424 private void distance1Entered() { 425 contentPanel.remove(distance1Field); 426 distance1Value.setText(dist1Value); 427 contentPanel.add(distance1Value, new GridBagConstraints(3, 3, 2, 1, 0.0, 0.0, 428 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 429 new Insets(5, 5, 5, 30), 0, 0)); 430 431 distance1Checked.setIcon(getCheckedIcon()); 432 contentPanel.add(distance1Checked, new GridBagConstraints(6, 3, 3, 1, 0.0, 0.0, 433 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 434 new Insets(5, 5, 5, 5), 0, 0)); 435 } 436 437 private void distance2Entered() { 438 contentPanel.remove(distance2Field); 439 distance2Value.setText(dist2Value); 440 contentPanel.add(distance2Value, new GridBagConstraints(3, 4, 2, 1, 0.0, 0.0, 441 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 442 new Insets(5, 5, 5, 30), 0, 0)); 443 444 distance2Checked.setIcon(getCheckedIcon()); 445 contentPanel.add(distance2Checked, new GridBagConstraints(6, 4, 3, 1, 0.0, 0.0, 446 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 447 new Insets(5, 5, 5, 5), 0, 0)); 448 } 449 450 private void refFileEntered() { 451 contentPanel.remove(selectLayerButton); 452 contentPanel.remove(openButton); 453 refFileName.setText("<html>"+tr("Reference Name:")+"</html>"); 454 refFileNameValue.setText(referenceFileName); 455 contentPanel.add(refFileNameValue, new GridBagConstraints(3, 6, 2, 1, 0.0, 0.0, 456 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 457 new Insets(5, 5, 5, 30), 0, 0)); 458 459 fileChecked.setIcon(getCheckedIcon()); 460 contentPanel.add(fileChecked, new GridBagConstraints(6, 6, 3, 1, 0.0, 0.0, 461 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 462 new Insets(5, 5, 5, 5), 0, 0)); 463 } 464 465 private void refPointValuesEntered() { 466 Point2D p1 = null; 467 Point2D p2 = null; 468 Point2D p3 = null; 469 DecimalFormat df = new DecimalFormat("###,###.###"); 470 471 if (referencePoints.size() == 3) { 472 p1 = referencePoints.get(0); 473 p2 = referencePoints.get(1); 474 p3 = referencePoints.get(2); 475 } else return; 476 477 refPointValues.setText(tr("<html>" 478 + df.format(p1.getY()) + " , " + df.format(p1.getX()) + "<br>" 479 + df.format(p2.getY()) + " , " + df.format(p2.getX()) + "<br>" 480 + df.format(p3.getY()) + " , " + df.format(p3.getX()) + "<br>" 481 + "</html>")); 482 483 contentPanel.remove(addRefPointsButton); 484 contentPanel.add(refPointValues, new GridBagConstraints(3, 8, 3, 1, 0.0, 0.0, 485 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 486 new Insets(5, 5, 5, 30), 0, 0)); 487 488 refPointsChecked.setIcon(getCheckedIcon()); 489 contentPanel.add(refPointsChecked, new GridBagConstraints(6, 8, 3, 1, 0.0, 0.0, 490 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 491 new Insets(5, 5, 5, 5), 0, 0)); 492 } 493 494 private void setDistance1() { 495 distance1.setText(tr("Point 1 to Point 2 (meter):")); 496 contentPanel.add(distance1, new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0, 497 GridBagConstraints.CENTER, GridBagConstraints.BOTH, 498 new Insets(5, 5, 5, 30), 0, 0)); 499 } 500 501 502 // GETTER / SETTER 503 504 public JButton getOpenButton() { 505 return this.openButton; 506 } 507 508 public JTextField getDistance1Field() { 509 return this.distance1Field; 510 } 511 512 public JTextField getDistance2Field() { 513 return this.distance2Field; 514 } 515 516 public String getDistance1FieldText() { 517 return this.distance1Field.getText(); 518 } 519 520 public String getDistance2FieldText() { 521 return this.distance2Field.getText(); 522 } 523 524 public void setOriginPoints(List<Point2D> points) { 525 this.originPoints = points; 526 edgePointValuesEntered(); 527 updateState(); 528 } 529 530 public void setReferencePoints(List<Point2D> points) { 531 this.referencePoints = points; 532 refPointValuesEntered(); 533 updateState(); 534 } 535 536 public void setDistance1Field(String s) { 537 this.distance1Field.setText(s); 538 updateState(); 539 } 540 541 public void setDistance2Field(String s) { 542 this.distance2Field.setText(s); 543 updateState(); 544 } 545 546 public void setDistance1Value(String valueAsString) { 547 this.dist1Value = valueAsString; 548 if (!valueAsString.equals("")) distance1Entered(); 549 updateState(); 550 } 551 552 public void setDistance2Value(String valueAsString) { 553 this.dist2Value = valueAsString; 554 if (!valueAsString.equals("")) distance2Entered(); 555 updateState(); 556 } 557 558 public void setReferenceFileName(String name) { 559 this.referenceFileName = name; 560 } 561 562 private void setFileChooser() { 563 fileChooser.setFileSelectionMode(FILES_ONLY); 564 FileNameExtensionFilter filter = new FileNameExtensionFilter(".osm, .gpx", "osm", "gpx"); 565 fileChooser.setFileFilter(filter); 566 } 567 568 public void setReferenceFileNameValue(String value) { 569 this.referenceFileName = value; 570 this.refFileNameValue.setText(value); 571 refFileEntered(); 572 updateState(); 573 } 574 575 public JFileChooser getFileChooser() { 576 return this.fileChooser; 577 } 578 579 public String getFileName() { 580 return this.referenceFileName; 581 } 582 583 // LISTENER 584 585 public void setOkButtonListener(ActionListener l) { 586 this.runButton.addActionListener(l); 587 } 588 589 public void setCancelButtonListener(ActionListener l) { 590 this.cancelButton.addActionListener(l); 591 } 592 593 public void setWindowListener(WindowListener l) { 594 this.addWindowListener(l); 595 } 596 597 public void addOpenFileButtonListener(ActionListener l) { 598 this.openButton.addActionListener(l); 599 } 600 601 public void addSelectLayerButtonListener(ActionListener l) { 602 this.selectLayerButton.addActionListener(l); 603 } 604 605 public void addCancelButtonListener(ActionListener l) { 606 this.cancelButton.addActionListener(l); 607 } 608 609 public void addRunButtonListener(ActionListener l) { 610 this.runButton.addActionListener(l); 611 } 612 613 public void addEdgePointButtonListener(ActionListener l) { 614 this.addEdgePointsButton.addActionListener(l); 615 } 616 617 public void addReferencePointButtonListener(ActionListener l) { 618 this.addRefPointsButton.addActionListener(l); 619 } 620 621 public void addFrameWindowListener(WindowAdapter wAdapter) { 622 this.addWindowListener(wAdapter); 623 } 624 625 public void addDistance1FieldListener(FocusListener l) { 626 this.distance1Field.addFocusListener(l); 627 } 628 629 public void addDistance2FieldListener(FocusListener l) { 630 this.distance2Field.addFocusListener(l); 631 } 632 633 public void addHelpButtonListener(ActionListener l) { 634 this.helpButton.addActionListener(l); 635 } 636 637 638 // HELPER 639 640 private ImageIcon getCheckedIcon() { 641 String imageName = "checked.png"; 642 Image image = null; 643 try { 644 image = ImageIO.read(getClass().getResource("/images/" + imageName)); 645 } catch (Exception ex) { 646 System.out.println("Error: Could not load image " + imageName + "," + ex); 647 } 648 return new ImageIcon(image); 649 } 650 651 public void updateState() { 652 if (originPoints.isEmpty()) { 653 // button blink 654 distance1Field.setEnabled(false); 655 distance2Field.setEnabled(false); 656 openButton.setEnabled(false); 657 selectLayerButton.setEnabled(false); 658 addRefPointsButton.setEnabled(false); 659 runButton.setEnabled(false); 660 } else { 661 if (dist1Value == null && dist2Value == null) { 662 distance1Field.setEnabled(true); 663 distance2Field.setEnabled(true); 664 } 665 if (dist1Value != null) { 666 openButton.setEnabled(true); 667 selectLayerButton.setEnabled(true); 668 } 669 if (referenceFileName != null) addRefPointsButton.setEnabled(true); 670 if (!referencePoints.isEmpty()) runButton.setEnabled(true); 671 } 672 } 673 674 public void refresh() { 675 this.setVisible(true); 676 } 683 677 684 678 }
Note:
See TracChangeset
for help on using the changeset viewer.