001    package edu.nrao.sss.webapp.faces.component;
002    
003    import javax.faces.component.UIComponentBase;
004    import javax.faces.context.FacesContext;
005    import javax.faces.context.ResponseWriter;
006    import java.io.IOException;
007    
008    public class TabUIComponent extends UIComponentBase
009    {
010            private static String topCSS;
011            private static String leftCSS;
012            
013            static
014            {
015                    topCSS = 
016                            ".spiffy *{" +
017                            "display:block;" +
018                            "height:1px;" +
019                            "overflow:hidden;" +
020                            "background:#0a67e6" +
021                            "}" +
022                            ".spiffy1{" +
023                            "border-right:1px solid #95bdf4;" +
024                            "padding-right:1px;" +
025                            "margin-right:3px;" +
026                            "border-left:1px solid #95bdf4;" +
027                            "padding-left:1px;" +
028                            "margin-left:3px;" +
029                            "background:#478dec;" +
030                            "}" +
031                            ".spiffy2{" +
032                            "border-right:1px solid #e6effc;" +
033                            "padding:00px 1px;" +
034                            "margin:00px 1px;" +
035                            "border-left:1px solid #e6effc;" +
036                            "padding-left: 1px;" +
037                            "margin-left:1px;" +
038                            "background:#3883ea;" +
039                            "}" +
040                            ".spiffy3{" +
041                            "border-right:1px solid #3883ea;" +
042                            "border-left:1px solid #3883ea;" +
043                            "margin:00px 1px;" +
044                            "}" +
045                            ".spiffy4{" +
046                            "border-right:1px solid #95bdf4;" +
047                            "border-left:1px solid #95bdf4;" +
048                            "}" +
049                            ".spiffy5{" +
050                            "border-right:1px solid #478dec;" +
051                            "border-left:1px solid #478dec;" +
052                            "}" +
053                            ".spiffy_content{" +
054                            "padding:00px 5px;" +
055                            "background:#0a67e6;" +
056                            "}";
057                    
058                    
059                    leftCSS = 
060                            ".spiffy *{" +
061                            "display:block;" +
062                            "height:1px;" +
063                            "overflow:hidden;" +
064                            "background:#0a67e6" +
065                            "}" +
066                            ".spiffy1{" +
067                            "border-left:1px solid #95bdf4;" +
068                            "padding-left:1px;" +
069                            "margin-left:3px;" +
070                            "background:#478dec;" +
071                            "}" +
072                            ".spiffy2{" +
073                            "border-left:1px solid #e6effc;" +
074                            "padding-left: 1px;" +
075                            "margin-left:1px;" +
076                            "background:#3883ea;" +
077                            "}" +
078                            ".spiffy3{" +
079                            "border-left:1px solid #3883ea;" +
080                            "margin-left:1px;" +
081                            "}" +
082                            ".spiffy4{" +
083                            "border-left:1px solid #95bdf4;" +
084                            "}" +
085                            ".spiffy5{" +
086                            "border-left:1px solid #478dec;" +
087                            "}" +
088                            ".spiffy_content{" +
089                            "padding-left:5px;" +
090                            "background:#0a67e6;" +
091                            "}";
092            }
093            
094            public void encodeBegin(FacesContext context) throws IOException
095            {
096                    String value = (String)this.getAttributes().get("value");
097                    String orientation = (String)this.getAttributes().get("orientation");
098                    
099                    if (orientation == null)
100                            orientation = "top";
101                    
102                    boolean top = orientation.equalsIgnoreCase("top");
103                    boolean left = orientation.equalsIgnoreCase("left");
104                    
105                    ResponseWriter writer = context.getResponseWriter();
106                    
107                    writer.startElement("div", this);
108                    
109                    writer.startElement("style", this);
110                    writer.writeAttribute("type", "text/css", null);
111                    
112                    //Style is different if it's top versus left
113                    if (top)
114                            writer.write(topCSS);
115                    
116                    else if (left)
117                            writer.write(leftCSS);
118                    
119                    writer.endElement("style");
120                    
121                    //write the wacky blocks that take care of rounding the top corners.
122                    writer.startElement("b", this);
123                    writer.writeAttribute("class", "spiffy", null);
124                    
125                    writer.startElement("b", this);
126                    writer.writeAttribute("class", "spiffy1", null);
127                    
128                            //This is a filler element that is the same color as the background
129                            writer.startElement("b", this);
130                            writer.endElement("b");
131                    writer.endElement("b"); //End spiffy1
132                    
133                    writer.startElement("b", this);
134                    writer.writeAttribute("class", "spiffy2", null);
135                    
136                            //This is a filler element that is the same color as the background
137                            writer.startElement("b", this);
138                            writer.endElement("b");
139                    writer.endElement("b"); //End spiffy2
140                    
141                    
142                    writer.startElement("b", this);
143                    writer.writeAttribute("class", "spiffy3", null);
144                    writer.endElement("b"); //End spiffy3
145                    
146                    writer.startElement("b", this);
147                    writer.writeAttribute("class", "spiffy4", null);
148                    writer.endElement("b"); //End spiffy4
149                    
150                    writer.startElement("b", this);
151                    writer.writeAttribute("class", "spiffy5", null);
152                    writer.endElement("b"); //End spiffy5
153                    
154                    writer.endElement("b"); //End spiffy
155                    
156                    //Write out the actual content here.
157                    writer.startElement("div", this);
158                    writer.writeAttribute("class", "spiffy_content", null);
159                    writer.write(value);
160                    writer.endElement("div");
161                    
162                    //if we're a side tab we need the bottom too.
163                    if (left)
164                    {
165                            writer.startElement("b", this);
166                            writer.writeAttribute("class", "spiffy", null);
167                            
168                            writer.startElement("b", this);
169                            writer.writeAttribute("class", "spiffy5", null);
170                            writer.endElement("b"); //End spiffy5
171                            
172                            writer.startElement("b", this);
173                            writer.writeAttribute("class", "spiffy4", null);
174                            writer.endElement("b"); //End spiffy4
175                            
176                            writer.startElement("b", this);
177                            writer.writeAttribute("class", "spiffy3", null);
178                            writer.endElement("b"); //End spiffy3
179                            
180                            writer.startElement("b", this);
181                            writer.writeAttribute("class", "spiffy2", null);
182                            
183                                    //This is a filler element that is the same color as the background
184                                    writer.startElement("b", this);
185                                    writer.endElement("b");
186                            writer.endElement("b"); //End spiffy2
187                            
188                            writer.startElement("b", this);
189                            writer.writeAttribute("class", "spiffy1", null);
190                            
191                                    //This is a filler element that is the same color as the background
192                                    writer.startElement("b", this);
193                                    writer.endElement("b");
194                            writer.endElement("b"); //End spiffy1
195                            
196                            writer.endElement("b"); //End spiffy
197                    }
198                    writer.endElement("div");
199            }
200            
201            public void encodeChildren(FacesContext context) throws IOException
202            {
203            }
204            
205            public void encodeEnd(FacesContext context) throws IOException
206            {
207            }
208            
209            /**
210              * This method is only important if you're developing your own component
211              * family. If not, you can return whatever.
212              */
213            public String getFamily()
214            {
215                    return "NRAO";
216            }
217    }