1 """
2 /*
3 * Copyright 2008 Google Inc.
4 * Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License") you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * 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, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18 """
19 from Panel import Panel
20 from pyjamas import Factory
21 from pyjamas.ui import Event
22
23 from pyjamas import DOM
24
26 """ Abstract base class for {@link HorizontalSplitPanel} and
27 {@link VerticalSplitPanel}.
28 """
29
30 - def __init__(self, mainElem, splitElem, headElem, tailElem, **kwargs):
31 """ Initializes the split panel.
32 @param mainElem the root element for the split panel
33 @param splitElem the element that acts as the splitter
34 @param headElem the element to contain the top or left most widget
35 @param tailElem the element to contain the bottom or right most widget
36 """
37
38 self.widgets = [None, None]
39 self.elements = [headElem, tailElem]
40 self.isResizing = False
41
42 self.setElement(mainElem)
43 self.splitElem = splitElem
44
45 if not kwargs.has_key('ThumbImage'):
46 kwargs['ThumbImage'] = "splitPanelThumb.png"
47
48 Panel.__init__(self, **kwargs)
49
50 self.sinkEvents(Event.MOUSEEVENTS)
51
54
56 if self.thumb_image:
57 return '<img src="%s" />' % self.thumb_image
58 return ""
59
61 """ Sets an elements positioning to absolute.
62 """
63 DOM.setStyleAttribute(elem, "position", "absolute")
64
69
74
76 """ Sizes and element to consume the full area of its parent
77 using the CSS properties left, right, top, and
78 bottom. This method is used for all browsers except IE6/7.
79 """
80 zeroSize = "0px"
81
82 self.addAbsolutePositoning(elem)
83 self.setLeft(elem, zeroSize)
84 self.setRight(elem, zeroSize)
85 self.setTop(elem, zeroSize)
86 self.setBottom(elem, zeroSize)
87
89 """ Sizes an element to consume the full areas of its parent
90 using 100% width and height. This method is used on IE6/7
91 where CSS offsets don't work reliably.
92 """
93 zeroSize = "0px"
94 fullSize = "100%"
95
96 self.addAbsolutePositoning(elem)
97 self.setTop(elem, zeroSize)
98 self.setLeft(elem, zeroSize)
99 self.setElemWidth(elem, fullSize)
100 self.setElemHeight(elem, fullSize)
101
103 """ Adds zero or none CSS values for padding, margin and
104 border to prevent stylesheet overrides. Returns the
105 element for convenience to support builder pattern.
106 """
107 DOM.setIntStyleAttribute(elem, "padding", 0)
108 DOM.setIntStyleAttribute(elem, "margin", 0)
109 DOM.setStyleAttribute(elem, "border", "none")
110 return elem
111
113 """ Convenience method to set bottom offset of an element.
114 """
115 DOM.setStyleAttribute(elem, "bottom", size)
116
118 """ Convenience method to set the height of an element.
119 """
120 DOM.setStyleAttribute(elem, "height", height)
121
123 """ Convenience method to set the left offset of an element.
124 """
125 DOM.setStyleAttribute(elem, "left", left)
126
128 """ Convenience method to set the right offset of an element.
129 """
130 DOM.setStyleAttribute(elem, "right", right)
131
133 """ Convenience method to set the top offset of an element.
134 """
135 DOM.setStyleAttribute(elem, "top", top)
136
138 """ Convenience method to set the width of an element.
139 """
140 DOM.setStyleAttribute(elem, "width", width)
141
147
148
149
151 """ Indicates whether the split panel is being resized.
152
153 @return <code>True</code> if the user is dragging the splitter,
154 <code>False</code> otherwise
155 """
156 return self.isResizing
157
160
184
186 if widgets[0] == widget:
187 setWidget(0, None)
188 return True
189 elif widgets[1] == widget:
190 setWidget(1, None)
191 return True
192 return False
193
195 """ Moves the position of the splitter.
196 @param size the new size of the left region in CSS units
197 (e.g. "10px", "1em")
198 """
199 pass
200
207
209 """ Gets the element that is acting as the splitter.
210 @return the element
211 """
212 return self.splitElem
213
220
250
252 """ Called on each mouse drag event as the user is dragging
253 the splitter.
254 @param x the x coord of the mouse relative to the panel's extent
255 @param y the y coord of the mosue relative to the panel's extent
256 """
257 pass
258
260 """ Called when the user starts dragging the splitter.
261 @param x the x coord of the mouse relative to the panel's extent
262 @param y the y coord of the mouse relative to the panel's extent
263 """
264
268
271
272
273
274
275