001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * ClipData.java
044: *
045: * Created on October 22, 2004, 2:32 PM
046: */
047:
048: package org.netbeans.modules.css.visual.model;
049:
050: import java.util.StringTokenizer;
051:
052: /**
053: * Data Structure for the Clip data
054: * @author Winston Prakash
055: * @version 1.0
056: */
057: public class ClipData extends PropertyData {
058:
059: PropertyWithUnitData topValue = new PropertyWithUnitData();
060: PropertyWithUnitData bottomValue = new PropertyWithUnitData();
061: PropertyWithUnitData leftValue = new PropertyWithUnitData();
062: PropertyWithUnitData rightValue = new PropertyWithUnitData();
063:
064: public void setClip(String clip) {
065: topValue.clear();
066: bottomValue.clear();
067: leftValue.clear();
068: rightValue.clear();
069: if (clip != null) {
070: int start = clip.indexOf("(");
071: int stop = clip.indexOf(")");
072: if ((start != -1) && (stop != -1)) {
073: String clipString = clip.substring(start + 1, stop);
074: StringTokenizer st = new StringTokenizer(clipString,
075: ",");
076:
077: if (st.hasMoreTokens()) {
078: setTop(st.nextToken());
079: }
080: if (st.hasMoreTokens()) {
081: setRight(st.nextToken());
082: }
083: if (st.hasMoreTokens()) {
084: setBottom(st.nextToken());
085: }
086: if (st.hasMoreTokens()) {
087: setLeft(st.nextToken());
088: }
089: }
090: }
091: }
092:
093: public void setTop(String clipTopStr) {
094: topValue.setData(clipTopStr);
095: }
096:
097: public void setBottom(String clipBottomStr) {
098: bottomValue.setData(clipBottomStr);
099: }
100:
101: public void setLeft(String clipLeftStr) {
102: leftValue.setData(clipLeftStr);
103: }
104:
105: public void setRight(String clipRightStr) {
106: rightValue.setData(clipRightStr);
107: }
108:
109: public void setTopValue(String top) {
110: topValue.setValue(top);
111: }
112:
113: public void setTopUnit(String topUnit) {
114: topValue.setUnit(topUnit);
115: }
116:
117: public void setBottomValue(String bottom) {
118: bottomValue.setValue(bottom);
119: }
120:
121: public void setBottomUnit(String bottomUnit) {
122: bottomValue.setUnit(bottomUnit);
123: }
124:
125: public void setLeftValue(String left) {
126: leftValue.setValue(left);
127: }
128:
129: public void setLeftUnit(String leftUnit) {
130: leftValue.setUnit(leftUnit);
131: }
132:
133: public void setRightValue(String right) {
134: rightValue.setValue(right);
135: }
136:
137: public void setRightUnit(String rightUnit) {
138: rightValue.setUnit(rightUnit);
139: }
140:
141: public String getTopValue() {
142: return topValue.getValue();
143: }
144:
145: public String getTopUnit() {
146: return topValue.getUnit();
147: }
148:
149: public String getBottomValue() {
150: return bottomValue.getValue();
151: }
152:
153: public String getBottomUnit() {
154: return bottomValue.getUnit();
155: }
156:
157: public String getLeftValue() {
158: return leftValue.getValue();
159: }
160:
161: public String getLeftUnit() {
162: return leftValue.getUnit();
163: }
164:
165: public String getRightValue() {
166: return rightValue.getValue();
167: }
168:
169: public String getRightUnit() {
170: return rightValue.getUnit();
171: }
172:
173: public boolean isTopValueInteger() {
174: return topValue.isValueInteger();
175: }
176:
177: public boolean isBottomValueInteger() {
178: return bottomValue.isValueInteger();
179: }
180:
181: public boolean isLeftValueInteger() {
182: return leftValue.isValueInteger();
183: }
184:
185: public boolean isRightValueInteger() {
186: return rightValue.isValueInteger();
187: }
188:
189: public String toString() {
190: if (!topValue.hasValue() && !rightValue.hasValue()
191: && !bottomValue.hasValue() && !leftValue.hasValue()) {
192: return "";
193: }
194: String clipString = "";
195: if (topValue.hasValue()) {
196: clipString += " " + topValue.toString();
197: } else {
198: clipString += " 0px"; //NOI18N
199: }
200: if (rightValue.hasValue()) {
201: clipString += ", " + rightValue.toString();
202: } else {
203: clipString += ", 0px"; //NOI18N
204: }
205: if (bottomValue.hasValue()) {
206: clipString += ", " + bottomValue.toString();
207: } else {
208: clipString += ", 0px"; //NOI18N
209: }
210:
211: if (leftValue.hasValue()) {
212: clipString += ", " + leftValue.toString();
213: } else {
214: clipString += ", 0px"; //NOI18N
215: }
216: clipString = "rect(" + clipString.trim() + ")"; //NOI18N
217: return clipString.trim();
218: }
219:
220: }
|