Mercurial > projects > dwt-samples
annotate jface/ActionAndStatusbar.d @ 171:0a21c7cabc16
presentation windows
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 26 Oct 2008 14:07:11 +0100 |
parents | 6e6405809faf |
children |
rev | line source |
---|---|
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
1 /* |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
2 DWT/JFace in Action |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
3 GUI Design with Eclipse 3.0 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
4 Matthew Scarpino, Stephen Holder, Stanford Ng, and Laurent Mihalkovic |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
5 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
6 ISBN: 1932394273 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
7 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
8 Publisher: Manning |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
9 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
10 Port to the D programming language: |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
11 Frank Benoit <benoit@tionex.de> |
60 | 12 Added some stuff to play with the statusbar and its progressmonitor |
13 | |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
14 */ |
59 | 15 module jface.ActionAndStatusbar; |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
16 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
17 import dwtx.jface.action.Action; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
18 import dwtx.jface.action.ActionContributionItem; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
19 import dwtx.jface.action.MenuManager; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
20 import dwtx.jface.action.StatusLineManager; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
21 import dwtx.jface.action.ToolBarManager; |
171 | 22 import dwtx.jface.action.Separator; |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
23 import dwtx.jface.resource.ImageDescriptor; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
24 import dwtx.jface.window.ApplicationWindow; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
25 import dwtx.core.runtime.IProgressMonitor; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
26 import dwt.DWT; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
27 import dwt.widgets.Composite; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
28 import dwt.widgets.Control; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
29 import dwt.widgets.Display; |
171 | 30 import dwt.widgets.Group; |
31 import dwt.widgets.Button; | |
32 import dwt.widgets.Event; | |
33 import dwt.widgets.Listener; | |
34 import dwt.widgets.Text; | |
35 import dwt.layout.GridData; | |
36 import dwt.layout.GridLayout; | |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
37 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
38 import tango.text.convert.Format; |
60 | 39 version(JIVE) import jive.stacktrace; |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
40 import dwt.dwthelper.utils; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
41 import dwt.dwthelper.Runnable; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
42 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
43 void main() { |
59 | 44 auto swin = new ActionAndStatusbar(); |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
45 swin.setBlockOnOpen(true); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
46 swin.open(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
47 Display.getCurrent().dispose(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
48 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
49 |
59 | 50 public class ActionAndStatusbar : ApplicationWindow { |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
51 StatusLineManager slm; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
52 |
59 | 53 StatusAction status_action; |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
54 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
55 ActionContributionItem aci; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
56 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
57 public this() { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
58 super(null); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
59 slm = new StatusLineManager(); |
59 | 60 status_action = new StatusAction(slm); |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
61 aci = new ActionContributionItem(status_action); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
62 addStatusLine(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
63 addMenuBar(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
64 addToolBar(DWT.FLAT | DWT.WRAP); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
65 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
66 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
67 protected Control createContents(Composite parent) { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
68 getShell().setText("Action/Contribution Example"); |
171 | 69 //parent.setSize(290, 150); |
70 //aci.fill(parent); | |
71 Composite comp = cast(Composite) super.createContents(parent); | |
72 comp.setLayout( new GridLayout()); | |
73 new Text( comp, DWT.BORDER ); | |
74 auto grp = new Group(comp, DWT.None); | |
75 grp.setLayoutData( new GridData( GridData.FILL_BOTH )); | |
76 //grp.setSize( 200, 200 ); | |
77 grp.setText("Action enable" ); | |
78 grp.setLayout(new GridLayout( 1, true )); | |
79 with( new Button( grp, DWT.RADIO )){ | |
80 setText( "On" ); | |
81 addListener( DWT.Selection, dgListener( &doEnable, true )); | |
82 } | |
83 with( new Button( grp, DWT.RADIO )){ | |
84 setText( "Off" ); | |
85 addListener( DWT.Selection, dgListener( &doEnable, false )); | |
86 } | |
87 return comp; | |
88 } | |
89 void doEnable( Event e, bool state ){ | |
90 status_action.setEnabled( state ); | |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
91 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
92 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
93 protected MenuManager createMenuManager() { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
94 MenuManager main_menu = new MenuManager(null); |
171 | 95 MenuManager file_menu = new MenuManager("File"); |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
96 MenuManager action_menu = new MenuManager("Menu"); |
171 | 97 main_menu.add(file_menu); |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
98 main_menu.add(action_menu); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
99 action_menu.add(status_action); |
171 | 100 file_menu.add(status_action); |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
101 return main_menu; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
102 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
103 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
104 protected ToolBarManager createToolBarManager(int style) { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
105 ToolBarManager tool_bar_manager = new ToolBarManager(style); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
106 tool_bar_manager.add(status_action); |
171 | 107 tool_bar_manager.add(new Separator()); |
108 tool_bar_manager.add(status_action); | |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
109 return tool_bar_manager; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
110 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
111 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
112 protected StatusLineManager createStatusLineManager() { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
113 return slm; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
114 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
115 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
116 |
59 | 117 class StatusAction : Action { |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
118 StatusLineManager statman; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
119 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
120 short triggercount = 0; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
121 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
122 public this(StatusLineManager sm) { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
123 super("&Trigger@Ctrl+T", AS_PUSH_BUTTON); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
124 statman = sm; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
125 setToolTipText("Trigger the Action"); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
126 setImageDescriptor(ImageDescriptor.createFromFile( |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
127 getImportData!("eclipse-icon-red-16.png"))); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
128 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
129 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
130 public void run() { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
131 triggercount++; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
132 statman.setMessage( Format("The status action has fired. Count: {}", triggercount)); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
133 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
134 if( triggercount % 5 == 0 ){ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
135 statman.setCancelEnabled(true); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
136 auto pm = statman.getProgressMonitor(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
137 pm.setCanceled(false); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
138 pm.beginTask( "Task", 100 ); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
139 auto runner = new class(pm) Runnable { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
140 IProgressMonitor pm; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
141 int w; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
142 this(IProgressMonitor a){ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
143 this.pm = a; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
144 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
145 void run(){ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
146 const incr = 2; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
147 this.pm.worked( incr ); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
148 w += incr; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
149 if( w < 100 && !this.pm.isCanceled() ){ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
150 Display.getCurrent().timerExec( 100, this); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
151 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
152 else{ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
153 this.pm.done(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
154 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
155 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
156 }; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
157 Display.getCurrent().syncExec(runner); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
158 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
159 } |
60 | 160 } |