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 @@
20210321064238
20210505171935
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20210321064238
20210505171935
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public interface A2SWrappedComponent {
*
*/
private int 秘iPaintMyself = PAINTS_SELF_UNKNOWN;

/**
* paint(g) or paintComponent(g) or update(g) or paintContainer(g) is overridden
*/
private boolean 秘iPaintMyselfEntirely;
private boolean 秘repaintAsUpdate = true;
private static boolean 秘isRepaint = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public boolean equals(Object o) {
public int hashCode() {
int hashCode = 1;
for (E e : this)
hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
hashCode = (31*hashCode + (e==null ? 0 : e.hashCode()))& 0xFFFFFFFF;
return hashCode;
}

Expand Down
63 changes: 58 additions & 5 deletions sources/net.sf.j2s.java.core/src/javajs/util/CifDataParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -862,21 +862,35 @@ protected boolean isTerminator(char c) {
protected boolean isQuote(char ch) {
switch (ch) {
case '\'':
case '\"':
case '"':
case '\1':
case '[':
case ']':
return true;
}
return false;
}

/**
* CIF 1.0 only.
* CIF 1.0 only.
*
*
* @param ch current character being pointed to
*
* @param ch
* current character being pointed to
* @return a String data object
*/
protected Object getQuotedStringOrObject(char ch) {
switch (ch) {
case '[':
try {
return readList();
} catch (Exception e) {
System.out.println("exception in CifDataParser ; " + e);
}
case ']':
ich++;
return "]";
}
int ichStart = ich;
char chClosingQuote = ch;
boolean wasQuote = false;
Expand All @@ -896,10 +910,49 @@ protected Object getQuotedStringOrObject(char ch) {
pt2++;
} else {
// throw away the last white character
++ich;
++ich;
}
return str.substring(pt1, pt2);
}

/**
* Read a CIF 2.0 list structure, converting it to either a JSON string or to
* a Java data structure
*
* @return a string or data structure, depending upon setting asObject
* @throws Exception
*/
public Object readList() throws Exception {
ich++;
// save the current globals cterm and nullString,
// and restore them afterward.
// nullString is what is returned for '.' and '?';
// for the Jmol CifReader only, this needs to be "\0"
char cterm0 = cterm;
cterm = ']';
String ns = nullString;
nullString = null;
Lst<Object> lst = (asObject ? new Lst<Object>() : null);
int n = 0;
String str = "";
while (true) {
// Iteratively pick up all the objects until the closing bracket
// This is akin to an array "deep copy"
Object value = (asObject ? getNextTokenObject() : getNextToken());
if (value == null || value.equals("]"))
break;
if (asObject) {
lst.addLast(value);
} else {
if (n++ > 0)
str += ",";
str += value;
}
}
cterm = cterm0;
nullString = ns;
return (asObject ? lst : "[" + str + "]");
}


}
16 changes: 16 additions & 0 deletions sources/net.sf.j2s.java.core/src/javajs/util/DF.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,20 @@ public static String formatDecimalTrimmed(double x, int precision) {
return str.substring(0, m + 1); // 0.##...
}

/**
* an alternative to DecimalFormat "0.0"
*
* @param x
* @param precision
* @return formatted number
*/
public static String formatDecimalTrimmed0(double x, int precision) {
String str = DF.formatDecimalDbl(x, precision);
int m = str.length() - 1;
int pt = str.indexOf(".") + 1;
while (m > pt && str.charAt(m) == '0')
m--;
return str.substring(0, m + 1); // 0.0##...
}

}
13 changes: 10 additions & 3 deletions sources/net.sf.j2s.java.core/src/javax/swing/JEditorPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import javax.swing.event.HyperlinkListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.BoxView;
import javax.swing.text.Caret;
Expand All @@ -68,6 +69,7 @@
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.WrappedPlainView;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;

Expand All @@ -77,6 +79,7 @@
import swingjs.api.Interface;
//import swingjs.api.JSMinimalAbstractDocument;
//import java.io.ObjectOutputStream;
import swingjs.plaf.JSEditorPaneUI;

/**
* A text component to edit various kinds of content. You can find how-to
Expand Down Expand Up @@ -906,8 +909,11 @@ private Object getPostData() {
* @param reference the named location to scroll to
*/
public void scrollToReference(String reference) {
// Document d = getDocument();
// if (d instanceof HTMLDocument) {
Document d = getDocument();
if (d instanceof HTMLDocument) {
//SwingUtilities.invokeLater(() -> {
((JSEditorPaneUI) getUI()).scrollToReference(reference);
//});
// HTMLDocument doc = (HTMLDocument) d;
// HTMLDocument.Iterator iter = doc.getIterator(HTML.Tag.A);
// for (; iter.isValid(); iter.next()) {
Expand All @@ -919,6 +925,7 @@ public void scrollToReference(String reference) {
// int pos = iter.getStartOffset();
// Rectangle r = modelToView(pos);
// if (r != null) {
//
// // the view is visible, scroll it to the
// // center of the current visible area.
// Rectangle vis = getVisibleRect();
Expand All @@ -932,7 +939,7 @@ public void scrollToReference(String reference) {
// }
// }
// }
// }
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package sun.awt.image;

import java.io.InputStream;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.FileNotFoundException;

public class FileImageSource extends InputStreamImageSource {
String imagefile;

public FileImageSource(String filename) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(filename);
}
imagefile = filename;
}

final boolean checkSecurity(Object context, boolean quiet) {
// File based images only ever need to be checked statically
// when the image is retrieved from the cache.
return true;
}

protected ImageDecoder getDecoder() {
if (imagefile == null) {
return null;
}

InputStream is;
try {
is = new BufferedInputStream(new FileInputStream(imagefile));
} catch (FileNotFoundException e) {
return null;
}
// Don't believe the file suffix - many users don't know what
// kind of image they have and guess wrong...
/*
int suffixpos = imagefile.lastIndexOf('.');
if (suffixpos >= 0) {
String suffix = imagefile.substring(suffixpos+1).toLowerCase();
if (suffix.equals("gif")) {
return new GifImageDecoder(this, is);
} else if (suffix.equals("jpeg") || suffix.equals("jpg") ||
suffix.equals("jpe") || suffix.equals("jfif")) {
return new JPEGImageDecoder(this, is);
} else if (suffix.equals("xbm")) {
return new XbmImageDecoder(this, is);
}
}
*/
return getDecoder(is);
}
}
72 changes: 59 additions & 13 deletions sources/net.sf.j2s.java.core/src/swingjs/JSHTMLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.text.AttributeSet;
import javax.swing.text.Element;
import javax.swing.text.Style;
import javax.swing.text.StyleContext;
import javax.swing.text.StyleContext.NamedStyle;
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;
import swingjs.api.js.DOMNode;
import swingjs.api.js.J2SInterface;
import swingjs.api.js.JQueryObject;
import swingjs.plaf.JSComponentUI;

/**
Expand Down Expand Up @@ -75,7 +80,8 @@ public String getText() {
@SuppressWarnings("unused")
public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
EventType type = null;
String href = /** @j2sNative jQueryEvent.target.href || */
JQueryObject node = JSUtil.jQuery.$(/** @j2sNative jQueryEvent.target ||*/ null).closest("a");
String href = /** @j2sNative node && node[0].href || */
null;
if (href == null)
return JSComponentUI.HANDLED;
Expand Down Expand Up @@ -104,6 +110,10 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
String left = href.substring(0, pt);
elem = getElementFromHref(left);
href = trimHRef(href.substring(pt + 9));
J2SInterface j2s = JSUtil.J2S;
String j2sPath = /** @j2sNative j2s.thisApplet._j2sPath || */null;
if (href.startsWith(j2sPath))
href = href.substring(j2sPath.length());
url = new URL(doc.getBase(), href);
} catch (MalformedURLException e) {
// ignore -- could be anything the developer wants.
Expand Down Expand Up @@ -190,7 +200,8 @@ private String[] getStyles(String name) {
Style bodyStyle = sheet.getStyle(name);
if (bodyStyle != null)
{
return( /** @j2sNative bodyStyle.attributes.attributes || */null);
Object r = bodyStyle.getAttribute("resolver");
return( /** @j2sNative (r || bodyStyle).attributes.attributes || */null);
}
return null;
}
Expand All @@ -207,17 +218,52 @@ private String getCSS(String id) {
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 css.replaceAll("NamedStyle:", "#" + id + " ").replaceAll("=",":").replaceAll(",", ";");
Enumeration styles = sheet.getStyleNames();
while (styles.hasMoreElements()) {
String name = (String) styles.nextElement();
// Don't write out the default style.
Style s = sheet.getStyle(name);
NamedStyle r = (NamedStyle) s.getAttribute("resolver");
String a;
if (name.equals(StyleContext.DEFAULT_STYLE) || name.equals("body")) {
continue;
// a = (r == null ? s : r).toString();
// a = "#" + id + "_body" + a.substring(a.indexOf("{"));
} else if (r == null) {
a = s.toString();
} else {
r.setName(name);
a = r.toString();
}
css += a + "\n";
}
return css.replaceAll("NamedStyle:", "#" + id + " ").replaceAll("=", ":").replaceAll(",", ";");
}

public static String fixLinks(String html, URL page) {
if (page != null && page.getProtocol().equals("file") && html.indexOf("src=\".") >= 0) {
String rp = JSUtil.J2S.getResourcePath("", true);
if (rp.indexOf("://") < 0)
rp = "file:/" + rp;
try {
page = new URL(rp + page.getPath().substring(1));
} catch (MalformedURLException e1) {
}
String[] srcs = PT.split(html, "src=\"");
String out = srcs[0];
for (int i = 1; i < srcs.length; i++) {
int pt = srcs[i].indexOf('"');
String src = srcs[i].substring(0, pt);
try {
if (!src.startsWith("http://") && !src.startsWith("https://"))
src = new URL(page, src).getPath().substring(1);
} catch (MalformedURLException e) {
}
out += "src=\"" + src + srcs[i].substring(pt);
}
html = out;
}
return html;
}


Expand Down
Loading