private Holder() { TextTerminal<?> t = getTerminalFromProperty(); if(t == null) { t = getTerminalFromService(); } if(t == null) { t = getDefaultTerminal(); } t.init(); this.terminal = t; this.textIO = new TextIO(t); }
/** * Provides the list of error messages for the input string <tt>s</tt>. * If a {@link #parseErrorMessagesProvider} exists, it will be used. Otherwise, {@link #getDefaultErrorMessages(String)} will be called. */ protected final List<String> getErrorMessages(String s) { if(parseErrorMessagesProvider != null) return parseErrorMessagesProvider.getErrorMessages(s, itemName); return getDefaultErrorMessages(s); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public AbstractTextTerminal() { this.properties = new TerminalProperties(this); addDefaultProperty(PropertiesConstants.PROP_USER_INTERRUPT_KEY, DEFAULT_USER_INTERRUPT_KEY); }
public static ReadInterruptionData from(ReadHandlerData handlerData, String partialInput) { Function<String, String> valueProvider = handlerData.getReturnValueProvider(); String retVal = (valueProvider == null) ? null : valueProvider.apply(partialInput); return new ReadInterruptionData(handlerData.getAction()) .withRedrawRequired(handlerData.isRedrawRequired()) .withPayload(handlerData.getPayload()) .withReturnValue(retVal); }
private static void configurePort(TextIO textIO, WebTextIoExecutor webTextIoExecutor, int defaultPort) { int port = textIO.newIntInputReader() .withDefaultValue(defaultPort) .read("Server port number"); webTextIoExecutor.withPort(port); }
/** * Clears the text after the given bookmark. * The bookmark name can be subsequently used in a call to {@link #resetToBookmark(String)} in order to clear the text after this bookmark. * Since not all terminals support this feature, the default implementation calls {@link #println()} and returns false. * @return true, if the terminal supports bookmarking, the given bookmark exists and the text after it has been successfully cleared. */ default boolean resetToBookmark(String bookmark) { println(); return false; }
/** Convenience method that associates the specified {@code bgcolor} with the key {@value PropertiesConstants#PROP_PANE_BGCOLOR} */ public void setPaneBackgroundColor(String bgcolor) { put(PROP_PANE_BGCOLOR, bgcolor); } /** Convenience method that associates the hex representation of the specified {@code bgcolor} with the key {@value PropertiesConstants#PROP_PANE_BGCOLOR} */
@Override protected ParseResult<Float> parse(String s) { try { return new ParseResult<>(Float.parseFloat(s)); } catch (NumberFormatException e) { return new ParseResult<>(null, getErrorMessages(s)); } } }
@Override protected ParseResult<Byte> parse(String s) { try { return new ParseResult<>(Byte.parseByte(s)); } catch (NumberFormatException e) { return new ParseResult<>(null, getErrorMessages(s)); } } }
@Override protected ParseResult<Long> parse(String s) { try { return new ParseResult<>(Long.parseLong(s)); } catch (NumberFormatException e) { return new ParseResult<>(null, getErrorMessages(s)); } } }
@Override protected ParseResult<Double> parse(String s) { try { return new ParseResult<>(Double.parseDouble(s)); } catch (NumberFormatException e) { return new ParseResult<>(null, getErrorMessages(s)); } } }
@Override protected ParseResult<Short> parse(String s) { try { return new ParseResult<>(Short.parseShort(s)); } catch (NumberFormatException e) { return new ParseResult<>(null, getErrorMessages(s)); } } }
@Override protected ParseResult<Boolean> parse(String s) { if(trueInput.equalsIgnoreCase(s)) return new ParseResult<>(true); if(falseInput.equalsIgnoreCase(s)) return new ParseResult<>(false); return new ParseResult<>(null, getErrorMessages(s)); }
/** * Convenience method that adds a listener for the long property with the specified key. * @param key the key of the property for which the listener is added. * @param defaultValue the value to be used if the new value cannot be converted to a long. * @param listener the listener to be added. */ public void addLongListener(String key, long defaultValue, LongChangeListener<T> listener) { listeners.add(new ChangeListenerForKey<>(key, defaultValue, Long::parseLong, listener.get())); }
/** * Convenience method that adds a listener for the boolean property with the specified key. * @param key the key of the property for which the listener is added. * @param defaultValue the value to be used if the new value is null. * @param listener the listener to be added. */ public void addBooleanListener(String key, boolean defaultValue, BooleanChangeListener<T> listener) { listeners.add(new ChangeListenerForKey<>(key, defaultValue, Boolean::parseBoolean, listener.get())); }
@Override public String toString() { return super.toString() + ", returnValue: " + returnValue; } }
@SuppressWarnings("unchecked") public B withInlinePossibleValues(T... possibleValues) { withPossibleValues(possibleValues); this.inlinePossibleValues = true; return (B)this; }
/** Convenience method that associates the specified {@code width} with the key {@value PropertiesConstants#PROP_PANE_WIDTH} */ public void setPaneWidth(int width) { put(PROP_PANE_WIDTH, width); } /** Convenience method that associates the specified {@code height} with the key {@value PropertiesConstants#PROP_PANE_HEIGHT} */
/** Convenience method that associates the specified {@code height} with the key {@value PropertiesConstants#PROP_PANE_HEIGHT} */ public void setPaneHeight(int height) { put(PROP_PANE_HEIGHT, height); } /** Convenience method that associates the specified {@code width} and {@code height} with the keys {@value PropertiesConstants#PROP_PANE_WIDTH} and {@value PropertiesConstants#PROP_PANE_HEIGHT}*/