001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.portal.alpharenderer;
030:
031: import com.caucho.util.L10N;
032:
033: import java.util.logging.Logger;
034:
035: public class HtmlMenu extends Menu {
036: private static L10N L = new L10N(HtmlMenu.class);
037:
038: static protected final Logger log = Logger.getLogger(HtmlMenu.class
039: .getName());
040:
041: private String _cssClass;
042: private boolean _showSeparators = true;
043:
044: public HtmlMenu() {
045: }
046:
047: public void setCssClass(String cssClass) {
048: _cssClass = cssClass;
049: }
050:
051: /**
052: * If true, show menu separators: `[ ' at beginning, ' | ' to separate
053: * items, ' ]' at end, default true
054: */
055: public void setShowSeparators(boolean showSeparators) {
056: _showSeparators = showSeparators;
057: }
058:
059: protected void menuStart(StringBuffer buf) {
060: if (_cssClass != null) {
061: buf.append("<div class='");
062: buf.append(_cssClass);
063: buf.append("'>");
064: } else {
065: buf.append("<div>");
066: }
067: }
068:
069: protected void menuItem(StringBuffer buf, int count, String name,
070: String shortDescription, String url, boolean isSelected)
071:
072: {
073: if (_showSeparators) {
074: if (count == 1)
075: buf.append("[ ");
076: else
077: buf.append(" | ");
078: }
079:
080: if (isSelected)
081: buf.append("<span class='sel'");
082: else {
083: if (url == null)
084: buf.append("<span class='nosel'");
085: else
086: buf.append("<span class='unsel'");
087: }
088:
089: if (url == null && shortDescription != null) {
090: buf.append(" title='");
091: appendEscaped(buf, shortDescription);
092: buf.append("'");
093: }
094:
095: buf.append('>');
096:
097: if (url != null) {
098: buf.append("<a href='");
099: buf.append(url);
100: buf.append("'");
101:
102: if (shortDescription != null) {
103: buf.append(" title='");
104: appendEscaped(buf, shortDescription);
105: buf.append("'");
106: }
107: buf.append(">");
108: }
109:
110: appendEscaped(buf, name);
111:
112: if (url != null)
113: buf.append("</a>");
114:
115: buf.append("</span>");
116: }
117:
118: protected void menuEnd(StringBuffer buf, int count) {
119: if (_showSeparators && count > 0)
120: buf.append("]");
121:
122: buf.append("</div>");
123: }
124: }
|