@Test public void testVerifyBitcoinAmount_mBTC() throws Exception { FormattedDecimalField textField = TextBoxes.newBitcoinAmount(21_000_000_000f); ThemeAwareDecimalInputVerifier testObject = (ThemeAwareDecimalInputVerifier) textField.getInputVerifier(); textField.setText(""); assertThat(testObject.verify(textField)).isTrue(); textField.setText(" "); assertThat(testObject.verify(textField)).isFalse(); textField.setText("a"); assertThat(testObject.verify(textField)).isFalse(); textField.setText("0x"); assertThat(testObject.verify(textField)).isFalse(); textField.setText("$1"); assertThat(testObject.verify(textField)).isFalse(); textField.setText("0"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("-1"); assertThat(testObject.verify(textField)).isFalse(); textField.setText("0.1"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("0.001"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("0.00001"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("1"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("1000"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("20000000000"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("21000000001"); assertThat(testObject.verify(textField)).isFalse(); textField.setText("1,000"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("20,000,000,000"); assertThat(testObject.verify(textField)).isTrue(); textField.setText("21,000,000,001"); assertThat(testObject.verify(textField)).isFalse(); }
public boolean verify(JComponent component) { if (!(component instanceof JTextComponent)) { return false; } String text = ((JTextComponent) component).getText(); Optional<BigDecimal> value = Numbers.parseBigDecimal(text); if (value.isPresent()) { BigDecimal amount = value.get(); if (amount.compareTo(minValue) == -1 || amount.compareTo(maxValue) == 1) { component.setBackground(invalidColor); return false; } else { component.setBackground(validColor); return true; } } else { if (Strings.isNullOrEmpty(text)) { return true; } component.setBackground(invalidColor); return false; } }
ThemeAwareDecimalInputVerifier extends InputVerifier { public boolean verify(JComponent component) { if (!(component instanceof JTextComponent)) { return false; } String text = ((JTextComponent) component).getText(); Optional<BigDecimal> value = Numbers.parseBigDecimal(text); if (value.isPresent()) { BigDecimal amount = value.get(); if (amount.compareTo(minValue) == -1 || amount.compareTo(maxValue) == 1) { component.setBackground(invalidColor); return false; } else { component.setBackground(validColor); return true; } } else { if (Strings.isNullOrEmpty(text)) { return true; } component.setBackground(invalidColor); return false; } } }
ThemeAwareDecimalInputVerifier extends InputVerifier { public boolean verify(JComponent component) { if (!(component instanceof JTextComponent)) { return false; } String text = ((JTextComponent) component).getText(); Optional<BigDecimal> value = Numbers.parseBigDecimal(text); if (value.isPresent()) { BigDecimal amount = value.get(); if (amount.compareTo(minValue) == -1 || amount.compareTo(maxValue) == 1) { component.setBackground(invalidColor); return false; } else { component.setBackground(validColor); return true; } } else { if (Strings.isNullOrEmpty(text)) { return true; } component.setBackground(invalidColor); return false; } } ThemeAwareDecimalInputVerifier();  ThemeAwareDecimalInputVerifier(Double min, Double max); }
ThemeAwareDecimalInputVerifier extends InputVerifier { public boolean verify(JComponent component) { if (!(component instanceof JTextComponent)) { return false; } String text = ((JTextComponent) component).getText(); Optional<BigDecimal> value = Numbers.parseBigDecimal(text); if (value.isPresent()) { BigDecimal amount = value.get(); if (amount.compareTo(minValue) == -1 || amount.compareTo(maxValue) == 1) { component.setBackground(invalidColor); return false; } else { component.setBackground(validColor); return true; } } else { if (Strings.isNullOrEmpty(text)) { return true; } component.setBackground(invalidColor); return false; } } ThemeAwareDecimalInputVerifier();  ThemeAwareDecimalInputVerifier(Double min, Double max); boolean verify(JComponent component); }
ThemeAwareDecimalInputVerifier extends InputVerifier { public boolean verify(JComponent component) { if (!(component instanceof JTextComponent)) { return false; } String text = ((JTextComponent) component).getText(); Optional<BigDecimal> value = Numbers.parseBigDecimal(text); if (value.isPresent()) { BigDecimal amount = value.get(); if (amount.compareTo(minValue) == -1 || amount.compareTo(maxValue) == 1) { component.setBackground(invalidColor); return false; } else { component.setBackground(validColor); return true; } } else { if (Strings.isNullOrEmpty(text)) { return true; } component.setBackground(invalidColor); return false; } } ThemeAwareDecimalInputVerifier();  ThemeAwareDecimalInputVerifier(Double min, Double max); boolean verify(JComponent component);  }