ImageUploadPanel.java
001 /*
002  * Created on Aug 12, 2007
003  
004  * Copyright 2005 CafeSip.org 
005  *
006  * Licensed under the Apache License, Version 2.0 (the "License"); 
007  * you may not use this file except in compliance with the License. 
008  * You may obtain a copy of the License at 
009  *
010  *  http://www.apache.org/licenses/LICENSE-2.0 
011  *
012  * Unless required by applicable law or agreed to in writing, software 
013  * distributed under the License is distributed on an "AS IS" BASIS, 
014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
015  * See the License for the specific language governing permissions and 
016  * limitations under the License.
017  *
018  */
019 package org.cafesip.gwtcomp.examples.client;
020 
021 import org.cafesip.gwtcomp.client.ui.DataEntryPanel;
022 import org.cafesip.gwtcomp.client.ui.EventfulFileUpload;
023 import org.cafesip.gwtcomp.client.ui.FileUploadEventListener;
024 import org.cafesip.gwtcomp.client.ui.TitleBar;
025 import org.cafesip.gwtcomp.client.ui.WizardPanel;
026 
027 import com.google.gwt.user.client.Event;
028 import com.google.gwt.user.client.Window;
029 import com.google.gwt.user.client.ui.Label;
030 import com.google.gwt.user.client.ui.TextArea;
031 import com.google.gwt.user.client.ui.TextBox;
032 
033 /**
034  @author Amit Chatterjee
035  
036  */
037 public class ImageUploadPanel extends DataEntryPanel
038 {
039     private WizardPanel parent;
040 
041     private TextBox caption = new TextBox();
042 
043     private TextArea description = new TextArea();
044 
045     private EventfulFileUpload upload = new EventfulFileUpload();
046 
047     public ImageUploadPanel(WizardPanel parent)
048     {
049         this.parent = parent;
050 
051         setTitleBar(new TitleBar("Upload Pictures", null, 2));
052 
053         caption.setName("caption");
054         addField(new Label("Caption"), caption, true);
055 
056         description.setName("description");
057         addField(new Label("Description"), description);
058 
059         upload.addEventListener(new FileUploadEventListener()
060         {
061             public void onEvent(Event event)
062             {
063                 String file = upload.getFilename();
064                 if (!file.endsWith(".jpg"&& !file.endsWith(".bmp")
065                         && !file.endsWith(".png"))
066                 {
067                     Window.alert("Only image files are allowed");
068                 }
069 
070             }
071         });
072         
073         upload.setName("upload");
074         addField(new Label("Select Picture"), upload, true);
075     }
076 
077     /**
078      @return Returns the caption.
079      */
080     public TextBox getCaption()
081     {
082         return caption;
083     }
084 
085     /**
086      @return Returns the description.
087      */
088     public TextArea getDescription()
089     {
090         return description;
091     }
092 
093     /**
094      @return Returns the upload.
095      */
096     public EventfulFileUpload getUpload()
097     {
098         return upload;
099     }
100 }