KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: PrefixAndSuffixDelegate.java,v 1.8 2005/05/26 13:18:10 neurolabs 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  */
package org.wings.plaf.css;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17 import org.wings.LowLevelEventListener;
18 import org.wings.SComponent;
19 import org.wings.SConstants;
20 import org.wings.SDimension;
21 import org.wings.SPopupMenu;
22 import org.wings.border.STitledBorder;
23 import org.wings.io.Device;
24 import org.wings.plaf.ComponentCG;
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     public void writePrefix(Device device, SComponent component) throws IOException JavaDoc {
38         SDimension prefSize = component.getPreferredSize();
39         Utils.printDebugNewline(device, component);
40         Utils.printDebug(device, "<!-- ").print(component.getName()).print(" -->");
41         device.print("<div");
42         if (component.getStyle() != null && component.getStyle().length() > 0) {
43             device.print(" class=\"");
44             device.print(component.getStyle());
45             device.print("_Box\"");
46         }
47
48         // if sizes are spec'd in percentages, we need the outer box to have full size...
49
boolean isHeightPercentage = prefSize != null && prefSize.height != null && prefSize.height.indexOf("%") != -1;
50         boolean isWidthPercentage = prefSize != null && prefSize.width != null && prefSize.width.indexOf("%") != -1;
51         // special case of special case: if the component with relative size is vertically aligned, we must avoid 100% heigth
52
boolean isVAligned = (component.getVerticalAlignment() == SConstants.CENTER || component.getVerticalAlignment() == SConstants.BOTTOM );
53
54         if ( isHeightPercentage || isWidthPercentage ) {
55             device.print(" style=\"");
56             if (isHeightPercentage && isVAligned == false) {
57                 device.print("height:100%;");
58             }
59             if (isWidthPercentage) {
60                 device.print("width:100%;");
61             }
62             device.print("\"");
63         }
64         
65         device.print(">");
66         device.print("<div id=\"").print(component.getName()).print("\"");
67         Utils.optAttribute(device, "class", component.getStyle());
68         Utils.printCSSInlinePreferredSize(device, prefSize);
69
70         if (component instanceof LowLevelEventListener) {
71             LowLevelEventListener lowLevelEventListener = (LowLevelEventListener) component;
72             device.print(" eid=\"")
73                     .print(lowLevelEventListener.getEncodedLowLevelEventId()).print("\"");
74         }
75
76         String JavaDoc toolTip = component.getToolTipText();
77         if (toolTip != null)
78             device.print(" onmouseover=\"return makeTrue(domTT_activate(this, event, 'content', '")
79                     .print(toolTip)
80                     .print("', 'predefined', 'default'));\"");
81
82         InputMap inputMap = component.getInputMap();
83         if (inputMap != null && !(inputMap instanceof VersionedInputMap)) {
84             log.debug("inputMap = " + inputMap);
85             inputMap = new VersionedInputMap(inputMap);
86             component.setInputMap(inputMap);
87         }
88
89         if (inputMap != null) {
90             VersionedInputMap versionedInputMap = (VersionedInputMap) inputMap;
91             Integer JavaDoc inputMapVersion = (Integer JavaDoc) component.getClientProperty("inputMapVersion");
92             if (inputMapVersion == null || versionedInputMap.getVersion() != inputMapVersion.intValue()) {
93                 log.debug("inputMapVersion = " + inputMapVersion);
94                 InputMapScriptListener.install(component);
95                 component.putClientProperty("inputMapVersion", new Integer JavaDoc(versionedInputMap.getVersion()));
96             }
97         }
98
99         SPopupMenu menu = component.getComponentPopupMenu();
100         if (menu != null) {
101             ComponentCG menuCG = menu.getCG();
102             String JavaDoc componentId = menu.getName();
103             String JavaDoc popupId = componentId + "_pop";
104             device.print(" onContextMenu=\"javascript:return wpm_menuPopup(event, '");
105             device.print(popupId);
106             device.print("');\" onMouseDown=\"javascript:return wpm_menuPopup(event, '");
107             device.print(popupId);
108             device.print("');\"");
109         }
110
111         device.print(">"); // div
112

113         // Special handling: Render title of STitledBorder
114
if (component.getBorder() instanceof STitledBorder) {
115             STitledBorder titledBorder = (STitledBorder) component.getBorder();
116             device.print("<div class=\"STitledBorderLegend\" style=\"");
117             titledBorder.getTitleAttributes().write(device);
118             device.print("\">");
119             device.print(titledBorder.getTitle());
120             device.print("</div>");
121         }
122
123         component.fireRenderEvent(SComponent.START_RENDERING);
124     }
125
126     public void writeSuffix(Device device, SComponent component) throws IOException JavaDoc {
127         component.fireRenderEvent(SComponent.DONE_RENDERING);
128         device.print("</div></div>");
129         Utils.printDebug(device, "<!-- /").print(component.getName()).print(" -->");
130     }
131
132 }
133
Popular Tags