ScaleInfoEditor extends PropertyEditorSupport { @Override public void setAsText(String text) throws IllegalArgumentException { text = text.replaceAll(" ", ""); text = text.replaceAll(",", ""); int pos = text.indexOf(':'); if (pos > 0) { try { double numerator = Double.parseDouble(text.substring(0, pos)); double denominator = Double.parseDouble(text.substring(pos + 1)); setValue(new ScaleInfo(numerator, denominator)); } catch (NumberFormatException e) { throw new IllegalArgumentException("Scale " + text + " could not be parsed. The following format was expected:" + " (x : y).", e); } } else { try { setValue(new ScaleInfo(Double.parseDouble(text))); } catch (NumberFormatException e) { throw new IllegalArgumentException("Scale " + text + " could not be parsed. The following format was expected:" + " (x : y).", e); } } }  @Override void setAsText(String text);  }
@Test public void testSetAsText() { ScaleInfoEditor editor = new ScaleInfoEditor(); editor.setAsText("1:2000"); Object o = editor.getValue(); Assert.assertTrue(o instanceof ScaleInfo); ScaleInfo info = (ScaleInfo)o; Assert.assertEquals(1, info.getNumerator(), 0.001); Assert.assertEquals(2000, info.getDenominator(), 0.001); Assert.assertEquals(1.8890, info.getPixelPerUnit(), 0.001); }