【源码】findjobj函数——查找Matlab图形对象的Java句柄

二叶草 2020年2月14日21:31:01函数代码评论阅读模式

 查找Java容器Matlab GUI句柄中包含的所有Java对象

Find all java objects contained within a java container or Matlab GUI handle

如果没有指定输出参数,那么将显示一个交互式GUI窗口,其中包含所有容器组件、属性和回调的树视图。

If no output parameter is specified, then an interactive GUI window will be displayed with a tree-view of all container components, their properties and callbacks.

本函数的使用语法:

[handles,levels,parentIds,listing] = findjobj(container,'PropName',PropValue(s),...)

输入:

Inputs:

- container:可选的GUI句柄,如果没有指定,则使用当前图形界面。

- container - optional GUI handle. If unsupplied then current figure will be used

- 'PropName',PropValue:不区分大小写属性对的可选列表。

- 'PropName',PropValue - optional list of case insensitive property pairs. PropName may also be named -PropName.

Supported properties:

- 'position' - filter results based on those elements that contain the specified X,Y position or a java element

Note: specify a Matlab position (X,Y = pixels from bottom left corner), not a java one

- 'size' - filter results based on those elements that have the specified W,H (in pixels)

- 'class' - filter results based on those elements that contain the substring (or java class) PropValue

Note: filtering is case insensitive and relies on regexp, so you can pass wildcards etc.

- 'property' - filter results based on elements that possess the specified case-insensitive property string or have property values in cell array format: {'propName', 'propValue'}. Example: findjobj(...,'property', {'Text','click me'})

- 'depth' - filter results based on specified depth. 0=top-level, Inf=all levels (default=Inf)

- 'flat' - same as: 'depth',0

- 'not' - negates the following filter: 'not','class','c' returns all elements EXCEPT those with class 'c'

- 'persist' - persist figure components information, allowing much faster results for subsequent invocations

- 'print' - display all java elements in a hierarchical list

Note1: optional PropValue of element index or handle to java container

Note2: normally this option would be placed last, after all filtering is complete.

- 'list' - same as 'print'

输出:

Outputs:

- handles:Java元素句柄列表

- handles - list of handles to java elements

- levels:Java元素的对应层次结构列表(top=0)

- levels - list of corresponding hierarchy level of the java elements (top=0)

- parentIds:对应Java元素父容器的索引列表(未经过滤的句柄)

- parentIds - list of indexes (in unfiltered handles) of the parent container of the corresponding java element

- listing:“print”/“list”选项的结果(如果未指定“print”/“list”,则为空)

- listing - results of 'print'/'list' options (empty if 'print'/'list' were unspecified)

使用举例:

>> hButton = uicontrol('string','click me');

>> jButton = findjobj(hButton,'nomenu'); % or: jButton = findjobj('property',{'Text','click me'});

>> jButton.setFlyOverAppearance(1);

>> jButton.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));

>> set(jButton,'FocusGainedCallback',@myMatlabFunction); % some 30 callback points available...

>> jButton.get; % list all changeable properties...

>> hEditbox = uicontrol('style',edit');

>> jEditbox = findjobj(hEditbox,'nomenu');

>> jEditbox.setCaretColor(java.awt.Color.red);

>> jEditbox.KeyTypedCallback = @myCallbackFunc; % many more callbacks where this came from...

>> jEdit.requestFocus;

(Many more examples in the utility's help section)

需要注意的问题:

无法处理多个容器对象,一次只能处理一个

- Cannot currently process multiple container objects - just one at a time

当图形中包含许多UI组件时,初始处理速度会稍慢(因此最好使用“persist”)

- Initial processing is a bit slow when the figure is laden with many UI components (so better use 'persist')

目前按照位置+大小查找传递容器的Matlab句柄:应该可以找到更好的方法来实现

- Passing a container Matlab handle is currently found by position+size: should find a better way to do this

标签在Java中只有一个只写文本属性,所以不能使用“属性”、“文本”、“字符串”来表示

- Labels have a write-only text property in java, so can't be found using 'property',{'Text','string'} notation

本文来源于:【源码】findjobj函数——查找Matlab图形对象的Java句柄-变化吧门户
特别声明:以上文章内容仅代表作者本人观点,不代表变化吧门户观点或立场。如有关于作品内容、版权或其它问题请于作品发表后的30日内与变化吧联系。

  • 赞助本站
  • 微信扫一扫
  • weinxin
  • 加入Q群
  • QQ扫一扫
  • weinxin
二叶草
Go语言中的常量 函数代码

Go语言中的常量

1 概述 常量,一经定义不可更改的量。功能角度看,当出现不需要被更改的数据时,应该使用常量进行存储,例如圆周率。从语法的角度看,使用常量可以保证数据,在整个运行期间内,不会被更改。例如当前处理器的架构...
Go语言的接口 函数代码

Go语言的接口

Go语言-接口 在Go语言中,一个接口类型总是代表着某一种类型(即所有实现它的类型)的行为。一个接口类型的声明通常会包含关键字type、类型名称、关键字interface以及由花括号包裹的若干方法声明...
Go语言支持的正则语法 函数代码

Go语言支持的正则语法

1 字符 语法 说明 . 任意字符,在单行模式(s标志)下,也可以匹配换行 字符类 否定字符类 d Perl 字符类 D 否定 Perl 字符类 ASCII 字符类 否定 ASCII 字符类 pN U...
Go语言的包管理 函数代码

Go语言的包管理

1 概述 Go 语言的源码复用建立在包(package)基础之上。包通过 package, import, GOPATH 操作完成。 2 main包 Go 语言的入口 main() 函数所在的包(pa...

发表评论