001/*
002 *  Copyright 2012 GWT-Bootstrap
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package com.github.gwtbootstrap.client.ui;
017
018import com.github.gwtbootstrap.client.ui.base.DivWidget;
019import com.github.gwtbootstrap.client.ui.base.Style;
020import com.github.gwtbootstrap.client.ui.base.StyleHelper;
021import com.github.gwtbootstrap.client.ui.base.UnorderedList;
022import com.github.gwtbootstrap.client.ui.resources.Bootstrap;
023import com.google.gwt.user.client.ui.Widget;
024
025//@formatter:off
026/**
027 * Multi-Page Pagination
028 * 
029 * @since 2.0.4.0
030 * @author Dominik Mayer
031 */
032//@formatter:on
033public class Pagination extends DivWidget {
034
035        private UnorderedList list = new UnorderedList();
036
037        public Pagination() {
038                setStyle(Bootstrap.Pagination.LEFT);
039                super.add(list);
040                setSize(PaginationSize.NORMAL);
041        }
042        
043        public static enum PaginationSize implements Style {
044            MINI,
045            SMALL,
046            NORMAL,
047            LARGE;
048
049        @Override
050        public String get() {
051            if(this != NORMAL) {
052                return "pagination-" + this.name().toLowerCase();
053            }
054            return "";
055        }
056        }
057
058        public void setAlignment(String alignment) {
059                if (alignment.equalsIgnoreCase("right"))
060                        setStyle(Bootstrap.Pagination.RIGHT);
061                else if (alignment.equalsIgnoreCase("centered"))
062                        setStyle(Bootstrap.Pagination.CENTERED);
063                else
064                        setStyle(Bootstrap.Pagination.LEFT);
065        }
066        
067        public void setSize(PaginationSize size) {
068            StyleHelper.changeStyle(this, size, PaginationSize.class);
069        }
070
071        @Override
072        public void add(Widget child) {
073                list.add(child);
074        }
075        
076        @Override
077        public void clear() {
078                list.clear();
079        }
080}