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 BorderData extends PropertyData{ 37 38 PropertyData styleValue = new PropertyData(); 39 PropertyData colorValue = new PropertyData(); 40 PropertyWithUnitData widthValue = new PropertyWithUnitData(); 41 42 ColorModel colorModel = new ColorModel(); 43 44 public static final int ALL = 0; 45 public static final int LEFT = 1; 46 public static final int RIGHT = 2; 47 public static final int TOP = 3; 48 public static final int BOTTOM = 4; 49 50 private int borderSide = ALL; 51 52 public void setBorder(String boderStr){ 53 setBorder(boderStr, 0); 54 } 55 56 public void setBorder(String boderStr, int side){ 57 borderSide = side; 58 if(boderStr != null){ 59 boderStr = boderStr.toLowerCase(); 62 if(boderStr.indexOf("rgb") >= 0){ String borderColor = boderStr.substring(boderStr.indexOf("rgb")); String borderColorTrimmed = borderColor.replaceAll(" ",""); 65 boderStr = boderStr.substring(0,boderStr.indexOf("rgb")) + " " + borderColorTrimmed; } 67 68 StringTokenizer st = new StringTokenizer (boderStr); 69 70 if(st.hasMoreTokens()){ 71 setWidth(st.nextToken()); 72 } 73 if(st.hasMoreTokens()){ 74 setStyle(st.nextToken()); 75 } 76 if(st.hasMoreTokens()){ 77 setColor(st.nextToken()); 78 } 79 } 80 } 81 82 public void setWidth(String widthStr){ 83 widthValue.setUnit(getUnit(widthStr)); 84 widthValue.setValue(widthStr.replaceAll(widthValue.getUnit(),"").trim()); 85 } 86 87 private String getUnit(String positionStr){ 88 DefaultComboBoxModel unitList = new BorderModel().getWidthUnitList(); 89 for(int i=0; i< unitList.getSize(); i++){ 90 String unit = (String )unitList.getElementAt(i); 91 if(positionStr.trim().endsWith(unit)){ 92 return unit; 93 } 94 } 95 return ""; 96 } 97 98 public void setStyle(String style){ 99 styleValue.setValue(style); 100 } 101 102 public void setColor(String color){ 103 if(color.toLowerCase().trim().startsWith("rgb")){ color = color.replaceAll(" ",""); 105 } 106 colorValue.setValue(color); 107 } 108 109 public void setWidthValue(String width){ 110 widthValue.setValue(width); 111 } 112 113 public void setWidthUnit(String widthUnit){ 114 widthValue.setUnit(widthUnit); 115 } 116 117 public String getStyle(){ 118 return styleValue.getValue(); 119 } 120 121 public String getColor(){ 122 return colorValue.getValue(); 123 } 124 125 public String getWidthValue(){ 126 return widthValue.getValue(); 127 } 128 129 public String getWidthUnit(){ 130 return widthValue.getUnit(); 131 } 132 133 public String toString(){ 134 String borderString = ""; 135 if (!widthValue.toString().equals("")){ 136 borderString += " " + widthValue.toString(); 137 } 138 if (!styleValue.toString().equals("")){ 139 borderString += " " + styleValue.toString(); 140 } 141 if (!colorValue.toString().equals("")){ 142 borderString += " " + colorValue.toString(); 143 } 144 return borderString.trim(); 145 } 146 147 } 148 | Popular Tags |