1   /*
2    * Created on Aug 12, 2007
3    * 
4    * Copyright 2005 CafeSip.org 
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License"); 
7    * you may not use this file except in compliance with the License. 
8    * You may obtain a copy of the License at 
9    *
10   *	http://www.apache.org/licenses/LICENSE-2.0 
11   *
12   * Unless required by applicable law or agreed to in writing, software 
13   * distributed under the License is distributed on an "AS IS" BASIS, 
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15   * See the License for the specific language governing permissions and 
16   * limitations under the License.
17   *
18   */
19  package org.cafesip.gwtcomp.examples.client;
20  
21  import org.cafesip.gwtcomp.client.ui.DataEntryPanel;
22  import org.cafesip.gwtcomp.client.ui.EventfulFileUpload;
23  import org.cafesip.gwtcomp.client.ui.FileUploadEventListener;
24  import org.cafesip.gwtcomp.client.ui.TitleBar;
25  import org.cafesip.gwtcomp.client.ui.WizardPanel;
26  
27  import com.google.gwt.user.client.Event;
28  import com.google.gwt.user.client.Window;
29  import com.google.gwt.user.client.ui.Label;
30  import com.google.gwt.user.client.ui.TextArea;
31  import com.google.gwt.user.client.ui.TextBox;
32  
33  /**
34   * @author Amit Chatterjee
35   * 
36   */
37  public class ImageUploadPanel extends DataEntryPanel
38  {
39      private TextBox caption = new TextBox();
40  
41      private TextArea description = new TextArea();
42  
43      private EventfulFileUpload upload = new EventfulFileUpload();
44  
45      public ImageUploadPanel(WizardPanel parent)
46      {
47          setTitleBar(new TitleBar("Upload Pictures", null, 2));
48  
49          caption.setName("caption");
50          addField(new Label("Caption"), caption, true);
51  
52          description.setName("description");
53          addField(new Label("Description"), description);
54  
55          upload.addEventListener(new FileUploadEventListener()
56          {
57              public void onEvent(Event event)
58              {
59                  String file = upload.getFilename();
60                  if (!file.endsWith(".jpg") && !file.endsWith(".bmp")
61                          && !file.endsWith(".png"))
62                  {
63                      Window.alert("Only image files are allowed");
64                  }
65  
66              }
67          });
68          
69          upload.setName("upload");
70          addField(new Label("Select Picture"), upload, true);
71      }
72  
73      /**
74       * @return Returns the caption.
75       */
76      public TextBox getCaption()
77      {
78          return caption;
79      }
80  
81      /**
82       * @return Returns the description.
83       */
84      public TextArea getDescription()
85      {
86          return description;
87      }
88  
89      /**
90       * @return Returns the upload.
91       */
92      public EventfulFileUpload getUpload()
93      {
94          return upload;
95      }
96  }