1   /*
2    * Created on Aug 18, 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.Audio;
22  import org.cafesip.gwtcomp.client.utils.ContextUtil;
23  
24  import com.google.gwt.user.client.Command;
25  import com.google.gwt.user.client.ui.Anchor;
26  import com.google.gwt.user.client.ui.FlowPanel;
27  import com.google.gwt.user.client.ui.MenuBar;
28  import com.google.gwt.user.client.ui.RootPanel;
29  import com.google.gwt.user.client.ui.SimplePanel;
30  import com.google.gwt.user.client.ui.Widget;
31  
32  /**
33   * @author Amit Chatterjee
34   * 
35   */
36  public class Example
37  {
38      private SimplePanel samplePanel;
39  
40      private SimplePanel sourcePanel;
41  
42      /**
43       * A constructor for this class.
44       * 
45       */
46      public Example()
47      {
48          RootPanel rootPanel = RootPanel.get();
49          rootPanel.setSize("100%", "100%");
50  
51          Audio.setRoot(rootPanel);
52  
53          FlowPanel panel = new FlowPanel();
54          rootPanel.add(panel);
55          panel.setSize("100%", "100%");
56  
57          MenuBar bar = new MenuBar();
58          panel.add(bar);
59          bar.setWidth("100%");
60  
61          sourcePanel = new SimplePanel();
62          panel.add(sourcePanel);
63          sourcePanel.setWidth("100%");
64  
65          MenuBar form = new MenuBar(true);
66          form.addItem("Editable List", new Command()
67          {
68              public void execute()
69              {
70                  setSamplePanel(new EditableListSample());
71              }
72          });
73  
74          form.addItem("Server File Selector", new Command()
75          {
76              public void execute()
77              {
78                  setSamplePanel(new ServerFileBrowserSample());
79              }
80          });
81  
82          form.addItem("WizardPanel", new Command()
83          {
84              public void execute()
85              {
86                  setSamplePanel(new WizardPanelSample());
87              }
88          });
89  
90          bar.addItem("Form Elements", form);
91  
92          MenuBar viewer = new MenuBar(true);
93          viewer.addItem("Property Viewer", new Command()
94          {
95  
96              public void execute()
97              {
98                  setSamplePanel(new PropertyViewerSample());
99              }
100         });
101 
102         viewer.addItem("Super Table", new Command()
103         {
104 
105             public void execute()
106             {
107                 setSamplePanel(new SuperTableSample());
108             }
109         });
110 
111         viewer.addItem("Super Tree", new Command()
112         {
113 
114             public void execute()
115             {
116                 setSamplePanel(new SuperTreeSample());
117             }
118         });
119 
120         bar.addItem("Viewers", viewer);
121 
122         MenuBar charts = new MenuBar(true);
123         charts.addItem("Live Data Panel", new Command()
124         {
125 
126             public void execute()
127             {
128                 setSamplePanel(new LiveDataPanelSample());
129             }
130         });
131         bar.addItem("Charts", charts);
132 
133         MenuBar audio = new MenuBar(true);
134         audio.addItem("Audio Widgets", new Command()
135         {
136 
137             public void execute()
138             {
139                 setSamplePanel(new AudioSample());
140             }
141         });
142         bar.addItem("Audio", audio);
143 
144         MenuBar drag = new MenuBar(true);
145         drag.addItem("Drag and Drop Widgets", new Command()
146         {
147 
148             public void execute()
149             {
150                 setSamplePanel(new DraggableSample());
151             }
152         });
153         bar.addItem("Drag & Drop", drag);
154 
155         samplePanel = new SimplePanel();
156         panel.add(samplePanel);
157         samplePanel.setWidth("100%");
158 
159         MenuBar misc = new MenuBar(true);
160         misc.addItem("Miscelleneous Widgets", new Command()
161         {
162             public void execute()
163             {
164                 setSamplePanel(new MiscWidgetsSample());
165             }
166         });
167         
168         bar.addItem("Miscelleneous", misc);
169 
170         samplePanel = new SimplePanel();
171         samplePanel.setStyleName("gwtcomp-Examples-MainPanel");
172         panel.add(samplePanel);
173         samplePanel.setWidth("100%");
174     }
175 
176     private void setSamplePanel(Widget w)
177     {
178         samplePanel.setWidget(w);
179 
180         String clazz = w.getClass().getName();
181         int i = clazz.lastIndexOf('.');
182         String pkg = clazz.substring(0, i);
183         String cl = clazz.substring(i + 1);
184 
185         pkg = pkg.replaceAll("\\.", "/");
186 
187         sourcePanel.setWidget(new Anchor("View source", ContextUtil
188                 .getContextURL() + "/xref/"
189                 + pkg + "/" + cl + ".html", "_source"));
190     }
191 }