KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > editors > CharsetDisplayPreferenceEditor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * CharsetDisplayPreferenceEditor.java
21  *
22  * Created on March 19, 2004, 1:17 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.editors;
26 import org.openide.util.NbBundle;
27
28 /**
29  *
30  * @author vkraemer
31  */

32 public class CharsetDisplayPreferenceEditor extends LogLevelEditor{
33
34     public static Integer JavaDoc DEFAULT_PREF_VAL = Integer.valueOf("1"); // NOI18N
35

36     private Integer JavaDoc val = DEFAULT_PREF_VAL;
37
38
39     /** Creates a new instance of CharsetDisplayPreferenceEditor */
40     public CharsetDisplayPreferenceEditor() {
41     }
42
43     static String JavaDoc[] choices = {
44         NbBundle.getMessage(CharsetDisplayPreferenceEditor.class,"VAL_CANONICAL"), // NOI18N
45
NbBundle.getMessage(CharsetDisplayPreferenceEditor.class,"VAL_ALIAS_ASIDE"), // NOI18N
46
NbBundle.getMessage(CharsetDisplayPreferenceEditor.class,"VAL_ALIAS"), // NOI18N
47
};
48     
49     public String JavaDoc[] getTags() {
50         return choices;
51     }
52         
53     public String JavaDoc getAsText() {
54         return choices[val.intValue()];
55     }
56     
57     public void setAsText(String JavaDoc string) throws IllegalArgumentException JavaDoc {
58         int intVal = 1;
59         if((string==null)||(string.equals(""))) // NOI18N
60
throw new IllegalArgumentException JavaDoc();
61         else
62             intVal = java.util.Arrays.binarySearch(choices,string);
63         if (intVal < 0) {
64             intVal = 1;
65         }
66         if (intVal > 2){
67             intVal = 1;
68         }
69         String JavaDoc valS = String.valueOf(intVal);
70         val = Integer.valueOf(valS);
71         this.firePropertyChange();
72     }
73     
74     public void setValue(Object JavaDoc val) {
75         if (val==null){
76             val=DEFAULT_PREF_VAL;
77         }
78         if (! (val instanceof Integer JavaDoc)) {
79             throw new IllegalArgumentException JavaDoc();
80         }
81         
82         this.val = (Integer JavaDoc) val;
83         int ival = this.val.intValue();
84         if (ival < 0 || ival > 2){
85             this.val = DEFAULT_PREF_VAL;
86         }
87 // super.setValue(this.val);
88
}
89     
90     public Object JavaDoc getValue() {
91         return this.val;
92     }
93 }
94
Popular Tags