KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BackgroundPositionData.java
22  *
23  * Created on October 21, 2004, 8:04 PM
24  */

25
26 package org.netbeans.modules.css.visual.model;
27
28 import java.util.StringTokenizer JavaDoc;
29 import javax.swing.DefaultComboBoxModel JavaDoc;
30
31 /**
32  * Data structure for the Background Position
33  * @author Winston Prakash
34  * @version 1.0
35  */

36 public class BackgroundPositionData {
37
38     /**
39      * Holds value of property horizontalUnit.
40      */

41     private String JavaDoc horizontalUnit = "px"; //NOI18N
42

43     /**
44      * Holds value of property verticalUnit.
45      */

46     private String JavaDoc verticalUnit = "px"; //NOI18N
47

48     /**
49      * Holds value of property verticalValue.
50      */

51     private String JavaDoc verticalValue = ""; //NOI18N
52

53     /**
54      * Holds value of property horizontalValue.
55      */

56     private String JavaDoc horizontalValue = "left"; //NOI18N
57

58     /** Creates a new instance of BackgroundPositionData */
59     public BackgroundPositionData() {
60     }
61
62     public void setBackgroundPosition(String JavaDoc bgPositionStr){
63         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(bgPositionStr);
64         if(bgPositionStr.indexOf(",") != -1){
65             st = new StringTokenizer JavaDoc(bgPositionStr, ",");
66         }else{
67             st = new StringTokenizer JavaDoc(bgPositionStr);
68         }
69         // Horizontal Postion
70
if(st.hasMoreTokens()){
71             String JavaDoc token = st.nextToken();
72             horizontalUnit = getUnit(token);
73             horizontalValue = token.replaceAll(horizontalUnit,"");
74         }
75         if(st.hasMoreTokens()){
76             String JavaDoc token = st.nextToken();
77             verticalUnit = getUnit(token);
78             verticalValue = token.replaceAll(verticalUnit,"");
79         }
80     }
81
82     private String JavaDoc getUnit(String JavaDoc postionStr){
83         DefaultComboBoxModel JavaDoc unitList = new BackgroundModel().getBackgroundPositionUnitList();
84         for(int i=0; i< unitList.getSize(); i++){
85             String JavaDoc unit = (String JavaDoc)unitList.getElementAt(i);
86             if(postionStr.endsWith(unit)){
87                 return unit;
88             }
89         }
90         return "";
91     }
92
93     /**
94      * Setter for property horizontalUnit.
95      * @param horizontalUnit New value of property horizontalUnit.
96      */

97     public void setHorizontalUnit(String JavaDoc horizontalUnit) {
98         this.horizontalUnit = horizontalUnit;
99     }
100
101     public String JavaDoc getHorizontalUnit() {
102         return this.horizontalUnit;
103     }
104
105     /**
106      * Setter for property verticalUnit.
107      * @param verticalUnit New value of property verticalUnit.
108      */

109     public void setVerticalUnit(String JavaDoc verticalUnit) {
110         this.verticalUnit = verticalUnit;
111     }
112
113     public String JavaDoc getVerticalUnit() {
114         return this.verticalUnit;
115     }
116
117     /**
118      * Setter for property verticalValue.
119      * @param verticalValue New value of property verticalValue.
120      */

121     public void setVerticalValue(String JavaDoc verticalValue) {
122         this.verticalValue = verticalValue;
123     }
124
125     public String JavaDoc getVerticalValue() {
126         return this.verticalValue;
127     }
128
129     /**
130      * Setter for property horizontalValue.
131      * @param horizontalValue New value of property horizontalValue.
132      */

133     public void setHorizontalValue(String JavaDoc horizontalValue) {
134         this.horizontalValue = horizontalValue;
135     }
136
137     public String JavaDoc getHorizontalValue() {
138         return this.horizontalValue;
139     }
140
141     public String JavaDoc toString(){
142         String JavaDoc bgPosition = "";
143
144         if (!(horizontalValue.equals("") || horizontalValue.startsWith(CssStyleData.NOT_SET))){
145             bgPosition += horizontalValue;
146             if(Utils.isInteger(horizontalValue)){
147                 bgPosition += horizontalUnit;
148             }
149         }
150
151         if (!(verticalValue.equals("") || verticalValue.startsWith(CssStyleData.NOT_SET))){
152             if(bgPosition.equals("")){
153                 bgPosition = "left" + " " + verticalValue; //NOI18N
154
}else{
155                 bgPosition = bgPosition + " " + verticalValue;
156             }
157             if(Utils.isInteger(verticalValue)){
158                 bgPosition += verticalUnit;
159             }
160         }
161         
162         return bgPosition;
163     }
164 }
165
Popular Tags