Skip to content

Commit da49f1c

Browse files
author
zhourenjian
committed
Fixed bug that MouseEvent/KeyEvent's properties are not correctly
Fixed bug that Link#setText is inserting new link rather than replacing with new link Now "exporting HTML sources" is in a lazy-loading *.js
1 parent 7462a6b commit da49f1c

File tree

5 files changed

+155
-114
lines changed

5 files changed

+155
-114
lines changed

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

Lines changed: 8 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import org.eclipse.swt.SWT;
1616
import org.eclipse.swt.SWTException;
17-
import org.eclipse.swt.events.SelectionAdapter;
18-
import org.eclipse.swt.events.SelectionEvent;
1917
import org.eclipse.swt.graphics.Color;
2018
import org.eclipse.swt.graphics.Image;
2119
import org.eclipse.swt.graphics.Point;
@@ -31,8 +29,6 @@
3129
import org.eclipse.swt.internal.xhtml.HTMLEvent;
3230
import org.eclipse.swt.internal.xhtml.document;
3331
import org.eclipse.swt.internal.xhtml.window;
34-
import org.eclipse.swt.layout.GridData;
35-
import org.eclipse.swt.layout.GridLayout;
3632

3733
/**
3834
* Instances of this class provide the appearance and
@@ -732,110 +728,16 @@ void addModalLayer() {
732728
}
733729

734730
/**
735-
* TODO: Move this function into external *.js
736-
* @xj2sIgnore
731+
* @j2sNative
732+
* ClazzLoader.loadClass ("$wt.widgets.HTMLSource", function () {
733+
* new $wt.widgets.HTMLSource ().exportSource (this, a);
734+
* });
735+
* @j2sNativeSrc
736+
* ClazzLoader.loadClass ("$wt.widgets.HTMLSource", function () {
737+
* new $wt.widgets.HTMLSource ().exportSource (this, onlyContent);
738+
* });
737739
*/
738740
void exportHTMLSource(boolean onlyContent) {
739-
final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.APPLICATION_MODAL);
740-
// shell.setLayout(new FillLayout());
741-
shell.setText("Export HTML Source");
742-
String c = null; // always be "b" for "@j2sNative/Src"
743-
if (onlyContent) {
744-
c = contentHandle.innerHTML;
745-
} else {
746-
c = handle.innerHTML;
747-
}
748-
//b.replaceAll("(<\\/?)(\\w+)(\\s|>)", "$0$1$2");
749-
if (OS.isIE)
750-
/**
751-
* @j2sNative
752-
c = c.replace (/(<\/?)(\w+)(\s|>)/ig, function ($0, $1, $2, $3) {
753-
return $1 + $2.toLowerCase () + $3;
754-
}).replace (/(style\s*=\s*")([^"]+)(")/ig, function ($0, $1, $2, $3) {
755-
if (!((/;$/).test ($2))) {
756-
$2 += ";";
757-
}
758-
return "style=\"" + $2.toLowerCase ().replace (/(:|;)\s+/g, "$1") + "\"";
759-
}).replace (/(\s+(\w+)\s*=\s*)([^\"\s>]+)(\s|>)/ig, function ($0, $1, $2, $3, $4) {
760-
return " " + $2 + "=\"" + $3 + "\"" + $4;
761-
//}).replace (/\s+(\w+)(\s|>)/ig, function ($0, $1, $2) {
762-
// $1 = $1.toLowerCase ();
763-
// return " " + $1 + "=\"" + $1 + "\"" + $2;
764-
});
765-
*/ {} else
766-
/**
767-
* @j2sNative
768-
c = c.replace (/(style\s*=\s*")([^"]+)(")/ig, function ($0, $1, $2, $3) {
769-
return "style=\"" + $2.replace (/(:|;)\s+/g, "$1") + "\"";
770-
});
771-
*/ {}
772-
/**
773-
* @j2sNative
774-
c = c.replace (/(\sclass\s*=\s*)"([^"]*)"(\s|>)/ig, function ($0, $1, $2, $3) {
775-
$2 = $2.replace (/\s\s+/g, ' ').replace (/^\s+/, '').replace (/\s+$/g, '');
776-
if ($2.length == 0) {
777-
if ($3 != ">") {
778-
return $3;
779-
} else {
780-
return ">";
781-
}
782-
} else {
783-
return " class=\"" + $2 + "\"" + $3;
784-
}
785-
});
786-
*/ {}
787-
// int length = innerHTML.length();
788-
// if (length < 200) {
789-
// length = 200;
790-
// } else if (length > 1800) {
791-
// length = 1800;
792-
// }
793-
// length = (length - 200) / 400;
794-
// shell.setSize(480 + 80 * length, 280 + 50 * length);
795-
// Composite composite = new Composite(shell, SWT.NONE);
796-
// composite.setLayout(new GridLayout());
797-
shell.setLayout(new GridLayout());
798-
Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL);
799-
GridData gd = new GridData(GridData.FILL_BOTH);
800-
gd.widthHint = 400;
801-
gd.heightHint = 275;
802-
text.setLayoutData(gd);
803-
Rectangle rect = getClientArea();
804-
String html = null;
805-
if (onlyContent) {
806-
html = "<div class=\"shell-content\" style=\"" + "width:"
807-
+ rect.width + "px;height:" + rect.height + "px;\">" + c
808-
+ "</div>";
809-
} else {
810-
String cssText = handle.style.cssText;
811-
if (cssText != null && cssText.trim().length() != 0)
812-
/**
813-
* @j2sNative
814-
* cssText = cssText.replace (/([;\s]*)(top|left|right|bottom)\s*:\s*[^;"']*([;"'])/i, "$3").replace (/([;\s]*)(top|left|right|bottom)\s*:\s*[^;"']*([;"'])/i, "$3");
815-
*/ {}
816-
html = "<div class=\"" + handle.className + "\"" +
817-
((cssText != null && cssText.trim().length() != 0) ?
818-
" style=\"" + cssText + "\"" : "") +
819-
">" + c + "</div>";
820-
}
821-
text.setText(html);
822-
new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR)
823-
.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
824-
Button button = new Button(shell, SWT.PUSH);
825-
button.setText("&OK");
826-
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
827-
gridData.widthHint = 80;
828-
button.setLayoutData(gridData);
829-
button.addSelectionListener(new SelectionAdapter() {
830-
public void widgetSelected(SelectionEvent e) {
831-
shell.close();
832-
}
833-
});
834-
shell.pack();
835-
shell.open();
836-
while (!shell.isDisposed ()) {
837-
if (!display.readAndDispatch ()) display.sleep ();
838-
}
839741
}
840742

841743
protected void createWidget () {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2007 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Zhou Renjian - initial API and implementation
10+
*******************************************************************************/
11+
12+
package org.eclipse.swt.widgets;
13+
14+
import org.eclipse.swt.SWT;
15+
import org.eclipse.swt.events.SelectionAdapter;
16+
import org.eclipse.swt.events.SelectionEvent;
17+
import org.eclipse.swt.graphics.Rectangle;
18+
import org.eclipse.swt.internal.browser.OS;
19+
import org.eclipse.swt.layout.GridData;
20+
import org.eclipse.swt.layout.GridLayout;
21+
22+
/**
23+
*
24+
* @author Zhou Renjian
25+
*
26+
* 2007-6-20
27+
*/
28+
public class HTMLSource {
29+
30+
public void exportSource(Shell objShell, boolean onlyContent) {
31+
final Shell shell = new Shell(objShell.display, SWT.SHELL_TRIM | SWT.APPLICATION_MODAL);
32+
// shell.setLayout(new FillLayout());
33+
shell.setText("Export HTML Source");
34+
String c = null; // always be "b" for "@j2sNative/Src"
35+
if (onlyContent) {
36+
c = objShell.contentHandle.innerHTML;
37+
} else {
38+
c = objShell.handle.innerHTML;
39+
}
40+
//b.replaceAll("(<\\/?)(\\w+)(\\s|>)", "$0$1$2");
41+
if (OS.isIE)
42+
/**
43+
* @j2sNative
44+
c = c.replace (/(<\/?)(\w+)(\s|>)/ig, function ($0, $1, $2, $3) {
45+
return $1 + $2.toLowerCase () + $3;
46+
}).replace (/(style\s*=\s*")([^"]+)(")/ig, function ($0, $1, $2, $3) {
47+
if (!((/;$/).test ($2))) {
48+
$2 += ";";
49+
}
50+
return "style=\"" + $2.toLowerCase ().replace (/(:|;)\s+/g, "$1") + "\"";
51+
}).replace (/(\s+(\w+)\s*=\s*)([^\"\s>]+)(\s|>)/ig, function ($0, $1, $2, $3, $4) {
52+
return " " + $2 + "=\"" + $3 + "\"" + $4;
53+
//}).replace (/\s+(\w+)(\s|>)/ig, function ($0, $1, $2) {
54+
// $1 = $1.toLowerCase ();
55+
// return " " + $1 + "=\"" + $1 + "\"" + $2;
56+
});
57+
*/ {} else
58+
/**
59+
* @j2sNative
60+
c = c.replace (/(style\s*=\s*")([^"]+)(")/ig, function ($0, $1, $2, $3) {
61+
return "style=\"" + $2.replace (/(:|;)\s+/g, "$1") + "\"";
62+
});
63+
*/ {}
64+
/**
65+
* @j2sNative
66+
c = c.replace (/(\sclass\s*=\s*)"([^"]*)"(\s|>)/ig, function ($0, $1, $2, $3) {
67+
$2 = $2.replace (/\s\s+/g, ' ').replace (/^\s+/, '').replace (/\s+$/g, '');
68+
if ($2.length == 0) {
69+
if ($3 != ">") {
70+
return $3;
71+
} else {
72+
return ">";
73+
}
74+
} else {
75+
return " class=\"" + $2 + "\"" + $3;
76+
}
77+
});
78+
*/ {}
79+
// int length = innerHTML.length();
80+
// if (length < 200) {
81+
// length = 200;
82+
// } else if (length > 1800) {
83+
// length = 1800;
84+
// }
85+
// length = (length - 200) / 400;
86+
// shell.setSize(480 + 80 * length, 280 + 50 * length);
87+
// Composite composite = new Composite(shell, SWT.NONE);
88+
// composite.setLayout(new GridLayout());
89+
shell.setLayout(new GridLayout());
90+
Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL);
91+
GridData gd = new GridData(GridData.FILL_BOTH);
92+
gd.widthHint = 400;
93+
gd.heightHint = 275;
94+
text.setLayoutData(gd);
95+
Rectangle rect = objShell.getClientArea();
96+
String html = null;
97+
if (onlyContent) {
98+
html = "<div class=\"shell-content\" style=\"" + "width:"
99+
+ rect.width + "px;height:" + rect.height + "px;\">" + c
100+
+ "</div>";
101+
} else {
102+
String cssText = objShell.handle.style.cssText;
103+
if (cssText != null && cssText.trim().length() != 0)
104+
/**
105+
* @j2sNative
106+
* cssText = cssText.replace (/([;\s]*)(top|left|right|bottom)\s*:\s*[^;"']*([;"'])/i, "$3").replace (/([;\s]*)(top|left|right|bottom)\s*:\s*[^;"']*([;"'])/i, "$3");
107+
*/ {}
108+
html = "<div class=\"" + objShell.handle.className + "\"" +
109+
((cssText != null && cssText.trim().length() != 0) ?
110+
" style=\"" + cssText + "\"" : "") +
111+
">" + c + "</div>";
112+
}
113+
text.setText(html);
114+
new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR)
115+
.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
116+
Button button = new Button(shell, SWT.PUSH);
117+
button.setText("&OK");
118+
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
119+
gridData.widthHint = 80;
120+
button.setLayoutData(gridData);
121+
button.addSelectionListener(new SelectionAdapter() {
122+
public void widgetSelected(SelectionEvent e) {
123+
shell.close();
124+
}
125+
});
126+
shell.pack();
127+
shell.open();
128+
while (!shell.isDisposed ()) {
129+
if (!objShell.display.readAndDispatch ()) objShell.display.sleep ();
130+
}
131+
}
132+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,10 @@ public void setText (String string) {
771771
checkWidget ();
772772
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
773773
if (string.equals (text)) return;
774-
text = string;
775-
textSizeCached = false;
774+
text = string;
775+
textSizeCached = false;
776+
anchors = new Element[0];
777+
OS.clearChildren(handle);
776778
parse (string, handle);
777779
/*
778780
System.out.println(cachedText);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ public void forceActive () {
634634
checkWidget ();
635635
if(!isVisible()) return;
636636
// OS.SetForegroundWindow (handle);
637+
bringToTop();
637638
}
638639

639640
protected void forceResize () {

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ public void run() {
829829
dragStatus = true;
830830
}
831831
if (!hoverHooked || hooks(SWT.MouseDown)) {
832-
sendEvent(SWT.MouseDown);
832+
sendMouseEvent(SWT.MouseDown, ((HTMLEvent) getEvent()).button, e.target, e.x, e.y);
833833
}
834834
}
835835
};
@@ -840,7 +840,8 @@ public void run() {
840840
boolean hoverHooked = mouseHoverProc();
841841
dragStatus = false;
842842
if (!hoverHooked || hooks(SWT.MouseUp)) {
843-
sendEvent(SWT.MouseUp);
843+
HTMLEventWrapper e = new HTMLEventWrapper (getEvent());
844+
sendMouseEvent(SWT.MouseUp, ((HTMLEvent) getEvent()).button, e.target, e.x, e.y);
844845
}
845846
}
846847
};
@@ -858,7 +859,7 @@ && hooks(SWT.DragDetect)) {
858859
dragStatus = false;
859860
}
860861
if ((!dragHooked && !hoverHooked) || hooks(SWT.MouseMove)) {
861-
sendEvent(SWT.MouseMove);
862+
sendMouseEvent(SWT.MouseMove, ((HTMLEvent) getEvent()).button, e.target, e.x, e.y);
862863
}
863864
}
864865
};
@@ -868,7 +869,8 @@ void hookMouseEnter() {
868869
public void run() {
869870
boolean hoverHooked = mouseHoverProc();
870871
if (!hoverHooked || hooks(SWT.MouseEnter)) {
871-
sendEvent(SWT.MouseEnter);
872+
HTMLEventWrapper e = new HTMLEventWrapper (getEvent());
873+
sendMouseEvent(SWT.MouseEnter, ((HTMLEvent) getEvent()).button, e.target, e.x, e.y);
872874
}
873875
}
874876
};
@@ -883,15 +885,17 @@ public void run() {
883885
hoverTimerID = 0;
884886
}
885887
if (!hoverHooked || hooks(SWT.MouseExit)) {
886-
sendEvent(SWT.MouseExit);
888+
HTMLEventWrapper e = new HTMLEventWrapper (getEvent());
889+
sendMouseEvent(SWT.MouseExit, ((HTMLEvent) getEvent()).button, e.target, e.x, e.y);
887890
}
888891
}
889892
};
890893
}
891894
void hookMouseDoubleClick() {
892895
handle.ondblclick = new RunnableCompatibility() {
893896
public void run() {
894-
sendEvent(SWT.MouseDoubleClick);
897+
HTMLEventWrapper e = new HTMLEventWrapper (getEvent());
898+
sendMouseEvent(SWT.MouseDoubleClick, ((HTMLEvent) getEvent()).button, e.target, e.x, e.y);
895899
}
896900
};
897901
}

0 commit comments

Comments
 (0)