package com.digitbit.effects.client; import org.gwtwidgets.client.wrap.Effect; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.ClickListener; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.MouseListener; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; /* * Copyright 2007 Chris Fong * * 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. */ public class EffectPanel extends Composite { private Image panelImage; private Label panelLabel; private String effectOptionsDescription; private FlowPanel flowPanel; public EffectPanel(String imageName, String labelText) { // We put everything in a flow panel because slideDown() and // slideUp() only works inside of it. flowPanel = new FlowPanel(); flowPanel.addStyleName("effectPanel"); VerticalPanel vertPanel = new VerticalPanel(); // vertPanel.addStyleName("effectPanel"); initWidget(flowPanel); vertPanel.setSpacing(5); vertPanel.setWidth("100px"); vertPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); panelImage = new Image() { public String toString() { return effectOptionsDescription; } }; panelImage.setUrl("images/"+imageName); panelLabel = new Label(labelText) { public String toString() { return effectOptionsDescription; } }; panelLabel.addStyleName("panelLabel"); vertPanel.add(panelImage); vertPanel.add(panelLabel); flowPanel.add(vertPanel); } public void addMouseListener(MouseListener listener) { panelImage.addMouseListener(listener); panelLabel.addMouseListener(listener); } public EffectPanel fade() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.fade(flowPanel); reappear(2000); } } effectOptionsDescription = "fade options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel blindDown() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.blindDown(flowPanel); } } effectOptionsDescription = "blindDown options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel blindUp() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.blindUp(flowPanel); reappear(2000); } } effectOptionsDescription = "blindUp options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel switchOff() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.switchOff(flowPanel); reappear(2000); } } effectOptionsDescription = "switchOff options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel slideDown() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.slideDown(flowPanel); } } effectOptionsDescription = "slideDown options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel slideUp() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.slideUp(flowPanel); reappear(2000); } } effectOptionsDescription = "slideUp options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel dropOut() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.dropOut(flowPanel); reappear(2000); } } effectOptionsDescription = "dropOut options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel shake() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.shake(flowPanel); } } effectOptionsDescription = "shake options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel highlight() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.highlight(flowPanel); } } effectOptionsDescription = "highlight options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel pulsate() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.pulsate(flowPanel); } } effectOptionsDescription = "pulsate options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel squish() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.squish(flowPanel); reappear(2000); } } effectOptionsDescription = "squish options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel fold() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.fold(flowPanel); reappear(3000); } } effectOptionsDescription = "fold options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel grow() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.grow(flowPanel); } } effectOptionsDescription = "grow options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel shrink() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.shrink(flowPanel); reappear(2000); } } effectOptionsDescription = "shrink options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } public EffectPanel puff() { class MyEffect implements ClickListener { public void onClick(Widget sender) { Effect.puff(flowPanel); reappear(2000); } } effectOptionsDescription = "puff options" + ""; panelImage.addClickListener(new MyEffect()); panelLabel.addClickListener(new MyEffect()); return this; } /** * Allows our EffectPanel to reappear after a short delay. * @param time */ private void reappear(int delay) { Timer t = new Timer() { public void run() { Effect.appear(flowPanel); } }; t.schedule(delay); } }