1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Used to create external or internal URL links."""
17
18 from muntjac.ui.abstract_component import AbstractComponent
19 from muntjac.ui.window import Window
20
21
22 -class Link(AbstractComponent):
23 """Link is used to create external or internal URL links.
24
25 @author: Vaadin Ltd.
26 @author: Richard Lincoln
27 @version: 1.1.2
28 """
29
30 CLIENT_WIDGET = None
31
32
33 TARGET_BORDER_NONE = Window.BORDER_NONE
34
35
36 TARGET_BORDER_MINIMAL = Window.BORDER_MINIMAL
37
38
39 TARGET_BORDER_DEFAULT = Window.BORDER_DEFAULT
40
41
42 - def __init__(self, caption=None, resource=None, targetName=None,
43 width=None, height=None, border=None):
44 """Creates a new instance of Link.
45
46 @param caption:
47 the Link text.
48 @param resource:
49 @param targetName:
50 the name of the target window where the link opens to. Empty
51 name of null implies that the target is opened to the window
52 containing the link.
53 @param width:
54 the Width of the target window.
55 @param height:
56 the Height of the target window.
57 @param border:
58 the Border style of the target window.
59 """
60 super(Link, self).__init__()
61
62 self._resource = None
63 self._targetName = None
64 self._targetBorder = self.TARGET_BORDER_DEFAULT
65 self._targetWidth = -1
66 self._targetHeight = -1
67
68 if caption is not None:
69 self.setCaption(caption)
70
71 if resource is not None:
72 self._resource = resource
73
74 if targetName is not None:
75 self.setTargetName(targetName)
76
77 if width is not None:
78 self.setTargetWidth(width)
79
80 if height is not None:
81 self.setTargetHeight(height)
82
83 if border is not None:
84 self.setTargetBorder(border)
85
86
87 - def paintContent(self, target):
88 """Paints the content of this component.
89
90 @param target:
91 the Paint Event.
92 @raise PaintException:
93 if the paint operation failed.
94 """
95 if self._resource is not None:
96 target.addAttribute('src', self._resource)
97 else:
98 return
99
100
101 name = self.getTargetName()
102 if name is not None and len(name) > 0:
103 target.addAttribute('name', name)
104
105
106 if self.getTargetWidth() >= 0:
107 target.addAttribute('targetWidth', self.getTargetWidth())
108
109 if self.getTargetHeight() >= 0:
110 target.addAttribute('targetHeight', self.getTargetHeight())
111
112
113 test = self.getTargetBorder()
114 if test == self.TARGET_BORDER_MINIMAL:
115 target.addAttribute('border', 'minimal')
116 elif test == self.TARGET_BORDER_NONE:
117 target.addAttribute('border', 'none')
118
119
121 """Returns the target window border.
122
123 @return: the target window border.
124 """
125 return self._targetBorder
126
127
129 """Returns the target window height or -1 if not set.
130
131 @return: the target window height.
132 """
133 return -1 if self._targetHeight < 0 else self._targetHeight
134
135
137 """Returns the target window name. Empty name of null implies
138 that the target is opened to the window containing the link.
139
140 @return: the target window name.
141 """
142 return self._targetName
143
144
146 """Returns the target window width or -1 if not set.
147
148 @return: the target window width.
149 """
150 return -1 if self._targetWidth < 0 else self._targetWidth
151
152
164
165
167 """Sets the target window height.
168
169 @param targetHeight:
170 the targetHeight to set.
171 """
172 self._targetHeight = targetHeight
173 self.requestRepaint()
174
175
177 """Sets the target window name.
178
179 @param targetName:
180 the targetName to set.
181 """
182 self._targetName = targetName
183 self.requestRepaint()
184
185
187 """Sets the target window width.
188
189 @param targetWidth:
190 the targetWidth to set.
191 """
192 self._targetWidth = targetWidth
193 self.requestRepaint()
194
195
197 """Returns the resource this link opens.
198
199 @return: the Resource.
200 """
201 return self._resource
202
203
205 """Sets the resource this link opens.
206
207 @param resource:
208 the resource to set.
209 """
210 self._resource = resource
211 self.requestRepaint()
212