Skip to content

Commit db0a9ea

Browse files
hansonrhansonr
authored andcommitted
jQuery.ui.j2smenu adaptation of jQuery.ui.menu
actions all set to doCmd() function for clarity and debugging fully isolated from the original ui.menu adds many useful features
1 parent fb9df5d commit db0a9ea

File tree

14 files changed

+733
-704
lines changed

14 files changed

+733
-704
lines changed
-1.35 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190119065335
1+
20190121000416
-1.35 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190119065335
1+
20190121000416
-1.35 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/swingjs/jquery/JQueryUI.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
/**
44
* This "class" simply checks for jQuery.ui having been loaded and loads it if it has not been loaded.
5-
* Used by swingjs.plaf.JSSliderUI
5+
* Used by swingjs.plaf.JSSliderUI and swingjs.plaf.JSPopupMenuUI
66
*
77
* Note that if you change one of the JavaScript files in this directory,
88
* the transpiler will not transfer it to the site directory unless you touch this java file.
99
*
1010
* @author Bob Hanson
1111
*
12-
*
12+
*
1313
*/
14-
public class JQueryUI {
14+
public class JQueryUI {
1515

16-
public JQueryUI() {
16+
public JQueryUI() {
1717
// for reflection
1818
}
1919
static {

sources/net.sf.j2s.java.core/src/swingjs/jquery/j2sMenu.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ try{
5858
// BH 2018
5959
// -- added stopPropagation
6060
// -- changed to mouseover from mouseenter, since we have children
61+
me.clickoutDiasabled = false;
6162
var a = e(t.target).closest("li")
6263
if (a.hasClass(".ui-state-focus"))
6364
return;
@@ -80,10 +81,14 @@ try{
8081
||(me.element.trigger("focus",[!0]),me.active&&me.active.parents(".ui-j2smenu").length===1&&clearMe(me.timer, trigger)));
8182
doCmd("_hide", me, e, e(".ui-j2smenu"));
8283
break;
84+
case "noclickout":
85+
me.clickoutDiasabled = true;
86+
setTimeout(function(){me.clickoutDiasabled = false;},50);
87+
return;
8388
case "onclick_out":
84-
e(t.target).closest(".j2s-menuBar-menu").length == 0
89+
me.clickoutDiasabled || e(t.target).closest(".j2s-menuBar-menu").length == 0
8590
&& (e(t.target).closest(".ui-j2smenu").length||me.collapseAll(t));
86-
break;
91+
return;
8792
case "onleave":
8893
me.collapseAll(t);
8994
break;
@@ -280,6 +285,8 @@ try{
280285

281286
_create:function(){
282287

288+
this.clickoutDiasabled = true;
289+
283290
if (typeof this.options.delay == "number")
284291
this.delay = this.options.delay;
285292

@@ -391,7 +398,7 @@ try{
391398
refresh:function(t,n){ doCmd("refresh", this, e, t, n); },
392399
expand:function(t){ doCmd("expand", this, e, t);},
393400
select:function(t){ doCmd("select", this, e, t); },
394-
401+
noclickout:function() { doCmd("noclickout", this); },
395402
next:function(t){this._move("next","first",t)},
396403
previous:function(t){this._move("prev","last",t)},
397404
isFirstItem:function(){return this.active&&!this.active.prevAll(".ui-j2smenu-item").length},
@@ -478,6 +485,9 @@ Swing.setMenu = function(menu) {
478485
Swing.__getMenuStyle && J2S.$after("head", '<style>'+Swing.__getMenuStyle(menu._applet)+'</style>');
479486
Swing.__getMenuStyle = null; // "static"
480487
if (menu.uiClassID) {
488+
489+
// TODO: We can't be creating fields in JPopupMenu! This is ancient stuff.
490+
481491
menu._visible = false;
482492
menu._j2sname = menu.id = menu.ui.id + '_' + (++Swing.menuCounter);
483493
menu.$ulTop = J2S.__$(); // empty jQuery selector
@@ -554,10 +564,13 @@ Swing.showMenu = function(menu, x, y) {
554564
if (J2S._showMenuCallback)
555565
J2S._showMenuCallback(menu, x, y);
556566
var wasTainted = menu._tainted;
567+
568+
// TODO: We can't be creating fields in JPopupMenu!
569+
557570
if (menu._tainted)
558571
Swing.updateMenu(menu);
559572
menu.setPosition(x, y);
560-
menu.$ulTop.hide().j2smenu().show();
573+
menu.$ulTop.hide().j2smenu("noclickout").show();
561574
menu._visible = true;
562575
menu.timestamp = System.currentTimeMillis$();
563576
menu.dragBind(true);

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import javax.swing.JMenu;
3737
import javax.swing.JMenuItem;
3838
import javax.swing.JPopupMenu;
39+
import javax.swing.JRootPane;
3940
import javax.swing.JTable.BooleanRenderer;
4041
import javax.swing.KeyStroke;
4142
import javax.swing.SwingConstants;
@@ -1292,21 +1293,23 @@ protected void setMnemonic(int newValue) {
12921293

12931294
protected boolean imagePersists;
12941295

1295-
private boolean allowDivOverflow;
1296+
protected boolean allowDivOverflow;
12961297

12971298

12981299
/**
1299-
* we can allow frames -- particularly JInternalFrames -- to overflow.
1300+
* we can allow frames -- particularly JInternalFrames in a JDesktopFrame -- to overflow.
13001301
*
13011302
* To do this, we need to make this indication for both the Root pane and the
1302-
* contentPane for the parent JFrame:
1303+
* contentPane for the parent JFrame, as well as the JDesktopPane, if that pane is not the contentPane.
1304+
* The developer need only indicate this for the rootPane
13031305
*
13041306
* this.getRootPane().putClientProperty("swingjs.overflow.hidden", "false");
13051307
*
13061308
*
13071309
*/
13081310
protected void checkAllowDivOverflow() {
1309-
allowDivOverflow = "false".equals(jc.getRootPane().getClientProperty("swingjs.overflow.hidden"));
1311+
JRootPane root = jc.getRootPane();
1312+
allowDivOverflow = (root != null && "false".equals(root.getClientProperty("swingjs.overflow.hidden")));
13101313
}
13111314

13121315
public void setAllowPaintedBackground(boolean TF) {
@@ -2363,7 +2366,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
23632366
"margin", "0px 5px",
23642367
"transform", "translateY(15%)");
23652368
}
2366-
DOMNode.setStyles(menuAnchorNode, "width", "95%", "min-width", (wCtr + wAccel + margins.left + margins.right) + "px");
2369+
DOMNode.setStyles(menuAnchorNode, "width", "90%", "min-width", Math.max(75,(wCtr + wAccel + margins.left + margins.right)*1.1) + "px");
23672370
}
23682371

23692372
if (alignHCenter) {

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSDesktopPaneUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import sun.swing.DefaultLookup;
2828
import sun.swing.UIAction;
29-
import swingjs.JSUtil;
3029
import swingjs.api.js.DOMNode;
3130

3231
public class JSDesktopPaneUI extends JSPanelUI {
@@ -49,6 +48,7 @@ public DOMNode updateDOMNode() {
4948
if (isNew) {
5049
$(domNode).addClass("swingjs-desktop");
5150
}
51+
checkAllowDivOverflow();
5252
return domNode;
5353
}
5454

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSMenuBarUI.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import java.awt.Component;
3232
import java.awt.Dimension;
33+
import java.awt.Insets;
3334
import java.awt.event.ActionEvent;
3435
import java.awt.event.ContainerEvent;
3536
import java.awt.event.ContainerListener;
@@ -120,6 +121,12 @@ protected int getContainerHeight() {
120121
return height = menuBar.getFont().getFontMetrics().getHeight();
121122
}
122123

124+
@Override
125+
public Insets getInsets() {
126+
return new Insets(2,10,2,10);
127+
128+
}
129+
123130
@Override
124131
public Dimension getPreferredSize(JComponent jc) {
125132
// layout manager will call this specifically for the height

0 commit comments

Comments
 (0)