KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > css > msie > PrefixAndSuffixDelegate


1 /*
2  * $Id: PrefixAndSuffixDelegate.java,v 1.13 2005/06/03 13:16:16 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf.css.msie;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.wings.*;
19 import org.wings.border.STitledBorder;
20 import org.wings.io.Device;
21 import org.wings.plaf.css.AbstractLayoutCG;
22 import org.wings.plaf.css.InputMapScriptListener;
23 import org.wings.plaf.css.Utils;
24 import org.wings.plaf.css.VersionedInputMap;
25
26 import javax.swing.*;
27 import java.io.IOException JavaDoc;
28
29 /**
30  * @author ole
31  */

32 public class PrefixAndSuffixDelegate implements org.wings.plaf.PrefixAndSuffixDelegate {
33     private final static transient Log log = LogFactory.getLog(PrefixAndSuffixDelegate.class);
34
35     public PrefixAndSuffixDelegate() {
36     }
37
38     public void writePrefix(Device device, SComponent component) throws IOException JavaDoc {
39         SDimension prefSize = component.getPreferredSize();
40         final int align = component.getHorizontalAlignment();
41
42         // For centering or right-alignment we need we surrounding helper table to be stretched to full width.
43
if (prefSize == null && (align == SConstants.CENTER || align == SConstants.RIGHT))
44             prefSize = new SDimension("100%", null);
45
46         StringBuffer JavaDoc inlineStyles = Utils.generateCSSInlinePreferredSize(prefSize);
47
48         Utils.printDebugNewline(device, component);
49         Utils.printDebug(device, "<!-- ").print(component.getName()).print(" -->");
50         device.print("<table id=\"").print(component.getName()).print("\"");
51         Utils.optAttribute(device, "class", "SLayout " + component.getStyle());
52         Utils.optAttribute(device, "style", inlineStyles.toString());
53
54         if (component instanceof LowLevelEventListener) {
55             LowLevelEventListener lowLevelEventListener = (LowLevelEventListener) component;
56             device.print(" eid=\"")
57                     .print(lowLevelEventListener.getEncodedLowLevelEventId()).print("\"");
58         }
59
60         String JavaDoc toolTip = component.getToolTipText();
61         if (toolTip != null)
62             device.print(" onmouseover=\"return makeTrue(domTT_activate(this, event, 'content', '")
63                     .print(toolTip)
64                     .print("', 'predefined', 'default'));\"");
65
66         InputMap inputMap = component.getInputMap();
67         if (inputMap != null && !(inputMap instanceof VersionedInputMap)) {
68             log.debug("inputMap = " + inputMap);
69             inputMap = new VersionedInputMap(inputMap);
70             component.setInputMap(inputMap);
71         }
72
73         if (inputMap != null) {
74             VersionedInputMap versionedInputMap = (VersionedInputMap) inputMap;
75             Integer JavaDoc inputMapVersion = (Integer JavaDoc) component.getClientProperty("inputMapVersion");
76             if (inputMapVersion == null || versionedInputMap.getVersion() != inputMapVersion.intValue()) {
77                 log.debug("inputMapVersion = " + inputMapVersion);
78                 InputMapScriptListener.install(component);
79                 component.putClientProperty("inputMapVersion", new Integer JavaDoc(versionedInputMap.getVersion()));
80             }
81         }
82
83         SPopupMenu menu = component.getComponentPopupMenu();
84         if (menu != null) {
85             //ComponentCG menuCG = menu.getCG();
86
String JavaDoc componentId = menu.getName();
87             String JavaDoc popupId = componentId + "_pop";
88             //String hookId = component.getName();
89
device.print(" onContextMenu=\"javascript:return wpm_menuPopup(event, '");
90             device.print(popupId);
91             device.print("');\" onMouseDown=\"javascript:return wpm_menuPopup(event, '");
92             device.print(popupId);
93             device.print("');\"");
94         }
95
96         device.print("><tr>"); // table
97
AbstractLayoutCG.openLayouterCell(device, false, 0, 0, 0, component);
98         device.print(">");
99
100         // Special handling: Render title of STitledBorder
101
if (component.getBorder() instanceof STitledBorder) {
102             STitledBorder titledBorder = (STitledBorder) component.getBorder();
103             device.print("<div class=\"STitledBorderLegend\" style=\"");
104             titledBorder.getTitleAttributes().write(device);
105             device.print("\">");
106             device.print(titledBorder.getTitle());
107             device.print("</div>");
108         }
109
110         component.fireRenderEvent(SComponent.START_RENDERING);
111     }
112
113     public void writeSuffix(Device device, SComponent component) throws IOException JavaDoc {
114         component.fireRenderEvent(SComponent.DONE_RENDERING);
115         AbstractLayoutCG.closeLayouterCell(device, false);
116         device.print("</tr></table>");
117         Utils.printDebug(device, "<!-- /").print(component.getName()).print(" -->");
118     }
119
120 }
121
Popular Tags