KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > visual > model > PropertyWithUnitData


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * PropertyWithUnitData.java
22  *
23  * Created on October 21, 2004, 9:51 PM
24  */

25
26 package org.netbeans.modules.css.visual.model;
27
28 import javax.swing.DefaultComboBoxModel JavaDoc;
29
30 /**
31  * Data Structure to hold the value of a property with Unit
32  * @author Winston Prakash
33  * @version 1.0
34  */

35 public class PropertyWithUnitData extends PropertyData{
36
37     /**
38      * Holds value of property unit.
39      */

40     protected String JavaDoc unit="px"; //NOI18N
41

42     public void setData(String JavaDoc value){
43         if(!((value == null) || value.equals(""))){
44             if(Utils.isInteger(value)){
45                 setValue(value);
46                 setUnit("px"); //NOI18N
47
}else{
48                 unit = getUnit(value);
49                 setValue(value.replaceAll(unit,"").trim());
50             }
51         }
52     }
53
54     private String JavaDoc getUnit(String JavaDoc positionStr){
55         DefaultComboBoxModel JavaDoc unitList = new BorderModel().getWidthUnitList();
56         for(int i=0; i< unitList.getSize(); i++){
57             String JavaDoc unit = (String JavaDoc)unitList.getElementAt(i);
58             if(positionStr.trim().endsWith(unit)){
59                 return unit;
60             }
61         }
62         return "";
63     }
64
65     public void clear(){
66       setValue(CssStyleData.NOT_SET);
67       setUnit("px"); //NOI18N
68
}
69
70     public String JavaDoc toString(){
71         String JavaDoc valueString = super.toString();
72         if(Utils.isInteger(valueString)){
73             valueString += unit;
74         }
75         return valueString;
76     }
77
78
79     /**
80      * Setter for property unit.
81      * @param unit New value of property unit.
82      */

83     public void setUnit(String JavaDoc unit) {
84         this.unit = unit;
85     }
86
87     /**
88      * Getter for property unit.
89      * @return Value of property unit.
90      */

91     public java.lang.String JavaDoc getUnit() {
92         return unit;
93     }
94
95 }
96
Popular Tags