Java tutorial
/* * Copyright 2008 Google Inc. * * 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 fr.drop.client.content.projects; import fr.drop.client.content.projects.ProjectInfoForm; import fr.drop.client.utils.text.CwRichText; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.RunAsyncCallback; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.i18n.client.Constants; import com.google.gwt.i18n.shared.AnyRtlDirectionEstimator; import fr.drop.client.ContentWidget; import fr.drop.client.Drop; import fr.drop.client.DropAnnotations.DropData; import fr.drop.client.DropAnnotations.DropSource; import fr.drop.client.DropAnnotations.DropStyle; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.DecoratedPopupPanel; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; /** * Example file. */ @DropStyle({ ".gwt-PopupPanel", "html>body .gwt-PopupPanel", "* html .gwt-PopupPanel", ".gwt-DecoratedPopupPanel", "html>body .gwt-DecoratedPopupPanel", "* html .gwt-DecoratedPopupPanel" }) public class CwProjectCreation extends ContentWidget { /** * The constants used in this Content Widget. */ @DropSource public static interface CwConstants extends Constants { String cwProjectCreationName(); String cwProjectCreationDescription(); String cwBasicPopupClickOutsideInstructions(); String cwBasicPopupDescription(); String cwBasicPopupInstructions(); String cwBasicPopupName(); String cwBasicPopupShowButton(); } /** * An instance of the constants. */ @DropData private final CwConstants constants; /** * Constructor. * * @param constants the constants */ public CwProjectCreation(CwConstants constants) { super(constants.cwProjectCreationName(), constants.cwProjectCreationDescription(), true); this.constants = constants; } /** * Initialize this example. */ @DropSource @Override public Widget onInitialize() { // Create a basic popup widget /* final DecoratedPopupPanel simplePopup = new DecoratedPopupPanel(true); simplePopup.ensureDebugId("cwBasicPopup-simplePopup"); simplePopup.setWidth("150px"); simplePopup.setWidget( new HTML(constants.cwBasicPopupClickOutsideInstructions())); // Create a button to show the popup Button openButton = new Button( constants.cwBasicPopupShowButton(), new ClickHandler() { public void onClick(ClickEvent event) { // Reposition the popup relative to the button Widget source = (Widget) event.getSource(); int left = source.getAbsoluteLeft() + 10; int top = source.getAbsoluteTop() + 10; simplePopup.setPopupPosition(left, top); // Show the popup simplePopup.show(); } }); */ // Create a popup to show the full size image // Image jimmyFull = new Image(Drop.images.jimmy()); // final PopupPanel imagePopup = new PopupPanel(true); // imagePopup.setAnimationEnabled(true); // imagePopup.ensureDebugId("cwBasicPopup-imagePopup"); // imagePopup.setWidget(jimmyFull); // jimmyFull.addClickHandler(new ClickHandler() { // public void onClick(ClickEvent event) { // imagePopup.hide(); // } // }); // // // Add an image thumbnail // Image jimmyThumb = new Image(Drop.images.jimmyThumb()); // jimmyThumb.ensureDebugId("cwBasicPopup-thumb"); // jimmyThumb.addStyleName("cw-BasicPopup-thumb"); // jimmyThumb.addClickHandler(new ClickHandler() { // public void onClick(ClickEvent event) { // imagePopup.center(); // } // }); // Add the widgets to a panel VerticalPanel vPanel = new VerticalPanel(); vPanel.setSpacing(5); //vPanel.add(openButton); //AddTextBox(vPanel, "Project Name","cwProjectName-textbox"); // vPanel.add(new HTML("<br><br><br>" + constants.cwBasicPopupInstructions())); // vPanel.add(jimmyThumb); vPanel.add(new ProjectInfoForm()); // Return the panel return vPanel; } protected void AddTextBox(VerticalPanel vPanel, String description, String identifier) { // Project Name TextBox normalText = new TextBox(); normalText.ensureDebugId("cwCreateProjectName-textbox"); // Set the normal text box to automatically adjust its direction according // to the input text. Use the Any-RTL heuristic, which sets an RTL direction // iff the text contains at least one RTL character. normalText.setDirectionEstimator(AnyRtlDirectionEstimator.get()); vPanel.add(normalText); } @Override protected void asyncOnInitialize(final AsyncCallback<Widget> callback) { GWT.runAsync(CwProjectCreation.class, new RunAsyncCallback() { public void onFailure(Throwable caught) { callback.onFailure(caught); } public void onSuccess() { callback.onSuccess(onInitialize()); } }); } }