Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20200313003834
20200313123132
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20200313003834
20200313123132
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.java.core/src/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,7 @@ public InputStream getResourceAsStream(String name) {
var javapath = fname;
try {
if (fname.indexOf(":/") < 0) {
var d = document.location.href.split("?")[0].split("/");
var d = document.location.href.split("#")[0].split("?")[0].split("/");
d[d.length - 1] = fname;
fname = d.join("/");
}
Expand Down
Binary file not shown.
90 changes: 84 additions & 6 deletions sources/net.sf.j2s.java.core/src/swingjs/JSHTMLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.text.Element;
import javax.swing.text.Style;
import javax.swing.text.StyleContext;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLDocument.Iterator;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

import javajs.util.PT;

Expand Down Expand Up @@ -65,7 +69,7 @@ public String getText() {
* @param target
* @param eventType
* @param jQueryEvent
* @return
* @return true if handled
*/
@SuppressWarnings("unused")
public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
Expand Down Expand Up @@ -93,20 +97,28 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
try {
int pt = href.indexOf("#_JSHREF_");
if (pt < 0) {
System.out.println("JSHTMLHelper could not find '#_JSREF_' in " + href);
System.out.println("JSHTMLHelper could not find '#_JSHREF_' in " + href);
return true;
}
String left = href.substring(0, pt);
elem = getElementFromHref(left);
href = href.substring(pt + 9);
href = trimHRef(href.substring(pt + 9));

url = new URL(href);
} catch (MalformedURLException e) {
System.out.println("JSHTMLHelper invalidURL: " + href);
// ignore -- could be anything the developer wants.
}
editor.fireHyperlinkUpdate(new HyperlinkEvent(editor, type, url, href, elem));
return true;
}

private String trimHRef(String href) {
href = PT.trim(href,"'\"");
if (href.startsWith("%22") && href.endsWith("%22"))
href = href.substring(3, href.length() - 3);
return href;
}

/**
* Retrieve the anchor element index
* @param left
Expand All @@ -119,7 +131,7 @@ private Element getElementFromHref(String left) {
if (n >= 0 && n < aTagElements.size())
return aTagElements.get(n);
}
System.out.println("JSHTMLHelper could not find 'href=#n' in " + left);
System.out.println("JSHTMLHelper could not find '#_JSINDEX' in " + left);
return null;
}

Expand All @@ -131,7 +143,7 @@ private Element getElementFromHref(String left) {
* @return
*/
public String indexAnchors(String text) {
String html = PT.rep(text, "href=", "href=#_JSINDEX_##_JSHREF_");
String html = PT.rep(text, "href=", "onclick='return false' href=#_JSINDEX_##_JSHREF_");
Iterator iter = doc.getIterator(HTML.Tag.A);
aTagElements = new ArrayList<Element>();
for (int i = 0; iter.isValid(); i++) {
Expand All @@ -143,4 +155,70 @@ public String indexAnchors(String text) {
return html;
}

/**
* Generic method to get information from the HTMLDocument model.
* @param what "html", "css", or "styles"
* @param data secondary information
* @return appropriate object (String or String[])
*/
public Object get(String what, String data) {
switch (what) {
case "html":
return indexAnchors(data);
case "css":
return getCSS(data);
case "styles":
return getStyles(data);
default:
System.out.println("JSHTMLHelper.get what? " + what);
return null;
}

}

/**
* Return styles as an array of key/value pairs suitable for DOMNode.setStyles(node, []).
* This will just be the Java doc.getStyleSheet().getStyle("body").attributes.attributes.
*
* @return [key,value,key,value,...]
*/
private String[] getStyles(String name) {
StyleSheet sheet = doc.getStyleSheet();
if (sheet == null)
return null;
Style bodyStyle = sheet.getStyle(name);
if (bodyStyle != null)
{
return( /** @j2sNative bodyStyle.attributes.attributes || */null);
}
return null;
}

/**
* retrieve all CSS styles not including "default" or "body" that would appear
* within <style></style> in Java, scoped to this id.
*
* @param id
* @return CSS string
*/
private String getCSS(String id) {
String css = "";
StyleSheet sheet = doc.getStyleSheet();
if (sheet == null)
return null;
Enumeration styles = sheet.getStyleNames();
while (styles.hasMoreElements()) {
String name = (String) styles.nextElement();
// Don't write out the default style.
if (!name.equals(StyleContext.DEFAULT_STYLE)
&& !name.equals("body")) {
Style s = sheet.getStyle(name);
css += s + "\n";
}
}
return PT.rep(css, "NamedStyle:", "#" + id + " ").replace('=',':').replace(',',';');
}


}

33 changes: 24 additions & 9 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSDialogUI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package swingjs.plaf;

import java.util.List;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.peer.DialogPeer;

Expand All @@ -10,6 +12,8 @@
import javax.swing.JFrame;
import javax.swing.LookAndFeel;

import swingjs.api.js.DOMNode;


public class JSDialogUI extends JSFrameUI implements DialogPeer {

Expand All @@ -28,14 +32,13 @@ public JSDialogUI() {
setDoc();
}

@Override
public void installUI(JComponent jc) {
frame = (JFrame) c;
isModal = ((JDialog) c).isModal();
LookAndFeel.installColors(jc,
"Frame.background",
"Frame.foreground");
}
@Override
public void installUI(JComponent jc) {
frame = (JFrame) jc;
LookAndFeel.installColors(jc,
"Frame.background",
"Frame.foreground");
}

@Override
public void uninstallUI(JComponent jc) {
Expand All @@ -56,4 +59,16 @@ public void setVisible(boolean b) {

}

@Override
protected boolean isModal() {
boolean isModal = ((JDialog) jc).isModal();
if (isModal && modalNode == null) {
modalNode = DOMNode.createElement("div", id + "_modaldiv");
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
DOMNode.setStyles(modalNode, "position", "sticky", "left","0px", "top", "0px",
"background", toCSSString(new Color(100, 100, 100, 100)));
DOMNode.setSize(modalNode, screen.width, screen.height);
}
return isModal;
}
}
39 changes: 7 additions & 32 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ public void propertyChange(PropertyChangeEvent e) {
private String currentHTML;
private boolean isStyled;
private String mytext;
private String[] styles;
private String css;
private DOMNode styleNode;


Expand Down Expand Up @@ -343,13 +341,15 @@ public void setText(String text) {
if (editor.秘jsHTMLHelper != null) {
mytext = html = text;
isHTML = true;
html = editor.秘jsHTMLHelper.indexAnchors(getInner(text, "body"));
getStyles();
html = (String) editor.秘jsHTMLHelper.get("html", getInner(text, "body"));
DOMNode.setAttrs(domNode, "contentEditable", FALSE);
styleNode = DOMNode.createElement("div", id + "_style");
domNode.appendChild(styleNode);
String[] styles = (String[]) editor.秘jsHTMLHelper.get("styles", "body");
if (styles != null)
DOMNode.setStyles(styleNode, styles);
String css = (String) editor.秘jsHTMLHelper.get("css", id);
setStyle(id + "_style", css);
} else {
styleNode = domNode;
mytext = text;
Expand Down Expand Up @@ -387,38 +387,13 @@ public void setText(String text) {
}
}

private void getStyles() {
styles = null;
css = "";
StyleSheet sheet = editor.秘jsHTMLHelper.doc.getStyleSheet();
if (sheet == null)
return;
Enumeration styles = sheet.getStyleNames();
while (styles.hasMoreElements()) {
String name = (String) styles.nextElement();
// Don't write out the default style.
if (!name.equals(StyleContext.DEFAULT_STYLE)
&& !name.equals("body")) {
Style s = sheet.getStyle(name);
css += s + "\n";
}
}
css = PT.rep(css, "NamedStyle:", "#" + id + " ").replace('=',':');
setStyle(id + "_style", css);
Style bodyStyle = sheet.getStyle("body");
if (bodyStyle != null)
{
this.styles = /** @j2sNative bodyStyle.attributes.attributes || */null;
}
}

private void setStyle(String id, String css) {
DOMNode d = DOMNode.getElement(id);
if (d == null) {
d = DOMNode.createElement("style", id);
$(body).append(d);
$(body).append("<style id=" + id +">" + css + "</style>");
} else {
DOMNode.setAttr(d, "innerText", css);
}
DOMNode.setAttr(d, "innerText", css);
}

private String getInner(String html, String body) {
Expand Down
14 changes: 5 additions & 9 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class JSFrameUI extends JSWindowUI implements FramePeer, JSComponentUI.Em
// private String title;
private int state;
private DOMNode closerWrap;
protected boolean isModal;
protected int zModal;

protected boolean isInternalFrame;
Expand Down Expand Up @@ -138,13 +137,6 @@ public DOMNode updateDOMNode() {
DOMNode.setStyles(closerNode, "background-color", "#DDD");// strColor);
}
bindWindowEvents();
if (isModal) {
modalNode = DOMNode.createElement("div", id + "_modaldiv");
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
DOMNode.setStyles(modalNode, "position", "sticky", "left","0px", "top", "0px",
"background", toCSSString(new Color(100, 100, 100, 100)));
DOMNode.setSize(modalNode, screen.width, screen.height);
}
Insets s = getInsets();
DOMNode.setTopLeftAbsolute(frameNode, 0, 0);
DOMNode.setAttrs(frameNode, "width", "" + frame.getWidth() + s.left + s.right, "height",
Expand Down Expand Up @@ -426,7 +418,7 @@ public void setVisible(boolean b) {
if (isDummyFrame)
b = false;
super.setVisible(b);
if (isModal) {
if (isModal()) {
modalBlocked = b;
if (b) {
$(body).after(modalNode);
Expand All @@ -441,4 +433,8 @@ public void setVisible(boolean b) {
DOMNode.setVisible(domNode, b);
}

protected boolean isModal() {
// see JSDialogUI
return false;
}
}
28 changes: 26 additions & 2 deletions sources/net.sf.j2s.java.core/src/test/Test_Html.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package test;

import java.net.URL;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.event.HyperlinkEvent;
Expand All @@ -19,17 +21,39 @@ public Test_Html() {
editor.setEditable(false);
editor.setEditorKit(new HTMLEditorKit());
editor.setText(
"<html><head><style type=\"text/css\">body { margin:10px 10px 10px 10px;font-size: 12 pt; font-family: Dialog }</style></head><body><b>PhET Interactive Simulations</b><br>Copyright &copy; 2004-2015 University of Colorado.<br><a href=http://phet.colorado.edu/about/licensing.php>Some rights reserved.</a><br>Visit <a href=http://phet.colorado.edu>http://phet.colorado.edu</a></body></html>");
"<html>"
+ "<head>"
+ "<style type=\"text/css\">"
+ "body { margin:10px 10px 10px 10px;font-size: 24pt; font-family: Dialog }"
+ "a { text-decoration:none;font-size:12pt;}"
+ "</style>"
+ "</head>"
+ "<body>"
+ "<b><font color=red>PhET Interactive Simulations</font></b>"
+ "<br>Copyright &copy; 2004-2015 University of Colorado."
+ "<br><a href=http://phet.colorado.edu/about/licensing.php>Some rights reserved.</a>"
+ "<br>Visit <a href=http://phet.colorado.edu>http://phet.colorado.edu</a>"
+ " <a href=proxy-href>proxy</a>"
+ "</body>"
+ "</html>");
add(editor);
editor.addHyperlinkListener(new HyperlinkListener() {

@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
URL url = e.getURL();
System.out.println("source=" + e.getSource()
+ "\nsourceElement=" + e.getSourceElement()
+ "\neventType=" + e.getEventType()
+ "\ndesc=" + e.getDescription()
+ "\nurl=" + e.getURL() + "\n");
+ "\nurl=" + url + "\n");
if (url != null) {
/** @j2sNative
*
* open(url.toString());
*
*/
}
}

});
Expand Down
Loading