/** Loads dialog fields. */ private void load() { oldThreshold = String.valueOf(controller.getFuzzyThreshold()); oldMaxResults = String.valueOf(controller.getMaxResults()); txtFuzzyThreshold.setText(oldThreshold); txtMaxResultNum.setText(oldMaxResults); }
/** Saves the inserted values. */ private void save() { String thresholdString = txtFuzzyThreshold.getText(); String maxResultsString = txtMaxResultNum.getText(); boolean showMessage = false; boolean canSave = true; if (thresholdString.isEmpty()) { txtFuzzyThreshold.setBorder(new LineBorder(Color.red)); showMessage = true; } if (maxResultsString.isEmpty()) { txtMaxResultNum.setBorder(new LineBorder(Color.red)); showMessage = true; } if (showMessage) { int option = JOptionPane.showConfirmDialog( this, "Empty fields are not admitted. Do you want to use default values?", "TM Settings Empty Fields", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { if (thresholdString.isEmpty()) { thresholdString = String.valueOf(controller.getDefaultFuzzyThreshold()); } if (maxResultsString.isEmpty()) { maxResultsString = String.valueOf(controller.getDefaultMaxResults()); } } else { canSave = false; } } if (canSave) { if (!oldThreshold.equals(thresholdString) || !oldMaxResults.equals(maxResultsString)) { float threshold = Float.parseFloat(thresholdString) / 100; int maxResults = Integer.parseInt(maxResultsString); try { controller.saveTmSettings(threshold, maxResults); close(); } catch (TransferException e) { LOG.trace( "Error while saving TM settings: threshold = " + threshold + " - max results = " + maxResults, e); JOptionPane.showMessageDialog( this, "An error has occurred while saving settings.", "TM Settings Error", JOptionPane.ERROR_MESSAGE); } } else { close(); } } }
/** Closes the dialog. */ private void close() { controller.closeDialog(); setVisible(false); dispose(); }