1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.google.gwt.sample.showcase.client.content.panels;
17 
18 import com.google.gwt.core.client.GWT;
19 import com.google.gwt.core.client.RunAsyncCallback;
20 import com.google.gwt.i18n.client.Constants;
21 import com.google.gwt.sample.showcase.client.ContentWidget;
22 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseData;
23 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseSource;
24 import com.google.gwt.sample.showcase.client.ShowcaseAnnotations.ShowcaseStyle;
25 import com.google.gwt.user.client.rpc.AsyncCallback;
26 import com.google.gwt.user.client.ui.Label;
27 import com.google.gwt.user.client.ui.ScrollPanel;
28 import com.google.gwt.user.client.ui.SplitLayoutPanel;
29 import com.google.gwt.user.client.ui.Widget;
30 
31 /**
32  * Example file.
33  */
34 @ShowcaseStyle(".gwt-SplitLayoutPanel")
35 public class CwSplitLayoutPanel extends ContentWidget {
36   /**
37    * The constants used in this Content Widget.
38    */
39   @ShowcaseSource
40   public static interface CwConstants extends Constants {
cwSplitLayoutPanelCenter()41     String cwSplitLayoutPanelCenter();
42 
cwSplitLayoutPanelDescription()43     String cwSplitLayoutPanelDescription();
44 
cwSplitLayoutPanelEast()45     String cwSplitLayoutPanelEast();
46 
cwSplitLayoutPanelName()47     String cwSplitLayoutPanelName();
48 
cwSplitLayoutPanelNorth1()49     String cwSplitLayoutPanelNorth1();
50 
cwSplitLayoutPanelNorth2()51     String cwSplitLayoutPanelNorth2();
52 
cwSplitLayoutPanelSouth1()53     String cwSplitLayoutPanelSouth1();
54 
cwSplitLayoutPanelSouth2()55     String cwSplitLayoutPanelSouth2();
56 
cwSplitLayoutPanelWest()57     String cwSplitLayoutPanelWest();
58   }
59 
60   /**
61    * An instance of the constants.
62    */
63   @ShowcaseData
64   private final CwConstants constants;
65 
66   /**
67    * Constructor.
68    *
69    * @param constants the constants
70    */
CwSplitLayoutPanel(CwConstants constants)71   public CwSplitLayoutPanel(CwConstants constants) {
72     super(constants.cwSplitLayoutPanelName(), constants
73         .cwSplitLayoutPanelDescription(), true);
74     this.constants = constants;
75   }
76 
77   @Override
hasMargins()78   public boolean hasMargins() {
79     return false;
80   }
81 
82   @Override
hasScrollableContent()83   public boolean hasScrollableContent() {
84     return false;
85   }
86 
87   /**
88    * Initialize this example.
89    */
90   @ShowcaseSource
91   @Override
onInitialize()92   public Widget onInitialize() {
93     // Create a Split Panel
94     SplitLayoutPanel splitPanel = new SplitLayoutPanel(5);
95     splitPanel.ensureDebugId("cwSplitLayoutPanel");
96     splitPanel.getElement().getStyle()
97         .setProperty("border", "3px solid #e7e7e7");
98 
99     // Add text all around.
100     splitPanel.addNorth(new Label(constants.cwSplitLayoutPanelNorth1()), 50);
101     splitPanel.addSouth(new Label(constants.cwSplitLayoutPanelSouth1()), 50);
102     splitPanel.addEast(new Label(constants.cwSplitLayoutPanelEast()), 100);
103     splitPanel.addWest(new Label(constants.cwSplitLayoutPanelWest()), 100);
104     splitPanel.addNorth(new Label(constants.cwSplitLayoutPanelNorth2()), 50);
105     splitPanel.addSouth(new Label(constants.cwSplitLayoutPanelSouth2()), 50);
106 
107     // Add scrollable text to the center.
108     String centerText = constants.cwSplitLayoutPanelCenter();
109     for (int i = 0; i < 3; i++) {
110       centerText += " " + centerText;
111     }
112     Label centerLabel = new Label(centerText);
113     ScrollPanel centerScrollable = new ScrollPanel(centerLabel);
114     splitPanel.add(centerScrollable);
115 
116     // Return the content
117     return splitPanel;
118   }
119 
120   @Override
asyncOnInitialize(final AsyncCallback<Widget> callback)121   protected void asyncOnInitialize(final AsyncCallback<Widget> callback) {
122     GWT.runAsync(CwSplitLayoutPanel.class, new RunAsyncCallback() {
123 
124       public void onFailure(Throwable caught) {
125         callback.onFailure(caught);
126       }
127 
128       public void onSuccess() {
129         callback.onSuccess(onInitialize());
130       }
131     });
132   }
133 }
134