Skip to content

Commit b8d61bc

Browse files
author
zhourenjian
committed
1. Add Console support improvement
2. Other SWT updates
1 parent c867ee5 commit b8d61bc

File tree

20 files changed

+369
-112
lines changed

20 files changed

+369
-112
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/ResizeSystem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
}, 50);
3232
};
3333
34-
try {
34+
if (document.addEventListener) {
3535
window.addEventListener('resize', $browserLayoutResize, true);
36-
} catch (e) {
37-
window.onresize = $browserLayoutResize;
36+
} else if (document.attachEvent) {
37+
document.attachEvent('onresize', $browserLayoutResize);
3838
}
3939
*/
4040
public class ResizeSystem {

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/printing/PrintDialog.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@
1313

1414
import org.eclipse.swt.SWT;
1515
import org.eclipse.swt.SWTException;
16+
import org.eclipse.swt.events.SelectionAdapter;
17+
import org.eclipse.swt.events.SelectionEvent;
18+
import org.eclipse.swt.graphics.Point;
19+
import org.eclipse.swt.internal.ResizeSystem;
20+
import org.eclipse.swt.layout.GridData;
21+
import org.eclipse.swt.layout.GridLayout;
22+
import org.eclipse.swt.widgets.Button;
23+
import org.eclipse.swt.widgets.Composite;
1624
import org.eclipse.swt.widgets.Dialog;
25+
import org.eclipse.swt.widgets.Event;
26+
import org.eclipse.swt.widgets.Label;
27+
import org.eclipse.swt.widgets.Listener;
1728
import org.eclipse.swt.widgets.Shell;
1829
import org.eclipse.swt.widgets.Widget;
1930

@@ -323,7 +334,47 @@ public PrinterData open() {
323334
}
324335
return data;
325336
*/
326-
dialogUnimplemented();
337+
dialogShell = new Shell(parent.getDisplay(), style | SWT.CLOSE | SWT.APPLICATION_MODAL);
338+
dialogShell.addListener(SWT.Close, new Listener() {
339+
public void handleEvent(Event event) {
340+
//updateReturnCode();
341+
}
342+
});
343+
dialogShell.setText(title);
344+
dialogShell.setLayout(new GridLayout(2, false));
345+
346+
Label icon = new Label(dialogShell, SWT.NONE);
347+
icon.setImage(parent.getDisplay().getSystemImage(SWT.ICON_WARNING));
348+
GridData gridData = new GridData(32, 32);
349+
icon.setLayoutData(gridData);
350+
351+
Label label = new Label(dialogShell, SWT.NONE);
352+
label.setText("Not implemented yet.");
353+
354+
Composite buttonPanel = new Composite(dialogShell, SWT.NONE);
355+
GridData gd = new GridData(GridData.END, GridData.CENTER, false, false); //new GridData();
356+
gd.horizontalSpan = 2;
357+
buttonPanel.setLayoutData(gd);
358+
buttonPanel.setLayout(new GridLayout());
359+
360+
Button btn = new Button(buttonPanel, SWT.PUSH);
361+
btn.setText("&OK");
362+
btn.setLayoutData(new GridData(75, 24));
363+
btn.addSelectionListener(new SelectionAdapter() {
364+
public void widgetSelected(SelectionEvent e) {
365+
dialogShell.close();
366+
}
367+
});
368+
369+
dialogShell.pack();
370+
dialogShell.open();
371+
Point size = dialogShell.getSize();
372+
int y = (dialogShell.getMonitor().getBounds().height - size.y) / 2 - 20;
373+
if (y < 0) {
374+
y = 0;
375+
}
376+
dialogShell.setLocation((dialogShell.getMonitor().getBounds().width - size.x) / 2, y);
377+
ResizeSystem.register(dialogShell, SWT.CENTER);
327378
return null;
328379
}
329380
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Console.java

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,84 @@
33
import org.eclipse.swt.SWT;
44
import org.eclipse.swt.events.ShellAdapter;
55
import org.eclipse.swt.events.ShellEvent;
6+
import org.eclipse.swt.graphics.Point;
7+
import org.eclipse.swt.graphics.Rectangle;
8+
import org.eclipse.swt.internal.browser.OS;
69
import org.eclipse.swt.internal.xhtml.Element;
710
import org.eclipse.swt.internal.xhtml.document;
8-
import org.eclipse.swt.layout.FillLayout;
11+
import org.eclipse.swt.layout.GridData;
12+
import org.eclipse.swt.layout.GridLayout;
913
import org.eclipse.swt.widgets.Composite;
1014

1115
public class Console extends Shell {
1216

17+
static Console console;
18+
19+
static Rectangle lastBounds;
20+
21+
static Point scrollOffset;
22+
23+
Composite consoleWrapper;
24+
25+
1326
/**
1427
* Launch the console
1528
*/
1629
public static void openConsole() {
30+
if (console != null && !console.isDisposed()) {
31+
console.setVisible(true);
32+
console.bringToTop();
33+
return;
34+
}
1735
try {
1836
Display display = Display.getDefault();
19-
Console console = new Console(display, SWT.SHELL_TRIM);
37+
console = new Console(display, SWT.SHELL_TRIM);
2038

2139
console.addShellListener(new ShellAdapter() {
2240

23-
@Override
2441
public void shellClosed(ShellEvent e) {
2542
//console.setVisible(false);
2643
//e.doit = false;
44+
lastBounds = console.getBounds();
45+
Element wrapperEl = console.consoleWrapper.handle;
46+
scrollOffset = new Point(wrapperEl.scrollLeft, wrapperEl.scrollTop);
2747
Element el = document.getElementById("_console_");
2848
if (el != null) {
2949
el.parentNode.removeChild(el);
3050
el.style.display = "none";
3151
el.style.fontSize = "";
3252
document.body.appendChild(el);
3353
}
54+
console = null;
3455
}
3556

3657
});
3758

3859
console.open();
60+
if (lastBounds != null) {
61+
console.setBounds(lastBounds);
62+
} else {
63+
console.pack();
64+
}
3965
console.layout();
66+
if (scrollOffset != null) {
67+
// Wait 50ms, so console shell may complete its layout
68+
console.getDisplay().timerExec(50, new Runnable() {
69+
70+
public void run() {
71+
Element wrapperEl = console.consoleWrapper.handle;
72+
wrapperEl.scrollLeft = scrollOffset.x;
73+
wrapperEl.scrollTop = scrollOffset.y;
74+
75+
}
76+
77+
});
78+
}
4079
while (!console.isDisposed()) {
4180
if (!display.readAndDispatch())
4281
display.sleep();
4382
}
83+
display.dispose();
4484
} catch (Exception e) {
4585
e.printStackTrace();
4686
}
@@ -54,21 +94,37 @@ public void shellClosed(ShellEvent e) {
5494
public Console(Display display, int style) {
5595
super(display, style);
5696
createContents();
57-
setLayout(new FillLayout());
97+
GridLayout gridLayout = new GridLayout();
98+
gridLayout.marginWidth = 0;
99+
gridLayout.marginHeight = 0;
100+
gridLayout.horizontalSpacing = 0;
101+
gridLayout.verticalSpacing = 0;
102+
setLayout(gridLayout);
58103
}
59104

60105
/**
61106
* Create contents of the window
62107
*/
63108
protected void createContents() {
64109
setText("Console");
65-
setSize(500, 375);
66-
67-
final Composite composite = new Composite(this, SWT.NONE);
68-
composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
110+
this.shellIcon.className = "shell-title-icon shell-title-icon-console";
111+
consoleWrapper = new Composite(this, SWT.NONE);
112+
consoleWrapper.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
69113
//
114+
String str = "0123456789";
115+
str += str; // 20
116+
str += str; // 40
117+
str += str; // 80
118+
Point defaultSize = OS.getStringStyledSize(str, null, "font-size:10pt;font-family:monospace,Arial,sans-serif;");
70119

71-
composite.handle.style.overflow = "scroll";
120+
GridData gridData = new GridData(GridData.FILL_BOTH);
121+
gridData.widthHint = defaultSize.x + OS.getScrollBarWidth();
122+
gridData.heightHint = defaultSize.y * 25 + OS.getScrollBarHeight();
123+
consoleWrapper.setLayoutData(gridData);
124+
125+
consoleWrapper.handle.style.overflow = "scroll";
126+
consoleWrapper.handle.style.backgroundColor = "black";
127+
consoleWrapper.handle.style.color = "white";
72128

73129
Element el = document.getElementById("_console_");
74130
if (el == null) {
@@ -80,10 +136,9 @@ protected void createContents() {
80136
el.style.display = "";
81137
}
82138
el.style.fontSize = "10pt";
83-
composite.handle.appendChild(el);
139+
consoleWrapper.handle.appendChild(el);
84140
}
85141

86-
@Override
87142
protected void checkSubclass() {
88143
// Disable the check that prevents subclassing of SWT components
89144
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Decorations.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,17 @@ public class Decorations extends Canvas {
122122
//int oldWidth = OS.CW_USEDEFAULT, oldHeight = OS.CW_USEDEFAULT;
123123
Element contentHandle;
124124
Element shellTitle;
125-
Element modalHandle;
126-
private Rectangle oldBounds;
125+
Element shellIcon;
126+
Element modalHandle;
127+
private Rectangle oldBounds;
127128
private String lastClientAreaCSSText;
128129
private String lastBodyCSSText;
129130
private int lastBodyScrollLeft;
130131
private int lastBodyScrollTop;
131132
private Object lastClientAreaOnScroll;
132-
private Element shellMin;
133-
private Element shellMax;
134-
private Element shellIcon;
135-
private Element shellClose;
133+
Element shellMin;
134+
Element shellMax;
135+
Element shellClose;
136136
Element titleBar;
137137
Element shellMenuBar;
138138
Element shellToolBar;
@@ -1919,6 +1919,18 @@ public void setMinimized (boolean minimized) {
19191919
}
19201920
if (!minimized) {
19211921
bringToTop();
1922+
} else {
1923+
Shell topShell = Display.getTopShell();
1924+
if (topShell != null) {
1925+
topShell.bringToTop();
1926+
} else
1927+
/**
1928+
* Return to default title
1929+
* @j2sNative
1930+
* if (window["document.title"] != null) {
1931+
* document.title = window["document.title"];
1932+
* }
1933+
*/ {}
19221934
}
19231935
this.minimized = minimized;
19241936
return;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Dialog.java

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212

1313

1414
import org.eclipse.swt.*;
15-
import org.eclipse.swt.events.SelectionAdapter;
16-
import org.eclipse.swt.events.SelectionEvent;
17-
import org.eclipse.swt.graphics.Point;
18-
import org.eclipse.swt.internal.ResizeSystem;
19-
import org.eclipse.swt.layout.GridData;
20-
import org.eclipse.swt.layout.GridLayout;
2115

2216
/**
2317
* This class is the abstract superclass of the classes
@@ -120,11 +114,11 @@
120114
*/
121115

122116
public abstract class Dialog {
123-
int style;
124-
Shell parent;
125-
String title;
126-
Shell dialogShell;
127-
Object dialogReturn;
117+
public int style;
118+
public Shell parent;
119+
public String title;
120+
public Shell dialogShell;
121+
public Object dialogReturn;
128122

129123
/**
130124
* Constructs a new instance of this class given only its
@@ -295,49 +289,4 @@ public void setText (String string) {
295289
title = string;
296290
}
297291

298-
299-
protected void dialogUnimplemented() {
300-
dialogShell = new Shell(parent.display, style | SWT.CLOSE | SWT.APPLICATION_MODAL);
301-
dialogShell.addListener(SWT.Close, new Listener() {
302-
public void handleEvent(Event event) {
303-
//updateReturnCode();
304-
}
305-
});
306-
dialogShell.setText(title);
307-
dialogShell.setLayout(new GridLayout(2, false));
308-
309-
Label icon = new Label(dialogShell, SWT.NONE);
310-
icon.setImage(parent.display.getSystemImage(SWT.ICON_WARNING));
311-
GridData gridData = new GridData(32, 32);
312-
icon.setLayoutData(gridData);
313-
314-
Label label = new Label(dialogShell, SWT.NONE);
315-
label.setText("Not implemented yet.");
316-
317-
Composite buttonPanel = new Composite(dialogShell, SWT.NONE);
318-
GridData gd = new GridData(GridData.END, GridData.CENTER, false, false); //new GridData();
319-
gd.horizontalSpan = 2;
320-
buttonPanel.setLayoutData(gd);
321-
buttonPanel.setLayout(new GridLayout());
322-
323-
Button btn = new Button(buttonPanel, SWT.PUSH);
324-
btn.setText("&OK");
325-
btn.setLayoutData(new GridData(75, 24));
326-
btn.addSelectionListener(new SelectionAdapter() {
327-
public void widgetSelected(SelectionEvent e) {
328-
dialogShell.close();
329-
}
330-
});
331-
332-
dialogShell.pack();
333-
dialogShell.open();
334-
Point size = dialogShell.getSize();
335-
int y = (dialogShell.getMonitor().clientHeight - size.y) / 2 - 20;
336-
if (y < 0) {
337-
y = 0;
338-
}
339-
dialogShell.setLocation((dialogShell.getMonitor().clientWidth - size.x) / 2, y);
340-
ResizeSystem.register(dialogShell, SWT.CENTER);
341-
}
342-
343292
}

0 commit comments

Comments
 (0)