Skip to content

Commit 26854e0

Browse files
author
zhourenjian
committed
1. Add SWT Console support
2. Use monospace font in HTML source dialog 3. Fixed bug on minimize and restore maximized Shell
1 parent 60d2429 commit 26854e0

File tree

5 files changed

+161
-16
lines changed

5 files changed

+161
-16
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.eclipse.swt.widgets;
2+
3+
import org.eclipse.swt.SWT;
4+
import org.eclipse.swt.events.ShellAdapter;
5+
import org.eclipse.swt.events.ShellEvent;
6+
import org.eclipse.swt.internal.xhtml.Element;
7+
import org.eclipse.swt.internal.xhtml.document;
8+
import org.eclipse.swt.layout.FillLayout;
9+
import org.eclipse.swt.widgets.Composite;
10+
11+
public class Console extends Shell {
12+
13+
/**
14+
* Launch the console
15+
*/
16+
public static void openConsole() {
17+
try {
18+
Display display = Display.getDefault();
19+
Console console = new Console(display, SWT.SHELL_TRIM);
20+
21+
console.addShellListener(new ShellAdapter() {
22+
23+
@Override
24+
public void shellClosed(ShellEvent e) {
25+
//console.setVisible(false);
26+
//e.doit = false;
27+
Element el = document.getElementById("_console_");
28+
if (el != null) {
29+
el.parentNode.removeChild(el);
30+
el.style.display = "none";
31+
el.style.fontSize = "";
32+
document.body.appendChild(el);
33+
}
34+
}
35+
36+
});
37+
38+
console.open();
39+
console.layout();
40+
while (!console.isDisposed()) {
41+
if (!display.readAndDispatch())
42+
display.sleep();
43+
}
44+
} catch (Exception e) {
45+
e.printStackTrace();
46+
}
47+
}
48+
49+
/**
50+
* Create the shell
51+
* @param display
52+
* @param style
53+
*/
54+
public Console(Display display, int style) {
55+
super(display, style);
56+
createContents();
57+
setLayout(new FillLayout());
58+
}
59+
60+
/**
61+
* Create contents of the window
62+
*/
63+
protected void createContents() {
64+
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));
69+
//
70+
71+
composite.handle.style.overflow = "scroll";
72+
73+
Element el = document.getElementById("_console_");
74+
if (el == null) {
75+
el = document.createElement("DIV");
76+
el.id = "_console_";
77+
el.style.fontFamily = "monospace,Arial,sans-serif";
78+
} else {
79+
el.parentNode.removeChild(el);
80+
el.style.display = "";
81+
}
82+
el.style.fontSize = "10pt";
83+
composite.handle.appendChild(el);
84+
}
85+
86+
@Override
87+
protected void checkSubclass() {
88+
// Disable the check that prevents subclassing of SWT components
89+
}
90+
91+
}

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,18 @@ void bringToTop (boolean parentShell, boolean childShells) {
253253
/**
254254
* @j2sNative
255255
* var title = this.getText();
256-
* if (title == null) {
257-
* title = "-";
256+
* if (title != null) {
257+
* // Record default title
258+
* if (window["document.title"] == null) {
259+
* window["document.title"] = document.title;
260+
* }
261+
* if (window["document.title.setter"] == null) {
262+
* document.title = title; // set title directly
263+
* } else {
264+
* // document.title.setter may modify title
265+
* window["document.title.setter"] (title);
266+
* }
258267
* }
259-
* if (window["document.title"] == null) {
260-
* window["document.title"] = document.title;
261-
* }
262-
* document.title = title;
263268
*/ {}
264269
int count = children.length; //handle.childNodes.length;
265270
for (int i = 0; i < count; i++) {
@@ -816,14 +821,10 @@ public void dispose () {
816821

817822
if ((this.style & SWT.TOOL) == 0)
818823
/**
824+
* Return to default title
819825
* @j2sNative
820826
* if (window["document.title"] != null) {
821-
* if (this.parent != null) {
822-
* var title = this.parent.getText();
823-
* document.title = (title == null ? "-" : title);
824-
* } else {
825-
* document.title = window["document.title"];
826-
* }
827+
* document.title = window["document.title"];
827828
* }
828829
*/ {}
829830
if ((this.getStyle() & SWT.TOOL) == 0 && display.taskBar != null) {
@@ -1901,7 +1902,10 @@ public void setMinimized (boolean minimized) {
19011902
if (!minimized) {
19021903
if (this.maximized) {
19031904
this.minimized = minimized;
1904-
this.setMaximized(true);
1905+
// this.setMaximized(true);
1906+
if (display.taskBar != null) {
1907+
this.handle.style.display = minimized ? "none" : "";
1908+
}
19051909
return;
19061910
}
19071911
}

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,26 @@ void initializeDekstop() {
24792479
}
24802480
if (desktopItems != null) return;
24812481

2482+
Element el = document.getElementById("_console_");
2483+
if (el != null) {
2484+
el.style.display = "none";
2485+
insertOpenConsoleLink(el);
2486+
} else
2487+
/**
2488+
* @j2sNative
2489+
* if (Console == null) Console = C_$;
2490+
* if (C_$.createC_$Window.wrapped == null) {
2491+
* C_$.createC_$Window_ = Console.createC_$Window;
2492+
* C_$.createC_$Window = function (parentEl) {
2493+
* var console = C_$.createC_$Window_ (parentEl);
2494+
* console.style.display = "none";
2495+
* $wt.widgets.Display.insertOpenConsoleLink(console);
2496+
* return console;
2497+
* };
2498+
* C_$.createC_$Window.wrapped = true;
2499+
* }
2500+
*/ {}
2501+
24822502
taskBar = new TaskBar(this);
24832503
topBar = new MaximizedTitle(this);
24842504
if (QuickLaunch.defaultQuickLaunch != null) {
@@ -2528,6 +2548,19 @@ public void run() {
25282548

25292549
}
25302550

2551+
static void insertOpenConsoleLink(Element el) {
2552+
Element anchor = document.createElement ("A");
2553+
anchor.id = "_launch_console_";
2554+
anchor.title = "Open System Console";
2555+
anchor.className = "alaa ignored";
2556+
anchor.href = "javascript:ClazzLoader.loadClass('org.eclipse.swt.widgets.Console',function(){$wt.widgets.Console.openConsole();});";
2557+
document.body.insertBefore (anchor, el);
2558+
Element iconSpan = document.createElement ("SPAN");
2559+
iconSpan.className = "alaa-icon";
2560+
anchor.appendChild (iconSpan);
2561+
anchor.appendChild (document.createTextNode ("Open System Console"));
2562+
}
2563+
25312564
/**
25322565
* Invokes platform specific functionality to dispose a GC handle.
25332566
* <p>
@@ -4538,8 +4571,6 @@ static Shell getTopShell() {
45384571
}
45394572

45404573
static void deactivateAllTitleBarShells() {
4541-
Shell lastShell = null;
4542-
int lastZIndex = 0;
45434574
Display[] disps = Displays;
45444575
for (int k = 0; k < disps.length; k++) {
45454576
if (disps[k] == null) continue;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.eclipse.swt.SWT;
1515
import org.eclipse.swt.events.SelectionAdapter;
1616
import org.eclipse.swt.events.SelectionEvent;
17+
import org.eclipse.swt.graphics.Font;
1718
import org.eclipse.swt.graphics.Rectangle;
1819
import org.eclipse.swt.internal.browser.OS;
1920
import org.eclipse.swt.layout.GridData;
@@ -88,6 +89,12 @@ public void exportSource(Shell objShell, boolean onlyContent) {
8889
// composite.setLayout(new GridLayout());
8990
shell.setLayout(new GridLayout());
9091
Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL);
92+
Font font = null;
93+
/**
94+
* @j2sNative
95+
* font = new $wt.graphics.Font ($wt.widgets.Display.getCurrent (), new $wt.graphics.FontData ("Courier New", 10, 0));
96+
*/ {}
97+
text.setFont(font);
9198
GridData gd = new GridData(GridData.FILL_BOTH);
9299
gd.widthHint = 400;
93100
gd.heightHint = 275;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ int callWindowProc (int hwnd, int msg, int wParam, int lParam) {
489489
*/
490490
public void close () {
491491
checkWidget ();
492-
if ((this.getStyle() & SWT.TOOL) == 0 && display.taskBar != null) {
492+
if (parent == null && (this.getStyle() & SWT.TOOL) == 0 && display.taskBar != null) {
493493
TaskBar taskBar = display.taskBar;
494494
taskBar.removeShellItem(this);
495495
taskBar.handleApproaching();
@@ -498,6 +498,18 @@ public void close () {
498498
taskBar.updateLastModified();
499499
}
500500
closeWidget ();
501+
Shell topShell = Display.getTopShell();
502+
if (topShell != null && !topShell.isDisposed()) {
503+
topShell.bringToTop();
504+
} else
505+
/**
506+
* Return to default title
507+
* @j2sNative
508+
* if (window["document.title"] != null) {
509+
* document.title = window["document.title"];
510+
* }
511+
*/ {}
512+
501513
}
502514

503515
protected void createHandle () {

0 commit comments

Comments
 (0)