Sie sind auf Seite 1von 8

Undocumented Secrets of

MATLAB-Java Programming

Yair Altman
i*.

CRC Press
Taylor & Francis Group
Boca Raton London New York

CRC Press is an imprint of the


Taylor & Francis Group, an informa business

A CHAPMAN & HALL BOOK


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
1.2 Java Object Properties 12
1.3 Java Object Methods and Actions 14
1.4 Java Events and MATLAB Callbacks 19
1.5 Safe Java Programming in MATLAB A How-to Guide 24
1.6 Compiling and Debugging User-Created Java Classes in MATLAB .27
1.7 . Compatibility Issues 35
1.8 Java Versions in MATLAB 37
1.8.1 Pre-Bundled JVM Versions 37
1.8.2 . Configuring MATLAB to Use a Different JVM 39
1.9 Java.opts 42
References 48

Chapter 2 Using Non-GUI Java Libraries in MATLAB 55

2.1 Complex Data Structures 56


1.1.1 Java Collections 56
2.1.2 Collections Example: Hashtable 59
2.1.3- Enumerators 60
2.2 Database Connectivity 61
2.2.1 Using Java Database Connectivity (JDBC) in MATLAB 62
2.2.2 Initializing the JDBC Driver 63
2.2.3 Connecting to a Database 65
2.2.4 Sending SQL Requests 66
2.2.5 Handling SQL Result Sets 67
2.3 Miscellaneous Other Uses 71
2.4 A Short Pause forReflection 72
References 73

ix
x Contents

Chapter 3 Rich GUI Using Java Swing 79

3.1 Adding Java Swing Components to MATLAB Figures 80


3.1.1 The javacomponent Function 80
3.1.2 The Swing Component Library 86
3.1.3 Displaying Swing-Derived Components 90
3.1.4 UlComponent and JControl 91
3.2 MATLAB's Main Thread and the Event Dispatch Thread (EDT) 91
3.3 Customizing Java Components 96
3.3.1 Component Properties and Methods 96
3.3.2 Look-and-Feel 102
3.3.3 HTML Support 106
3.3.4 Focus Traversal 110
3.4 Component Callbacks Ill
3.5 Using Third-Party Libraries in MATLAB 119
3.5.1 JFreeChart and Other Charting Libraries 119
3.5.2 JFreeReport and Other Reporting Libraries 122
3.5.3 JGraph and Other Visualization Libraries 125
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 4 ""Uitools 153

4.1 Uitable 155


4.1.1 Customizing Uitable 158
4.1.2 Table Callbacks 166
4.1.3 Customizing Scrollbars, Column Widths, and Selection Behavior 168
4.1.4 Data Sorting and Filtering 170
4.1.5 JIDE Customizations 173
4.1.6 Controlling Table Structure (Adding/Deleting Rows) 174
4.1.7 Final Remarks 176
4.2 Uitree 176
4.2.1 Customizing Uitree 178
4.2.2 Accessing Tree Nodes 181
4.2.3 Controlling Tree Nodes 183
Contents xi

4.2.4 Customizing Tree Nodes 185


4.2.5 FindJObj 189
4.3 Uitab 190
4.3.1 Customizing Tabs at the Java Level 192
4.3.2 Tabdlg and Other Alternatives 196
4.4 Uiundo 197
4.5 Toolbars 202
4.5.1 Uitoolfactory 203
4.5.2 Other Undocumented Toolbar Functions 205
4.5.3 Customizing Toolbars at the Java Level 206
4.5.4 Uisplittool and Uitogglesplittool 212
4.5.5 Adding Undo/Redo Toolbar Buttons 216
4.6 Menus 222
4.6.1 Accessing Menu Items 222
4.6.2 Customizing Menus via Uitools 224
4.6.3 Customizing Menus via HTML 225
4.6.4 Customizing Menus via Java 226
4.7 Status Bar 231
References 236

Chapter 5 Built-in MATLAB Widgets and Java Classes 241

5.1 Internal MATLAB Java Packages 242


5.1.1 Inspecting Package Contents 242
5.1.2 Inspecting an Internal MATLAB Class 243
5.1.3 Standard MATLAB Packages 246
5.2 MWSwing Package 250
5.2.1 Enhancements of Standard Java Swing Controls 250
5.2.2 Entirely New Java Controls 257
5.2.3 Other MWSwing Controls 266
5.3 MWT Package 266
5.4 MLWidgets Package 268
5.4.1 Color-Selection Components 275
5.4.2 Plot-Type Selection Components 284
5.5- Widgets Package 287
5.5.1 Widget Components 287
5.5.2 Font-Selection Components 299
5.5.3 Dialogs 303
5.5.4 Closable (Collapsible) Panels 306
5.5.5 Specialized Widgets 308
5.6 MLServices Package 310
5.7 JIDE ;.. . 318
5.7.1 Important JIDE Classes 319
xii Contents

5.7.2 JIDE Grids 322


5.7.3 MATLAB's Propertylnspector 326
5.7.4 JIDE's PropertyTable 328
5.7.5 Nonstandard Property Renderers and Editors 331
5.7.6 Nested Properties 334
5.7.7 Trapping Property Change Events 334
5.7.8 Date-Selection Components 336
5.8 Miscellaneous Other Internal Classes 339
5.8.1 Logging Utilities ... 341
5.8.2 JGoodies 344
5.8.3 Additional Others 344
References 346

Chapter 6 Customizing MATLAB Controls 353

6.1 PushButton 357


6.2 ToggleButton 365
6.3 RadioButton 365
6.4 Checkbox 367
6.5 Editbox 370
6.5.1 Single-Line Editbox 371
6.5.2 Multi-Line Editbox 377
6.5.3 The JEditorPane Alternative 389
6.6 Listbox 390
6.6.1 The Listbox Data Model 398
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. 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 7 The J.va Frame 435

7.1 Java Frame Properties and Methods 437


7.1.1 Window Minimization and Maximization 437
Contents xiii

.
7.1.2. Docking and Undocking 437
,
7.1.3 UI-Related JavaFrame Properties 439
,
7.1.4, Miscellaneous Other JavaFrame Properties 441
7.2 FindJObj and the Java Frame Components Hierarchy 443
. 7.2.1 FindJObj 445
7.2.2. Finding the Underlying Java Object of a MATLAB Control 445
' 7.2.3 GUI for Displaying Container Hierarchy, Properties, and Callbacks 447
7.2.4 The Java Frame Container Hierarchy 450
7.3 Important Java Frame Containers 450
7.3.1 AxisCanvas 450
7.3.2 FigureComponentContainer 452
7.3.3 Component's Private Container 452
7.3.4 FigurePanel or ContainerFactory 453
7.3.5 DTToolBarContainer 454
7.3.6 FigureMenuBar and Docking Controls 455
7.3.7 FigureFrame 456
7.4 BeanAdapters 461
References 461

Chapter 8 The MATLAB Desktop 463

8.1 Desktop Functionality and Layout 464


8.1.1 The Java Desktop Object 464
8.1.2 The Desktop Frame 475
8.1.3 Organizing the Desktop Clients 477
8.1.4 Customizing the Desktop Toolbars 480
8.2 System Preferences 482
8.3 Command Window , 484
8.3.1 Controlling Command Window Colors 486
8.3.2 Help Popup and Integrated Browser Controls 490
8.3.3 Modifying the Command Window Prompt 497
8.3.^ Tab Completions 501
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
8.4 Editor.. 506
8.4.1 The EditorServices/matlab.desktop.editor Object 507
8.4.2 The Editor Frame Object 512
8.5 Keyboard Bindings 515
8.5.1 Inserting/Replacing Text 516
8.5.2 Running Action Macros 519
8.5.3 Running Built-in Actions 521
xiv Contents

8.6 Workspace. 525


8.7 Other Desktop Tools 528
8.7.1 Profiler 529
8.7.2 Find-Files Dialog 532
8.7.3 GUIDE 533
8.7.4 Variable (Array) Editor 537
References ; : 539

Chapter 9 Using MATLAB from within Java. 543

9.1 Approaches for Java Control of MATLAB 544


9.1.1 Controlling the MATLAB GUI. 545
9.1.2 Controlling the MATLAB Engine. ! 546
9.1.3 Controlling a MATLAB Session from Another MATLAB Session 547
9.1.4 Running or Modifying MATLAB Code without MATLAB 547
9.1.5 MATLAB Clones Written in Java 548
9.2 JMI Java-to-MATLAB Interface 548
9.2.1 com.mathworks.jmi.Matlab 549
9.2.2 Other Interesting JMI Classes 553
9.3 JMI Wrapper Local MatlabControl 554
9.3.1 Local and Remote MatlabControl 554
9.3.2 LocalMatlabProxy 554
9.3.3 Some Usage Examples. 556
9.4 JMI Wrapper Remote MatlabControl 560
9.4.1 Remote Control of MATLAB 560
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
LK,
V

Chapter 10 Putting It All Together 577

10.1 UlSplitPane 578


10.1.1 Technical Description 579
10.1.2 Source-Code Listing 580
10.2 Integration Debriefing System 609
10.2.1 DataSetup 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
Contents xv

10.3 Concluding Exercise: UIMultiListbox 618


References 619

Appendix A: What Is Java? 621

Appendix B: UDD 627

Appendix C: Open Questions 639

Index 641

i*.

Das könnte Ihnen auch gefallen