1010import javax .swing .JEditorPane ;
1111import javax .swing .event .HyperlinkEvent ;
1212import javax .swing .event .HyperlinkEvent .EventType ;
13+ import javax .swing .text .AttributeSet ;
1314import javax .swing .text .Element ;
1415import javax .swing .text .Style ;
1516import javax .swing .text .StyleContext ;
17+ import javax .swing .text .StyleContext .NamedStyle ;
1618import javax .swing .text .html .HTML ;
1719import javax .swing .text .html .HTMLDocument ;
1820import javax .swing .text .html .HTMLDocument .Iterator ;
1921import javax .swing .text .html .HTMLEditorKit ;
2022import javax .swing .text .html .StyleSheet ;
2123
2224import javajs .util .PT ;
25+ import swingjs .api .js .DOMNode ;
26+ import swingjs .api .js .J2SInterface ;
27+ import swingjs .api .js .JQueryObject ;
2328import swingjs .plaf .JSComponentUI ;
2429
2530/**
@@ -75,7 +80,8 @@ public String getText() {
7580 @ SuppressWarnings ("unused" )
7681 public boolean handleJSEvent (Object target , int eventType , Object jQueryEvent ) {
7782 EventType type = null ;
78- String href = /** @j2sNative jQueryEvent.target.href || */
83+ JQueryObject node = JSUtil .jQuery .$ (/** @j2sNative jQueryEvent.target ||*/ null ).closest ("a" );
84+ String href = /** @j2sNative node && node[0].href || */
7985 null ;
8086 if (href == null )
8187 return JSComponentUI .HANDLED ;
@@ -104,6 +110,10 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
104110 String left = href .substring (0 , pt );
105111 elem = getElementFromHref (left );
106112 href = trimHRef (href .substring (pt + 9 ));
113+ J2SInterface j2s = JSUtil .J2S ;
114+ String j2sPath = /** @j2sNative j2s.thisApplet._j2sPath || */ null ;
115+ if (href .startsWith (j2sPath ))
116+ href = href .substring (j2sPath .length ());
107117 url = new URL (doc .getBase (), href );
108118 } catch (MalformedURLException e ) {
109119 // ignore -- could be anything the developer wants.
@@ -190,7 +200,8 @@ private String[] getStyles(String name) {
190200 Style bodyStyle = sheet .getStyle (name );
191201 if (bodyStyle != null )
192202 {
193- return ( /** @j2sNative bodyStyle.attributes.attributes || */ null );
203+ Object r = bodyStyle .getAttribute ("resolver" );
204+ return ( /** @j2sNative (r || bodyStyle).attributes.attributes || */ null );
194205 }
195206 return null ;
196207 }
@@ -207,17 +218,26 @@ private String getCSS(String id) {
207218 StyleSheet sheet = doc .getStyleSheet ();
208219 if (sheet == null )
209220 return null ;
210- Enumeration styles = sheet .getStyleNames ();
211- while (styles .hasMoreElements ()) {
212- String name = (String ) styles .nextElement ();
213- // Don't write out the default style.
214- if (!name .equals (StyleContext .DEFAULT_STYLE )
215- && !name .equals ("body" )) {
216- Style s = sheet .getStyle (name );
217- css += s + "\n " ;
218- }
219- }
220- return css .replaceAll ("NamedStyle:" , "#" + id + " " ).replaceAll ("=" ,":" ).replaceAll ("," , ";" );
221+ Enumeration styles = sheet .getStyleNames ();
222+ while (styles .hasMoreElements ()) {
223+ String name = (String ) styles .nextElement ();
224+ // Don't write out the default style.
225+ Style s = sheet .getStyle (name );
226+ NamedStyle r = (NamedStyle ) s .getAttribute ("resolver" );
227+ String a ;
228+ if (name .equals (StyleContext .DEFAULT_STYLE ) || name .equals ("body" )) {
229+ continue ;
230+ // a = (r == null ? s : r).toString();
231+ // a = "#" + id + "_body" + a.substring(a.indexOf("{"));
232+ } else if (r == null ) {
233+ a = s .toString ();
234+ } else {
235+ r .setName (name );
236+ a = r .toString ();
237+ }
238+ css += a + "\n " ;
239+ }
240+ return css .replaceAll ("NamedStyle:" , "#" + id + " " ).replaceAll ("=" , ":" ).replaceAll ("," , ";" );
221241 }
222242
223243 public static String fixLinks (String html , URL page ) {
0 commit comments