KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BorderData.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 import javax.swing.DefaultComboBoxModel JavaDoc;
30
31 /**
32  * Data Structure for the Border Data
33  * @author Winston Prakash
34  * @version 1.0
35  */

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 JavaDoc boderStr){
53         setBorder(boderStr, 0);
54     }
55
56     public void setBorder(String JavaDoc boderStr, int side){
57         borderSide = side;
58         if(boderStr != null){
59             // Bug fix: boder data parse fails if rgb has space
60
// i.e convert rgb(255, 245, 125) to rgb(255,245,125)
61
boderStr = boderStr.toLowerCase();
62             if(boderStr.indexOf("rgb") >= 0){ //NOI18N
63
String JavaDoc borderColor = boderStr.substring(boderStr.indexOf("rgb")); //NOI18N
64
String JavaDoc borderColorTrimmed = borderColor.replaceAll(" ","");
65                 boderStr = boderStr.substring(0,boderStr.indexOf("rgb")) + " " + borderColorTrimmed; //NOI18N
66
}
67
68             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(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 JavaDoc widthStr){
83         widthValue.setUnit(getUnit(widthStr));
84         widthValue.setValue(widthStr.replaceAll(widthValue.getUnit(),"").trim());
85     }
86
87     private String JavaDoc getUnit(String JavaDoc positionStr){
88         DefaultComboBoxModel JavaDoc unitList = new BorderModel().getWidthUnitList();
89         for(int i=0; i< unitList.getSize(); i++){
90             String JavaDoc unit = (String JavaDoc)unitList.getElementAt(i);
91             if(positionStr.trim().endsWith(unit)){
92                 return unit;
93             }
94         }
95         return "";
96     }
97
98     public void setStyle(String JavaDoc style){
99         styleValue.setValue(style);
100     }
101
102     public void setColor(String JavaDoc color){
103         if(color.toLowerCase().trim().startsWith("rgb")){ //NOI18N
104
color = color.replaceAll(" ","");
105         }
106         colorValue.setValue(color);
107     }
108
109     public void setWidthValue(String JavaDoc width){
110         widthValue.setValue(width);
111     }
112
113     public void setWidthUnit(String JavaDoc widthUnit){
114         widthValue.setUnit(widthUnit);
115     }
116
117     public String JavaDoc getStyle(){
118         return styleValue.getValue();
119     }
120
121     public String JavaDoc getColor(){
122         return colorValue.getValue();
123     }
124
125     public String JavaDoc getWidthValue(){
126         return widthValue.getValue();
127     }
128
129     public String JavaDoc getWidthUnit(){
130         return widthValue.getUnit();
131     }
132
133     public String JavaDoc toString(){
134         String JavaDoc 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