/** * 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 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 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 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; }
/** * 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; }
/** * 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 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); } }
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); } }
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 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 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 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 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(); } } } }