Java tutorial
/* * Copyright (c) 2011, Paul Merlin. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package org.qipki.clients.web.client.ui.widgets; import com.google.gwt.layout.client.Layout.AnimationCallback; import com.google.gwt.layout.client.Layout.Layer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.IsWidget; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.Widget; public class SidebarPanel extends ScrollPanel { private final MainLayout mainLayout; private boolean active = false; public SidebarPanel(MainLayout mainLayout) { this.mainLayout = mainLayout; } @Override public void setWidget(IsWidget w) { final Widget widget = Widget.asWidgetOrNull(w); if (widget != getWidget()) { setHorizontalScrollPosition(0); setVerticalScrollPosition(0); boolean oldWidget = getWidget() != null; boolean newWidget = widget != null; if (oldWidget && newWidget) { // Replace //Window.alert( "replace" ); setWidget(widget); mainLayout.setSidebarActivated(this, true, false, null); } else if (oldWidget) { // Hide //Window.alert( "hide" ); setWidget(widget); // FIXME This statement should be in the animation complete callback mainLayout.setSidebarActivated(this, false, true, new AnimationCallback() { @Override public void onAnimationComplete() { } @Override public void onLayout(Layer layer, double progress) { } }); } else if (newWidget) { // Show //Window.alert( "show" ); setWidget(widget); mainLayout.setSidebarActivated(this, true, true, null); } else { // Should not happen Window.alert( "SidebarPanel\n\n!oldWidget && !newWidget\nThis should not happen\n\nExpect bad layout behaviour!"); } } } public boolean isActive() { return active; } public void setActive(boolean active) { this.active = active; } }