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.base; 017 018import com.github.gwtbootstrap.client.ui.TextBox; 019import com.github.gwtbootstrap.client.ui.Form; 020import com.github.gwtbootstrap.client.ui.constants.Alignment; 021 022//@formatter:off 023/** 024 * Base class for forms inside a {@link com.github.gwtbootstrap.client.ui.Navbar 025 * Navbar.} 026 * 027 * @since 2.0.4.0 028 * 029 * @author Dominik Mayer 030 * 031 * @see <a href="http://getbootstrap.com/2.3.2/components.html#navbar">Bootstrap documentation</a> 032 */ 033//@formatter:on 034public class NavFormBase extends Form implements HasAlignment, HasSize { 035 036 private TextBox input = new TextBox(); 037 038 /** 039 * Creates a new, left-aligned form. 040 */ 041 public NavFormBase() { 042 addStyle(Alignment.LEFT); 043 add(input); 044 } 045 046 //@formatter:off 047 /** 048 * Creates a new, left aligned form of the given size. 049 * 050 * @param size the size of the form in the <a href="http://twitter.github.com/bootstrap/scaffolding.html#gridSystem">Bootstrap grid system</a> 051 */ 052 //@formatter:on 053 public NavFormBase(int size) { 054 this(); 055 setSize(size); 056 } 057 058 /** 059 * {@inheritDoc} 060 */ 061 public void setAlignment(Alignment alignment) { 062 removeStyle(Alignment.RIGHT); 063 removeStyle(Alignment.LEFT); 064 addStyle(alignment); 065 } 066 067 /** 068 * {@inheritDoc} 069 */ 070 public void setSize(int size) { 071 SizeHelper.setSize(input, size); 072 } 073 074 /** 075 * Returns the {@link TextBox} used by the widget. 076 * <p> 077 * Use it to append your own handlers or change its behavior. 078 * 079 * @return the TextBox 080 */ 081 public TextBox getTextBox() { 082 return input; 083 } 084 085 /** 086 * Sets a placeholder in the the TextBox. 087 * <p> 088 * A placeholder is a piece of text in the TextBox that disappears when the 089 * TextBox receives focus. 090 * 091 * @param placeholder 092 * the placeholder text 093 */ 094 public void setPlaceholder(String placeholder) { 095 input.setPlaceholder(placeholder); 096 } 097}