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: package org.netbeans.modules.visualweb.propertyeditors.css.model;
042:
043: import java.util.StringTokenizer;
044: import javax.swing.DefaultComboBoxModel;
045:
046: /**
047: *
048: * @author Winston Prakash
049: */
050: public class BackgroundPositionData {
051:
052: /**
053: * Holds value of property horizontalUnit.
054: */
055: private String horizontalUnit = "px"; //NOI18N
056:
057: /**
058: * Holds value of property verticalUnit.
059: */
060: private String verticalUnit = "px"; //NOI18N
061:
062: /**
063: * Holds value of property verticalValue.
064: */
065: private String verticalValue = ""; //NOI18N
066:
067: /**
068: * Holds value of property horizontalValue.
069: */
070: private String horizontalValue = ""; //NOI18N
071:
072: /** Creates a new instance of BackgroundPositionData */
073: public BackgroundPositionData() {
074: }
075:
076: public void setBackgroundPosition(String bgPositionStr) {
077: StringTokenizer st = new StringTokenizer(bgPositionStr);
078: if (bgPositionStr.indexOf(",") != -1) {
079: st = new StringTokenizer(bgPositionStr, ",");
080: } else {
081: st = new StringTokenizer(bgPositionStr);
082: }
083: // Horizontal Postion
084: if (st.hasMoreTokens()) {
085: String token = st.nextToken();
086: horizontalUnit = getUnit(token);
087: horizontalValue = token.replaceAll(horizontalUnit, "");
088: }
089: if (st.hasMoreTokens()) {
090: String token = st.nextToken();
091: verticalUnit = getUnit(token);
092: verticalValue = token.replaceAll(verticalUnit, "");
093: }
094: }
095:
096: private String getUnit(String postionStr) {
097: DefaultComboBoxModel unitList = new BackgroundModel()
098: .getBackgroundPositionUnitList();
099: for (int i = 0; i < unitList.getSize(); i++) {
100: String unit = (String) unitList.getElementAt(i);
101: if (postionStr.endsWith(unit)) {
102: return unit;
103: }
104: }
105: return "";
106: }
107:
108: /**
109: * Setter for property horizontalUnit.
110: * @param horizontalUnit New value of property horizontalUnit.
111: */
112: public void setHorizontalUnit(String horizontalUnit) {
113: this .horizontalUnit = horizontalUnit;
114: }
115:
116: public String getHorizontalUnit() {
117: return this .horizontalUnit;
118: }
119:
120: /**
121: * Setter for property verticalUnit.
122: * @param verticalUnit New value of property verticalUnit.
123: */
124: public void setVerticalUnit(String verticalUnit) {
125: this .verticalUnit = verticalUnit;
126: }
127:
128: public String getVerticalUnit() {
129: return this .verticalUnit;
130: }
131:
132: /**
133: * Setter for property verticalValue.
134: * @param verticalValue New value of property verticalValue.
135: */
136: public void setVerticalValue(String verticalValue) {
137: this .verticalValue = verticalValue;
138: }
139:
140: public String getVerticalValue() {
141: return this .verticalValue;
142: }
143:
144: /**
145: * Setter for property horizontalValue.
146: * @param horizontalValue New value of property horizontalValue.
147: */
148: public void setHorizontalValue(String horizontalValue) {
149: this .horizontalValue = horizontalValue;
150: }
151:
152: public String getHorizontalValue() {
153: return this .horizontalValue;
154: }
155:
156: public String toString() {
157: String bgPosition = "";
158: if (!(horizontalValue.equals("") || horizontalValue
159: .startsWith(CssStyleData.NOT_SET))) {
160: bgPosition += horizontalValue;
161: if (Utils.isInteger(horizontalValue)) {
162: bgPosition += horizontalUnit;
163: }
164: }
165:
166: if (!(verticalValue.equals("") || verticalValue
167: .startsWith(CssStyleData.NOT_SET))) {
168: bgPosition = bgPosition + " " + verticalValue;
169: if (Utils.isInteger(verticalValue)) {
170: bgPosition += verticalUnit;
171: }
172: }
173:
174: return bgPosition;
175: }
176: }
|