Developing the Application

Once the design is well understood, the development process can begin. In this case, much of the development work has already been done in earlier examples—especially the toolbar example that was built in Chapter 4. From that core, development of the SWTTextEditor class, shown in Example 18-1, can be completed.

Example 18-1. The main SWTTextEditor class

import*; import org.eclipse.swt.SWT; import*; import; import org.eclipse.swt.widgets.*; public class SWTTextEditor { Display d; Shell s; SWTTextEditor( ) { d = new Display( ); s = new Shell(d, SWT.CLOSE ); s.setSize(500,500); s.setImage(new Image(d, "c:\\icons\\JavaCup.ico")); s.setText("SWT Text Editor"); final ToolBar bar = new ToolBar(s,SWT.HORIZONTAL); final Text t = new Text(s, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP | SWT.BORDER); //create images for toolbar buttons final Image saveIcon = new Image(d, "c:\\icons\\save.jpg"); final Image openIcon = new Image(d, "c:\\icons\\open.jpg"); final Image childIcon = new Image(d, "c:\\icons\\userH.ico"); final Image cutIcon = new Image(d, "c:\\icons\\cut.jpg"); final Image copyIcon = new Image(d, "c:\\icons\\copy.jpg"); final Image pasteIcon = new Image(d, "c:\\icons\\paste.jpg"); //create ToolBar and ToolItems final ToolItem openToolItem = new ToolItem(bar, SWT.PUSH); final ToolItem saveToolItem = new ToolItem(bar, SWT.PUSH); final ToolItem sep1 = new ToolItem(bar, SWT.SEPARATOR); ...

Get SWT: A Developer's Notebook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.