1 19 20 25 26 package org.netbeans.modules.css.visual.model; 27 28 import java.util.StringTokenizer ; 29 import javax.swing.DefaultComboBoxModel ; 30 31 36 public class BackgroundPositionData { 37 38 41 private String horizontalUnit = "px"; 43 46 private String verticalUnit = "px"; 48 51 private String verticalValue = ""; 53 56 private String horizontalValue = "left"; 58 59 public BackgroundPositionData() { 60 } 61 62 public void setBackgroundPosition(String bgPositionStr){ 63 StringTokenizer st = new StringTokenizer (bgPositionStr); 64 if(bgPositionStr.indexOf(",") != -1){ 65 st = new StringTokenizer (bgPositionStr, ","); 66 }else{ 67 st = new StringTokenizer (bgPositionStr); 68 } 69 if(st.hasMoreTokens()){ 71 String token = st.nextToken(); 72 horizontalUnit = getUnit(token); 73 horizontalValue = token.replaceAll(horizontalUnit,""); 74 } 75 if(st.hasMoreTokens()){ 76 String token = st.nextToken(); 77 verticalUnit = getUnit(token); 78 verticalValue = token.replaceAll(verticalUnit,""); 79 } 80 } 81 82 private String getUnit(String postionStr){ 83 DefaultComboBoxModel unitList = new BackgroundModel().getBackgroundPositionUnitList(); 84 for(int i=0; i< unitList.getSize(); i++){ 85 String unit = (String )unitList.getElementAt(i); 86 if(postionStr.endsWith(unit)){ 87 return unit; 88 } 89 } 90 return ""; 91 } 92 93 97 public void setHorizontalUnit(String horizontalUnit) { 98 this.horizontalUnit = horizontalUnit; 99 } 100 101 public String getHorizontalUnit() { 102 return this.horizontalUnit; 103 } 104 105 109 public void setVerticalUnit(String verticalUnit) { 110 this.verticalUnit = verticalUnit; 111 } 112 113 public String getVerticalUnit() { 114 return this.verticalUnit; 115 } 116 117 121 public void setVerticalValue(String verticalValue) { 122 this.verticalValue = verticalValue; 123 } 124 125 public String getVerticalValue() { 126 return this.verticalValue; 127 } 128 129 133 public void setHorizontalValue(String horizontalValue) { 134 this.horizontalValue = horizontalValue; 135 } 136 137 public String getHorizontalValue() { 138 return this.horizontalValue; 139 } 140 141 public String toString(){ 142 String 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; }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 |