private static Pair<Integer, Integer> size(String s, int index, int height) { if (height < 1) { throw new IllegalArgumentException("A non positive height=" + height + " cannot be accepted"); } if (index < s.length()) { int pos = s.indexOf('\n', index); if (pos == -1) { return Pair.of(s.length() - index, height); } else { Pair<Integer, Integer> ret = size(s, pos + 1, height + 1); return new Pair<Integer, Integer>(Math.max(pos - index, ret.getFirst()), ret.getSecond()); } } else { return Pair.of(0, height); } }
public synchronized boolean previousRow() throws IOException { // Current strategy is to increment updates, a bit dumb, but fast (in memory) and works // correctly if (row > 0) { int previousOffset = 0; int previousIndex = 0; int previousRow = 0; while (previousRow < row - 1) { Pair<Integer, Integer> next = nextRow(previousOffset, previousIndex, width); if (next != null) { previousOffset = next.getFirst(); previousIndex = next.getSecond(); previousRow++; } else { break; } } status = REFRESH; cursorX = cursorY = 0; cursorOffset = offset = previousOffset; cursorIndex = index = previousIndex; row = previousRow; return true; } else { return false; } }
public static <F, S> Pair<F, S> of(F first, S second) { return new Pair<F, S>(first, second); }
public boolean hasNext() { if (next == null) { if (index != Integer.MAX_VALUE) { int pos = value.indexOf('\n', index); int nextIndex; if (pos == -1) { pos = Math.min(index + width, value.length()); nextIndex = pos; } else { if (pos <= index + width) { nextIndex = pos + 1; } else { nextIndex = pos = index + width; } } next = Pair.of(index, pos); if (pos < value.length()) { index = nextIndex; } else { // Stop value index = Integer.MAX_VALUE; } } } return next != null; }
/** * Create a new label element * * @param value the label value * @param minWidth the label minimum width * @throws IllegalArgumentException if the minimum width is negative */ public LabelElement(Object value, int minWidth) throws IllegalArgumentException { if (minWidth < 0) { throw new IllegalArgumentException("No negative min size allowed"); } // String s = String.valueOf(value); // Determine size CharSlicer slicer = new CharSlicer(s); Pair<Integer, Integer> size = slicer.size(); // this.value = s; this.minWidth = Math.min(size.getFirst(), minWidth); this.actualWidth = size.getFirst(); this.actualHeight = size.getSecond(); this.slicer = slicer; }
private Pair<Integer, Integer> nextRow(int offset, int index, int width) { int count = 0; while (true) { if (index >= buffer.get(offset).text.length()) { if (offset + 1 >= buffer.size()) { return null; } else { index = 0; offset++; } } else { char c = buffer.get(offset).text.charAt(index++); if (c == '\n') { return new Pair<Integer, Integer>(offset, index); } else if (c >= 32) { if (++count == width) { return new Pair<Integer, Integer>(offset, index); } } } } }
public boolean hasNext() { if (next == null) { if (index != Integer.MAX_VALUE) { int pos = value.indexOf('\n', index); int nextIndex; if (pos == -1) { pos = Math.min(index + width, value.length()); nextIndex = pos; } else { if (pos <= index + width) { nextIndex = pos + 1; } else { nextIndex = pos = index + width; } } next = Pair.of(index, pos); if (pos < value.length()) { index = nextIndex; } else { // Stop value index = Integer.MAX_VALUE; } } } return next != null; }
private static Pair<Integer, Integer> size(String s, int index, int height) { if (height < 1) { throw new IllegalArgumentException("A non positive height=" + height + " cannot be accepted"); } if (index < s.length()) { int pos = s.indexOf('\n', index); if (pos == -1) { return Pair.of(s.length() - index, height); } else { Pair<Integer, Integer> ret = size(s, pos + 1, height + 1); return new Pair<Integer, Integer>(Math.max(pos - index, ret.getFirst()), ret.getSecond()); } } else { return Pair.of(0, height); } }
Pair<Integer, Integer> next = nextRow(_offset, _index, width); if (next != null) { _offset = next.getFirst(); _index = next.getSecond(); count++; } else { for (int i = 0;i < count;i++) { Pair<Integer, Integer> next = nextRow(_offset, _index, width); _offset = next.getFirst(); _index = next.getSecond();
public static <F, S> Pair<F, S> of(F first, S second) { return new Pair<F, S>(first, second); }
public boolean hasNext() { if (next == null) { if (index != Integer.MAX_VALUE) { int pos = value.indexOf('\n', index); int nextIndex; if (pos == -1) { pos = Math.min(index + width, value.length()); nextIndex = pos; } else { if (pos <= index + width) { nextIndex = pos + 1; } else { nextIndex = pos = index + width; } } next = Pair.of(index, pos); if (pos < value.length()) { index = nextIndex; } else { // Stop value index = Integer.MAX_VALUE; } } } return next != null; }
private static Pair<Integer, Integer> size(String s, int index, int height) { if (height < 1) { throw new IllegalArgumentException("A non positive height=" + height + " cannot be accepted"); } if (index < s.length()) { int pos = s.indexOf('\n', index); if (pos == -1) { return Pair.of(s.length() - index, height); } else { Pair<Integer, Integer> ret = size(s, pos + 1, height + 1); return new Pair<Integer, Integer>(Math.max(pos - index, ret.getFirst()), ret.getSecond()); } } else { return Pair.of(0, height); } }
public void renderLine(RenderAppendable to) { if (index >= height) { throw new IllegalStateException(); } else { Style.Composite style = element.getStyle(); if (style != null) { to.enterStyle(style); } if (index < lines.length) { Pair<Integer, Integer> a = lines[index]; to.append(element.value, a.getFirst(), a.getSecond()); int missing = width - (a.getSecond() - a.getFirst()); if (missing > 0) { to.append(BlankSequence.create(missing)); } } else { for (int i = 0;i < width;i++) { to.append(' '); } } index++; if (style != null) { to.leaveStyle(); } } } }
public static <F, S> Pair<F, S> of(F first, S second) { return new Pair<F, S>(first, second); }
public boolean hasNext() { if (next == null) { if (index != Integer.MAX_VALUE) { int pos = value.indexOf('\n', index); int nextIndex; if (pos == -1) { pos = Math.min(index + width, value.length()); nextIndex = pos; } else { if (pos <= index + width) { nextIndex = pos + 1; } else { nextIndex = pos = index + width; } } next = Pair.of(index, pos); if (pos < value.length()) { index = nextIndex; } else { // Stop value index = Integer.MAX_VALUE; } } } return next != null; }
private static Pair<Integer, Integer> size(String s, int index, int height) { if (height < 1) { throw new IllegalArgumentException("A non positive height=" + height + " cannot be accepted"); } if (index < s.length()) { int pos = s.indexOf('\n', index); if (pos == -1) { return Pair.of(s.length() - index, height); } else { Pair<Integer, Integer> ret = size(s, pos + 1, height + 1); return new Pair<Integer, Integer>(Math.max(pos - index, ret.getFirst()), ret.getSecond()); } } else { return Pair.of(0, height); } }
public LabelElement(String value, int minWidth) { if (minWidth < 0) { throw new IllegalArgumentException("No negative min size allowed"); } // Determine size CharSlicer slicer = new CharSlicer(value); Pair<Integer, Integer> size = slicer.size(); // this.value = value; this.minWidth = Math.min(size.getFirst(), minWidth); this.actualWidth = size.getFirst(); this.actualHeight = size.getSecond(); this.slicer = slicer; }
public static <F, S> Pair<F, S> of(F first, S second) { return new Pair<F, S>(first, second); }
public synchronized boolean previousRow() throws IOException { // Current strategy is to increment updates, a bit dumb, but fast (in memory) and works // correctly if (row > 0) { int previousOffset = 0; int previousIndex = 0; int previousRow = 0; while (previousRow < row - 1) { Pair<Integer, Integer> next = nextRow(previousOffset, previousIndex, width); if (next != null) { previousOffset = next.getFirst(); previousIndex = next.getSecond(); previousRow++; } else { break; } } status = REFRESH; cursorX = cursorY = 0; cursorOffset = offset = previousOffset; cursorIndex = index = previousIndex; row = previousRow; return true; } else { return false; } }
private Pair<Integer, Integer> nextRow(int offset, int index, int width) { int count = 0; while (true) { if (index >= buffer.get(offset).text.length()) { if (offset + 1 >= buffer.size()) { return null; } else { index = 0; offset++; } } else { char c = buffer.get(offset).text.charAt(index++); if (c == '\n') { return new Pair<Integer, Integer>(offset, index); } else if (c >= 32) { if (++count == width) { return new Pair<Integer, Integer>(offset, index); } } } } }