Coverage Report - org.kuali.student.common.ui.client.widgets.KSTextBox
 
Classes in this File Line Coverage Branch Coverage Complexity
KSTextBox
0%
0/58
0%
0/30
2.25
KSTextBox$1
0%
0/3
N/A
2.25
KSTextBox$2
0%
0/3
N/A
2.25
KSTextBox$3
0%
0/3
N/A
2.25
KSTextBox$4
0%
0/3
N/A
2.25
KSTextBox$5
0%
0/6
0%
0/2
2.25
KSTextBox$6
0%
0/6
0%
0/4
2.25
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.common.ui.client.widgets;
 17  
 
 18  
 import com.google.gwt.dom.client.Element;
 19  
 import com.google.gwt.event.dom.client.BlurEvent;
 20  
 import com.google.gwt.event.dom.client.BlurHandler;
 21  
 import com.google.gwt.event.dom.client.FocusEvent;
 22  
 import com.google.gwt.event.dom.client.FocusHandler;
 23  
 import com.google.gwt.event.dom.client.MouseOutEvent;
 24  
 import com.google.gwt.event.dom.client.MouseOutHandler;
 25  
 import com.google.gwt.event.dom.client.MouseOverEvent;
 26  
 import com.google.gwt.event.dom.client.MouseOverHandler;
 27  
 import com.google.gwt.user.client.ui.TextBox;
 28  
 
 29  
 /**
 30  
  * KSTextArea wraps gwt TextArea.  This class provides most of the same functionality, but sets KS css styles
 31  
  * for its default look and a variety of TextArea events (for improved browser compatibility and customizability).
 32  
  *
 33  
  * @author Kuali Student Team
 34  
  *
 35  
  *
 36  
  */
 37  0
 public class KSTextBox extends TextBox implements HasWatermark{
 38  0
         private boolean hasWatermark = false;
 39  0
         private boolean watermarkShowing = false;
 40  
         private String watermarkText;
 41  
         
 42  
     /**
 43  
      * Creates an empty text box.
 44  
      *
 45  
      */
 46  
     public KSTextBox() {
 47  0
         super();
 48  0
         setupDefaultStyle();
 49  0
     }
 50  
 
 51  
     /**
 52  
      *  Creates a new text box using the text box element specified.
 53  
      *
 54  
      * @param element a <input> element of type 'text'
 55  
      */
 56  
     public KSTextBox(Element element) {
 57  0
         super(element);
 58  0
         setupDefaultStyle();
 59  0
     }
 60  
 
 61  
     /**
 62  
      * This method sets the default style for the text box and text box events.
 63  
      *
 64  
      */
 65  
     private void setupDefaultStyle() {
 66  0
         addStyleName("KS-Textbox");
 67  
 
 68  0
         this.addBlurHandler(new BlurHandler(){
 69  
             public void onBlur(BlurEvent event) {
 70  0
                 KSTextBox.this.removeStyleName("KS-Textbox-Focus");
 71  
 
 72  0
             }
 73  
         });
 74  
 
 75  0
         this.addFocusHandler(new FocusHandler(){
 76  
             public void onFocus(FocusEvent event) {
 77  0
                 KSTextBox.this.addStyleName("KS-Textbox-Focus");
 78  
 
 79  0
             }
 80  
         });
 81  
 
 82  0
         this.addMouseOverHandler(new MouseOverHandler(){
 83  
             public void onMouseOver(MouseOverEvent event) {
 84  0
                 KSTextBox.this.addStyleName("KS-Textbox-Hover");
 85  
 
 86  0
             }
 87  
         });
 88  
 
 89  0
         this.addMouseOutHandler(new MouseOutHandler(){
 90  
 
 91  
             public void onMouseOut(MouseOutEvent event) {
 92  0
                 KSTextBox.this.removeStyleName("KS-Textbox-Hover");
 93  
 
 94  0
             }
 95  
 
 96  
         });
 97  
 
 98  0
     }
 99  
 
 100  
         @Override
 101  
         public void setWatermarkText(String text) {
 102  0
                 if(!hasWatermark){
 103  0
                         hasWatermark = true;
 104  0
                         watermarkText = text;
 105  0
                         if(getText() == null || getText().isEmpty()){
 106  0
                                 addStyleName("watermark-text");
 107  0
                                 super.setText(watermarkText);
 108  0
                                 watermarkShowing = true;
 109  
                         }
 110  
                         
 111  0
                         this.addFocusHandler(new FocusHandler(){
 112  
         
 113  
                                 @Override
 114  
                                 public void onFocus(FocusEvent event) {
 115  0
                                         if(watermarkShowing){
 116  0
                                                 removeStyleName("watermark-text");
 117  0
                                                 KSTextBox.super.setText("");
 118  0
                                                 watermarkShowing = false;
 119  
                                         }
 120  0
                                 }
 121  
                         });
 122  
                         
 123  0
                         this.addBlurHandler(new BlurHandler(){
 124  
         
 125  
                                 @Override
 126  
                                 public void onBlur(BlurEvent event) {
 127  0
                                         if(getText() == null || getText().isEmpty()){
 128  0
                                                 addStyleName("watermark-text");
 129  0
                                                 KSTextBox.super.setText(watermarkText);
 130  0
                                                 watermarkShowing = true;
 131  
                                         }
 132  0
                                 }
 133  
                         });
 134  
                 }
 135  
                 else{
 136  0
                         watermarkText = text;
 137  0
                         if(getText() == null || getText().isEmpty()){
 138  0
                                 addStyleName("watermark-text");
 139  0
                                 KSTextBox.super.setText(watermarkText);
 140  0
                                 watermarkShowing = true;
 141  
                         }
 142  
                 }
 143  0
         }
 144  
         
 145  
         @Override
 146  
         public boolean hasWatermark(){
 147  0
                 return hasWatermark;
 148  
         }
 149  
         
 150  
         @Override
 151  
         public boolean watermarkShowing() {
 152  0
                 return watermarkShowing;
 153  
         }
 154  
         
 155  
         @Override
 156  
         public String getText() {
 157  0
                 if(!watermarkShowing){
 158  0
                         return super.getText();
 159  
                 }
 160  0
                 return null;
 161  
         }
 162  
         
 163  
         @Override
 164  
         public String getValue() {
 165  0
                 if(!watermarkShowing){
 166  0
                         return super.getValue();
 167  
                 }
 168  0
                 return null;
 169  
         }
 170  
         
 171  
         @Override
 172  
         public void setValue(String value) {
 173  0
                 if(hasWatermark){
 174  0
                         if(value == null || (value != null && value.isEmpty())){
 175  0
                                 super.setValue(watermarkText);
 176  0
                                 addStyleName("watermark-text");
 177  0
                                 watermarkShowing = true;
 178  
                         }
 179  
                         else{
 180  0
                                 super.setValue(value);
 181  0
                                 removeStyleName("watermark-text");
 182  0
                                 watermarkShowing = false;
 183  
                         }
 184  
                 }
 185  
                 else{
 186  0
                         super.setValue(value);
 187  
                 }
 188  0
         }
 189  
         
 190  
         @Override
 191  
         public void setText(String text) {
 192  0
                 if(hasWatermark){
 193  0
                         if(text == null || (text != null && text.isEmpty())){
 194  0
                                 super.setText(watermarkText);
 195  0
                                 addStyleName("watermark-text");
 196  0
                                 watermarkShowing = true;
 197  
                         }
 198  
                         else{
 199  0
                                 super.setText(text);
 200  0
                                 removeStyleName("watermark-text");
 201  0
                 watermarkShowing = false;
 202  
                         }
 203  
                 }
 204  
                 else{
 205  0
                         super.setText(text);
 206  
                 }
 207  0
         }
 208  
 }