1 /* 2 * Copyright (c) 2021 Helmut Neemann. 3 * Use of this source code is governed by the GPL v3 license 4 * that can be found in the LICENSE file. 5 */ 6 package de.neemann.digital.core; 7 8 /** 9 * Used to format a Value 10 */ 11 public interface ValueFormatter { 12 /** 13 * Formats the value. 14 * Uses this method to create a string which is only shown to the user. 15 * If the user is able to edit the string use {@link ValueFormatter#formatToEdit(Value)} instead. 16 * 17 * @param inValue the value to format 18 * @return the formatted value as a string 19 */ formatToView(Value inValue)20 String formatToView(Value inValue); 21 22 /** 23 * Formats the value. 24 * Creates a string which can be parsed by {@link Bits#decode(String)} 25 * 26 * @param inValue the value to format 27 * @return the formatted value as a string 28 * @see Bits#decode(String) 29 */ formatToEdit(Value inValue)30 String formatToEdit(Value inValue); 31 32 /** 33 * Return the number of characters required to format a number with the given bit width. 34 * 35 * @param bits the number of bits 36 * @return the number of characters required 37 */ strLen(int bits)38 int strLen(int bits); 39 40 /** 41 * Returns true if formatter is suited to be used as a formatter for the addresses in a 42 * hex editor like table view. 43 * 44 * @return true if formatter is suited to display addresses 45 */ isSuitedForAddresses()46 boolean isSuitedForAddresses(); 47 48 /** 49 * Moves the given value 50 * 51 * @param initial the initial value 52 * @param bits the bits used of the initial value 53 * @param inc the increment, is i between -1 and 1 54 * @return the modified value 55 */ dragValue(long initial, int bits, double inc)56 long dragValue(long initial, int bits, double inc); 57 58 /** 59 * Returns true if there should be a separator in front of the given bit. 60 * 61 * @param bits the number of bits in the value to format 62 * @param bit the bit in question 63 * @return true if there should be a separator in front of the given bit. 64 */ isSeparatorInFrontOf(int bits, int bit)65 default boolean isSeparatorInFrontOf(int bits, int bit) { 66 return false; 67 } 68 } 69