SWT/Jface in Action

SWT/Jface in Action

How to design graphical applications with Eclipse 3.0 SWT/JFace INACTION Matthew Scarpino Stephen Holder Stanford Ng Laurent Mihalkovic MANNING SWT/JFace in Action MATTHEW SCARPINO STEPHEN HOLDER STANFORD NG AND LAURENT MIHALKOVIC MANNING Greenwich (74° w. long.) Licensed to jromero <[email protected]> For online information and ordering of this and other Manning books, please go to www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. 209 Bruce Park Avenue Fax: (203) 661-9018 Greenwich, CT 06830 email: [email protected] ©2005 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books they publish printed on acid-free paper, and we exert our best efforts to that end. Manning Publications Co. Copyeditor: Tiffany Taylor 209 Bruce Park Avenue Typesetter: Tony Roberts Greenwich, CT 06830 Cover designer: Leslie Haimes ISBN 1-932394-27-3 Printed in the United States of America 12345678910–VHG–08 070605 04 Licensed to jromero <[email protected]> brief contents 1 ■ Overview of SWT and JFace 1 2 ■ Getting started with SWT and JFace 13 3 ■ Widgets: part 1 27 4 ■ Working with events 48 5 ■ More widgets 78 6 ■ Layouts 109 7 ■ Graphics 133 8 ■ Working with trees and lists 167 9 ■ Tables and menus 190 10 ■ Dialogs 212 11 ■ Wizards 234 12 ■ Advanced features 253 13 ■ Looking beyond SWT/JFace: the Rich Client Platform 284 v Licensed to jromero <[email protected]> Licensed to jromero <[email protected]> contents preface xv acknowledgments xvi about this book xviii about the authors xxiii about the title xxiv about the cover illustration xxv Overview of SWT and JFace 1 1 1.1 What is SWT/JFace? 2 Building GUIs with SWT 3 Simplifying GUI development with JFace 3 1.2 Looking under the hood 4 The old standby: Swing 4 ■ The newcomer: SWT/JFace 6 The SWT/Swing debate 9 1.3 SWT/JFace: licensing and platform support 9 The Common Public License 9 ■ Platforms supported 9 1.4 The WidgetWindow 11 1.5 Summary 12 vii Licensed to jromero <[email protected]> viii CONTENTS Getting started with SWT and JFace 13 2 2.1 Programming in SWT 14 The HelloSWT program 14 ■ The Display class 16 The Shell class 18 2.2 Programming in SWT/JFace 20 Model-based adapters 20 ■ The HelloSWT_JFace program 21 Coding in JFace and SWT/JFace 23 The ApplicationWindow class 23 2.3 Beginning the WidgetWindow application 24 2.4 Summary 26 Widgets: part 1 27 3 3.1 Introducing the Widget and Control classes 28 Understanding the Widget class 28 Working with Control objects 30 3.2 Labels 32 Styles and separators 33 ■ Label methods 33 3.3 Involving the user with buttons 34 Causing action with push buttons and SWT.PUSH 34 Moving on with arrow buttons and SWT.ARROW 35 Changing state with toggle buttons and SWT.TOGGLE 35 ■ Choosing with check buttons and SWT.CHECK 36 ■ Making a single choice with radio buttons and SWT.RADIO 36 3.4 Containing components with Composites 38 Understanding the Composite class 39 ■ Groups 40 SashForms 43 ■ TabFolders 44 3.5 Updating WidgetWindow 45 Creating the Ch3_Composite class 45 Creating the WidgetWindow TabFolder 46 3.6 Summary 47 Licensed to jromero <[email protected]> CONTENTS ix Working with events 48 4 4.1 Event processing in SWT 49 Using typed listeners and events 50 ■ Adapters 54 Keyboard events 55 ■ Customizing event processing with untyped events 58 ■ An SWT listener/event application 60 4.2 Event processing in JFace 62 Understanding actions and contributions 63 ■ Creating Action classes 65 ■ Implementing contributions in an ApplicationWindow 66 ■ Interfacing with contributions 69 Exploring the Action class 70 4.3 Updating the WidgetWindow 74 Building the chapter 4 Composite 74 Adding Ch4_Composite to the WidgetWindow 75 4.4 Summary 77 More widgets 78 5 5.1 Editing text with SWT 79 The basic Text widget 79 ■ The StyledText widget 82 5.2 JFace text support 88 Obtaining the JFace text packages 88 ■ TextViewer and Document 89 ■ A JFace example 91 5.3 The Combo widget 100 5.4 ToolBarManager 101 ControlContribution 102 ■ Creating toolbars by hand 103 5.5 CoolBar 103 5.6 Slider 105 5.7 ProgressBar 106 5.8 ProgressIndicator 107 5.9 Summary 108 Licensed to jromero <[email protected]> x CONTENTS Layouts 109 6 6.1 The fill layout 110 6.2 The row layout 112 Customizing individual layout cells 114 6.3 The grid layout 116 GridData 117 6.4 The form layout 119 Using FormData 120 ■ Specifying relations using FormAttachment 120 ■ Laying out controls using a form layout 122 6.5 Custom layouts 124 Calculating the layout’s size 125 ■ Laying out the widgets 126 Updating WidgetWindow 128 6.6 Summary 132 Graphics 133 7 7.1 The graphic context 134 Creating a GC object 134 ■ Drawing shapes on a Canvas 136 Painting and PaintEvents 138 Clipping and Canvas styles 139 7.2 Programming with colors 140 Color development with SWT 140 Additional color capability with JFace 144 7.3 Displaying text with fonts 145 Using fonts with SWT 145 ■ Coding with fonts 148 Improved font management with JFace 150 7.4 Incorporating images in graphics 152 Allocating images 152 ■ Coding graphics with images 154 Creating a bitmap with ImageData 155 ■ Manipulating images with ImageData 159 ■ Managing images with JFace 163 7.5 Updating the WidgetWindow 164 Building the chapter 7 composite 164 Adding Ch7_Composite to the WidgetWindow 165 7.6 Summary 166 Licensed to jromero <[email protected]> CONTENTS xi Working with trees and lists 167 8 8.1 Viewers and the Viewer framework 168 Providers 170 ■ Listeners 172 ■ Filters and sorters 173 8.2 Trees 176 SWT trees 176 ■ JFace TreeViewers 177 8.3 Using the List widget 180 SWT lists 180 ■ JFace ListViewers 181 8.4 Updating WidgetWindow 182 8.5 Summary 189 Tables and menus 190 9 9.1 Tables 191 Understanding SWT tables 191 ■ JFace TableViewers 194 9.2 Creating menus 200 Accelerator keys 201 ■ Creating menus in SWT 201 Using JFace actions to add to menus 204 9.3 Updating WidgetWindow 205 9.4 Summary 211 Dialogs 212 10 10.1 SWT dialogs 213 ColorDialog 213 ■ DirectoryDialog 214 ■ FileDialog 215 FontDialog 216 ■ MessageBox 216 10.2 JFace dialogs 218 Message dialogs 219 ■ Error dialogs 220 ■ Input dialogs 222 ■ Progress monitor dialogs 224 Custom dialogs 228 10.3 Updating WidgetWindow 230 10.4 Summary 233 Wizards 234 11 11.1 Multipage dialogs 236 IDialogPage 236 ■ IWizardPage 237 ■ WizardPage 237 Licensed to jromero <[email protected]> xii CONTENTS 11.2 The wizard 239 IWizard 239 ■ Wizard 240 11.3 Putting it all together 241 Wizard containers 241 ■ WizardDialog 242 11.4 Combining wizards 243 WizardSelectionPage 243 ■ IWizardNode 244 11.5 Persistent wizard data 244 DialogSettings 245 11.6 Updating WidgetWindow 246 11.7 Summary 252 Advanced features 253 12 12.1 Transferring data 254 The Transfer class 255 ■ Drag-and-drop capability 256 Using the clipboard 261 ■ The filesystem browser 262 12.2 Preferences 268 Preference pages 268 ■ Field editors 270 ■ Preference page containers 273 ■ Persistent preferences 274 12.3 Label decorators 276 ILabelDecorator 276 ■ DecoratingLabelProvider 277 An example 277 12.4 The Browser widget 280 12.5 Summary 283 Looking beyond SWT/JFace: the Rich Client Platform 284 13 13.1 Understanding RCP workbenches 285 Entering data with editors 285 ■ Displaying information with views 287 ■ Combining editors and views with perspectives 288 13.2 RCP: Looking under the hood 288 Creating and configuring an RCP project 288 ■ Building the application class 290 ■ Adding a WorkbenchAdvisor 291 13.3 Adding views and perspectives 294 Building views 294 ■ Arranging workbench windows with a perspective 295 ■ Executing an RCP application 296 Reviewing the RCP process 297 Licensed to jromero <[email protected]> CONTENTS xiii 13.4 Populating forms with Eclipse Forms widgets 299 Using FormToolkit and the Eclipse Forms containers 299 Firing text-based events with Hyperlinks 302 13.5 Building a standalone RCP application 306 Exporting RCPExample to an application directory 306 Adding plug-ins to the application directory 307 Executing the application 308 13.6 Summary 308 appendix A Creating projects with SWT/JFace 311 appendix B OLE and ActiveX in SWT/JFace 324 appendix C Changeable GUIs with Draw2D 362 appendix D The Graphical Editing Framework (GEF) 388 index 461 Licensed to jromero <[email protected]> Licensed to jromero <[email protected]> preface We developed this book with one primary goal in mind: to introduce the SWT and JFace toolsets as simply and as thoroughly as possible. Although the available doc- umentation covers many aspects of the two libraries, we were disappointed by the amount (particularly in graphics) that has gone undocumented. So, we came together in late 2003 to create an approachable book that covers both the high-level theory and the low-level details of the combined SWT/JFace development tools.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    495 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us