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 @@
20210301062205
20210321064238
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 @@
20210301062205
20210321064238
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
4 changes: 3 additions & 1 deletion sources/net.sf.j2s.java.core/src/javajs/async/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,10 @@ private URL _getURLFromPath(String fullPath, boolean zipOnly) {
if (fullPath.startsWith(sortedList[i])) {
url = assetsByPath.get(sortedList[i]).getURL(fullPath);
ZipEntry ze = findZipEntry(url);
if (ze == null)
if (ze == null) {
url = null;
break;
}
if (isJS) {
jsutil.setURLBytes(url, jsutil.getZipBytes(ze));
}
Expand Down
32 changes: 26 additions & 6 deletions sources/net.sf.j2s.java.core/src/javax/swing/JEditorPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import javax.swing.text.html.HTMLEditorKit;

import swingjs.JSHTMLHelper;
import swingjs.JSUtil;
//import swingjs.JSAbstractDocument;
import swingjs.api.Interface;
//import swingjs.api.JSMinimalAbstractDocument;
Expand Down Expand Up @@ -423,6 +424,7 @@ public void fireHyperlinkUpdate(HyperlinkEvent e) {
* @see #getPage
* @beaninfo description: the URL used to set content bound: true expert: true
*/
@SuppressWarnings("unused")
public void setPage(URL page) throws IOException {
if (page == null) {
throw new IOException("invalid url");
Expand Down Expand Up @@ -464,6 +466,7 @@ public void setPage(URL page) throws IOException {
// load asynchronously
setDocument(doc);
synchronized (this) {
秘setPage(doc, page);
loading = new PageStream(in);
Thread pl = new PageLoader(doc, loading, p, loaded, page);
pl.start();
Expand All @@ -472,6 +475,7 @@ public void setPage(URL page) throws IOException {
}
read(in, doc);
setDocument(doc);
秘setPage(doc, page);
reloaded = true;
}
} else {
Expand Down Expand Up @@ -501,6 +505,16 @@ public void run() {
firePropertyChange("page", loaded, page);
}

private void 秘setPage(Document doc, URL page) {
if (doc instanceof HTMLDocument) {
byte[] bytes = JSUtil.getBytes(page);
if (bytes != null) {
if (秘jsHTMLHelper != null)
秘jsHTMLHelper.setText(new String(bytes));
}
}
}

/**
* Create model and initialize document properties from page properties.
*/
Expand Down Expand Up @@ -1225,6 +1239,7 @@ public static EditorKit createEditorKitForContentType(String type) {
// try to dynamically load the support
String classname = (String) getKitTypeRegistry().get(type);
// ClassLoader loader = (ClassLoader) getKitLoaderRegistry().get(type);
if (classname != null)
try {
k = (EditorKit) Interface.getInstance(classname, false);
// Class c;
Expand Down Expand Up @@ -1436,12 +1451,7 @@ public void setText(String t) {
try {
Document doc = getDocument();
if (doc instanceof HTMLDocument) {
if (t.indexOf("<body")< 0)
t = "<body>" + t + "</body>";
if (t.indexOf("<head")< 0)
t = "<head>" + t + "</head>";
if (t.indexOf("<html")< 0)
t = "<html>" + t + "</html>";
t = 秘fixHTML(t);
}
if (秘jsHTMLHelper != null)
秘jsHTMLHelper.setText(t);
Expand All @@ -1459,6 +1469,16 @@ public void setText(String t) {
}
}

private static String 秘fixHTML(String t) {
if (t.indexOf("<body")< 0)
t = "<body>" + t + "</body>";
if (t.indexOf("<head")< 0)
t = "<head>" + t + "</head>";
if (t.indexOf("<html")< 0)
t = "<html>" + t + "</html>";
return t;
}

/**
* Returns the text contained in this <code>TextComponent</code> in terms of the
* content type of this editor. If an exception is thrown while attempting to
Expand Down
4 changes: 3 additions & 1 deletion sources/net.sf.j2s.java.core/src/javax/swing/JTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3723,10 +3723,12 @@ public boolean editCellAt(int row, int column, EventObject e) {
comp.setVisible(true);
// force domNode to be visible as well as outer node
comp.秘getUI().setVisible(null, true);
JTable me = this;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
comp.requestFocus();
if (me.hasFocus())
comp.requestFocus();
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion sources/net.sf.j2s.java.core/src/swingjs/JSHTMLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public String indexAnchors(String text) {
for (int i = 0; iter.isValid(); i++) {
aTagElements.add(iter.秘getElement());
int pt = html.indexOf("href=#_JSINDEX_#");
html = html.substring(0, pt + 14) + i + html.substring(pt + 16);
if (pt > 0)
html = html.substring(0, pt + 14) + i + html.substring(pt + 16);
iter.next();
}
return html;
Expand Down
4 changes: 2 additions & 2 deletions sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,11 @@ public static Color getColorFromName(String c) {

/**
*
* @param f anything with 秘bytes (File, JSPath)
* @param f anything with 秘bytes (File, JSPath) or URL._streamData
* @return
*/
public static byte[] getBytes(Object f) {
return ((File) f).秘bytes;
return (f instanceof URL ? (byte[]) ((URL) f)._streamData : ((File) f).秘bytes);
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/CellHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,15 @@ public static void setJ2SRendererComponent(JComponent comp) {
comp.秘getUI().setRenderer(comp, 0, 0, null);
}

public static DOMNode findOrCreateNode(JSComponentUI ui, int row, int col, int tx, int ty, int w, DOMNode tr) {
DOMNode td = findCellNode(ui, null, row, col);
if (td == null) {
td = createCellOuterNode(ui, row, col);
tr.appendChild(td);
}
DOMNode.setStyles(td, "left", tx + "px", "width", w + "px", "height", "inherit", "top", ty + "px");
return td;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,9 @@ protected void setMnemonic(int newValue) {
/**
* table cell width and height
*/
private int cellWidth, cellHeight;
private int cellWidth;

protected int cellHeight;

/**
* this ui has been disabled from receiving any events; see JTableUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.InputMap;
import javax.swing.JComponent;
Expand All @@ -35,6 +37,7 @@
import javax.swing.text.StyledEditorKit;
import javax.swing.text.View;

import javajs.util.PT;
import javajs.util.SB;
import sun.swing.DefaultLookup;
import swingjs.JSToolkit;
Expand Down Expand Up @@ -271,6 +274,7 @@ public void propertyChange(PropertyChangeEvent e) {
private boolean isStyled;
private String mytext;
private DOMNode bodyNode;
private String rawHTML;

// private int epTimer;
// @Override
Expand Down Expand Up @@ -405,8 +409,35 @@ public void setText(String text) {
}
}
if (isHTML) {
html = fixText(html);
setBackgroundDOM(domNode, jc.getBackground());
if (html.equals(rawHTML))
return;
rawHTML = html;
html = fixText(html);
if (isHtmlKit) {
URL page = (URL) editor.getDocument().getProperty("stream");
if (page != null && page.getProtocol().equals("file") && text.indexOf("src=\".") >= 0) {
String rp = 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(text, "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 {
src = new URL(page, src).getPath().substring(1);
} catch (MalformedURLException e) {
}
out += "src=\"" +src+ srcs[i].substring(pt);
}
html = out;
}
}
}
// System.out.println(html);
if (html == currentHTML)
Expand Down
61 changes: 40 additions & 21 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTableHeaderUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,20 @@ protected void addChildrenToDOM(Component[] children, int n) {
DOMNode.setStyle(headdiv, "height", thh + "px");
domNode.appendChild(headdiv);
for (int col = 0, tx = 0; col < ncols; col++) {
DOMNode td = CellHolder.createCellOuterNode(this, -1, col);
DOMNode.setStyles(td, "width", cw[col] + "px", "height", thh + "px", "left", tx + "px", "top", "0px");
tx += cw[col];
headdiv.appendChild(td);
CellHolder.updateCellNode(td, (JSComponent) getHeaderComponent(col), cw[col], thh);
int w = cw[col];
DOMNode td = CellHolder.findOrCreateNode(this, -1, col, tx, 0, w, headdiv);
updateCellNode(td, col, w, thh);
tx += w;
}

}

private void updateCellNode(DOMNode td, int col, int w, int thh) {
JSComponent c = (JSComponent) getHeaderComponent(col, w, thh, td);
if (c != null)
CellHolder.updateCellNode(td, c, -1, -1);
}

private static Cursor resizeCursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);

//
Expand Down Expand Up @@ -727,7 +732,6 @@ public void paint(Graphics g, JComponent c) {
working = true;

boolean ltr = tableHeader.getComponentOrientation().isLeftToRight();

Rectangle clip = g.getClipBounds();
Point left = clip.getLocation();
Point right = new Point(clip.x + clip.width - 1, clip.y);
Expand Down Expand Up @@ -798,13 +802,12 @@ public void paint(Graphics g, JComponent c) {

private void paintGrid(Graphics g, int cMin, int cMax) {
g.setColor(table.getGridColor());

int h = tableHeader.getHeight();
table._getCellRect(0, cMin, true, JSTableUI.minCell);
table._getCellRect(0, cMax, true, JSTableUI.maxCell);
Rectangle damagedArea = JSTableUI.minCell.union(JSTableUI.maxCell);
int tableHeight = getHeaderHeight();
if (table.getShowHorizontalLines()) {
g.drawLine(0, tableHeight - 1, damagedArea.width, tableHeight - 1);
g.drawLine(0, h - 1, damagedArea.width, h - 1);
}
if (table.getShowVerticalLines()) {
TableColumnModel cm = table.getColumnModel();
Expand All @@ -814,14 +817,15 @@ private void paintGrid(Graphics g, int cMin, int cMax) {
for (int column = cMin; column <= cMax; column++) {
int w = cm.getColumn(column).getWidth();
x += w;
g.drawLine(x - 1, 0, x - 1, tableHeight - 1);
g.drawLine(x, 0, x, h - 1);
// BH don't know why we need x not x-1 here and below
}
} else {
x = damagedArea.x;
for (int column = cMax; column >= cMin; column--) {
int w = cm.getColumn(column).getWidth();
x += w;
g.drawLine(x - 1, 0, x - 1, tableHeight - 1);
g.drawLine(x, 0, x, h - 1);
}
}
}
Expand All @@ -831,27 +835,40 @@ private void paintGrid(Graphics g, int cMin, int cMax) {
// Paint Methods and support
//

private Component getHeaderComponent(int columnIndex) {
TableColumn aColumn = tableHeader.getColumnModel().getColumn(columnIndex);
private JSComponent getHeaderComponent(int col) {
return getHeaderComponent(col, 0, 0, null);
}
private JSComponent getHeaderComponent(int col, int w, int h, DOMNode td) {
TableColumn aColumn = tableHeader.getColumnModel().getColumn(col);
TableCellRenderer renderer = aColumn.getHeaderRenderer();
if (renderer == null) {
renderer = tableHeader.getDefaultRenderer();
}

boolean hasFocus = !tableHeader.isPaintingForPrint() && (columnIndex == getSelectedColumnIndex())
boolean hasFocus = !tableHeader.isPaintingForPrint() && (col == getSelectedColumnIndex())
&& tableHeader.hasFocus();

JComponent c = (JComponent) renderer.getTableCellRendererComponent(tableHeader.getTable(), aColumn.getHeaderValue(), false, hasFocus,
-1, columnIndex);
-1, col);
if (c != null && td != null) {
JSTableUI.prepareCellRendererUI(c, false, w, h, td, true, tableHeader);
}
return c;
}

private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) {
// System.out.println("paintCell header" + columnIndex);
JComponent c = (JComponent) getHeaderComponent(columnIndex);
c.秘getUI().setRenderer(c, cellRect.width, cellRect.height, null);
rendererPane.paintComponent(g, c, tableHeader, cellRect.x, cellRect.y, cellRect.width, cellRect.height,
true);
DOMNode td = CellHolder.findCellNode(this, null, -1, columnIndex);
if (td == null)
return;
int w = cellRect.width;
int h = cellRect.height;
JComponent comp = (JComponent) getHeaderComponent(columnIndex, w, h, td);
if (comp == null)
return;
rendererPane.paintComponent(g, comp, tableHeader, cellRect.x, cellRect.y, w, h, true);
if (td != null)
comp.秘getUI().setRenderer(null, 0, 0, td);
}

private int viewIndexForColumn(TableColumn aColumn) {
Expand All @@ -877,8 +894,10 @@ private int getHeaderHeight() {
boolean isDefault = (aColumn.getHeaderRenderer() == null);

if (!isDefault || !accomodatedDefault) {
Component comp = getHeaderComponent(column);
int rendererHeight = comp.getPreferredSize().height;

JSComponent comp = getHeaderComponent(column);
JSComponentUI ui = comp.秘getUI();
int rendererHeight = (ui.isUIDisabled ? ui.cellHeight : comp.getPreferredSize().height);
height = Math.max(height, rendererHeight);

// Configuring the header renderer to calculate its preferred size
Expand Down
Loading