001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.plaf.html;
006:
007: import java.awt.*;
008: import java.util.*;
009: import java.io.*;
010:
011: import com.javelin.swinglets.*;
012: import com.javelin.swinglets.plaf.*;
013: import com.javelin.swinglets.theme.*;
014:
015: /**
016: * HTMLMenuItemUI defines a look and feel for default HTML.
017: *
018: * @author Robin Sharp
019: */
020:
021: public class HTMLMenuItemUI extends HTMLComponentUI {
022: /**
023: * Render the UI on the PrintWriter
024: */
025: public void update(PrintWriter out, SComponent c) {
026: if (!c.isVisible())
027: return;
028:
029: SMenuItem menuItem = (SMenuItem) c;
030:
031: STheme theme = getTheme();
032:
033: SMenu menu = menuItem.getParentMenu();
034: SMenuBar menuBar = menuItem.getMenuBar();
035:
036: SColor menuBackground = menuItem.getBackground();
037: if (menuBackground == null && menu != null)
038: menuBackground = menu.getBackground();
039: if (menuBackground == null && menuBar != null)
040: menuBackground = menuBar.getBackground();
041: if (menuBackground == null)
042: menuBackground = theme.getMenuBackground();
043:
044: SColor menuForeground = menuItem.getForeground();
045: if (menuForeground == null && menu != null)
046: menuForeground = menu.getForeground();
047: if (menuForeground == null && menuBar != null)
048: menuForeground = menuBar.getForeground();
049: if (menuForeground == null)
050: menuForeground = theme.getMenuForeground();
051:
052: SFont menuFont = menuItem.getFont();
053: if (menuFont == null && menu != null)
054: menuFont = menu.getFont();
055: if (menuFont == null && menuBar != null)
056: menuFont = menuBar.getFont();
057: if (menuFont == null)
058: menuFont = theme.getMenuTextFont();
059:
060: out.print("<TD");
061:
062: //Background
063: if (!menuItem.isOpaque()) {
064: } else if (menuBackground != null) {
065: out.print(" BGCOLOR=\"#");
066: out.print(SColor.toHexString(menuBackground));
067: out.print("\"");
068: }
069:
070: out.print(" NOWRAP>");
071:
072: //LINK - if enabled
073: if (menuItem.isEnabled()) {
074: if (menuItem.getLink() != null
075: && menuItem.getLink().getUrl() != null) {
076: out.print("<A HREF=\"");
077: out.print(menuItem.getLink().getUrl());
078: out.print("\"");
079:
080: if (menuItem.getLink().getTarget() != null) {
081: out.print(" target=\"");
082: out.print(menuItem.getLink().getTarget());
083: out.print("\"");
084: }
085:
086: out.print(" >");
087: } else {
088: out.print("<A HREF=\"");
089:
090: out.print(menuItem.getComponentUrl());
091:
092: out.print("&");
093: out.print(menuItem.getIndex());
094: out.print("=");
095: out.print(menuItem.getName());
096: out.print("\"");
097:
098: if (menuItem.getLink() != null
099: && menuItem.getLink().getTarget() != null) {
100: out.print(" target=\"");
101: out.print(menuItem.getLink().getTarget());
102: out.print("\"");
103: }
104:
105: out.print(" >");
106: }
107: }
108:
109: //ICON
110: if (menuItem.getIcon() != null) {
111: menuItem.getIcon().paint(out);
112: }
113:
114: HTMLUtility.updateText(out, menuItem.getText(), menuFont,
115: menuForeground, menuItem.getHorizontalAlignment());
116:
117: if (menuItem.isEnabled()) {
118: out.print("</A>");
119: }
120:
121: out.println("</TD>");
122: }
123: }
|