logo资料库

Undocumented Secrets of MATLAB-Java Programming 原版pdf 无封面 by Altman.pdf

第1页 / 共671页
第2页 / 共671页
第3页 / 共671页
第4页 / 共671页
第5页 / 共671页
第6页 / 共671页
第7页 / 共671页
第8页 / 共671页
资料共671页,剩余部分请下载后查看
Contents
Preface
Book Organization
A Quick Q&A
Conventions Used in This Book
Disclaimer and Warning
Chapter 1 Introduction to Java in Matlab®
1.1 Creating Java Objects
1.1.1 The Basics
1.1.2 Accessing Java Objects
1.1.3 Memory Usage
1.2 Java Object Properties
1.3 Java Object Methods and Actions
1.4 Java Events and MATlAB Callbacks31
1.5 Safe Java Programming in MATlAB — A How- to Guide
1.6 Compiling and Debugging User- Created Java Classes in MATlAB
1.7 Compatibility Issues
1.8 Java Versions in MATlAB
1.8.1 Pre- Bundled JVM Versions
1.8.2 Configuring MATlAB to Use a Different JVM
1.9 Java.opts
Chapter 2 Using Non-GUI Java libraries in Matlab®
2.1 Complex Data Structures
2.1.1 Java Collections
2.1.2 Collections Example: Hashtable
2.1.3 Enumerators
2.2 Database Connectivity
2.2.1 Using Java Database Connectivity ( JDBC) in MATlAB
2.2.2 Initializing the JDBC Driver
2.2.3 Connecting to a Database
2.2.4 Sending SQl Requests
2.2.5 Handling SQl Result Sets
2.3 Miscellaneous Other Uses
2.4 A Short Pause for Reflection
References
Chapter 3 Rich GUI Using Java Swing
3.1 Adding Java Swing Components to MATlAB Figures
3.1.1 The javacomponent Function5
3.1.2 The Swing Component library
3.1.3 Displaying Swing- Derived Components
3.1.4 UIComponent and JControl
3.2 MATlAB's Main Thread and the Event Dispatch Thread ( EDT)
3.3 Customizing Java Components
3.3.1 Component Properties and Methods
3.3.2 look- and- Feel
3.3.3 HTMl Support
3.3.4 Focus Traversal60
3.4 Component Callbacks
3.5 Using Third- Party libraries in MATlAB
3.5.1 JFreeChart and Other Charting libraries93
3.5.2 JFreeReport and Other Reporting libraries
3.5.3 JGraph and Other Visualization libraries
3.5.4 ImageJ and Other Image- Processing libraries
3.5.5 Swing Extension Class libraries
3.5.6 A Note of Caution
3.6 System- Tray Icons
3.7 Drag- and- Drop
3.7.1 Data Transfer Mechanism in MATlAB
3.7.2 A Sample MATlAB Application That Supports DND
3.8 Adding MATlAB Components to Java Swing Containers
3.9 Alternatives to Swing
References
Chapter 4 Uitools
4.1 Uitable
4.1.1 Customizing Uitable
4.1.2 Table Callbacks
4.1.3 Customizing Scrollbars, Column Widths, and Selection Behavior
4.1.4 Data Sorting and Filtering
4.1.5 JIDE Customizations
4.1.6 Controlling Table Structure ( Adding/ Deleting Rows)
4.1.7 Final Remarks
4.2 Uitree
4.2.1 Customizing Uitree
4.2.2 Accessing Tree Nodes
4.2.3 Controlling Tree Nodes
4.2.4 Customizing Tree Nodes
4.2.5 FindJObj
4.3 Uitab
4.3.1 Customizing Tabs at the Java level
4.3.2 Tabdlg and Other Alternatives
4.4 Uiundo
4.5 Toolbars
4.5.1 Uitoolfactory
4.5.2 Other Undocumented Toolbar Functions
4.5.3 Customizing Toolbars at the Java level
4.5.4 Uisplittool and Uitogglesplittool
4.5.5 Adding Undo/ Redo Toolbar Buttons
4.6 Menus
4.6.1 Accessing Menu Items
4.6.2 Customizing Menus via Uitools
4.6.3 Customizing Menus via HTMl
4.6.4 Customizing Menus via Java
4.7 Status Bar
References
Chapter 5 built-In Matlab® Widgets and Java Classes
5.1 Internal MATlAB Java Packages
5.1.1 Inspecting Package Contents
5.1.2 Inspecting an Internal MATlAB Class
5.1.3 Standard MATlAB Packages
5.2 MWSwing Package
5.2.1 Enhancements of Standard Java Swing Controls
5.2.2 Entirely New Java Controls
5.2.3 Other MWSwing Controls
5.3 MWT Package
5.4 MlWidgets Package
5.4.1 Color- Selection Components83
5.4.2 Plot- Type Selection Components
5.5 Widgets Package
5.5.1 Widget Components
5.5.2 Font- Selection Components
5.5.3 Dialogs
5.5.4 Closable ( Collapsible) Panels
5.5.5 Specialized Widgets
5.6 MlServices Package
5.7 JIDE
5.7.1 Important JIDE Classes
5.7.2 JIDE Grids
5.7.3 MATlAB's PropertyInspector121
5.7.4 JIDE's PropertyTable
5.7.5 Nonstandard Property Renderers and Editors135
5.7.6 Nested Properties
5.7.7 Trapping Property Change Events
5.7.8 Date- Selection Components146
5.8 Miscellaneous Other Internal Classes
5.8.1 logging Utilities
5.8.2 JGoodies
5.8.3 Additional Others
References
Chapter 6 Customizing Matlab® Controls
6.1 PushButton
6.2 ToggleButton
6.3 RadioButton
6.4 Checkbox
6.5 Editbox
6.5.1 Single- line Editbox
6.5.2 Multi- line Editbox
6.5.3 The JEditorPane Alternative
6.6 listbox
6.6.1 The listbox Data Model
6.6.2 Customizing the Appearance of listbox Items
6.6.3 Dynamic ( Item- Specific) Context- Menus and Tooltips
6.7 Popup Menu ( a. k. a. Drop- Down, Combo- Box)
6.8 Slider
6.9 Text label
6.10 Frame
6.11 Uipanel
6.12 Tooltipsƒ
6.12.1 Displaying a Tooltip on Disabled Controls95
6.12.2 Displaying a Tooltip on Truncated Text
6.12.3 Controlling Tooltip Timing
6.12.4 Displaying a Tooltip on Inactive Controls97
References
Chapter 7 the Java Frame
7.1 Java Frame Properties and Methods
7.1.1 Window Minimization and Maximization
7.1.2 Docking and Undocking
7.1.3 UI- Related JavaFrame Properties
7.1.4 Miscellaneous Other JavaFrame Properties
7.2 FindJObj and the Java Frame Components Hierarchy
7.2.1 FindJObj
7.2.2 Finding the Underlying Java Object of a MATlAB Control
7.2.3 GUI for Displaying Container Hierarchy, Properties, and Callbacks
7.2.4 The Java Frame Container Hierarchy
7.3 Important Java Frame Containers
7.3.1 AxisCanvas
7.3.2 FigureComponentContainer
7.3.3 Component's Private Container
7.3.4 FigurePanel or ContainerFactory
7.3.5 DTToolBarContainer
7.3.6 FigureMenuBar and Docking Controls
7.3.7 FigureFrame
7.4 BeanAdapters
References
Chapter 8 the Matlab® Desktop
8.1 Desktop Functionality and layout
8.1.1 The Java Desktop Object
8.1.2 The Desktop Frame
8.1.3 Organizing the Desktop Clients
8.1.4 Customizing the Desktop Toolbars
8.2 System Preferences23
8.3 Command Window
8.3.1 Controlling Command Window Colors
8.3.2 Help Popup and Integrated Browser Controls
8.3.3 Modifying the Command Window Prompt
8.3.4 Tab Completions
8.3.5 Additional Command Window Uses
8.4 Editor
8.4.1 The EditorServices/ matlab. desktop. editor Object
8.4.2 The Editor Frame Object
8.5 Keyboard Bindings
8.5.1 Inserting/ Replacing Text
8.5.2 Running Action Macros
8.5.3 Running Built- In Actions
8.6 Workspace
8.7 Other Desktop Tools
8.7.1 Profiler
8.7.2 Find- Files Dialog
8.7.3 GUIDE
8.7.4 Variable ( Array) Editor
References
Chapter 9 Using Matlab® from within Java
9.1 Approaches for Java Control of MATlAB
9.1.1 Controlling the MATlAB GUI
9.1.2 Controlling the MATlAB Engine
9.1.3 Controlling a MATlAB Session from Another MATlAB Session
9.1.4 Running or Modifying MATlAB Code without MATlAB
9.1.5 MATlAB Clones Written in Java
9.2 JMI — Java- to- MATlAB Interface62
9.2.1 com. mathworks. jmi. Matlab
9.2.2 Other Interesting JMI Classes
9.3 JMI Wrapper — local MatlabControl77
9.3.1 local and Remote MatlabControl
9.3.2 localMatlabProxy
9.3.3 Some Usage Examples
9.4 JMI Wrapper — Remote MatlabControl91
9.4.1 Remote Control of MATlAB
9.4.2 A Simple RemoteExample
9.4.3 Parsing MATlAB's Return Values
9.5 Using JNI to Connect Java and MATlAB
References
Chapter 10 Putting It all together
10.1 UISplitPane1
10.1.1 Technical Description
10.1.2 Source- Code listing
10.2 Integration Debriefing System
10.2.1 Data Setup
10.2.2 Defining Data Items and Events
10.2.3 Defining Analyses
10.2.4 Defining Reports
10.2.5 Displaying Analysis Results
10.3 Concluding Exercise: UIMultilistbox
Appendix A: What Is Java?
Appendix B: Udd
Appendix C: Open Questions
Index
K13163_Book.indb 3 11/8/2011 8:06:12 PM © 2012 by Taylor & Francis Group, LLC
MATLAB® is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks does not warrant the accuracy of the text or exercises in this book. This book’s use or discussion of MATLAB® software or related products does not consti- tute endorsement or sponsorship by The MathWorks of a particular pedagogical approach or particular use of the MATLAB® software. CRC Press Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300 Boca Raton, FL 33487-2742 © 2012 by Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Version Date: 20111004 International Standard Book Number-13: 978-1-4398-6904-8 (eBook - PDF) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material repro- duced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copy- right.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identifica- tion and explanation without intent to infringe. Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com © 2012 by Taylor & Francis Group, LLC
Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Chapter 1 Introduction to Java in Matlab® . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 .1 Creating Java Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 1 .1 .1 the basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 1 .1 .2 accessing Java Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 1 .1 .3 Memory Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Java Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Java Object Methods and actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Java Events and Matlab Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Safe Java Programming in Matlab — a How-to Guide . . . . . . . . . . . . . . . . . . . . . . . . . .24 Compiling and Debugging User-Created Java Classes in Matlab . . . . . . . . . . . . . . . . . .27 Compatibility Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Java Versions in Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Pre-bundled JVM Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 1 .8 .1 1 .8 .2 Configuring Matlab to Use a Different JVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 1 .9 Java.opts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48 1 .2 1 .3 1 .4 1 .5 1 .6 1 .7 1 .8 Chapter Using Non-GUI Java libraries in Matlab® . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 2 2 .1 2 .2 Complex Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Java Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 2 .1 .1 2 .1 .2 Collections Example: Hashtable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2 .1 .3 Enumerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60 Database Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Using Java Database Connectivity (JDbC) in Matlab . . . . . . . . . . . . . . . . . . . . . 62 2 .2 .1 2 .2 .2 Initializing the JDbC Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 2 .2 .3 Connecting to a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65 Sending SQl Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66 2 .2 .4 2 .2 .5 Handling SQl Result Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Miscellaneous Other Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 2 .3 2 .4 a Short Pause for Reflection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73 K13163_Book.indb 9 11/8/2011 8:06:13 PM ix © 2012 by Taylor & Francis Group, LLC
x Contents Chapter Rich GUI Using Java Swing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 3 3 .1 3 .3 .1 3 .3 .2 3 .3 .3 3 .3 .4 adding Java Swing Components to Matlab Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . .80 3 .1 .1 the javacomponent Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .80 the Swing Component library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86 3 .1 .2 3 .1 .3 Displaying Swing-Derived Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90 3 .1 .4 UIComponent and JControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 3 .2 Matlab’s Main thread and the Event Dispatch thread (EDt) . . . . . . . . . . . . . . . . . . . . . 91 3 .3 Customizing Java Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96 Component Properties and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96 look-and-Feel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 HtMl Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Focus traversal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 3 .4 Component Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 3 .5 Using third-Party libraries in Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 JFreeChart and Other Charting libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 3 .5 .1 JFreeReport and Other Reporting libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 3 .5 .2 JGraph and Other Visualization libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 3 .5 .3 3 .5 .4 ImageJ and Other Image-Processing libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 3 .5 .5 Swing Extension Class libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 3 .5 .6 a Note of Caution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 3 .6 System-tray Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 3 .7 Drag-and-Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 3 .7 .1 Data transfer Mechanism in Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 3 .7 .2 a Sample Matlab application that Supports DND . . . . . . . . . . . . . . . . . . . . . 138 3 .8 adding Matlab Components to Java Swing Containers . . . . . . . . . . . . . . . . . . . . . . . . . 143 3 .9 alternatives to Swing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147 Chapter Uitools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 4 4 .1 4 .2 Uitable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Customizing Uitable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 4 .1 .1 4 .1 .2 table Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Customizing Scrollbars, Column Widths, and Selection behavior . . . . . . . . . . . . . 168 4 .1 .3 Data Sorting and Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 4 .1 .4 4 .1 .5 JIDE Customizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Controlling table Structure (adding/Deleting Rows) . . . . . . . . . . . . . . . . . . . . . . . 174 4 .1 .6 4 .1 .7 Final Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Uitree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 4 .2 .1 Customizing Uitree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 accessing tree Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 4 .2 .2 4 .2 .3 Controlling tree Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 K13163_Book.indb 10 11/8/2011 8:06:14 PM © 2012 by Taylor & Francis Group, LLC
Contents xi 4 .3 4 .6 4 .4 4 .5 Customizing tree Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 4 .2 .4 4 .2 .5 FindJObj . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Uitab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 4 .3 .1 Customizing tabs at the Java level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 4 .3 .2 tabdlg and Other alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 Uiundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .202 Uitoolfactory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .203 4 .5 .1 Other Undocumented toolbar Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .205 4 .5 .2 Customizing toolbars at the Java level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .206 4 .5 .3 4 .5 .4 Uisplittool and Uitogglesplittool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 4 .5 .5 adding Undo/Redo toolbar buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 accessing Menu Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 4 .6 .1 4 .6 .2 Customizing Menus via Uitools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .224 Customizing Menus via HtMl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .225 4 .6 .3 4 .6 .4 Customizing Menus via Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .226 4 .7 Status bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .236 Chapter built-In Matlab® Widgets and Java Classes . . . . . . . . . . . . . . . . . . . . . . . . . 241 5 5 .1 5 .2 5 .3 5 .4 5 .5 5 .6 5 .7 Internal Matlab Java Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 Inspecting Package Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .242 5 .1 .1 Inspecting an Internal Matlab Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 5 .1 .2 5 .1 .3 Standard Matlab Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .246 MWSwing Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .250 Enhancements of Standard Java Swing Controls . . . . . . . . . . . . . . . . . . . . . . . . . . .250 5 .2 .1 5 .2 .2 Entirely New Java Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 5 .2 .3 Other MWSwing Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .266 MWt Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .266 MlWidgets Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .268 5 .4 .1 Color-Selection Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 5 .4 .2 Plot-type Selection Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .284 Widgets Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .287 Widget Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .287 5 .5 .1 5 .5 .2 Font-Selection Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .299 Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .303 5 .5 .3 Closable (Collapsible) Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .306 5 .5 .4 5 .5 .5 Specialized Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .308 MlServices Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 JIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 5 .7 .1 Important JIDE Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 K13163_Book.indb 11 11/8/2011 8:06:14 PM © 2012 by Taylor & Francis Group, LLC
xii Contents JIDE Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 5 .7 .2 Matlab’s PropertyInspector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 5 .7 .3 JIDE’s Propertytable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 5 .7 .4 Nonstandard Property Renderers and Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 5 .7 .5 5 .7 .6 Nested Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334 5 .7 .7 trapping Property Change Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334 5 .7 .8 Date-Selection Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 Miscellaneous Other Internal Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 5 .8 .1 logging Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 JGoodies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .344 5 .8 .2 5 .8 .3 additional Others . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .344 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .346 5 .8 Chapter Customizing Matlab® Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 6 6 .6 6 .1 6 .2 6 .3 6 .4 6 .5 Pushbutton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 togglebutton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 Radiobutton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 Checkbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 Editbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370 Single-line Editbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 6 .5 .1 6 .5 .2 Multi-line Editbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 6 .5 .3 the JEditorPane alternative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 listbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .390 the listbox Data Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 6 .6 .1 6 .6 .2 Customizing the appearance of listbox Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 6 .6 .3 Dynamic (Item-Specific) Context-Menus and tooltips . . . . . . . . . . . . . . . . . . . . . .404 6 .7 Popup Menu (a .k .a . Drop-Down, Combo-box) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .407 6 .8 Slider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 6 .9 text label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 6 .10 Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422 6 .11 Uipanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 6 .12 tooltips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .424 6 .12 .1 Displaying a tooltip on Disabled Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424 6 .12 .2 Displaying a tooltip on truncated text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 6 .12 .3 Controlling tooltip timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426 6 .12 .4 Displaying a tooltip on Inactive Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .431 Chapter the Java Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 7 7 .1 Java Frame Properties and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 7 .1 .1 Window Minimization and Maximization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 K13163_Book.indb 12 11/8/2011 8:06:14 PM © 2012 by Taylor & Francis Group, LLC
Contents xiii 7 .3 7 .2 Docking and Undocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 7 .1 .2 UI-Related JavaFrame Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 7 .1 .3 7 .1 .4 Miscellaneous Other JavaFrame Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 FindJObj and the Java Frame Components Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 FindJObj . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .445 7 .2 .1 Finding the Underlying Java Object of a Matlab Control . . . . . . . . . . . . . . . . .445 7 .2 .2 7 .2 .3 GUI for Displaying Container Hierarchy, Properties, and Callbacks . . . . . . . . . . . 447 7 .2 .4 the Java Frame Container Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 Important Java Frame Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 axisCanvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 7 .3 .1 7 .3 .2 FigureComponentContainer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 Component’s Private Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452 7 .3 .3 FigurePanel or ContainerFactory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 7 .3 .4 DttoolbarContainer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 7 .3 .5 7 .3 .6 FigureMenubar and Docking Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 7 .3 .7 FigureFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 7 .4 beanadapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .461 Chapter the Matlab® Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463 8 8 .1 8 .2 8 .3 8 .4 8 .5 Desktop Functionality and layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .464 the Java Desktop Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .464 8 .1 .1 the Desktop Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 8 .1 .2 Organizing the Desktop Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477 8 .1 .3 8 .1 .4 Customizing the Desktop toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .480 System Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482 Command Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .484 Controlling Command Window Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .486 8 .3 .1 8 .3 .2 Help Popup and Integrated browser Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . .490 Modifying the Command Window Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 8 .3 .3 tab Completions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 8 .3 .4 8 .3 .4 .1 tC .xml and tC .xsd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 8 .3 .4 .2 tabComplete Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503 8 .3 .4 .3 additional aspects of tab Completion . . . . . . . . . . . . . . . . . . . . . . . . . .504 8 .3 .5 additional Command Window Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .506 the EditorServices/matlab .desktop .editor Object . . . . . . . . . . . . . . . . . . . . . . . . . .507 8 .4 .1 8 .4 .2 the Editor Frame Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512 Keyboard bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515 8 .5 .1 Inserting/Replacing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516 Running action Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 8 .5 .2 8 .5 .3 Running built-In actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521 K13163_Book.indb 13 11/8/2011 8:06:14 PM © 2012 by Taylor & Francis Group, LLC
xiv Contents 8 .6 8 .7 Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 Other Desktop tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529 8 .7 .1 8 .7 .2 Find-Files Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532 GUIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533 8 .7 .3 8 .7 .4 Variable (array) Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .539 Chapter Using Matlab® from within Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 9 9 .1 9 .2 approaches for Java Control of Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .544 Controlling the Matlab GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545 9 .1 .1 Controlling the Matlab Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .546 9 .1 .2 Controlling a Matlab Session from another Matlab Session . . . . . . . . . . . . 547 9 .1 .3 9 .1 .4 Running or Modifying Matlab Code without Matlab . . . . . . . . . . . . . . . . . 547 9 .1 .5 Matlab Clones Written in Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .548 JMI — Java-to-Matlab Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .548 9 .2 .1 com .mathworks .jmi .Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549 9 .2 .2 Other Interesting JMI Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553 JMI Wrapper — local MatlabControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554 local and Remote MatlabControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554 9 .3 .1 9 .3 .2 localMatlabProxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554 9 .3 .3 Some Usage Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556 JMI Wrapper — Remote MatlabControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .560 Remote Control of Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .560 9 .4 .1 9 .4 .2 a Simple RemoteExample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561 9 .4 .3 Parsing Matlab’s Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563 9 .5 Using JNI to Connect Java and Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .564 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .572 9 .3 9 .4 Chapter 0 Putting It all together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 1 10 .1 UISplitPane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578 10 .1 .1 technical Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579 10 .1 .2 Source-Code listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580 10 .2 Integration Debriefing System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .609 10 .2 .1 Data Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .609 10 .2 .2 Defining Data Items and Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611 10 .2 .3 Defining analyses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612 10 .2 .4 Defining Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614 10 .2 .5 Displaying analysis Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615 K13163_Book.indb 14 11/8/2011 8:06:15 PM © 2012 by Taylor & Francis Group, LLC
分享到:
收藏