Skip to content

Commit 0fe5b83

Browse files
authored
Merge pull request #211 from BobHanson/hanson1
Hanson1 - JTable, JEditorPane fixes
2 parents df9b674 + 1269324 commit 0fe5b83

File tree

17 files changed

+198
-99
lines changed

17 files changed

+198
-99
lines changed
352 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20210301062205
1+
20210321064238
352 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20210301062205
1+
20210321064238
352 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/javajs/async/Assets.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,10 @@ private URL _getURLFromPath(String fullPath, boolean zipOnly) {
446446
if (fullPath.startsWith(sortedList[i])) {
447447
url = assetsByPath.get(sortedList[i]).getURL(fullPath);
448448
ZipEntry ze = findZipEntry(url);
449-
if (ze == null)
449+
if (ze == null) {
450+
url = null;
450451
break;
452+
}
451453
if (isJS) {
452454
jsutil.setURLBytes(url, jsutil.getZipBytes(ze));
453455
}

sources/net.sf.j2s.java.core/src/javax/swing/JEditorPane.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import javax.swing.text.html.HTMLEditorKit;
7373

7474
import swingjs.JSHTMLHelper;
75+
import swingjs.JSUtil;
7576
//import swingjs.JSAbstractDocument;
7677
import swingjs.api.Interface;
7778
//import swingjs.api.JSMinimalAbstractDocument;
@@ -423,6 +424,7 @@ public void fireHyperlinkUpdate(HyperlinkEvent e) {
423424
* @see #getPage
424425
* @beaninfo description: the URL used to set content bound: true expert: true
425426
*/
427+
@SuppressWarnings("unused")
426428
public void setPage(URL page) throws IOException {
427429
if (page == null) {
428430
throw new IOException("invalid url");
@@ -464,6 +466,7 @@ public void setPage(URL page) throws IOException {
464466
// load asynchronously
465467
setDocument(doc);
466468
synchronized (this) {
469+
秘setPage(doc, page);
467470
loading = new PageStream(in);
468471
Thread pl = new PageLoader(doc, loading, p, loaded, page);
469472
pl.start();
@@ -472,6 +475,7 @@ public void setPage(URL page) throws IOException {
472475
}
473476
read(in, doc);
474477
setDocument(doc);
478+
秘setPage(doc, page);
475479
reloaded = true;
476480
}
477481
} else {
@@ -501,6 +505,16 @@ public void run() {
501505
firePropertyChange("page", loaded, page);
502506
}
503507

508+
private void 秘setPage(Document doc, URL page) {
509+
if (doc instanceof HTMLDocument) {
510+
byte[] bytes = JSUtil.getBytes(page);
511+
if (bytes != null) {
512+
if (秘jsHTMLHelper != null)
513+
秘jsHTMLHelper.setText(new String(bytes));
514+
}
515+
}
516+
}
517+
504518
/**
505519
* Create model and initialize document properties from page properties.
506520
*/
@@ -1225,6 +1239,7 @@ public static EditorKit createEditorKitForContentType(String type) {
12251239
// try to dynamically load the support
12261240
String classname = (String) getKitTypeRegistry().get(type);
12271241
// ClassLoader loader = (ClassLoader) getKitLoaderRegistry().get(type);
1242+
if (classname != null)
12281243
try {
12291244
k = (EditorKit) Interface.getInstance(classname, false);
12301245
// Class c;
@@ -1436,12 +1451,7 @@ public void setText(String t) {
14361451
try {
14371452
Document doc = getDocument();
14381453
if (doc instanceof HTMLDocument) {
1439-
if (t.indexOf("<body")< 0)
1440-
t = "<body>" + t + "</body>";
1441-
if (t.indexOf("<head")< 0)
1442-
t = "<head>" + t + "</head>";
1443-
if (t.indexOf("<html")< 0)
1444-
t = "<html>" + t + "</html>";
1454+
t = 秘fixHTML(t);
14451455
}
14461456
if (秘jsHTMLHelper != null)
14471457
秘jsHTMLHelper.setText(t);
@@ -1459,6 +1469,16 @@ public void setText(String t) {
14591469
}
14601470
}
14611471

1472+
private static String 秘fixHTML(String t) {
1473+
if (t.indexOf("<body")< 0)
1474+
t = "<body>" + t + "</body>";
1475+
if (t.indexOf("<head")< 0)
1476+
t = "<head>" + t + "</head>";
1477+
if (t.indexOf("<html")< 0)
1478+
t = "<html>" + t + "</html>";
1479+
return t;
1480+
}
1481+
14621482
/**
14631483
* Returns the text contained in this <code>TextComponent</code> in terms of the
14641484
* content type of this editor. If an exception is thrown while attempting to

sources/net.sf.j2s.java.core/src/javax/swing/JTable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3723,10 +3723,12 @@ public boolean editCellAt(int row, int column, EventObject e) {
37233723
comp.setVisible(true);
37243724
// force domNode to be visible as well as outer node
37253725
comp.秘getUI().setVisible(null, true);
3726+
JTable me = this;
37263727
SwingUtilities.invokeLater(new Runnable() {
37273728
@Override
37283729
public void run() {
3729-
comp.requestFocus();
3730+
if (me.hasFocus())
3731+
comp.requestFocus();
37303732
}
37313733
});
37323734
}

sources/net.sf.j2s.java.core/src/swingjs/JSHTMLHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ public String indexAnchors(String text) {
149149
for (int i = 0; iter.isValid(); i++) {
150150
aTagElements.add(iter.秘getElement());
151151
int pt = html.indexOf("href=#_JSINDEX_#");
152-
html = html.substring(0, pt + 14) + i + html.substring(pt + 16);
152+
if (pt > 0)
153+
html = html.substring(0, pt + 14) + i + html.substring(pt + 16);
153154
iter.next();
154155
}
155156
return html;

sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,11 @@ public static Color getColorFromName(String c) {
804804

805805
/**
806806
*
807-
* @param f anything with 秘bytes (File, JSPath)
807+
* @param f anything with 秘bytes (File, JSPath) or URL._streamData
808808
* @return
809809
*/
810810
public static byte[] getBytes(Object f) {
811-
return ((File) f).秘bytes;
811+
return (f instanceof URL ? (byte[]) ((URL) f)._streamData : ((File) f).秘bytes);
812812
}
813813

814814
@Override

0 commit comments

Comments
 (0)