我正在使用Justinmind的API来开发插件。我需要的基本上是通过ID找到一个元素,但是,当我搜索整个文档时,API似乎没有像findById()这样的方法。我想我必须创建一个方法。在这里,我解释了问题的细节和一般结构在Justinmind,虽然这个问题并不是专门针对Justinmind的。
假设我有以下页面布局:

我将在Justinmind中设计这个页面,如下所示:
Screen
----Image
----Group
--------Button
------------Image
------------Label
--------Button
------------Image
------------Label
--------Button
------------Image
------------Label
--------Button
------------Image
------------Label
--------Button
------------Image
------------Label
--------Button
------------Image
------------Label
----Text
----Text
----Text在Justinmind中,屏幕是一个ICanvas对象。我将屏幕存储在myScreen变量中。然后,getApiRoot()返回页面的最顶层组件。之后,每个组件都是子组件,可以通过getApiChildren()方法访问。
List<IComponent> components = myScreen.getApiRoot().getApiChildren();以上代码返回图像、组和文本,即一阶高耳组件。例如,我可以访问第一个按钮的标签(概述)如下:
IComponent group = components.get(1); //Returns the Group
IComponent button1 = group.getApiChildren().get(0); //Returns the first button group, which is the first child of group
IComponent label1 = button1.getApiChildren().get(1); //Returns the label, which is the second child of the first button group正如您所看到的,我总是通过getApiChildren()方法访问组件。这在大而动态的页面中是不可行的。例如,因为我正在编写的插件会在按钮组中缺少标签时发出警报。为了检查标签的存在,我必须使用getApiChildren()方法遍历屏幕的所有组件。
我可以用一棵树来表示:

然而,这种结构总是会改变的。我应该建一棵树还是一个hashmap?在非常复杂的对象中找到对象的最佳方法是什么?
发布于 2016-06-17 09:24:42
我不知道我只是在想。但是,如果在java中有一个复杂对象的图形,您可以尝试这个库http://commons.apache.org/proper/commons-jxpath/并使用XPATH来指定查询。
https://stackoverflow.com/questions/37877501
复制相似问题