package com.zaranux.os.client.ui;
import com.google.gwt.user.client.Timer;
import com.smartgwt.client.widgets.HeaderControl;
import com.smartgwt.client.widgets.Window;
import com.google.gwt.user.client.ui.Widget;
import com.zaranux.client.api.AsyncCallback;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.events.CloseClickHandler;
import com.smartgwt.client.widgets.events.CloseClientEvent;
import com.smartgwt.client.widgets.events.MaximizeClickEvent;
import com.smartgwt.client.widgets.events.MaximizeClickHandler;
import com.allen_sauer.gwt.log.client.Log;
import com.smartgwt.client.widgets.events.ResizedHandler;
import com.smartgwt.client.widgets.events.ResizedEvent;
public class ZWindow extends Window{
private Timer timer;
//private ScrollPanel panel = new ScrollPanel();
private Widget widget;
//private int viewNumber;
private View view;
private AsyncCallback<Boolean> callback;
public ZWindow(final Widget widget, int width, int height, final AsyncCallback<Boolean> callback)
{
this.setTitle("");
this.callback = callback;
setWindowPreperties(width,height);
setWidget(widget);
//setHeaderIcons();
addHandlers();
}
private void setWindowPreperties(int width, int height) {
setOverflow(Overflow.HIDDEN);
setShowCustomScrollbars(false); // does not work!
setCanFocus(true);
setCanDragReposition(true);
setCanDragResize(true);
setResizeFrom("L","R","T","B");
setShowFooter(true);
setWidth(width);
setHeight(height);
setAutoSize(false);
setMaximized(false);
setAnimateMinimize(true);
setShowMaximizeButton(true);
}
private void setWidget(Widget widget) {
widget.setSize("100%", "100%");
if(! (widget instanceof Canvas)){
this.widget = widget;
alignWidget();
ZWindow.this.timer = new Timer() {
public void run() {
alignWidget();
}
};
addResizedHandler(new ResizedHandler()
{
public void onResized(ResizedEvent event)
{
alignWidget();
timer.schedule(1000);
}
});
}else{
this.widget = widget;
}
addItem(this.widget);
}
private void addHandlers() {
addCloseClickHandler(new CloseClickHandler(){
public void onCloseClick(CloseClientEvent event) {
close();
}
});
}
/*////this method is done with a just simple code:etShowMaximizeButton(true);
*
private void setHeaderIcons() {
HeaderControl maximize = new HeaderControl(HeaderControl.MAXIMIZE, new ClickHandler(){
public void onClick(ClickEvent event) {
if(!getMaximized()){
maximize();
setMaximized(true);
}
else{
restore();
setMaximized(false);
}
}
});
HeaderControl close = new HeaderControl(HeaderControl.CLOSE, new ClickHandler(){
public void onClick(ClickEvent event) {
close();
}
});
HeaderControl minimize = new HeaderControl(HeaderControl.MINIMIZE, new ClickHandler(){
public void onClick(ClickEvent event) {
if(!getMinimized()){
minimize();
setMinimized(true);
}else{
restore();
setMinimized(false);
}
}
});
setHeaderControls(HeaderControls.HEADER_LABEL, maximize,minimize,close);
}
*/
public void close()
{
callback.onSuccess(true);
}
public void terminate()
{
destroy();
}
private void alignWidget()
{
widget.setSize("100%", "100%");
}
public void setView(View view)
{
this.view = view;
}
public int getViewNumber()
{
return view.getViewNumber();
}
}