001 package org.gwtbootstrap3.client.ui;
002
003 /*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2013 - 2014 GwtBootstrap3
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023 import org.gwtbootstrap3.client.ui.base.HasResponsiveness;
024 import org.gwtbootstrap3.client.ui.constants.IconPosition;
025 import org.gwtbootstrap3.client.ui.constants.IconSize;
026 import org.gwtbootstrap3.client.ui.constants.IconType;
027 import org.gwtbootstrap3.client.ui.constants.Styles;
028 import org.gwtbootstrap3.client.ui.html.UnorderedList;
029
030 import com.google.gwt.event.dom.client.ClickHandler;
031 import com.google.web.bindery.event.shared.HandlerRegistration;
032
033 /**
034 * Support for Bootstrap pager (http://getbootstrap.com/components/#pagination-pager)
035 *
036 * @author Joshua Godi
037 */
038 public class Pager extends UnorderedList implements HasResponsiveness {
039 private static final String DEFAULT_PREVIOUS = "Previous";
040 private static final String DEFAULT_NEXT = "Next";
041
042 private final AnchorListItem previous;
043 private final AnchorListItem next;
044
045 public Pager() {
046 setStyleName(Styles.PAGER);
047
048 previous = new AnchorListItem(DEFAULT_PREVIOUS);
049 next = new AnchorListItem(DEFAULT_NEXT);
050
051 add(previous);
052 add(next);
053 }
054
055 public void setAlignToSides(final boolean alignToSides) {
056 if (alignToSides) {
057 previous.setStyleName(Styles.PREVIOUS);
058 next.setStyleName(Styles.NEXT);
059 } else {
060 previous.removeStyleName(Styles.PREVIOUS);
061 next.removeStyleName(Styles.NEXT);
062 }
063 }
064
065 /**
066 * Adds a click handler to the previous button
067 *
068 * @param clickHandler click handler
069 * @return handler registration of the handler
070 */
071 public HandlerRegistration addPreviousClickHandler(final ClickHandler clickHandler) {
072 return previous.addClickHandler(clickHandler);
073 }
074
075 /**
076 * Adds a click handler to the next button
077 *
078 * @param clickHandler click handler
079 * @return handler registration of the handler
080 */
081 public HandlerRegistration addNextClickHandler(final ClickHandler clickHandler) {
082 return next.addClickHandler(clickHandler);
083 }
084
085 public void setPreviousText(final String text) {
086 previous.setText(text);
087 }
088
089 public void setPreviousIcon(final IconType icon) {
090 previous.setIcon(icon);
091 }
092
093 public void setPreviousIconSize(final IconSize iconSize) {
094 previous.setIconSize(iconSize);
095 }
096
097 public void setNextText(final String text) {
098 next.setText(text);
099 }
100
101 public void setNextIcon(final IconType icon) {
102 next.setIcon(icon);
103 next.setIconPosition(IconPosition.RIGHT);
104 }
105
106 public void setNextIconSize(final IconSize iconSize) {
107 next.setIconSize(iconSize);
108 }
109 }