Skip to content

Commit b4bf99b

Browse files
author
jossonsmith
committed
Move CSS related methods from Class and ClassLoader into SWT
package.js with namespace of "$WTC$$" for SWT only.
1 parent 541fb70 commit b4bf99b

File tree

2 files changed

+6
-156
lines changed

2 files changed

+6
-156
lines changed

sources/net.sf.j2s.java.core/src/java/lang/ClassExt.js

Lines changed: 6 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,17 @@ Clazz.prepareCallback = function (objThis, args) {
7272
var className = Clazz.getClassName (classThisObj, true);
7373
//if (obs[className] == null) { /* == null make no sense! */
7474
//obs[className] = classThisObj;
75+
/*
76+
* TODO: the following line is SWT-specific! Try to move it out!
77+
*/
7578
obs[className.replace (/org\.eclipse\.swt\./, "$wt.")] = classThisObj;
7679
var clazz = Clazz.getClass (classThisObj);
7780
while (clazz.superClazz != null) {
7881
clazz = clazz.superClazz;
7982
//obs[Clazz.getClassName (clazz)] = classThisObj;
83+
/*
84+
* TODO: the following line is SWT-specific! Try to move it out!
85+
*/
8086
obs[Clazz.getClassName (clazz, true)
8187
.replace (/org\.eclipse\.swt\./, "$wt.")] = classThisObj;
8288
}
@@ -792,100 +798,3 @@ Clazz.forName = function (clazzName) {
792798
}
793799
};
794800

795-
/* protected */
796-
Clazz.cssAlreadyAggregated = false;
797-
Clazz.cssForcedUsingFile = false;
798-
799-
/**
800-
* Register css for the given class. If the given css text is null, it will
801-
* try to find relative *.css file instead loading css text directly.
802-
* @param clazzName Qualified name of a class
803-
* @param cssText Optional, if given, it will loaded into the page directly.
804-
*/
805-
/* public */
806-
Clazz.registerCSS = function (clazzName, cssText) {
807-
if (Clazz.cssAlreadyAggregated || window["ClazzLoader"] == null) {
808-
return ;
809-
}
810-
clazzName = ClazzLoader.unwrapArray ([clazzName])[0];
811-
var cssPath = ClazzLoader.getClasspathFor (clazzName, false, ".css");
812-
813-
var basePath = ClazzLoader.getClasspathFor (clazzName, true);
814-
var cssID = "c$$." + clazzName;
815-
/*
816-
* Check whether the css resources is loaded or not
817-
*/
818-
if (!ClazzLoader.isResourceExisted (clazzName, cssPath, basePath)) {
819-
ClazzLoader.registeredCSSs[ClazzLoader.registeredCSSs.length] = clazzName;
820-
if (cssText == null || Clazz.cssForcedUsingFile) {
821-
var cssLink = document.createElement ("LINK");
822-
cssLink.rel = "stylesheet";
823-
cssLink.id = cssID;
824-
cssLink.href = cssPath;
825-
document.getElementsByTagName ("HEAD")[0].appendChild (cssLink);
826-
} else {
827-
var prefix = "";
828-
var idx = cssPath.lastIndexOf ("/");
829-
if (idx != -1) {
830-
prefix = cssPath.substring (0, idx + 1);
831-
}
832-
if (document.createStyleSheet != null) {
833-
// prepare for createStyleSheet with "javascript:...";
834-
/*
835-
* TODO: Make more tests on the correctness of prefix!
836-
*/
837-
//var protocol = window.location.protocol;
838-
//var host = window.location.host;
839-
var location = window.location.href.toString ();
840-
//if (protocol == "file:" || host == "") {
841-
var idx = location.lastIndexOf ("/");
842-
if (idx != -1) {
843-
prefix = location.substring (0, idx + 1) + prefix;
844-
}
845-
//}
846-
}
847-
/*
848-
* Fix the css images location
849-
*/
850-
cssText = cssText.replace (/(url\s*\(\s*['"])(.*)(['"])/ig,
851-
//"
852-
function ($0, $1, $2, $3) {
853-
if ($2.indexOf ("/") == 0
854-
|| $2.indexOf ("http://") == 0
855-
|| $2.indexOf ("https://") == 0
856-
|| $2.indexOf ("file:/") == 0
857-
|| $2.indexOf ("ftp://") == 0
858-
|| $2.indexOf ("javascript:") == 0) {
859-
return $0;
860-
}
861-
return $1 + prefix + $2 + $3;
862-
});
863-
if (document.createStyleSheet != null) {
864-
/*
865-
* Internet Explorer does not support loading dynamic css styles
866-
* by creating <STYLE> element!
867-
*/
868-
var sheet = document.createStyleSheet ();
869-
sheet.cssText = cssText;
870-
//sheet.id = cssID; // No ID support the this element for IE
871-
window[cssID] = true;
872-
} else {
873-
var cssStyle = document.createElement ("STYLE");
874-
cssStyle.id = cssID;
875-
cssStyle.appendChild (document.createTextNode (cssText));
876-
document.getElementsByTagName ("HEAD")[0].appendChild (cssStyle);
877-
}
878-
}
879-
880-
var len = ClazzLoader.themes.length;
881-
for(var i = 0; i < len; i++){
882-
var themeName = ClazzLoader.themes[i];
883-
var themePath = ClazzLoader.themePaths[themeName] + "/" + clazzName.replace (/\./g, "/") + ".css";
884-
var cssLink = document.createElement ("LINK");
885-
cssLink.rel = "stylesheet";
886-
cssLink.id = cssID + themeName;
887-
cssLink.href = themePath;
888-
document.getElementsByTagName ("HEAD")[0].appendChild (cssLink);
889-
}
890-
}
891-
};

sources/net.sf.j2s.java.core/src/java/lang/ClassLoader.js

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -847,65 +847,6 @@ ClazzLoader.isResourceExisted = function (id, path, base) {
847847
}
848848
return false;
849849
};
850-
851-
/*
852-
* loadCSS may be considered part of SWT library. Should be packed with
853-
* SWT not with Java core.
854-
*/
855-
/* public */
856-
ClazzLoader.loadCSS = function (cssName) {
857-
var cssKey = "";
858-
var idx = cssName.lastIndexOf (".");
859-
if (idx == -1) {
860-
cssKey = cssName + ".css";
861-
} else {
862-
cssKey = cssName.substring (idx + 1) + ".css";
863-
}
864-
var resLinks = document.getElementsByTagName ("LINK");
865-
for (var i = 0; i < resLinks.length; i++) {
866-
var cssPath = resLinks[i].href;
867-
if (cssPath.lastIndexOf (cssKey) == cssPath.length - cssKey.length) {
868-
return ;
869-
}
870-
}
871-
872-
/*-# cssLink -> rel #-*/
873-
var cssLink = document.createElement ("LINK");
874-
cssLink.rel = "stylesheet";
875-
var path = ClazzLoader.getClasspathFor (cssName);
876-
cssLink.href = path.substring (0, path.lastIndexOf (".js")) + ".css";
877-
document.getElementsByTagName ("HEAD")[0].appendChild (cssLink);
878-
};
879-
/*
880-
* This array will preserves the themes order.
881-
*/
882-
ClazzLoader.themes = new Array();
883-
ClazzLoader.themePaths = new Object();
884-
ClazzLoader.registeredCSSs = new Array();
885-
/**
886-
* This mehtod register a theme for overriding the default theme mechanism.
887-
*
888-
* @param themeName The name of the theme that must be unique
889-
* @param themePath The path of the theme that must contains the CSS files
890-
*/
891-
ClazzLoader.registerTheme = function(themeName, themePath){
892-
ClazzLoader.themes[ClazzLoader.themes.length] = themeName;
893-
ClazzLoader.themePaths[themeName] = themePath;
894-
895-
var len = ClazzLoader.registeredCSSs.length;
896-
var cssID = "c$$." + clazzName;
897-
898-
for (var i = 0 ; i < len; i++) {
899-
var clazzName = ClazzLoader.registeredCSSs[i];
900-
var cssPath = themePath + "/" + clazzName.replace (/\./g, "/") + ".css";
901-
var cssLink = document.createElement ("LINK");
902-
cssLink.rel = "stylesheet";
903-
cssLink.id = cssID + themeName;
904-
cssLink.href = cssPath;
905-
document.getElementsByTagName ("HEAD")[0].appendChild (cssLink);
906-
}
907-
908-
};
909850
/**
910851
* After class is loaded, this method will be executed to check whether there
911852
* are classes in the dependency tree that need to be loaded.

0 commit comments

Comments
 (0)