X Tutup
Skip to content

Commit 5582333

Browse files
author
zhourenjian
committed
1. Add narrow shadow for Menu, Shortcut item, Task item
2. Improve Dialog, so Dialog will be always on top layer 3. Fix bug of Menu's height 4. Optimization for Firefox's CSS base 64 image loading 5. Fix bugs of Tree, code refactoring of About
1 parent c44eb52 commit 5582333

33 files changed

+577
-116
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/package.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,24 @@ $WTC$$.getCSSRuleID = function (clazzName) {
139139
*/
140140
/* public */
141141
$WTC$$.registerCSS = function (clazzName, cssText) {
142+
var isDebugging = (window["swt.debugging"] == true);
143+
if (!isDebugging) {
144+
cssText = null;
145+
}
142146
if ($WTC$$.cssAlreadyAggregated || window["ClazzLoader"] == null) {
143-
return ;
147+
return;
148+
}
149+
if (!ClazzLoader.isIE && clazzName.indexOf (".IE") != -1) {
150+
return;
144151
}
145152
clazzName = ClazzLoader.unwrapArray ([clazzName])[0];
146-
var cssPath = ClazzLoader.getClasspathFor (clazzName, false, ".css");
153+
var cssPath = null;
154+
var idx = clazzName.indexOf (".IE");
155+
if (idx != -1) {
156+
cssPath = ClazzLoader.getClasspathFor (clazzName.substring(0, idx), false, ".IE.css");
157+
} else {
158+
cssPath = ClazzLoader.getClasspathFor (clazzName, false, ".css");
159+
}
147160

148161
var basePath = ClazzLoader.getClasspathFor (clazzName, true);
149162
var cssID = "c$$." + clazzName;
@@ -188,20 +201,20 @@ $WTC$$.registerCSS = function (clazzName, cssText) {
188201
//}
189202
}
190203
/*
191-
* Fix the css images location
204+
* Fix the css images location: url('...') or filter:...(src='...')
192205
*/
193-
cssText = cssText.replace (/(url\s*\(\s*['"])(.*)(['"])/ig,
206+
cssText = cssText.replace (/((url\s*\(\s*['"])|(src\s*=\s*['"]))(.*)(['"])/ig,
194207
//"
195-
function ($0, $1, $2, $3) {
196-
if ($2.indexOf ("/") == 0
197-
|| $2.indexOf ("http://") == 0
198-
|| $2.indexOf ("https://") == 0
199-
|| $2.indexOf ("file:/") == 0
200-
|| $2.indexOf ("ftp://") == 0
201-
|| $2.indexOf ("javascript:") == 0) {
208+
function ($0, $1, $2, $3, $4, $5) {
209+
if ($4.indexOf ("/") == 0
210+
|| $4.indexOf ("http://") == 0
211+
|| $4.indexOf ("https://") == 0
212+
|| $4.indexOf ("file:/") == 0
213+
|| $4.indexOf ("ftp://") == 0
214+
|| $4.indexOf ("javascript:") == 0) {
202215
return $0;
203216
}
204-
return $1 + prefix + $2 + $3;
217+
return $1 + prefix + $4 + $5;
205218
});
206219
if (document.createStyleSheet != null) {
207220
/*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ private static void createContents(Shell aboutShell) {
151151
gd_homepageLink.verticalIndent = 8;
152152
homepageLink.setLayoutData(gd_homepageLink);
153153
homepageLink.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
154-
homepageLink.setText("Home: <a href=\"http:/" + "/java2script.org/\">java2script.org</a> / <a href=\"http:/" + "/j2s.sourceforge.net/\">j2s.sourceforge.net</a>");
154+
homepageLink.setText("Home: <a href=\"http://java2script.org/\">java2script.org</a> / <a href=\"http://j2s.sourceforge.net/\">j2s.sourceforge.net</a>");
155155

156156
final Link founderLink = new Link(description, SWT.NONE);
157157
founderLink.setFont(j2sFont);
158158
founderLink.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
159-
founderLink.setText("Founder: <a href=\"http:/" + "/zhourenjian.name/\">Zhou Renjian</a>");
159+
founderLink.setText("Founder: <a href=\"http://zhourenjian.name/\">Zhou Renjian</a>");
160160

161161
Composite blank = new Composite(description, SWT.NONE);
162162
blank.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,11 @@ public void setAlignment (int alignment) {
812812
style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
813813
if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
814814
CSSStyle handleStyle = null;
815-
if ((style & (SWT.RADIO | SWT.CHECK)) != 0) {
815+
// if ((style & (SWT.RADIO | SWT.CHECK)) != 0) {
816816
handleStyle = btnText.style;
817-
} else {
818-
handleStyle = btnHandle.style;
819-
}
817+
// } else {
818+
// handleStyle = btnHandle.style;
819+
// }
820820
if ((style & SWT.LEFT) != 0) {
821821
btnText.style.textAlign = "left";
822822
handleStyle.backgroundPosition = "left center";
@@ -1028,17 +1028,17 @@ public void setImage (Image image) {
10281028
if (OS.isIENeedPNGFix && handleStyle.filter != null) handleStyle.filter = "";
10291029
handleStyle.backgroundRepeat = "no-repeat";
10301030
String bgXPos = "center";
1031-
if ((style & (SWT.RADIO | SWT.CHECK)) != 0) {
1031+
// if ((style & (SWT.RADIO | SWT.CHECK)) != 0) {
10321032
if ((style & SWT.RIGHT) != 0) {
10331033
bgXPos = "right";
10341034
} else if ((style & SWT.CENTER) != 0) {
10351035
bgXPos = "center";
10361036
} else {
10371037
bgXPos = "left";
10381038
}
1039-
} else if ((style & SWT.PUSH) != 0) {
1040-
bgXPos = "left";
1041-
}
1039+
// } else if ((style & SWT.PUSH) != 0) {
1040+
// bgXPos = "left";
1041+
// }
10421042
handleStyle.backgroundPosition = bgXPos + " center";
10431043
handleStyle.backgroundImage = "url(\"" + this.image.url + "\")";
10441044
}
@@ -1055,6 +1055,8 @@ public void setImage (Image image) {
10551055
// for (int i = 0; i < image.handle.childNodes.length; i++) {
10561056
// handle.insertBefore(image.handle.childNodes[i], txt);
10571057
// }
1058+
} else if (this.image != null) {
1059+
this.image.draw(btnHandle);
10581060
}
10591061
if (OS.isIE && (style & (SWT.RADIO | SWT.CHECK)) != 0) {
10601062
boolean emptyText = (image != null || text.length() == 0);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ public void run() {
8181
if (!display.readAndDispatch())
8282
display.sleep();
8383
}
84-
display.dispose();
84+
if (display.shortcutBar == null || display.shortcutBar.shortcutCount == 0) {
85+
display.dispose();
86+
}
8587
} catch (Exception e) {
8688
e.printStackTrace();
8789
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ protected void forceResize () {
733733
public Accessible getAccessible () {
734734
checkWidget ();
735735
// if (accessible == null) accessible = new_Accessible (this);
736+
if (accessible == null) accessible = new Accessible (this);
736737
return accessible;
737738
}
738739

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

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
* @see #getMaximized
108108
* @see Shell
109109
* @see SWT
110+
*
111+
* @j2sRequireImport org.eclipse.swt.internal.browser.OS
110112
*/
111113

112114
public class Decorations extends Canvas {
@@ -289,6 +291,12 @@ void bringToTop (boolean parentShell, boolean childShells) {
289291
s.bringToTop(false, true);
290292
}
291293
}
294+
295+
Dialog.checkExistedDialogs((Shell) this);
296+
}
297+
298+
if (modalHandle != null) {
299+
modalHandle.style.zIndex = "" + (Integer.parseInt("" + handle.style.zIndex) - 1);
292300
}
293301
}
294302

@@ -608,6 +616,32 @@ protected static void createShadowHandles(Element handle) {
608616
if (OS.isChrome) {
609617
handle.style.opacity = "1";
610618
}
619+
if (OS.isIE) {
620+
handle.style.filter = "";
621+
}
622+
}
623+
624+
protected static void createNarrowShadowHandles(Element handle) {
625+
String[] handles = new String[] {
626+
"shadow-narrow-left-top",
627+
"shadow-narrow-right-top",
628+
"shadow-narrow-center-top",
629+
"shadow-narrow-left-middle",
630+
"shadow-narrow-right-middle",
631+
"shadow-narrow-center-middle",
632+
"shadow-narrow-left-bottom",
633+
"shadow-narrow-right-bottom",
634+
"shadow-narrow-center-bottom"
635+
};
636+
for (int i = 0; i < handles.length; i++) {
637+
createCSSDiv(handle, handles[i]);
638+
}
639+
if (OS.isChrome) {
640+
handle.style.opacity = "1";
641+
}
642+
if (OS.isIE) {
643+
handle.style.filter = "";
644+
}
611645
}
612646

613647
protected void createHandle() {
@@ -654,16 +688,10 @@ public void run() {
654688
boolean supportShadow = false;
655689
/**
656690
* @j2sNative
657-
* supportShadow = window["swt.shell.shadow"];
691+
* supportShadow = window["swt.disable.shadow"] != true;
658692
*/ {}
659693
if (supportShadow) {
660-
if (OS.isIE) {
661-
if (!OS.isIE50 && !OS.isIE55 && OS.isIE60) {
662-
createShadowHandles(handle);
663-
}
664-
} else {
665-
createShadowHandles(handle);
666-
}
694+
createShadowHandles(handle);
667695
}
668696
if ((style & SWT.NO_TRIM) == 0
669697
&& (style & (SWT.TITLE | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
@@ -2267,13 +2295,27 @@ public void setText (String string) {
22672295
// TCHAR buffer = new TCHAR (0, string, true);
22682296
// OS.SetWindowText (handle, buffer);
22692297
if (shellTitle != null && shellTitle.childNodes != null) {
2270-
for (int i = shellTitle.childNodes.length - 1; i >= 0; i--) {
2271-
if (shellTitle.childNodes[i] != null) {
2272-
shellTitle.removeChild(shellTitle.childNodes[i]);
2273-
}
2274-
}
2298+
OS.clearChildren(shellTitle);
22752299
shellTitle.appendChild(document.createTextNode(string));
22762300

2301+
if ((this.style & SWT.TOOL) == 0 && Display.getTopShell() == this)
2302+
/**
2303+
* @j2sNative
2304+
* var title = this.getText();
2305+
* if (title != null) {
2306+
* // Record default title
2307+
* if (window["document.title"] == null) {
2308+
* window["document.title"] = document.title;
2309+
* }
2310+
* if (window["document.title.setter"] == null) {
2311+
* document.title = title; // set title directly
2312+
* } else {
2313+
* // document.title.setter may modify title
2314+
* window["document.title.setter"] (title);
2315+
* }
2316+
* }
2317+
*/ {}
2318+
22772319
if (this.parent == null && (this.getStyle() & SWT.TOOL) == 0
22782320
&& display.taskBar != null) {
22792321
display.taskBar.handleApproaching();

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
DialogSync2Async = {};
8686
DialogSync2Async.block = function (dialog, oThis, runnable) {
8787
if (dialog == null) return;
88+
org.eclipse.swt.widgets.Dialog.addDialog (dialog);
8889
dialog.open();
8990
var shell = dialog.dialogShell;
9091
if (shell == null) return;
@@ -98,6 +99,7 @@
9899
Clazz.decorateAsType (cla$$, "DialogSync2Async$1", null, $wt.events.DisposeListener);
99100
Clazz.defineMethod (cla$$, "widgetDisposed",
100101
function (e) {
102+
org.eclipse.swt.widgets.Dialog.removeDialog (dialog);
101103
var $runnable = this.f$.runnable;
102104
var $oThis = this.f$.oThis;
103105
window.setTimeout (function () {
@@ -120,6 +122,66 @@ public abstract class Dialog {
120122
public Shell dialogShell;
121123
public Object dialogReturn;
122124

125+
static Dialog[] activeDialogs;
126+
127+
static void addDialog(Dialog dialog) {
128+
if (activeDialogs == null) {
129+
activeDialogs = new Dialog[3];
130+
}
131+
int length = activeDialogs.length;
132+
for (int i = 0; i < length; i++) {
133+
if (activeDialogs[i] == dialog) {
134+
return;
135+
}
136+
}
137+
for (int i = 0; i < length; i++) {
138+
if (activeDialogs[i] == null) {
139+
activeDialogs[i] = dialog;
140+
return;
141+
}
142+
}
143+
Dialog[] newActiveDialogs = new Dialog[length + 3];
144+
System.arraycopy(activeDialogs, 0, newActiveDialogs, 0, length);
145+
activeDialogs[length] = dialog;
146+
}
147+
148+
static void removeDialog(Dialog dialog) {
149+
if (activeDialogs == null) {
150+
return;
151+
}
152+
int length = activeDialogs.length;
153+
for (int i = 0; i < length; i++) {
154+
if (activeDialogs[i] == dialog) {
155+
activeDialogs[i] = null;
156+
return;
157+
}
158+
}
159+
}
160+
161+
static void checkExistedDialogs(Shell shell) {
162+
if (activeDialogs == null) {
163+
return;
164+
}
165+
for (int i = 0; i < activeDialogs.length; i++) {
166+
Dialog dialog = activeDialogs[i];
167+
if (dialog != null && dialog.parent == shell) {
168+
dialog.dialogShell.bringToTop();
169+
}
170+
}
171+
}
172+
173+
static boolean isDialog(Shell shell) {
174+
if (activeDialogs == null) {
175+
return false;
176+
}
177+
for (int i = 0; i < activeDialogs.length; i++) {
178+
Dialog dialog = activeDialogs[i];
179+
if (dialog != null && dialog.dialogShell == shell) {
180+
return true;
181+
}
182+
}
183+
return false;
184+
}
123185
/**
124186
* Constructs a new instance of this class given only its
125187
* parent.

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
* @see #sleep
112112
* @see Device#dispose
113113
*
114+
* @j2sRequireImport org.eclipse.swt.widgets.Tray
115+
*
114116
* @j2sSuffix
115117
// Only IE need to release the resources so that no memory is leaked
116118
if (window.attachEvent) {
@@ -951,7 +953,10 @@ void destroyDisplay () {
951953
public void dispose() {
952954
Shell[] shells = getShells();
953955
if (shells == null || shells.length == 0) {
954-
super.dispose();
956+
if (shortcutBar == null || shortcutBar.shortcutCount == 0) {
957+
// only dispose Display object in ALAA mode
958+
super.dispose();
959+
}
955960
}
956961
//super.dispose();
957962
}
@@ -2533,14 +2538,22 @@ public void run() {
25332538
Element el = document.getElementById("_console_");
25342539
if (el != null) {
25352540
el.style.display = "none";
2536-
insertOpenConsoleLink(el);
2541+
/**
2542+
* @j2sNative
2543+
* window.setTimeout(org.eclipse.swt.widgets.Display.insertOpenConsoleLink, 500);
2544+
*/ {}
2545+
// insertOpenConsoleLink();
25372546
} else
25382547
/**
25392548
* @j2sNative
2549+
* if (window["C_$"] == null && Console != null) {
2550+
* C_$ = Console;
2551+
* C_$.createC_$Window = Console.createConsoleWindow;
2552+
* }
25402553
* if (Console == null) Console = C_$;
25412554
* if (C_$.createC_$Window.wrapped == null) {
25422555
* C_$.createC_$Window_ = Console.createC_$Window;
2543-
* C_$.createC_$Window = function (parentEl) {
2556+
* C_$.createConsoleWindow = C_$.createC_$Window = function (parentEl) {
25442557
* var console = C_$.createC_$Window_ (parentEl);
25452558
* console.style.display = "none";
25462559
* $wt.widgets.Display.insertOpenConsoleLink(console);
@@ -2552,7 +2565,7 @@ public void run() {
25522565

25532566
}
25542567

2555-
static void insertOpenConsoleLink(Element el) {
2568+
static void insertOpenConsoleLink() {
25562569
TrayItem item = new TrayItem(getTray(), SWT.NONE);
25572570
item.setText("Console");
25582571
item.handle.className = "tray-item tray-item-console";

0 commit comments

Comments
 (0)
X Tutup