KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ClipData.java
22  *
23  * Created on October 22, 2004, 2:32 PM
24  */

25
26 package org.netbeans.modules.css.visual.model;
27
28 import java.util.StringTokenizer JavaDoc;
29
30 /**
31  * Data Structure for the Clip data
32  * @author Winston Prakash
33  * @version 1.0
34  */

35 public class ClipData extends PropertyData{
36
37     PropertyWithUnitData topValue = new PropertyWithUnitData();
38     PropertyWithUnitData bottomValue = new PropertyWithUnitData();
39     PropertyWithUnitData leftValue = new PropertyWithUnitData();
40     PropertyWithUnitData rightValue = new PropertyWithUnitData();
41
42     public void setClip(String JavaDoc clip){
43         topValue.clear();
44         bottomValue.clear();
45         leftValue.clear();
46         rightValue.clear();
47         if(clip != null){
48             int start = clip.indexOf("(");
49             int stop = clip.indexOf(")");
50             if((start != -1) && (stop != -1)){
51                 String JavaDoc clipString = clip.substring(start + 1, stop);
52                 StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(clipString,",");
53
54                 if(st.hasMoreTokens()){
55                     setTop(st.nextToken());
56                 }
57                 if(st.hasMoreTokens()){
58                     setRight(st.nextToken());
59                 }
60                 if(st.hasMoreTokens()){
61                     setBottom(st.nextToken());
62                 }
63                 if(st.hasMoreTokens()){
64                     setLeft(st.nextToken());
65                 }
66             }
67         }
68     }
69
70     public void setTop(String JavaDoc clipTopStr){
71         topValue.setData(clipTopStr);
72     }
73
74     public void setBottom(String JavaDoc clipBottomStr){
75         bottomValue.setData(clipBottomStr);
76     }
77
78     public void setLeft(String JavaDoc clipLeftStr){
79         leftValue.setData(clipLeftStr);
80     }
81
82     public void setRight(String JavaDoc clipRightStr){
83         rightValue.setData(clipRightStr);
84     }
85
86     public void setTopValue(String JavaDoc top){
87         topValue.setValue(top);
88     }
89
90     public void setTopUnit(String JavaDoc topUnit){
91         topValue.setUnit(topUnit);
92     }
93
94     public void setBottomValue(String JavaDoc bottom){
95         bottomValue.setValue(bottom);
96     }
97
98     public void setBottomUnit(String JavaDoc bottomUnit){
99         bottomValue.setUnit(bottomUnit);
100     }
101
102     public void setLeftValue(String JavaDoc left){
103         leftValue.setValue(left);
104     }
105
106     public void setLeftUnit(String JavaDoc leftUnit){
107         leftValue.setUnit(leftUnit);
108     }
109
110     public void setRightValue(String JavaDoc right){
111         rightValue.setValue(right);
112     }
113
114     public void setRightUnit(String JavaDoc rightUnit){
115         rightValue.setUnit(rightUnit);
116     }
117
118     public String JavaDoc getTopValue(){
119         return topValue.getValue();
120     }
121
122     public String JavaDoc getTopUnit(){
123         return topValue.getUnit();
124     }
125
126     public String JavaDoc getBottomValue(){
127         return bottomValue.getValue();
128     }
129
130     public String JavaDoc getBottomUnit(){
131         return bottomValue.getUnit();
132     }
133
134     public String JavaDoc getLeftValue(){
135         return leftValue.getValue();
136     }
137
138     public String JavaDoc getLeftUnit(){
139         return leftValue.getUnit();
140     }
141
142     public String JavaDoc getRightValue(){
143         return rightValue.getValue();
144     }
145
146     public String JavaDoc getRightUnit(){
147         return rightValue.getUnit();
148     }
149
150     public boolean isTopValueInteger(){
151         return topValue.isValueInteger();
152     }
153
154     public boolean isBottomValueInteger(){
155         return bottomValue.isValueInteger();
156     }
157
158     public boolean isLeftValueInteger(){
159         return leftValue.isValueInteger();
160     }
161
162     public boolean isRightValueInteger(){
163         return rightValue.isValueInteger();
164     }
165
166     public String JavaDoc toString(){
167         if(!topValue.hasValue() && !rightValue.hasValue() && !bottomValue.hasValue() && !leftValue.hasValue()){
168             return "";
169         }
170         String JavaDoc clipString = "";
171         if (topValue.hasValue()){
172             clipString += " " + topValue.toString();
173         }else{
174             clipString += " 0px"; //NOI18N
175
}
176         if (rightValue.hasValue()){
177             clipString += ", " + rightValue.toString();
178         }else{
179             clipString += ", 0px"; //NOI18N
180
}
181         if (bottomValue.hasValue()){
182             clipString += ", " + bottomValue.toString();
183         }else{
184             clipString += ", 0px"; //NOI18N
185
}
186         
187         if (leftValue.hasValue()){
188             clipString += ", " + leftValue.toString();
189         }else{
190             clipString += ", 0px"; //NOI18N
191
}
192         clipString = "rect(" + clipString.trim() + ")"; //NOI18N
193
return clipString.trim();
194     }
195     
196     
197 }
198
Popular Tags