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:
014: /**
015: * HTMLIconUI defines a look and feel for default HTML.
016: *
017: * @author Robin Sharp
018: */
019:
020: public class HTMLIconUI extends HTMLComponentUI implements SIconUI {
021:
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: SIcon icon = (SIcon) c;
030:
031: if (icon.getAreaCount() > 0) {
032: out.print("<MAP NAME=\"");
033: out.print(icon.getName());
034: out.println("MAP\" >");
035:
036: for (Enumeration areas = icon.getAreas(); areas
037: .hasMoreElements();) {
038: SArea area = (SArea) areas.nextElement();
039:
040: out.print("<AREA");
041:
042: out.print(" SHAPE=\"");
043: out.print(area.getShape());
044: out.print("\"");
045:
046: if (area.getLink() != null) {
047: out.print(" HREF=\"");
048: if (area.getLink().getUrl() != null) {
049: out.print(area.getLink().getUrl());
050: } else {
051: out.print(icon.getComponentUrl());
052: }
053: out.print("\"");
054:
055: if (area.getLink().getTarget() != null) {
056: if (area.getLink().getTarget().equals(
057: SFrame.NEW))
058: out.print(" target=\"_blank\"");
059: else if (area.getLink().getTarget().equals(
060: SFrame.SELF))
061: out.print(" target=\"_self\"");
062: else if (area.getLink().getTarget().equals(
063: SFrame.PARENT))
064: out.print(" target=\"_parent\"");
065: else if (area.getLink().getTarget().equals(
066: SFrame.TOP))
067: out.print(" target=\"_top\"");
068: else {
069: out.print(" target=\"");
070: out.print(area.getLink().getTarget());
071: out.print("\"");
072: }
073: }
074: }
075:
076: if (area.getText() != null) {
077: out.print(" ALT=\"");
078: out.print(area.getText());
079: out.print("\"");
080: }
081:
082: out.print(" COORDS=\"");
083: if (area.getShape() == SArea.RECTANGLE) {
084: if (area.getRectangle().x >= 0) {
085: out.print(area.getRectangle().x);
086: out.print(",");
087: out.print(area.getRectangle().y);
088: out.print(",");
089: out.print((area.getRectangle().x + area
090: .getRectangle().width));
091: out.print(",");
092: out.print((area.getRectangle().y + area
093: .getRectangle().height));
094: } else {
095: out.print(area.getRectangle().x);
096: out.print("%,");
097: out.print(area.getRectangle().y);
098: out.print("%,");
099: out.print((area.getRectangle().x + area
100: .getRectangle().width));
101: out.print("%,");
102: out.print((area.getRectangle().y + area
103: .getRectangle().height));
104: out.print("%");
105: }
106: } else if (area.getShape() == SArea.CIRCLE) {
107: if (area.getPoint().x >= 0) {
108: out.print(area.getPoint().x);
109: out.print(",");
110: out.print(area.getPoint().y);
111: out.print(",");
112: out.print(area.getRadius());
113: } else {
114: out.print(area.getPoint().x);
115: out.print("%,");
116: out.print(area.getPoint().y);
117: out.print("%,");
118: out.print(area.getRadius());
119: }
120: } else if (area.getShape() == SArea.POLYGON) {
121: for (int index = 0; index < area.getPolygon().npoints; index++) {
122: if (index > 0) {
123: out.print(",");
124: }
125:
126: if (area.getPolygon().xpoints[index] >= 0) {
127: out.print(area.getPolygon().xpoints[index]);
128: out.print(",");
129: out.print(area.getPolygon().ypoints[index]);
130: } else {
131: out.print(area.getPolygon().xpoints[index]);
132: out.print("%,");
133: out.print(area.getPolygon().ypoints[index]);
134: out.print("%");
135: }
136: }
137: }
138:
139: out.println("\" >");
140: }
141: out.println("</MAP>");
142: }
143:
144: if (icon.getLink() != null) {
145: out.print("<A HREF=\"");
146: if (icon.getLink().getUrl() != null) {
147: out.print(icon.getLink().getUrl());
148: } else {
149: out.print(icon.getComponentUrl());
150: }
151: out.print("\"");
152:
153: HTMLUtility.setMouseOverStatusText(out, c.getToolTipText());
154:
155: updateLinkScript(out, c);
156:
157: if (icon.getLink().getTarget() != null) {
158: if (icon.getLink().getTarget().equals(SFrame.NEW))
159: out.print(" target=\"_blank\"");
160: else if (icon.getLink().getTarget().equals(SFrame.SELF))
161: out.print(" target=\"_self\"");
162: else if (icon.getLink().getTarget().equals(
163: SFrame.PARENT))
164: out.print(" target=\"_parent\"");
165: else if (icon.getLink().getTarget().equals(SFrame.TOP))
166: out.print(" target=\"_top\"");
167: else {
168: out.print(" target=\"");
169: out.print(icon.getLink().getTarget());
170: out.print("\"");
171: }
172: }
173:
174: out.print(">");
175: }
176:
177: if (icon.getUrl() != null) {
178: out.print("<IMG NAME=\"");
179: out.print(icon.getName());
180: out.print("\"");
181:
182: HTMLUtility.setSrc(out, icon);
183:
184: if (icon.getBorder() == null) {
185: out.print(" BORDER=0");
186: }
187:
188: //SET THE HEIGHT
189: if (icon.getSize().height > 0) {
190: out.print(" HEIGHT=");
191: out.print(icon.getSize().height);
192: } else if (icon.getSize().height < 0) {
193: out.print(" HEIGHT=");
194: out.print(0 - icon.getSize().height);
195: out.print("%");
196: }
197:
198: //SET THE WIDTH
199: if (icon.getSize().width > 0) {
200: out.print(" WIDTH=");
201: out.print(icon.getSize().width);
202: } else if (icon.getSize().width < 0) {
203: out.print(" WIDTH=");
204: out.print(0 - icon.getSize().width);
205: out.print("%");
206: }
207:
208: if (icon.getAreaCount() > 0) {
209: out.print(" USEMAP=\"#");
210: out.print(icon.getName());
211: out.print("MAP\"");
212: }
213:
214: updateEvent(out, c);
215:
216: out.print(">");
217: }
218:
219: if (icon.getLink() != null)
220: out.print("</A>");
221: }
222:
223: /**
224: * Render the script on the output, in the body part of the web page
225: */
226: public void updateLinkScript(Object out, SComponent c) {
227: updateLinkScript((PrintWriter) out, c);
228: }
229:
230: /**
231: * Render the script on the PrintWriter, in the body part of the web page
232: */
233: public void updateLinkScript(PrintWriter out, SComponent c) {
234: }
235:
236: }
|