3
* Copyright(c) 2006-2008, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.BorderLayout
11
* @extends Ext.LayoutManager
12
* This class represents a common layout manager used in desktop applications.
15
var layout = new Ext.BorderLayout(document.body, {
49
preferredTabWidth: 150
54
var CP = Ext.ContentPanel;
57
layout.add("north", new CP("north", "North"));
58
layout.add("south", new CP("south", {title: "South", closable: true}));
59
layout.add("west", new CP("west", {title: "West"}));
60
layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
61
layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
62
layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
63
layout.getRegion("center").showPanel("center1");
67
<b>The container the layout is rendered into can be either the body element or any other element.
68
If it is not the body element, the container needs to either be an absolute positioned element,
69
or you will need to add "position:relative" to the css of the container. You will also need to specify
70
the container size if it is not the body element.</b>
73
* Create a new BorderLayout
74
* @param {Mixed} container The container this layout is bound to
75
* @param {Object} config Configuration options
77
Ext.BorderLayout = function(container, config){
78
config = config || {};
79
Ext.BorderLayout.superclass.constructor.call(this, container, config);
80
this.factory = config.factory || Ext.BorderLayout.RegionFactory;
81
for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
82
var target = this.factory.validRegions[i];
84
this.addRegion(target, config[target]);
89
Ext.extend(Ext.BorderLayout, Ext.LayoutManager, {
91
* Creates and adds a new region if it doesn't already exist.
92
* @param {String} target The target region key (north, south, east, west or center).
93
* @param {Object} config The regions config object
94
* @return {BorderLayoutRegion} The new region
96
addRegion : function(target, config){
97
if(!this.regions[target]){
98
var r = this.factory.create(target, this, config);
99
this.bindRegion(target, r);
101
return this.regions[target];
105
bindRegion : function(name, r){
106
this.regions[name] = r;
107
r.on("visibilitychange", this.layout, this);
108
r.on("paneladded", this.layout, this);
109
r.on("panelremoved", this.layout, this);
110
r.on("invalidated", this.layout, this);
111
r.on("resized", this.onRegionResized, this);
112
r.on("collapsed", this.onRegionCollapsed, this);
113
r.on("expanded", this.onRegionExpanded, this);
117
* Performs a layout update.
120
if(this.updating) return;
121
var size = this.getViewSize();
122
var w = size.width, h = size.height;
123
var centerW = w, centerH = h, centerY = 0, centerX = 0;
126
var rs = this.regions;
127
var n = rs["north"], s = rs["south"], west = rs["west"], e = rs["east"], c = rs["center"];
128
//if(this.hideOnLayout){ // not supported anymore
129
//c.el.setStyle("display", "none");
131
if(n && n.isVisible()){
133
var m = n.getMargins();
134
b.width = w - (m.left+m.right);
137
centerY = b.height + b.y + m.bottom;
139
n.updateBox(this.safeBox(b));
141
if(s && s.isVisible()){
143
var m = s.getMargins();
144
b.width = w - (m.left+m.right);
146
var totalHeight = (b.height + m.top + m.bottom);
147
b.y = h - totalHeight + m.top;
148
centerH -= totalHeight;
149
s.updateBox(this.safeBox(b));
151
if(west && west.isVisible()){
152
var b = west.getBox();
153
var m = west.getMargins();
154
b.height = centerH - (m.top+m.bottom);
156
b.y = centerY + m.top;
157
var totalWidth = (b.width + m.left + m.right);
158
centerX += totalWidth;
159
centerW -= totalWidth;
160
west.updateBox(this.safeBox(b));
162
if(e && e.isVisible()){
164
var m = e.getMargins();
165
b.height = centerH - (m.top+m.bottom);
166
var totalWidth = (b.width + m.left + m.right);
167
b.x = w - totalWidth + m.left;
168
b.y = centerY + m.top;
169
centerW -= totalWidth;
170
e.updateBox(this.safeBox(b));
173
var m = c.getMargins();
177
width: centerW - (m.left+m.right),
178
height: centerH - (m.top+m.bottom)
180
//if(this.hideOnLayout){
181
//c.el.setStyle("display", "block");
183
c.updateBox(this.safeBox(centerBox));
186
this.fireEvent("layout", this);
189
safeBox : function(box){
190
box.width = Math.max(0, box.width);
191
box.height = Math.max(0, box.height);
196
* Adds a ContentPanel (or subclass) to this layout.
197
* @param {String} target The target region key (north, south, east, west or center).
198
* @param {Ext.ContentPanel} panel The panel to add
199
* @return {Ext.ContentPanel} The added panel
201
add : function(target, panel){
202
target = target.toLowerCase();
203
return this.regions[target].add(panel);
207
* Remove a ContentPanel (or subclass) to this layout.
208
* @param {String} target The target region key (north, south, east, west or center).
209
* @param {Number/String/Ext.ContentPanel} panel The index, id or panel to remove
210
* @return {Ext.ContentPanel} The removed panel
212
remove : function(target, panel){
213
target = target.toLowerCase();
214
return this.regions[target].remove(panel);
218
* Searches all regions for a panel with the specified id
219
* @param {String} panelId
220
* @return {Ext.ContentPanel} The panel or null if it wasn't found
222
findPanel : function(panelId){
223
var rs = this.regions;
224
for(var target in rs){
225
if(typeof rs[target] != "function"){
226
var p = rs[target].getPanel(panelId);
236
* Searches all regions for a panel with the specified id and activates (shows) it.
237
* @param {String/ContentPanel} panelId The panels id or the panel itself
238
* @return {Ext.ContentPanel} The shown panel or null
240
showPanel : function(panelId) {
241
var rs = this.regions;
242
for(var target in rs){
244
if(typeof r != "function"){
245
if(r.hasPanel(panelId)){
246
return r.showPanel(panelId);
254
* Restores this layouts state using Ext.state.Manager or the state provided by the passed provider.
255
* @param {Ext.state.Provider} provider (optional) An alternate state provider
257
restoreState : function(provider){
259
provider = Ext.state.Manager;
261
var sm = new Ext.LayoutStateManager();
262
sm.init(this, provider);
266
batchAdd : function(regions){
268
for(var rname in regions){
269
var lr = this.regions[rname];
271
this.addTypedPanels(lr, regions[rname]);
278
addTypedPanels : function(lr, ps){
279
if(typeof ps == 'string'){
280
lr.add(new Ext.ContentPanel(ps));
282
else if(Ext.isArray(ps)){
283
for(var i =0, len = ps.length; i < len; i++){
284
this.addTypedPanels(lr, ps[i]);
287
else if(!ps.events){ // raw config?
289
delete ps.el; // prevent conflict
290
lr.add(new Ext.ContentPanel(el || Ext.id(), ps));
292
else { // panel object assumed!
298
Ext.BorderLayout.create = function(config, targetEl){
299
var layout = new Ext.BorderLayout(targetEl || document.body, config);
300
layout.beginUpdate();
301
var regions = Ext.BorderLayout.RegionFactory.validRegions;
302
for(var j = 0, jlen = regions.length; j < jlen; j++){
304
if(layout.regions[lr] && config[lr].panels){
305
var r = layout.regions[lr];
306
var ps = config[lr].panels;
307
layout.addTypedPanels(r, ps);
314
Ext.BorderLayout.RegionFactory = {
315
validRegions : ["north","south","east","west","center"],
317
create : function(target, mgr, config){
318
target = target.toLowerCase();
319
if(config.lightweight || config.basic){
320
return new Ext.BasicLayoutRegion(mgr, config, target);
324
return new Ext.NorthLayoutRegion(mgr, config);
326
return new Ext.SouthLayoutRegion(mgr, config);
328
return new Ext.EastLayoutRegion(mgr, config);
330
return new Ext.WestLayoutRegion(mgr, config);
332
return new Ext.CenterLayoutRegion(mgr, config);
334
throw 'Layout region "'+target+'" not supported.';
b'\\ No newline at end of file'