org.wings.plaf.css.ScrollPaneCG Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2000,2005 wingS development team.
*
* This file is part of wingS (http://wingsframework.org).
*
* wingS is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* Please see COPYING for the complete licence.
*/
package org.wings.plaf.css;
import java.awt.Adjustable;
import java.io.IOException;
import org.wings.*;
import org.wings.style.CSSProperty;
import org.wings.io.Device;
import org.wings.script.JavaScriptDOMListener;
import org.wings.session.ScriptManager;
import org.wings.plaf.css.script.*;
public class ScrollPaneCG extends org.wings.plaf.css.AbstractComponentCG implements org.wings.plaf.ScrollPaneCG {
private static final long serialVersionUID = 1L;
@Override
public void writeInternal(Device device, SComponent component) throws IOException {
SScrollPane scrollpane = (SScrollPane) component;
if (scrollpane.getMode() == SScrollPane.MODE_COMPLETE) {
SDimension preferredSize = scrollpane.getPreferredSize();
if (preferredSize == null) {
scrollpane.setPreferredSize(new SDimension(200, 400));
} else {
if (preferredSize.getWidthInt() < 0) Utils.setPreferredSize(component, "200", preferredSize.getHeight());
if (preferredSize.getHeightInt() < 0) Utils.setPreferredSize(component, preferredSize.getWidth(), "400");;
}
ScriptManager.getInstance().addScriptListener(new LayoutScrollPaneScript(component.getName()));
writeContent(device, component);
} else {
writeContent(device, component);
}
Adjustable sb = scrollpane.getVerticalScrollBar();
SComponent viewport = (SComponent)scrollpane.getScrollable();
if (viewport != null && sb instanceof SScrollBar) {
final JavaScriptDOMListener handleMouseWheel = new JavaScriptDOMListener(
"DOMMouseScroll",
"wingS.scrollbar.handleMouseWheel", '\'' +((SScrollBar)sb).getName()+ '\'', viewport);
viewport.addScriptListener(handleMouseWheel);
}
}
public static void writeContent(Device device, SComponent c) throws IOException {
SScrollPane scrollPane = (SScrollPane) c;
SDimension preferredSize = scrollPane.getPreferredSize();
String height = preferredSize != null ? preferredSize.getHeight() : null;
boolean clientLayout = Utils.isMSIE(scrollPane) && height != null && !"auto".equals(height)
&& scrollPane.getMode() != SScrollPane.MODE_COMPLETE;
boolean clientFix = Utils.isMSIE(scrollPane) && (height == null || "auto".equals(height))
&& scrollPane.getMode() != SScrollPane.MODE_COMPLETE;
device.print("");
Utils.renderContainer(device, scrollPane);
device.print("
");
}
}