1 14 package org.wings; 15 16 17 21 public class SPageScroller 22 extends SAbstractAdjustable 23 { 24 private static final int DEFAULT_DIRECT_PAGES = 10; 25 26 private boolean marginVisible; 27 28 private boolean stepVisible; 29 30 36 protected int directPages = DEFAULT_DIRECT_PAGES; 37 38 42 protected int layoutMode; 43 44 47 protected SClickable[] clickables = new SClickable[4]; 48 49 52 protected SClickable[] directPageClickables; 53 54 protected SLabel pageCountLabel = new SLabel(); 55 56 69 public SPageScroller(int orientation, int value, int extent, int min, int max) { 70 super(new SPagingBoundedRangeModel(value, extent, min, max)); 71 unitIncrement = extent; 72 blockIncrement = extent; 73 74 for (int i = 0; i < clickables.length; i++) { 75 clickables[i] = new SClickable(); 76 clickables[i].setEventTarget(this); 77 } 78 79 setOrientation(orientation); 80 setMarginVisible(false); 81 setHorizontalAlignment(SConstants.CENTER); 82 setVerticalAlignment(SConstants.CENTER); 83 setEpochCheckEnabled(false); 84 } 85 86 96 public SPageScroller(int orientation) { 97 this(orientation, 0, 1, 0, 100); 98 } 99 100 109 public SPageScroller() { 110 this(SConstants.VERTICAL); 111 } 112 113 public SLabel getPageCountLabel() { 114 return pageCountLabel; 115 } 116 117 protected void setPageCountText(int pages) { 118 pageCountLabel.setText("/" + pages); 119 } 120 121 public int getLayoutMode() { 122 return layoutMode; 123 } 124 125 129 public void setLayoutMode(int orientation) { 130 switch (orientation) { 131 case SConstants.VERTICAL: 132 case SConstants.HORIZONTAL: 133 layoutMode = orientation; 134 break; 135 default: 136 throw new IllegalArgumentException ("layout mode must be one of: VERTICAL, HORIZONTAL"); 137 } 138 } 139 140 143 public final int getDirectPages() { 144 return directPages; 145 } 146 147 152 public void setDirectPages(int count) { 153 if (directPages != count) 154 directPages = count; 155 } 156 157 public final int getPageCount() { 158 if (getExtent() == 0) 160 return 0; 161 return ((getMaximum() + 1) + (getExtent() - 1) - getMinimum()) / getExtent(); 162 } 163 164 170 public final int getCurrentPage() { 171 if (getExtent() == 0) 173 return 0; 174 175 return (getValue() - getMinimum() + getExtent() - 1) / getExtent(); 176 } 177 178 protected String formatDirectPageLabel(int page) { 179 return Integer.toString(page + 1); 180 } 181 182 183 public boolean isMarginVisible() { 184 return marginVisible; 185 } 186 187 public void setMarginVisible(boolean marginVisible) { 188 this.marginVisible = marginVisible; 189 } 190 191 public boolean isStepVisible() { 192 return stepVisible; 193 } 194 195 public void setStepVisible(boolean stepVisible) { 196 this.stepVisible = stepVisible; 197 } 198 199 205 public void setExtent(int value) { 206 super.setExtent(value); 207 unitIncrement = value; 208 blockIncrement = value; 209 setValue(getValue()); 211 } 212 213 219 public void setVisibleAmount(int value) { 220 super.setVisibleAmount(value); 221 unitIncrement = value; 222 blockIncrement = value; 223 setValue(getValue()); 225 } 226 227 233 public void setValue(int value) { 234 super.setValue(value - (value % getExtent())); 235 } 236 } 237 | Popular Tags |