1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 /** 25 * 26 * @author fs93730 27 */ 28 public class BooleanValidator extends ControlValidator 29 { 30 private boolean m_preventChecked; 31 private com.sun.star.uno.AnyConverter m_converter; 32 33 /** Creates a new instance of BooleanValidator */ BooleanValidator( boolean preventChecked )34 public BooleanValidator( boolean preventChecked ) 35 { 36 m_preventChecked = preventChecked; 37 m_converter = new com.sun.star.uno.AnyConverter(); 38 } 39 explainInvalid( Object Value )40 public String explainInvalid( Object Value ) 41 { 42 try 43 { 44 if ( m_converter.isVoid( Value ) ) 45 return "'indetermined' is not an allowed state"; 46 boolean value = ((Boolean)Value).booleanValue(); 47 if ( m_preventChecked && ( value == true ) ) 48 return "no no no. Don't check it."; 49 } 50 catch( java.lang.Exception e ) 51 { 52 return "ooops. Unknown error"; 53 } 54 return ""; 55 } 56 isValid( Object Value )57 public boolean isValid( Object Value ) 58 { 59 try 60 { 61 if ( m_converter.isVoid( Value ) ) 62 return false; 63 64 boolean value = ((Boolean)Value).booleanValue(); 65 if ( m_preventChecked && ( value == true ) ) 66 return false; 67 return true; 68 } 69 catch( java.lang.Exception e ) 70 { 71 } 72 return false; 73 } 74 } 75