19 package org.turro.collections;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import org.turro.elephant.impl.navigation.DefaultNavigatorItem;
24 import org.turro.html.HTMLHelper;
34 private int pageSpan = 4;
35 private ArrayList<DefaultNavigatorItem> buttons;
38 this.iterator = iterator;
39 this.html = iterator.
html;
43 this.pageSpan = pageSpan;
48 current = Math.max(iterator.
current(), 0);
50 html.
startTag(
"div",
"class='dao-navigator'");
53 if(current - pageSpan > 1) {
67 for(
int i = current - pageSpan; i < current + pageSpan; i++) {
68 if(i >= 0 && i <
pages) {
69 html.
startTag(
"li", current == i ?
"class='active'" :
null);
71 html.
write((i + 1) +
"");
83 if(current + pageSpan <
pages) {
93 public Collection<DefaultNavigatorItem>
pages() {
95 buttons =
new ArrayList<>();
97 current = Math.max(iterator.
current(), 0);
98 if(
pages < current ||
pages == 1)
return buttons;
100 boolean navbut =
pages > pageSpan * 2;
101 int start = 0, limit = pageSpan * 2;
107 start = Integer.max(1, current - (limit / 2));
108 start = Integer.min(start,
pages - (limit + 1));
111 for(
int i = start; i < (start + limit) && i <
pages; i++) {
void setPageSpan(int pageSpan)
CollectionNavigator(CollectionHtmlIterator iterator)
Collection< DefaultNavigatorItem > pages()
HTMLGenerator startTag(String tag)
HTMLGenerator startAnchor(String url, String hint)
HTMLGenerator write(String value)