001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.plaf.css;
014:
015: import org.wings.plaf.CGManager;
016: import org.wings.plaf.Update;
017: import org.wings.session.SessionManager;
018: import org.wings.SComponent;
019: import org.wings.SLabel;
020: import org.wings.SIcon;
021: import org.wings.io.Device;
022: import java.io.IOException;
023:
024: /**
025: * CG for SLabel instances.
026: *
027: * @author <a href="mailto:B.Schmid@eXXcellent.de">Benjamin Schmid</a>
028: */
029: public class LabelCG extends AbstractLabelCG implements
030: org.wings.plaf.LabelCG {
031:
032: private static final long serialVersionUID = 1L;
033: private boolean wordWrapDefault;
034:
035: public LabelCG() {
036: final CGManager manager = SessionManager.getSession()
037: .getCGManager();
038: final String wordWrapDefaultString = (String) manager
039: .getObject("LabelCG.wordWrapDefault", String.class);
040: setWordWrapDefault(Boolean.valueOf(wordWrapDefaultString)
041: .booleanValue());
042: }
043:
044: public void installCG(SComponent component) {
045: super .installCG(component);
046: ((SLabel) component).setWordWrap(wordWrapDefault);
047: }
048:
049: public void writeInternal(final Device device,
050: final SComponent component) throws IOException {
051: final SLabel label = (SLabel) component;
052: final String text = label.getText();
053: final SIcon icon = label.isEnabled() ? label.getIcon() : label
054: .getDisabledIcon();
055: final int horizontalTextPosition = label
056: .getHorizontalTextPosition();
057: final int verticalTextPosition = label
058: .getVerticalTextPosition();
059: final boolean wordWrap = label.isWordWrap();
060:
061: if (icon == null && text != null) {
062: writeTablePrefix(device, component);
063: writeText(device, text, wordWrap);
064: writeTableSuffix(device, component);
065: } else if (icon != null && text == null) {
066: writeTablePrefix(device, component);
067: writeIcon(device, icon, Utils.isMSIE(component));
068: writeTableSuffix(device, component);
069: } else if (icon != null && text != null) {
070: new IconTextCompound() {
071: protected void text(Device d) throws IOException {
072: writeText(d, text, wordWrap);
073: }
074:
075: protected void icon(Device d) throws IOException {
076: writeIcon(d, icon, Utils.isMSIE(component));
077: }
078:
079: protected void tableAttributes(Device d)
080: throws IOException {
081: Utils.writeAllAttributes(d, label);
082: }
083: }.writeCompound(device, component, horizontalTextPosition,
084: verticalTextPosition, true);
085: } else {
086: //leeres label
087: writeTablePrefix(device, component);
088: writeTableSuffix(device, component);
089: }
090: }
091:
092: /**
093: * Default word wrap behaviour.
094: * @return <code>true</code> if CG should advise all new SLabel
095: * instances to allow word wrapping. Default is <code>false</code>
096: */
097: public boolean isWordWrapDefault() {
098: return wordWrapDefault;
099: }
100:
101: /**
102: * Default word wrap behaviour.
103: * @param wordWrapDefault <code>true</code> if CG should advise all new
104: * SLabel instances to allow word wrapping. Default is <code>false</code>
105: */
106: public void setWordWrapDefault(boolean wordWrapDefault) {
107: this .wordWrapDefault = wordWrapDefault;
108: }
109:
110: public Update getTextUpdate(SLabel label, String text) {
111: return text == null ? null : new TextUpdate(label, text);
112: }
113:
114: public Update getIconUpdate(SLabel label, SIcon icon) {
115: return icon == null ? null : new IconUpdate(label, icon);
116: }
117: }
|