Mercurial > projects > dwt-samples
annotate jface/ActionAndStatusbar.d @ 60:6e6405809faf
version for jive
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 10 Apr 2008 11:22:21 +0200 |
parents | 6fb20f548c46 |
children | 0a21c7cabc16 |
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; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
22 import dwtx.jface.resource.ImageDescriptor; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
23 import dwtx.jface.window.ApplicationWindow; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
24 import dwtx.core.runtime.IProgressMonitor; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
25 import dwt.DWT; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
26 import dwt.widgets.Composite; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
27 import dwt.widgets.Control; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
28 import dwt.widgets.Display; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
29 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
30 import tango.text.convert.Format; |
60 | 31 version(JIVE) import jive.stacktrace; |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
32 import dwt.dwthelper.utils; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
33 import dwt.dwthelper.Runnable; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
34 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
35 void main() { |
59 | 36 auto swin = new ActionAndStatusbar(); |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
37 swin.setBlockOnOpen(true); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
38 swin.open(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
39 Display.getCurrent().dispose(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
40 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
41 |
59 | 42 public class ActionAndStatusbar : ApplicationWindow { |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
43 StatusLineManager slm; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
44 |
59 | 45 StatusAction status_action; |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
46 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
47 ActionContributionItem aci; |
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 public this() { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
50 super(null); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
51 slm = new StatusLineManager(); |
59 | 52 status_action = new StatusAction(slm); |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
53 aci = new ActionContributionItem(status_action); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
54 addStatusLine(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
55 addMenuBar(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
56 addToolBar(DWT.FLAT | DWT.WRAP); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
57 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
58 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
59 protected Control createContents(Composite parent) { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
60 getShell().setText("Action/Contribution Example"); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
61 parent.setSize(290, 150); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
62 aci.fill(parent); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
63 return parent; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
64 } |
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 protected MenuManager createMenuManager() { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
67 MenuManager main_menu = new MenuManager(null); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
68 MenuManager action_menu = new MenuManager("Menu"); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
69 main_menu.add(action_menu); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
70 action_menu.add(status_action); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
71 return main_menu; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
72 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
73 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
74 protected ToolBarManager createToolBarManager(int style) { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
75 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
|
76 tool_bar_manager.add(status_action); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
77 return tool_bar_manager; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
78 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
79 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
80 protected StatusLineManager createStatusLineManager() { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
81 return slm; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
82 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
83 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
84 |
59 | 85 class StatusAction : Action { |
58
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
86 StatusLineManager statman; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
87 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
88 short triggercount = 0; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
89 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
90 public this(StatusLineManager sm) { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
91 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
|
92 statman = sm; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
93 setToolTipText("Trigger the Action"); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
94 setImageDescriptor(ImageDescriptor.createFromFile( |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
95 getImportData!("eclipse-icon-red-16.png"))); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
96 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
97 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
98 public void run() { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
99 triggercount++; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
100 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
|
101 |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
102 if( triggercount % 5 == 0 ){ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
103 statman.setCancelEnabled(true); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
104 auto pm = statman.getProgressMonitor(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
105 pm.setCanceled(false); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
106 pm.beginTask( "Task", 100 ); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
107 auto runner = new class(pm) Runnable { |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
108 IProgressMonitor pm; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
109 int w; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
110 this(IProgressMonitor a){ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
111 this.pm = a; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
112 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
113 void run(){ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
114 const incr = 2; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
115 this.pm.worked( incr ); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
116 w += incr; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
117 if( w < 100 && !this.pm.isCanceled() ){ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
118 Display.getCurrent().timerExec( 100, this); |
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 else{ |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
121 this.pm.done(); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
122 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
123 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
124 }; |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
125 Display.getCurrent().syncExec(runner); |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
126 } |
3b18f03b2f41
images into the res folder, first working jface example
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
127 } |
60 | 128 } |