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 @@
20181120230421
20181121134911
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20181120230421
20181121134911
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Hashtable;
import java.util.Map;

import javajs.api.js.J2SObjectInterface;

Expand Down Expand Up @@ -71,7 +73,25 @@ public void outputString(String post) {
public InputStream getInputStream() {
responseCode = 200;
BufferedInputStream is = getAttachedStreamData(url, false);
return (is == null ? attachStreamData(url, doAjax(true)) : is);
if (is != null || getUseCaches() && (is = getCachedStream(url)) != null)
return is;
is = attachStreamData(url, doAjax(true));
if (getUseCaches() && is != null)
setCachedStream(url);
return is;
}

static Map<String, Object> urlCache = new Hashtable<String, Object>();

private BufferedInputStream getCachedStream(URL url) {
Object data = urlCache.get(url.toString());
return (data == null ? null : Rdr.toBIS(data));
}

private void setCachedStream(URL url) {
Object data = url._streamData;
if (data != null)
urlCache.put(url.toString(), data);
}

/**
Expand All @@ -96,6 +116,7 @@ public static BufferedInputStream getAttachedStreamData(URL url, boolean andDele
}

public static BufferedInputStream attachStreamData(URL url, Object o) {

/**
* @j2sNative
*
Expand Down
8 changes: 3 additions & 5 deletions sources/net.sf.j2s.java.core/src/swingjs/JSGraphics2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,18 @@ public JSGraphics2D(Object canvas) { // this must be Object, because we are
*/
{
}
// removed - caused blurriness 9/17/2018
// // reduce antialiasing, thank you,
// // http://www.rgraph.net/docs/howto-get-crisp-lines-with-no- antialias.html
// having this set default TRUE gave extra lines around panels in Jalview
setAntialias(false);
setAntialias(true);
}

public void setAntialias(boolean tf) {
if (tf) {
if (!isShifted)
ctx.translate(-0.5, -0.5);
ctx.translate(0.5, 0.5);
} else {
if (isShifted)
ctx.translate(0.5, 0.5);
ctx.translate(-0.5, -0.5);
}
// this is important if images are being drawn - test/TAPP6
// see also http://vaughnroyko.com/state-of-nearest-neighbor-interpolation-in-canvas/
Expand Down
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.java.core/src/swingjs/jquery/j2sMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Swing.__getMenuStyle = function(applet) { return '\
.swingjsPopupMenu .ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat;position:absolute;top:.2em;left:.2em}\
.swingjsPopupMenu .ui-menu-icon{position:static;float:right}\
.swingjsPopupMenu .ui-icon-carat-1-e{min-width:10ex;text-align:right;background-image:none;background-position:0 0}\
.swingjsPopupMenu .ui-icon-carat-1-e:after{content:"\\0023F5"}\
.swingjsPopupMenu .ui-icon-carat-1-e:after{content:"\\0025B6"}\
.swingjsPopupMenu .ui-state-default{border:1px solid #c5dbec;background:#dfeffc;color:#2e6e9e}\
.swingjsPopupMenu .ui-state-default a{color:#2e6e9e;text-decoration:none}\
.swingjsPopupMenu .ui-state-hover,.swingjsPopupMenu .ui-state-focus{border:1px solid #79b7e7;background:#d0e5f5;color:#1d5987}\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@
},

_getPixelMouse : function(position, offsetHandle) {
var offset = this.element.offset;
var offset = this.element.offset();
var p = (this.orientation === "horizontal" ?
position.x
- offset.left
Expand Down
24 changes: 2 additions & 22 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSMenuUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import javax.swing.JComponent;
import javax.swing.JMenu;
import swingjs.api.js.DOMNode;
public class JSMenuUI extends JSMenuItemUI implements ContainerListener {

public class JSMenuUI extends JSMenuItemUI {
private JMenu jm;

public JSMenuUI() {
Expand Down Expand Up @@ -76,8 +76,6 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
public void installUI(JComponent jc) {
jm = (JMenu) jc;
super.installUI(jc);
// handle add/remove
jm.getPopupMenu().addContainerListener(this);
}

@Override
Expand All @@ -91,22 +89,4 @@ public Dimension getMaximumSize() {
return getPreferredSize();
}

@Override
public void componentAdded(ContainerEvent e) {
JSPopupMenuUI popupui = (JSPopupMenuUI) jm.getPopupMenu().getUI();
// OK, the idea here is that we detach all child nodes
// and then reattach them.
DOMNode.detachAll(popupui.outerNode);
popupui.setTainted();
popupui.setHTMLElement();
}

@Override
public void componentRemoved(ContainerEvent e) {
JSPopupMenuUI popupui = (JSPopupMenuUI) jm.getPopupMenu().getUI();
DOMNode.detachAll(popupui.outerNode);
popupui.setTainted();
popupui.setHTMLElement();
}

}
34 changes: 29 additions & 5 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSPopupMenuUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.awt.Dimension;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;

import javax.swing.JComponent;
import javax.swing.JPopupMenu;
Expand All @@ -13,17 +15,35 @@
import swingjs.jquery.JQueryUI;
import swingjs.api.js.DOMNode;

public class JSPopupMenuUI extends JSPanelUI {
public class JSPopupMenuUI extends JSPanelUI implements ContainerListener {


static {
Object jqueryui = JQueryUI.class; // loads jQuery.ui
}

// a frameless independent window

static JSSwingMenu j2sSwingMenu;
private static JSSwingMenu j2sSwingMenu;

int timer;

@Override
public void componentAdded(ContainerEvent e) {
// OK, the idea here is that we detach all child nodes
// and then reattach them.
DOMNode.detachAll(outerNode);
setTainted();
setHTMLElement();
}

@Override
public void componentRemoved(ContainerEvent e) {
DOMNode.detachAll(outerNode);
setTainted();
setHTMLElement();
}

/*private*/ int timer;

public JSPopupMenuUI() {

Expand Down Expand Up @@ -51,6 +71,7 @@ public DOMNode updateDOMNode() {

@Override
public void installUI(JComponent jc) {
((JPopupMenu) jc).addContainerListener(this);
LookAndFeel.installColorsAndFont(jc,
"PopupMenu.background",
"PopupMenu.foreground",
Expand All @@ -59,6 +80,7 @@ public void installUI(JComponent jc) {

@Override
public void uninstallUI(JComponent jc) {
((JPopupMenu) jc).removeContainerListener(this);
// TODO Auto-generated method stub

}
Expand Down Expand Up @@ -122,14 +144,16 @@ void stopTimer() {
void hideMenu() {
System.out.println("hideMenu");
// not private -- hideMenu$
j2sSwingMenu.hideMenu(menu);
if (menu != null)
j2sSwingMenu.hideMenu(menu);
}

@Override
public void dispose() {
DOMNode.dispose(domNode);
DOMNode.dispose(outerNode);
j2sSwingMenu.disposeMenu(menu);
if (menu != null)
j2sSwingMenu.disposeMenu(menu);
}

@Override
Expand Down
47 changes: 47 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/JalviewJSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
Expand All @@ -22,6 +24,7 @@
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.SwingConstants;
Expand Down Expand Up @@ -59,6 +62,50 @@ void doTest()
main.getJMenuBar().add(menu);
main.pack();
main.setVisible(true);

JPopupMenu pmenu = new JPopupMenu();
pmenu.add(new JMenuItem("testing1"));
pmenu.add(new JMenuItem("testing2"));
pmenu.add(new JMenuItem("testing3"));

main.addMouseListener(new MouseListener() {

@Override
public void mouseClicked(MouseEvent e) {
System.out.println(pmenu.getComponents().length);
pmenu.remove(pmenu.getComponents().length - 1);
System.out.println(pmenu.getComponents().length);
pmenu.show(main, 100, 100);
System.out.println(pmenu.getComponents().length);
// TODO Auto-generated method stub

}

@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}

});
}

/**
Expand Down