Skip to content

Commit fc5dc39

Browse files
author
jossonsmith
committed
Modify AddressBook and LayoutExample sources a little so that it can be run in both
native and Java2Script browser mode.
1 parent bb8e7ef commit fc5dc39

File tree

8 files changed

+106
-8
lines changed

8 files changed

+106
-8
lines changed

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/DataEntryDialog.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* is added to a <code>Table</code> widget or edits a <code>TableItem</code> entry
2525
* to represent the entered data.
2626
*/
27-
public class DataEntryDialog {
27+
public class DataEntryDialog extends Dialog {
2828

2929
private static ResourceBundle resAddressBook = ResourceBundle.getBundle("examples_addressbook");
3030

@@ -33,7 +33,8 @@ public class DataEntryDialog {
3333
String[] labels;
3434

3535
public DataEntryDialog(Shell parent) {
36-
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL);
36+
super(new Shell(parent, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL));
37+
shell = this.getParent();
3738
shell.setLayout(new GridLayout());
3839
}
3940

@@ -124,6 +125,9 @@ public String[] getValues() {
124125
* The state the dialog should be opened in.
125126
*/
126127
public String[] open() {
128+
/**
129+
* @j2sNative this.dialogShell = this.shell;
130+
*/ {}
127131
createTextWidgets();
128132
createControlButtons();
129133
shell.pack();
@@ -134,6 +138,10 @@ public String[] open() {
134138
display.sleep();
135139
}
136140

141+
/**
142+
* @j2sNative
143+
* this.dialogReturn = this.values;
144+
*/ {}
137145
return getValues();
138146
}
139147
public void setLabels(String[] labels) {

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/SearchDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void widgetSelected(SelectionEvent e) {
121121
if (!findHandler.find()){
122122
MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL);
123123
box.setText(shell.getText());
124-
box.setMessage(resAddressBook.getString("Cannot_find") + "\"" + searchText.getText() + "\"");
124+
box.setMessage(resAddressBook.getString("Cannot_find") + " \"" + searchText.getText() + "\"");
125125
box.open();
126126
}
127127
}

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FillLayoutTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FillLayoutTab extends Tab {
2929
/**
3030
* Creates the Tab within a given instance of LayoutExample.
3131
*/
32-
FillLayoutTab(LayoutExample instance) {
32+
public FillLayoutTab(LayoutExample instance) {
3333
super(instance);
3434
}
3535

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/FormLayoutTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class FormLayoutTab extends Tab {
4545
/**
4646
* Creates the Tab within a given instance of LayoutExample.
4747
*/
48-
FormLayoutTab(LayoutExample instance) {
48+
public FormLayoutTab(LayoutExample instance) {
4949
super(instance);
5050
}
5151

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/GridLayoutTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GridLayoutTab extends Tab {
4949
/**
5050
* Creates the Tab within a given instance of LayoutExample.
5151
*/
52-
GridLayoutTab(LayoutExample instance) {
52+
public GridLayoutTab(LayoutExample instance) {
5353
super(instance);
5454
}
5555

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/LayoutExample.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@
1111
package org.eclipse.swt.examples.layoutexample;
1212

1313

14+
import net.sf.j2s.ajax.ARunnable;
15+
import net.sf.j2s.ajax.ASWTClass;
1416
import org.eclipse.swt.*;
1517
import org.eclipse.swt.layout.*;
1618
import org.eclipse.swt.widgets.*;
1719
import org.eclipse.swt.events.*;
1820

21+
import java.lang.reflect.Constructor;
1922
import java.text.*;
2023
import java.util.*;
2124

25+
/**
26+
* @j2sRequireImport java.lang.reflect.Constructor
27+
*/
2228
public class LayoutExample {
2329
private static ResourceBundle resourceBundle = ResourceBundle.getBundle("examples_layout");
2430
private TabFolder tabFolder;
@@ -30,6 +36,7 @@ public class LayoutExample {
3036
* @param parent the container of the example
3137
*/
3238
public LayoutExample(Composite parent) {
39+
/*
3340
tabFolder = new TabFolder (parent, SWT.NULL);
3441
Tab [] tabs = new Tab [] {
3542
new FillLayoutTab (this),
@@ -42,6 +49,88 @@ public LayoutExample(Composite parent) {
4249
item.setText (tabs [i].getTabText ());
4350
item.setControl (tabs [i].createTabFolderPage (tabFolder));
4451
}
52+
*/
53+
tabFolder = new TabFolder (parent, SWT.NONE);
54+
String[] tabs = new String[] {
55+
"FillLayout",
56+
"RowLayout",
57+
"GridLayout",
58+
"FormLayout"
59+
};
60+
for (int i=0; i<tabs.length; i++) {
61+
TabItem item = new TabItem (tabFolder, SWT.NONE);
62+
item.setText (tabs [i]);
63+
//item.setControl (tabs [i].createTabFolderPage (tabFolder));
64+
item.setData ("org.eclipse.swt.examples.layoutexample." + tabs [i] + "Tab");
65+
//ProgressBar progressBar = new ProgressBar(tabFolder, SWT.INDETERMINATE);
66+
//item.setControl(progressBar);
67+
//*
68+
Label label = new Label(tabFolder, SWT.NONE);
69+
label.setText("Loading " + tabs [i] + " Tab ...");
70+
label.setAlignment(SWT.CENTER);
71+
item.setControl(label);
72+
// */
73+
}
74+
if (tabs.length > 0) {
75+
final TabItem item = tabFolder.getItem(0);
76+
ASWTClass.shellLoad(parent.getShell(), (String) item.getData(), new ARunnable() {
77+
public void run() {
78+
try {
79+
Constructor constructor = getClazz().getConstructor(new Class[] {LayoutExample.class});
80+
Object inst = constructor.newInstance(new Object[] {LayoutExample.this});
81+
Tab tab = (Tab) inst;
82+
Composite page = tab.createTabFolderPage(tabFolder);
83+
Control control = item.getControl();
84+
if (control != null && control instanceof Label) {
85+
control.dispose();
86+
}
87+
//item.setImage(images[(int) Math.floor(3 * Math.random())]);
88+
tabFolder.setSelection(tabFolder.getSelectionIndex());
89+
item.setControl(page);
90+
//item.getParent().getShell().pack();
91+
} catch (Throwable e) {
92+
//e.printStackTrace();
93+
throw (Error) e;
94+
}
95+
}
96+
});
97+
}
98+
if (tabs.length > 1) {
99+
tabFolder.addSelectionListener(new SelectionAdapter() {
100+
public void widgetSelected(SelectionEvent e) {
101+
int idx = tabFolder.getSelectionIndex();
102+
if (idx != -1) {
103+
final TabItem item = tabFolder.getItem(idx);
104+
Control control = item.getControl();
105+
if (control == null || control instanceof Label) {
106+
Object data = item.getData();
107+
if (data != null) {
108+
ASWTClass.shellLoad(tabFolder.getShell(), (String) data, new ARunnable() {
109+
public void run() {
110+
try {
111+
Constructor constructor = getClazz().getConstructor(new Class[] {LayoutExample.class});
112+
Object inst = constructor.newInstance(new Object[] {LayoutExample.this});
113+
Tab tab = (Tab) inst;
114+
Composite page = tab.createTabFolderPage(tabFolder);
115+
Control control = item.getControl();
116+
if (control != null && control instanceof Label) {
117+
control.dispose();
118+
}
119+
//item.setImage(images[(int) Math.floor(3 * Math.random())]);
120+
tabFolder.setSelection(tabFolder.getSelectionIndex());
121+
item.setControl(page);
122+
} catch (Throwable e) {
123+
e.printStackTrace();
124+
throw (Error) e;
125+
}
126+
}
127+
});
128+
}
129+
}
130+
}
131+
}
132+
});
133+
}
45134
}
46135

47136
/**
@@ -76,6 +165,7 @@ public void shellClosed(ShellEvent e) {
76165
}
77166
}
78167
});
168+
//shell.setSize(640, 480);
79169
shell.open();
80170
while (! shell.isDisposed()) {
81171
if (! display.readAndDispatch()) display.sleep();

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/RowLayoutTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class RowLayoutTab extends Tab {
4040
/**
4141
* Creates the Tab within a given instance of LayoutExample.
4242
*/
43-
RowLayoutTab(LayoutExample instance) {
43+
public RowLayoutTab(LayoutExample instance) {
4444
super(instance);
4545
}
4646

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/Tab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void createComboEditor (CCombo combo, TableEditor comboEditor) {
170170
combo.setItems (new String [] {
171171
"Button", "Canvas", "Combo", "Composite",
172172
"CoolBar", "Group", "Label", "List",
173-
"ProgressBar", "Scale", "Slider", "StyledText",
173+
"ProgressBar", "Scale", "Slider", /*"StyledText",*/
174174
"Table", "Text", "ToolBar", "Tree"});
175175
combo.setText (newItem.getText (1));
176176

0 commit comments

Comments
 (0)