Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/DataPaginator.java @ 173:aa564b1b5e1f public_by_author
publicByAuthor feature ui for selecting texts ready.
actual changing of public state not yet implemented.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 06 Jun 2018 21:01:05 +0200 |
parents | 2e911857a759 |
children |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.util.guiComponents; |
2 | |
3 import java.text.MessageFormat; | |
4 | |
5 public class DataPaginator { | |
6 /* This should be parameters or properties stored somewhere */ | |
173
aa564b1b5e1f
publicByAuthor feature ui for selecting texts ready.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
7 private int itemsPerPage = 20; |
1 | 8 private int rewindFastForwardBy = 10; |
9 | |
10 private int currentPage; | |
11 private int numberOfPages; | |
12 | |
13 private String recordStatus; | |
14 | |
15 public void first(){ | |
16 this.currentPage = 0; | |
17 } | |
18 | |
19 public void last(){ | |
20 this.currentPage = this.numberOfPages -1; | |
21 } | |
22 | |
23 public void fastRewind () { | |
24 this.rewind(this.rewindFastForwardBy); | |
25 } | |
26 | |
27 private void rewind (int aRewindFastForwardBy) { | |
28 int newPageNumber = currentPage - aRewindFastForwardBy; | |
29 if (newPageNumber < 0) { | |
30 currentPage = 0; | |
31 } else { | |
32 currentPage = newPageNumber; | |
33 } | |
34 } | |
35 | |
36 public void goToPage(int newPageNumber){ | |
37 if (newPageNumber > this.numberOfPages -1) { | |
38 currentPage = this.numberOfPages -1; | |
39 } else if(newPageNumber < 0 ){ | |
40 currentPage = 0; | |
41 }else{ | |
42 currentPage = newPageNumber; | |
43 } | |
44 | |
45 } | |
46 | |
47 private void forward (int aRewindFastForwardBy) { | |
48 int newPageNumber = currentPage + aRewindFastForwardBy; | |
49 if (newPageNumber > this.numberOfPages - 1) { | |
50 currentPage = this.numberOfPages -1; | |
51 } else { | |
52 currentPage = newPageNumber; | |
53 } | |
54 } | |
55 | |
56 public void previous () { | |
57 this.rewind(1); | |
58 } | |
59 | |
60 public void next () { | |
61 this.forward(1); | |
62 } | |
63 | |
64 public void fastForward () { | |
65 this.forward(this.rewindFastForwardBy); | |
66 } | |
67 | |
68 public void initCount() { | |
69 if (currentPage > numberOfPages) { | |
70 currentPage=numberOfPages; | |
71 } | |
72 } | |
73 | |
74 public int getNumberOfPages() { | |
75 return numberOfPages; | |
76 } | |
77 | |
78 public void setNumberOfPages(int numberOfPages) { | |
79 this.numberOfPages = numberOfPages; | |
80 } | |
81 | |
82 public void resetNumberOfPages(int itemsTotal){ | |
83 int numberOfPages = (itemsTotal | |
84 % this.getItemsPerPage() == 0) ? | |
85 itemsTotal | |
86 / this.getItemsPerPage() : | |
87 (itemsTotal | |
88 / this.getItemsPerPage()) + 1; | |
89 this.setNumberOfPages(numberOfPages); | |
90 } | |
91 | |
92 public int getCurrentPage() { | |
93 return currentPage; | |
94 } | |
95 | |
96 public void setCurrentPage(int currentPage) { | |
97 this.currentPage = currentPage; | |
98 } | |
99 | |
100 public String getRecordStatus () { | |
101 this.recordStatus = MessageFormat.format("{0} of {1}", | |
102 new Object []{ | |
103 Integer.valueOf(currentPage + 1), | |
104 Integer.valueOf(numberOfPages) | |
105 }); | |
106 return recordStatus; | |
107 } | |
108 | |
109 public void setRecordStatus(String recordStatus) { | |
110 this.recordStatus = recordStatus; | |
111 } | |
112 | |
113 public int getItemsPerPage() { | |
114 return itemsPerPage; | |
115 } | |
116 | |
117 public void setItemsPerPage(int itemsPerPage) { | |
118 this.itemsPerPage = itemsPerPage; | |
119 } | |
120 | |
121 public int getRewindFastForwardBy() { | |
122 return rewindFastForwardBy; | |
123 } | |
124 | |
125 public void setRewindFastForwardBy(int rewindFastForwardBy) { | |
126 this.rewindFastForwardBy = rewindFastForwardBy; | |
127 } | |
128 } |