📄 uiinspect.m
字号:
newData = '';
elseif isnumeric(data) || islogical(data) || any(ishandle(data)) || numel(data) > 1 %&& ~isscalar(data)
newData = ['[' newData ']'];
end
data = newData;
elseif ~isempty(data)
data = ['''' data ''''];
end
%end % charizeData
%% Prepare the callbacks pane
function [callbacksPanel, callbacksTable] = getCbsPane(obj, stripStdCbsFlag)
% Prepare the callbacks pane
import java.awt.* javax.swing.*
callbacksPanel = JPanel(BorderLayout);
[cbData, cbHeaders, cbTableEnabled] = getCbsData(obj, stripStdCbsFlag);
try
% Use JideTable if available on this system
%callbacksTableModel = javax.swing.table.DefaultTableModel(cbData,cbHeaders); %#ok
%callbacksTable = eval('com.jidesoft.grid.PropertyTable(callbacksTableModel);'); % prevent JIDE alert by run-time (not load-time) evaluation
callbacksTable = eval('com.jidesoft.grid.TreeTable(cbData,cbHeaders);'); % prevent JIDE alert by run-time (not load-time) evaluation
callbacksTable.setRowAutoResizes(true);
callbacksTable.setColumnAutoResizable(true);
callbacksTable.setColumnResizable(true);
jideTableUtils = eval('com.jidesoft.grid.TableUtils;'); % prevent JIDE alert by run-time (not load-time) evaluation
jideTableUtils.autoResizeAllColumns(callbacksTable);
callbacksTable.setTableHeader([]); % hide the column headers since now we can resize columns with the gridline
callbacksLabel = JLabel(' Callbacks:'); % The column headers are replaced with a header label
callbacksLabel.setForeground(Color.blue);
%callbacksPanel.add(callbacksLabel, BorderLayout.NORTH);
% Add checkbox to show/hide standard callbacks (only if not a HG handle)
callbacksTopPanel = JPanel;
callbacksTopPanel.setLayout(BoxLayout(callbacksTopPanel, BoxLayout.LINE_AXIS));
callbacksTopPanel.add(callbacksLabel);
hgHandleFlag = 0; try hgHandleFlag = ishghandle(obj); catch, end %#ok
if ~hgHandleFlag && ~iscom(obj)
callbacksTopPanel.add(Box.createHorizontalGlue);
jcb = JCheckBox('Hide standard callbacks', stripStdCbsFlag);
set(jcb, 'ActionPerformedCallback',@cbHideStdCbs_Callback, 'userdata',callbacksTable, 'tooltip','Hide standard Swing callbacks - only component-specific callbacks will be displayed');
callbacksTopPanel.add(jcb);
end
callbacksPanel.add(callbacksTopPanel, BorderLayout.NORTH);
catch
% Otherwise, use a standard Swing JTable (keep the headers to enable resizing)
callbacksTable = JTable(cbData,cbHeaders);
end
set(callbacksTable, 'userdata',obj);
if iscom(obj)
cbToolTipText = '<html> Callbacks may be ''string'' or @funcHandle';
else
cbToolTipText = '<html> Callbacks may be ''string'', @funcHandle or {@funcHandle,arg1,...}';
end
%cbToolTipText = [cbToolTipText '<br> {Cell} callbacks are displayed as: [Ljava.lang...'];
callbacksTable.setToolTipText(cbToolTipText);
%callbacksTable.setGridColor(inspectorTable.getGridColor);
cbNameTextField = JTextField;
cbNameTextField.setEditable(false); % ensure that the callback names are not modified...
cbNameCellEditor = DefaultCellEditor(cbNameTextField);
cbNameCellEditor.setClickCountToStart(intmax); % i.e, never enter edit mode...
callbacksTable.getColumnModel.getColumn(0).setCellEditor(cbNameCellEditor);
if ~cbTableEnabled && callbacksTable.getColumnModel.getColumnCount>1
callbacksTable.getColumnModel.getColumn(1).setCellEditor(cbNameCellEditor);
end
set(callbacksTable.getModel, 'TableChangedCallback',@tbCallbacksChanged, 'UserData',obj);
cbScrollPane = JScrollPane(callbacksTable);
cbScrollPane.setVerticalScrollBarPolicy(cbScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
callbacksPanel.add(cbScrollPane, BorderLayout.CENTER);
callbacksPanel.setToolTipText(cbToolTipText);
%end % getCbsPane
%% Prepare the methods pane
function methodsPane = getMethodsPane(methodsObj, obj)
import java.awt.* javax.swing.*
methodsPane = JPanel(BorderLayout);
% Get superclass if possible
superclass = '';
interfaces = '';
scSep = '';
try
if isjava(obj)
thisClass = obj.getClass;
try superclass = char(thisClass.getSuperclass.getCanonicalName); catch, end %#ok
interfaces = cellfun(@(c)char(toString(c.getName)),thisClass.getInterfaces.cell,'un',0);
elseif ischar(obj)
try
thisClass = java.lang.Class.forName(obj);
try superclass = char(thisClass.getSuperclass.getCanonicalName); catch, end %#ok
interfaces = cellfun(@(c)char(toString(c.getName)),thisClass.getInterfaces.cell,'un',0);
catch
% never mind...
end
end
catch
% never mind...
end
if ~isempty(superclass)
superclass = [' (superclass: ' superclass ')'];
scSep = ' <br> ';
end
% Add a label
if ischar(obj)
className = char(thisClass.toString);
className = regexprep(className,' ([^ ]+$)',' <b>$1');
else
className = ['class <b>' builtin('class',obj)];
end
labelStr = ['<html> Methods of ' className '</b>'];
methodsLabel = JLabel([labelStr superclass]);
toolTipStr = ['<html> ' labelStr scSep superclass];
if ~isempty(interfaces) && iscell(interfaces)
scSep = ' <br> ';
toolTipStr = [toolTipStr scSep ' implements: '];
if length(interfaces) > 1, toolTipStr=[toolTipStr scSep ' ']; end
for intIdx = 1 : length(interfaces)
if intIdx>1, toolTipStr=[toolTipStr scSep ' ']; end %#ok grow
toolTipStr = [toolTipStr interfaces{intIdx}]; %#ok grow
end
end
methodsLabel.setToolTipText(toolTipStr);
methodsLabel.setForeground(Color.blue);
methodsPane.add(methodsLabel, BorderLayout.NORTH);
% Method A: taken from Matlab's methodsview function (slightly modified)
%{
ncols = length(methodsObj.widths);
b = com.mathworks.mwt.MWListbox;
b.setColumnCount(ncols);
wb = 0;
for i=1:ncols,
wc = 7.5 * methodsObj.widths(i);
b.setColumnWidth(i-1, wc);
b.setColumnHeaderData(i-1, methodsObj.headers{i});
wb = wb+wc;
end;
co = b.getColumnOptions;
set(co, 'HeaderVisible', 'on');
set(co, 'Resizable', 'on');
b.setColumnOptions(co);
set(b.getHScrollbarOptions,'Visibility','Always'); %Yair: fix HScrollbar bug
ds = javaArray('java.lang.String', ncols);
for i=1:size(methodsObj.methods,1)
for j=1:ncols
ds(j) = java.lang.String(methodsObj.methods{methodsObj.sortIdx(i),j});
end;
b.addItem(ds);
end;
%}
% Method B: use a JTable - looks & refreshes much better...
try
com.mathworks.mwswing.MJUtilities.initJIDE;
b = eval('com.jidesoft.grid.TreeTable(methodsObj.methods(methodsObj.sortIdx,:), methodsObj.headers);'); % prevent JIDE alert by run-time (not load-time) evaluation
b.setRowAutoResizes(true);
b.setColumnAutoResizable(true);
b.setColumnResizable(true);
jideTableUtils = eval('com.jidesoft.grid.TableUtils;'); % prevent JIDE alert by run-time (not load-time) evaluation
jideTableUtils.autoResizeAllColumns(b);
catch
b = JTable(methodsObj.methods(methodsObj.sortIdx,:), methodsObj.headers);
end
% Hide the column header if only one column is shown
if length(methodsObj.headers) < 2
b.setTableHeader([]); % hide the column headers since now we can resize columns with the gridline
end
b.setShowGrid(0);
scroll = JScrollPane(b);
scroll.setVerticalScrollBarPolicy(scroll.VERTICAL_SCROLLBAR_AS_NEEDED);
scroll.setHorizontalScrollBarPolicy(scroll.HORIZONTAL_SCROLLBAR_AS_NEEDED);
b.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
b.setAutoResizeMode(b.AUTO_RESIZE_SUBSEQUENT_COLUMNS)
%b.setEnabled(0);
cbNameTextField = JTextField;
cbNameTextField.setEditable(false); % ensure that the callback names are not modified...
cbNameCellEditor = DefaultCellEditor(cbNameTextField);
cbNameCellEditor.setClickCountToStart(intmax); % i.e, never enter edit mode...
for colIdx = 1:length(methodsObj.headers)
b.getColumnModel.getColumn(colIdx-1).setCellEditor(cbNameCellEditor);
end
% Attach the listbox to the methods panel
methodsPane.add(scroll, BorderLayout.CENTER);
%end % getMethodsPane
%% Prepare the children pane (Display additional props that are not inspectable by the inspector)
function othersPane = getChildrenPane(obj, inspectorTable)
import java.awt.* javax.swing.*
% Label
othersLabel = JLabel(' Other properties');
othersLabel.setForeground(Color.blue);
othersLabel.setToolTipText('Properties not inspectable by the inspect table above');
ud.othersLabel = othersLabel;
othersPane = JPanel(BorderLayout);
%othersPane.add(othersLabel, BorderLayout.NORTH);
% Data table
[propsData, propsHeaders] = getPropsData(obj, false, false, inspectorTable);
try
% Use JideTable if available on this system
%propsTableModel = javax.swing.table.DefaultTableModel(cbData,cbHeaders); %#ok
%propsTable = eval('com.jidesoft.grid.PropertyTable(propsTableModel);'); % prevent JIDE alert by run-time (not load-time) evaluation
propsTable = eval('com.jidesoft.grid.TreeTable(propsData,propsHeaders);'); % prevent JIDE alert by run-time (not load-time) evaluation
propsTable.setRowAutoResizes(true);
propsTable.setColumnAutoResizable(true);
propsTable.setColumnResizable(true);
jideTableUtils = eval('com.jidesoft.grid.TableUtils;'); % prevent JIDE alert by run-time (not load-time) evaluation
jideTableUtils.autoResizeAllColumns(propsTable);
%propsTable.setTableHeader([]); % hide the column headers since now we can resize columns with the gridline
catch
% Otherwise, use a standard Swing JTable (keep the headers to enable resizing)
propsTable = JTable(propsData,propsHeaders);
end
%propsToolTipText = '<html> Callbacks may be ''strings'' or {@myFunc,arg1,...}';
%propsTable.setToolTipText(propsToolTipText);
%propsTable.setGridColor(inspectorTable.getGridColor);
propNameTextField = JTextField;
propNameTextField.setEditable(false); % ensure that the prop names are not modified...
propNameCellEditor = DefaultCellEditor(propNameTextField);
propNameCellEditor.setClickCountToStart(intmax); % i.e, never enter edit mode...
propsTable.getColumnModel.getColumn(0).setCellEditor(propNameCellEditor);
ud.obj = obj;
ud.inspectorTable = inspectorTable;
set(propsTable.getModel, 'TableChangedCallback',@tbPropChanged, 'UserData',ud);
scrollPane = JScrollPane(propsTable);
scrollPane.setVerticalScrollBarPolicy(scrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
%scrollPane.setHorizontalScrollBarPolicy(scrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
othersPane.add(scrollPane, BorderLayout.CENTER);
% Add checkbox to show/hide meta-data & inspectable properties
othersTopPanel = JPanel;
othersTopPanel.setLayout(BoxLayout(othersTopPanel, BoxLayout.LINE_AXIS));
othersTopPanel.add(othersLabel);
othersTopPanel.add(Box.createHorizontalGlue);
jcb = JCheckBox('Meta-data', 0);
set(jcb, 'ActionPerformedCallback',@updatePropsTable, 'userdata',propsTable, 'tooltip','Also show property meta-data (type, visibility, get/set availability, etc.)');
ud.cbMetaData = jcb;
othersTopPanel.add(jcb);
jcb = JCheckBox('Inspectable', 0);
set(jcb, 'ActionPerformedCallback',@updatePropsTable, 'userdata',propsTable, 'tooltip','Also show inspectable properties (displayed in the table above)');
ud.cbInspected = jcb;
othersTopPanel.add(jcb);
othersPane.add(othersTopPanel, BorderLayout.NORTH);
% Preserve persistent info in the propsTable's userdata
set(propsTable, 'userdata',ud);
%end % getChildrenPane
%% "dbstop if error" causes inspect.m to croak due to a bug - so workaround by temporarily disabling this dbstop
function identifiers = disableDbstopError
dbStat = dbstatus;
idx = find(strcmp({dbStat.cond},'error'));
identifiers = [dbStat(idx).identifier];
if ~isempty(idx)
dbclear if error;
msgbox('''dbstop if error'' had to be disabled due to a Matlab bug that would have caused Matlab to crash.', 'FindJObj', 'warn');
end
%end % disableDbstopError
%% Restore any previous "dbstop if error"
function restoreDbstopError(identifiers) %#ok unused
for itemIdx = 1 : length(identifiers)
eval(['dbstop if error ' identifiers{itemIdx}]);
end
%end % restoreDbstopError
%% Strip standard Swing callbacks from a list of events
function evNames = stripStdCbs(evNames)
try
stdEvents = {'AncestorAdded', 'AncestorMoved', 'AncestorRemoved', 'AncestorResized', ...
'CaretPositionChanged', 'ComponentAdded', 'ComponentRemoved', ...
'ComponentHidden', 'ComponentMoved', 'ComponentResized', 'ComponentShown', ...
'PropertyChange', 'FocusGained', 'FocusLost', ...
'HierarchyChanged', 'InputMethodTextChanged', ...
'KeyPressed', 'KeyReleased', 'KeyTyped', ...
'MouseClicked', 'MouseDragged', 'MouseEntered', 'MouseExited', ...
'MouseMoved', 'MousePressed', 'MouseReleased', 'MouseWheelMoved', ...
'VetoableChange'};
evNames = setdiff(evNames,strcat(stdEvents,'Callback'))';
catch
% Never mind...
disp(lasterr); rethrow(lasterror)
end
%end % stripStdCbs
%% Callback function for <Hide standard callbacks> checkbox
function cbHideStdCbs_Callback(src, evd, varargin)
try
% Update callbacks table data according to the modified checkbox state
callbacksTable = get(src,'userdata');
obj = get(callbacksTable, 'userdata');
[cbData, cbHeaders] = getCbsData(obj, evd.getSource.isSelected);
callbacksTableModel = javax.swing.table.DefaultTableModel(cbData,cbHeaders);
set(callbacksTableModel, 'TableChangedCallback',@tbCallbacksChanged, 'UserData',handle(obj,'CallbackProperties'));
callbacksTable.setModel(callbacksTableModel)
try
% Try to auto-resize the columns
callbacksTable.setRowAutoResizes(true);
jideTableUtils = eval('com.jidesoft.grid.TableUtils;'); % prevent JIDE alert by run-time (not load-time) evaluation
jideTableUtils.autoResizeAllColumns(callbacksTable);
catch
% JIDE is probably unavailable - never mind...
end
catch
% Never mind...
%disp(lasterr); rethrow(lasterror)
end
%end % cbHideStdCbs_Callback
%% Update the properties table following a checkbox modification
function updatePropsTable(src, evd, varargin) %#ok partially unused
try
% Update callbacks table data according to the modified checkbox state
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -