Lao Li Recommendation: 14th Chapter 8 "Monkeyrunner Source Analysis" Hierarchyviewer implementation principle-get the control list and build the control tree 4

Source: Internet
Author: User

Note here the differences between the parent control node and the children that point to the child control node, children points to the list of Viewnode types. Why is that? It is simple: Father only one, son can have multiple.

With these as a cushion, we can look back at the "code 14-8-4 bridgedevice-parseviewhierarchy" 430 line to create a Viewnode process:

CurrentNode = new Viewnode (window, CurrentNode, line.substring (depth));

Code 14-8-7 bridgedevice-parseviewhierarchy-Creating Viewnode

We go into the Viewnode constructor:

119 Public viewnode (Window window, viewnode parent, String data)

120 {

121 This.window = window;

122 this.parent = parent;

123 This.index = (this.parent = = null?)  0: this.parent.children.size ());

124 if (this.parent! = null) {

This.parent.children.add (this);

126}

127 int delimindex = data.indexof (' @ ');

if (Delimindex < 0) {

129 Throw new IllegalArgumentException ("Invalid format for Viewnode, missing @:" + data);

130}

131 this.name = data.substring (0, Delimindex);

data = data.substring (Delimindex + 1);

133 Delimindex = Data.indexof (");

134 This.hashcode = data.substring (0, Delimindex);

135

136 if (Data.length () > Delimindex + 1) {

137 loadProperties (data.substring (Delimindex + 1). Trim ());

138}

139 Else {

this.id = "Unknown";

141 this.width = (this.height = 10);

142}

143

144 This.measuretime =-1.0D;

145 this.layouttime =-1.0D;

146 this.drawtime =-1.0D;

147}

Code 14-8-8 viewnode-Constructors

The main thing that the whole constructor basically does is that it has something to do with the line of control information returned by Viewserver, essentially parsing the string and then giving Viewnode the corresponding attributes to save:

    • 121-122 Line: First, the incoming window representing the top of the entire screen to obtain the focus of Windows instance and the parent node of this control node to save
    • 124-126 rows: If the current newly created Viewnode instance is not the root control node, add yourself to the parent control's children list, allowing the parent control to find its own
    • 127-134 rows: Resolves the control name and its corresponding hash value from the control string information and saves it. This information is at the front of the control information line, and is separated by the symbol @, you do not remember the words please go back to see "Figure 13-6-1 Noteslist Control List", here is listed as an example "[email protected]"
    • 137 Rows: Call the Member method of Viewnode itself loadproperties to resolve the remaining properties of the control string.

So let's go down and look at the rest of the control property is how to parse out, loadproperties This method is a bit long, we take it as a matter of slow analysis, first look at the first part:

168 Private void loadProperties (String data) {

169 int start = 0;

A Boolean stop;

171 do {

172 int index = data.indexof (' = ', start);

173 Property = new Property ();

174 property.name = data.substring (start, index);

175

176 int index2 = Data.indexof (', ', index + 1);

177 int length = Integer.parseint (data.substring (index + 1, index2));

178 start = Index2 + 1 + length;

179 Property.Value = data.substring (Index2 + 1, index2 + 1 + length);

180

181 This.properties.add (property);

182 this.namedProperties.put (Property.Name, property);

183

184 stop = start >= data.length ();

185 if (!stop) {

186 start++;

187}

188} while (!stop);

...

}

Code 14-8-9 viewnode-loadproperties-Getting control properties

Lao Li Recommendation: 14th Chapter 8 "Monkeyrunner Source Analysis" Hierarchyviewer implementation principle-get the control list and build the control tree 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.