@Override public int previousTab(int position) { int tabStop = 0; // Search for the first tab stop before the given position... SortedSet<Integer> headSet = myTabStops.headSet(Integer.valueOf(position)); if (!headSet.isEmpty()) { tabStop = headSet.last(); } // Don't go beyond the start of the line... return Math.max(0, tabStop); }
@Override public int nextTab(int position) { int tabStop = Integer.MAX_VALUE; // Search for the first tab stop after the given position... SortedSet<Integer> tailSet = myTabStops.tailSet(position + 1); if (!tailSet.isEmpty()) { tabStop = tailSet.first(); } // Don't go beyond the end of the line... return Math.min(tabStop, (myWidth - 1)); }
public void resize(int columns) { if (columns > myWidth) { for (int i = myTabLength * (myWidth / myTabLength); i < columns; i += myTabLength) { if (i >= myWidth) { myTabStops.add(i); } } } else { Iterator<Integer> it = myTabStops.iterator(); while (it.hasNext()) { int i = it.next(); if (i > columns) { it.remove(); } } } myWidth = columns; }
@Override public void setTabStop(int position) { myTabStops.add(Integer.valueOf(position)); }
@Override public void clearAllTabStops() { myTabStops.clear(); }
@Override public void clearTabStop(int position) { myTabStops.remove(Integer.valueOf(position)); }
private void initTabStops(int columns, int tabLength) { for (int i = tabLength; i < columns; i += tabLength) { myTabStops.add(i); } }