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 @@
20200119225004
20200124055240
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.7/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.7/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20200119225004
20200124055240
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
3 changes: 3 additions & 0 deletions sources/net.sf.j2s.java.core/src/java/applet/JSApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import javax.swing.JRootPane;
import javax.swing.RepaintManager;

import swingjs.plaf.JSAppletUI;

/**
* SwingJS note: This class is the original java.applet.Applet class.
* It is subclassed by JApplet. The replacement java.applet.Applet class
Expand Down Expand Up @@ -290,6 +292,7 @@ public void resizeHTML(int width, int height) {
// ((JSComponentUI)root.getUI()).setPainted(null);
// root.秘isBackgroundPainted = false;
RepaintManager.currentManager(this).addInvalidComponent(root);
((JSAppletUI)getUI()).adjustCanvasForMenuBar();
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion sources/net.sf.j2s.java.core/src/java/io/FileDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public final class FileDescriptor {
*/
File _file;

public byte[] _getBytes(boolean checkDisk) {
if (_file.秘bytes == null && checkDisk) {
// a check for file existence sets the bytes
_file.exists();
}
return _file.秘bytes;
}

private int pos, len = -1;

public void _setPosAndLen(int pos, int len) {
Expand Down Expand Up @@ -283,5 +291,4 @@ synchronized void closeAll(Closeable releaser) throws IOException {
}
}


}
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.java.core/src/java/io/FileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private boolean _regular(File file) {
}

boolean _exists(File file) {
return (file.秘bytes != null || JSUtil.getFileAsBytes(file) != null);
return (file.秘bytes != null || (file.秘bytes=JSUtil.getFileAsBytes(file)) != null);
}

boolean _isDir(File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

package java.nio.channels;

import java.io.IOException;


/**
* A channel that can read and write bytes. This interface simply unifies
* {@link ReadableByteChannel} and {@link WritableByteChannel}; it does not
Expand Down
6 changes: 6 additions & 0 deletions sources/net.sf.j2s.java.core/src/swingjs/JSFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ private JSFileChannel(FileDescriptor fd, String path, boolean readable, boolean
this.fd = fd;
this.parent = parent;
this.path = (JSPath) new File(path).toPath();
if (fd != null && (readable || append))
this.path.秘bytes = fd._getBytes(true);
this.path.setIsTempFile(fd._isTempFile());
Set<StandardOpenOption> options = new HashSet<>();
if (readable)
Expand Down Expand Up @@ -406,6 +408,10 @@ public JSByteChannel(FileDescriptor fd, JSPath path, Set<? extends OpenOption> o
boolean truncate = options.contains(StandardOpenOption.TRUNCATE_EXISTING);
boolean create = options.contains(StandardOpenOption.CREATE);
boolean createNew = options.contains(StandardOpenOption.CREATE_NEW);
if ((read ||append) && path.秘bytes == null && fd != null) {
path.秘bytes = fd._getBytes(true);
}

if (read && write) {
秘bytes = getBytes();
if (秘bytes == null) {
Expand Down
2 changes: 2 additions & 0 deletions sources/net.sf.j2s.java.core/src/swingjs/api/js/JQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface JQuery {

Object parseJSON(String json);

Object data(Object node, String attr);

}
28 changes: 13 additions & 15 deletions sources/net.sf.j2s.java.core/src/swingjs/jquery/j2sMenu.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// J2SMenu.js from JSmolMenu.js
// Original version for JSmol Bob Hanson 2/17/2014
// author: Bob Hanson, hansonr@stolaf.edu
// last edited 1/23/2019 -- fixes for mouse-down effector (mac) operation

// last edited 1/24/2020 = fix for <u> in text
// NOTE: If you change this file, then you need to touch and save JQueryUI.java, as only then
// will the transpiler copy this file to site/swingjs/j2s/swingjs/jquery/

Expand Down Expand Up @@ -94,12 +93,13 @@ try{
var doCmd = function(trigger,me,t,n,why) {
why || (why = "");
var event = t;
var target = (!t || !t.target ? null : $(t.target).closest(".ui-j2smenu-item")[0]);
switch(trigger) {
case "onoutn":
me._closeMe();
break;
case "onmoven":
if ($(t && t.target).hasClass("ui-j2smenu")) {
if ($(target).hasClass("ui-j2smenu")) {
// this is the most likely way we will leave, via a mousemove on the border
me._closeMe();
break;
Expand All @@ -111,7 +111,7 @@ try{
// BH 2018
// -- added stopPropagation
// -- changed to mouseover from mouseenter, since we have children
var a = e(t.target).closest("li")
var a = e(target).closest("li")
if (a.hasClass(".ui-state-focus"))
return;
if (!a.hasClass("j2s-popup-menu")) {
Expand All @@ -128,10 +128,8 @@ try{
break;
case "onrelease":
case "onpress":
// t.preventDefault();
// break;
case "onclick":
var n=e(t.target).closest(".ui-j2smenu-item");
var n=e(target).closest(".ui-j2smenu-item");
if (n.has(".ui-state-disabled").length)
return;
if (trigger != "onclick")
Expand All @@ -144,8 +142,7 @@ try{
me.element.trigger("setFocus",[!0]);
me.active&&me.active.parents(".ui-j2smenu").length===1&&clearMe(me.timer, trigger);
}
doCmd("collapseAll", me, 0, 1);
// doCmd("_hide", me, e(".ui-j2smenu"));
doCmd("collapseAll", me, 0, 1);
}
break;
case "clearClickOut":
Expand All @@ -166,8 +163,8 @@ try{
doCmd("clearClickOut", me);
return;
}
e(t.target).closest(".j2s-menuBar-menu").length == 0
&& (e(t.target).closest(".ui-j2smenu").length||me.collapseAll(t));
e(target).closest(".j2s-menuBar-menu").length == 0
&& (e(target).closest(".ui-j2smenu").length||me.collapseAll(t));
return;
case "onleave":
me._closeMe("onleave");
Expand Down Expand Up @@ -283,7 +280,7 @@ try{
if ( me.closed
//
// || !n && (!someMenuOpen() ||
// ((u=e(t&&t.target)).hasClass("ui-j2smenu-node") || u.hasClass("ui-j2smenu"))
// ((u=e(t&&target)).hasClass("ui-j2smenu-node") || u.hasClass("ui-j2smenu"))
// )
//
)
Expand Down Expand Up @@ -325,11 +322,12 @@ try{
t = a;
break;
case "select":
me.active=me.active||e(t.target).closest(".ui-j2smenu-item");
me.active=me.active||e(target).closest(".ui-j2smenu-item");
me.active.has(".ui-j2smenu").length||me.collapseAll(t,!0);
me._trigger("select",t,{item:me.active});
if (!t[0])
if (!t[0]) {
return;
}
break;
case "refresh":
n=me.options.icons.submenu;
Expand Down Expand Up @@ -375,7 +373,7 @@ try{
}

var ui = me.activeMenu && me.activeMenu[0] && me.activeMenu[0]["data-ui"];
ui && ui.processJ2SMenuCmd$OA([trigger,me,event,t,n,why]);
ui && ui.processJ2SMenuCmd$OA([trigger,me,event,t,n,target,why]);
}

$.widget("ui.j2smenu",{
Expand Down
21 changes: 15 additions & 6 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSAppletUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@ public DOMNode updateDOMNode() {
containerNode = domNode = newDOMObject("div", id);
addClass(domNode, "swingjs-window");
}
adjustCanvasForMenuBar();
return updateDOMNodeCUI();
}

void checkMenuBar(int h) {
JMenuBar mb = ((JApplet) c).getJMenuBar();
HTML5Canvas canvas = c.getAppContext().getThreadGroup().秘html5Applet._getHtml5Canvas();
DOMNode.setStyles(canvas, "top", h + "px", "position", "absolute");
}

@Override
public void installUI(JComponent jc) {
LookAndFeel.installColorsAndFont(jc,
Expand All @@ -51,6 +46,20 @@ public void propertyChange(PropertyChangeEvent e) {
System.out.println("JSAPpletUI prop val " + prop + " " + value);
}

/**
* The JMenuBar on an applet pushes its canvas down typically about 20 pixels.
*/
public void adjustCanvasForMenuBar() {
JMenuBar mb = ((JApplet) c).getJMenuBar();
int h = (mb == null || !mb.isVisible() ? 0 : ((JSMenuBarUI) mb.getUI()).height);
DOMNode.setStyles(getCanvas(), "top", h + "px", "position", "absolute");
}

public HTML5Canvas getCanvas() {
return c.getAppContext().getThreadGroup().秘html5Applet._getHtml5Canvas();
}


// @Override
// public boolean isFocusable() {
// return true;
Expand Down
15 changes: 15 additions & 0 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSButtonUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,22 @@ protected void createButton() {
setDataComponent(textNode); // needed for mac safari/chrome
setEnabled(c.isEnabled());
}

/**
* We need to also set the data-component object for the mnemonic
*/
@Override
protected DOMNode setJSText(DOMNode obj, String prop, String val) {
DOMNode node = DOMNode.setAttr(obj, prop, val);
if (val.indexOf("<u>") >= 0) {
setDataComponent(DOMNode.firstChild(node));
}
return node;
}




/**
*
* @param type "_item" or "_menu" (unused)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ private void uninstallJS() {
protected JQueryObject $(Object node) {
return jquery.$(node);
}
protected Object $data(DOMNode node, String attr) {
return (node == null ? null : jquery.data(node,attr));
}

/**
* Set the associated JComponent. Setting comp null will disable this UI from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void setVisible(boolean b) {
super.setVisible(b);
Component top = menuBar.getTopLevelAncestor();
if ( top instanceof JApplet)
((JSAppletUI)((JApplet) top).getUI()).checkMenuBar(b ? height : 0);
((JSAppletUI)((JApplet) top).getUI()).adjustCanvasForMenuBar();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,8 @@ public static void processJ2SMenuCmd(Object[] data) {
Object n = data[4];
JQueryObject m = j2smenu.activeMenu;
String mid = (m == null ? null : m.attr("id"));
DOMNode base = (t == null ? null : t == e ? (DOMNode) DOMNode.getAttr(e, "target") : t.get(0));
DOMNode target = (DOMNode) data[5];
DOMNode base = (t == null ? null : target != null ? target : t == e ? (DOMNode) DOMNode.getAttr(e, "target") : t.get(0));
String id = (base == null ? null : (String) DOMNode.getAttr(base, "id"));
JComponent c = (base == null ? null : (JComponent) DOMNode.getAttr(base, "data-component"));
JSComponentUI tui = (base == null ? null : (JSComponentUI) DOMNode.getAttr(base, "data-ui"));
Expand Down
45 changes: 32 additions & 13 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSliderUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ public DOMNode updateDOMNode() {
if (!isScrollBar) {
minorSpacing = slider.getMinorTickSpacing();
majorSpacing = slider.getMajorTickSpacing();
paintTicks = slider.getPaintTicks();
paintLabels = slider.getPaintLabels();
paintTicks = (majorSpacing > 0 && slider.getPaintTicks());
paintLabels = (majorSpacing > 0 && slider.getPaintLabels());
paintTrack = slider.getPaintTrack();
snapToTicks = slider.getSnapToTicks();
snapToTicks = (majorSpacing > 0 && slider.getSnapToTicks());
}
orientation = (slider.getOrientation() == SwingConstants.VERTICAL ? "vertical" : "horizontal");
model = slider.getModel();
boolean isHoriz = (slider.getOrientation() == SwingConstants.HORIZONTAL);
boolean isVerticalScrollBar = (isScrollBar && !isHoriz);
boolean isInverted = isVerticalScrollBar || !isScrollBar && slider.getInverted();
boolean isChanged = false;
boolean isChanged = sliderDisposed;
if (isHoriz != this.isHoriz || isVerticalScrollBar != this.isVerticalScrollBar
|| isInverted != this.isInverted) {
this.isHoriz = isHoriz;
Expand All @@ -107,8 +107,6 @@ public DOMNode updateDOMNode() {
boolean isNew = (domNode == null);
if (isNew) {
domNode = wrap("div", id + "_wrap", jqSlider = DOMNode.createElement("div", id));
$(domNode).addClass("swingjs"); // ??
$(domNode).addClass("ui-j2sslider-wrap"); // ??
setJQuerySliderAndEvents();
setTainted();
} else if (isChanged) {
Expand All @@ -126,6 +124,7 @@ public DOMNode updateDOMNode() {
}

private String foreColor = null;
private boolean sliderDisposed;
@Override
public void setForeground(Color c) {
if (!paintTicks && !paintLabels)
Expand Down Expand Up @@ -188,11 +187,17 @@ protected void setBackgroundImpl(Color color) {
}

private void disposeSlider() {
Object slider = $(jqSlider);
/**
* @j2sNative slider.j2sslider("destroy");
*
*/
if (sliderInitialized()) {
Object slider = $(jqSlider);
/**
*
* @j2sNative
*
*
* slider.j2sslider("destroy");
*
*/
}
DOMNode.dispose(jqSlider);
}

Expand All @@ -209,8 +214,15 @@ private void setSliderFields() {
jScrollBar = (JScrollBar) jc;
}

private void setJQuerySliderAndEvents() {
@Override
public void dispose() {
sliderDisposed = true;
super.dispose();
}

void setJQuerySliderAndEvents() {
$(domNode).addClass("swingjs");
$(domNode).addClass("ui-j2sslider-wrap"); // for mouse-down event in jquery-ui-j2sslider.js
Object slider = $(jqSlider);
/**
* @j2sNative
Expand Down Expand Up @@ -306,6 +318,7 @@ private void setup(boolean isNew) {
setDataComponent(domNode);
setDataComponent(sliderHandle);
}
sliderDisposed = false;
}

/**
Expand All @@ -314,13 +327,15 @@ private void setup(boolean isNew) {
* @param val
*/
protected void setSliderAttr(String key, float val) {
if (!sliderInitialized())
noSnapping = true;
String id = null;
try {
Object jsslider = $(jqSlider);
/**
* @j2sNative
* id = this.jqSlider.id;
*
* id = this.jqSlider.id;
* jsslider.j2sslider("option",key,val);
*/
} catch (Throwable t) {
Expand All @@ -330,6 +345,10 @@ protected void setSliderAttr(String key, float val) {
noSnapping = isScrollBar;
}

private boolean sliderInitialized() {
return ($data(jqSlider, "ui-j2sslider") != null);
}

public void setSlider() {
setSliderAttr("min", min);
// hack is for list to not show bottom line
Expand Down
Loading