KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > portal > alpharenderer > HtmlMenu


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Sam
27  */

28
29
30 package com.caucho.portal.alpharenderer;
31
32 import com.caucho.util.L10N;
33
34 import java.util.logging.Logger JavaDoc;
35
36
37 public class HtmlMenu
38   extends Menu
39 {
40   private static L10N L = new L10N( HtmlMenu.class );
41
42   static protected final Logger JavaDoc log =
43     Logger.getLogger( HtmlMenu.class.getName() );
44
45
46   private String JavaDoc _cssClass;
47   private boolean _showSeparators = true;
48
49   public HtmlMenu()
50   {
51   }
52
53   public void setCssClass( String JavaDoc cssClass )
54   {
55     _cssClass = cssClass;
56   }
57
58   /**
59    * If true, show menu separators: `[ ' at beginning, ' | ' to separate
60    * items, ' ]' at end, default true
61    */

62   public void setShowSeparators( boolean showSeparators )
63   {
64     _showSeparators = showSeparators;
65   }
66
67   protected void menuStart( StringBuffer JavaDoc buf )
68   {
69     if ( _cssClass != null ) {
70       buf.append( "<div class='" );
71       buf.append( _cssClass );
72       buf.append( "'>" );
73     }
74     else {
75       buf.append( "<div>");
76     }
77   }
78
79   protected void menuItem( StringBuffer JavaDoc buf,
80                            int count,
81                            String JavaDoc name,
82                            String JavaDoc shortDescription,
83                            String JavaDoc url,
84                            boolean isSelected )
85
86   {
87     if ( _showSeparators ) {
88       if ( count == 1 )
89         buf.append("[ ");
90       else
91         buf.append(" | ");
92     }
93
94     if ( isSelected )
95       buf.append("<span class='sel'");
96     else {
97       if ( url == null)
98         buf.append("<span class='nosel'");
99       else
100         buf.append("<span class='unsel'");
101     }
102
103     if ( url == null && shortDescription != null ) {
104       buf.append(" title='");
105       appendEscaped( buf, shortDescription );
106       buf.append("'");
107     }
108
109     buf.append('>');
110
111     if ( url != null ) {
112       buf.append( "<a HREF='" );
113       buf.append( url );
114       buf.append( "'");
115
116       if ( shortDescription != null ) {
117         buf.append(" title='");
118         appendEscaped( buf,shortDescription );
119         buf.append("'");
120       }
121       buf.append( ">");
122     }
123
124     appendEscaped( buf, name );
125
126     if ( url != null )
127       buf.append( "</a>" );
128
129     buf.append( "</span>" );
130   }
131
132   protected void menuEnd( StringBuffer JavaDoc buf, int count )
133   {
134     if ( _showSeparators && count > 0 )
135       buf.append("]");
136
137     buf.append( "</div>");
138   }
139 }
140
Popular Tags