package com.digitbit.effects.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.MouseListener; import com.google.gwt.user.client.ui.RootPanel; 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 EffectsDemo implements EntryPoint { private EffectPanel fadePanel; private EffectPanel blindDownPanel; private EffectPanel blindUpPanel; private EffectPanel switchOffPanel; private EffectPanel highlightPanel; private EffectPanel dropOutPanel; private EffectPanel shakePanel; private EffectPanel pulsatePanel; private EffectPanel squishPanel; private EffectPanel foldPanel; private EffectPanel growPanel; private EffectPanel shrinkPanel; private HTML effectOptions; private EffectPanel puffPanel; private Grid grid; private EffectPanel slideDownPanel; private EffectPanel slideUpPanel; /** * This is the entry point method. */ public void onModuleLoad() { createEffectPanels(); grid = createGrid(); HorizontalPanel mainPanel = new HorizontalPanel(); effectOptions = new HTML(""); effectOptions.setStyleName("effectOptions"); effectOptions.setVisible(false); mainPanel.add(grid); mainPanel.add(effectOptions); RootPanel.get("main").add(mainPanel); addListeners(); } private void addListeners() { // Loop through each of the EffectPanels in the grid // and attach a MouseListener to each. for (int row=0; row < grid.getRowCount(); row++) { for (int col=0; col < grid.getColumnCount(); col++) { EffectPanel panel = (EffectPanel) grid.getWidget(row, col); if (panel != null) { panel.addMouseListener(new ShowOptions()); } } } } /** * We create an effect panel for each effect we want to demonstrate. * */ private void createEffectPanels() { fadePanel = new EffectPanel( "angry_32.gif", "fade").fade(); blindDownPanel = new EffectPanel( "bubble_32.gif", "blindDown").blindDown(); blindUpPanel = new EffectPanel( "chuckle_32.gif", "blindUp").blindUp(); switchOffPanel = new EffectPanel( "critter_32.gif", "switchOff").switchOff(); highlightPanel = new EffectPanel( "dark_hero_32.gif", "highlight").highlight(); dropOutPanel = new EffectPanel( "devilish_32.gif", "dropOut").dropOut(); shakePanel = new EffectPanel( "digital_32.gif", "shake").shake(); pulsatePanel = new EffectPanel( "embarrassed_32.gif", "pulsate").pulsate(); squishPanel = new EffectPanel( "executed_32.gif", "squish").squish(); foldPanel = new EffectPanel( "explorer_32.gif", "fold").fold(); growPanel = new EffectPanel( "fezzed_32.gif", "grow").grow(); shrinkPanel = new EffectPanel( "frownie_32.gif", "shrink").shrink(); puffPanel = new EffectPanel( "greedy_32.gif", "puff").puff(); slideDownPanel = new EffectPanel( "grin_32.gif", "slideDown").slideDown(); slideUpPanel = new EffectPanel( "groucho_32.gif", "slideUp").slideUp(); } /** * Simple grid which holds all of our effect panels. * @return */ private Grid createGrid() { final Grid grid = new Grid(4, 4); grid.setCellSpacing(10); grid.setWidget(0, 0, fadePanel); grid.setWidget(0, 1, blindDownPanel); grid.setWidget(0, 2, blindUpPanel); grid.setWidget(0, 3, switchOffPanel); grid.setWidget(1, 0, highlightPanel); grid.setWidget(1, 1, dropOutPanel); grid.setWidget(1, 2, shakePanel); grid.setWidget(1, 3, pulsatePanel); grid.setWidget(2, 0, squishPanel); grid.setWidget(2, 1, foldPanel); grid.setWidget(2, 2, growPanel); grid.setWidget(2, 3, shrinkPanel); grid.setWidget(3, 0, puffPanel); grid.setWidget(3, 1, slideDownPanel); grid.setWidget(3, 2, slideUpPanel); return grid; } /** * We attach this Listener to an Effect Panel so we can * display the effect options when we hover over the panel * with the mouse. * @author Chris * */ private class ShowOptions implements MouseListener { public void onMouseEnter(Widget sender) { // We display the options for an effect which // is contained in the hovered over widget's // toString() method. effectOptions.setVisible(true); effectOptions.setHTML(sender.toString()); } public void onMouseDown(Widget sender, int x, int y) {} public void onMouseLeave(Widget sender) {} public void onMouseMove(Widget sender, int x, int y) {} public void onMouseUp(Widget sender, int x, int y) {} } }