Skip to content

Commit a80e2dc

Browse files
committed
Fixes for JSTextBoxUI not reporting 4 for min width
1 parent 9d2f277 commit a80e2dc

File tree

11 files changed

+49
-23
lines changed

11 files changed

+49
-23
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20241112145321
1+
20241123180856
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20241112145321
1+
20241123180856
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/awt/Toolkit.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,12 @@ protected final void setDesktopProperty(String name, Object newValue) {
17481748
* an opportunity to lazily evaluate desktop property values.
17491749
*/
17501750
protected Object lazilyLoadDesktopProperty(String name) {
1751-
return null;
1751+
// BH SwingJS -- we store these in Clazz.js System.getProperty$S.
1752+
// but they will be Objects. For example,
1753+
1754+
// "awt.multiClickInterval" => Integer.valueOf(500);
1755+
1756+
return System.getProperty("DeskTop_" + name);
17521757
}
17531758

17541759
/**
@@ -1810,7 +1815,7 @@ public PropertyChangeListener[] getPropertyChangeListeners() {
18101815
public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
18111816
return desktopPropsSupport.getPropertyChangeListeners(propertyName);
18121817
}
1813-
1818+
18141819
protected final Map<String,Object> desktopProperties =
18151820
new HashMap<String,Object>();
18161821
protected final PropertyChangeSupport desktopPropsSupport =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ public boolean isFocusable() {
839839
@Override
840840
public Dimension getPreferredSize(JComponent jc) {
841841
if (isAWT && isSimpleButton)
842-
return JSLabelUI.getMinimumSizePeer(jc, button);
842+
return JSLabelUI.getMinimumSizePeer(jc, button, true);
843843
Icon ic;
844844
if (!isSimpleButton || isAWT || button.getText() != null || (ic = getIcon()) == null)
845845
return super.getPreferredSize(jc);

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public DOMNode updateDOMNode() {
9999
focusNode = enableNode = textNode = domNode;
100100
DOMNode.setStyles(domNode, "resize", "none", "margin", "0px", "padding", "1px", "box-sizing", "border-box");
101101
bindJSKeyEvents(focusNode, true);
102+
@SuppressWarnings("unused")
102103
JSEditorPaneUI me = this;
103104
$(domNode).on("paste", /** @j2sNative function(e){ return me.handleJSPasteEvent(e.originalEvent,e)} || */null);
104105
}
@@ -270,7 +271,6 @@ public void propertyChange(PropertyChangeEvent e) {
270271
super.propertyChange(e);
271272
}
272273

273-
@SuppressWarnings("unused")
274274
private String currentHTML;
275275
private boolean isStyled;
276276
private String mytext;
@@ -678,7 +678,6 @@ class Node {
678678
* @return range information or length: [textNode,charOffset] or
679679
* [nontextNode,charNodesOffset] or [null, nlen]
680680
*/
681-
@SuppressWarnings("unused")
682681
@Override
683682
protected Object[] getJSNodePt(DOMNode dnode, int pt, Object[] lastRange, int level) {
684683
// JavaScript below will call this method iteratively with off >= 0.
@@ -718,6 +717,7 @@ protected Object[] getJSNodePt(DOMNode dnode, int pt, Object[] lastRange, int le
718717
if (isTAB) {
719718
return (pt == 0 ? r = lastRange : setNode(r, null, pt - 1));
720719
}
720+
@SuppressWarnings("null")
721721
Node[] nodes = node.childNodes;
722722
String tag = node.tagName;
723723
int n = nodes.length;
@@ -1096,7 +1096,7 @@ private int[] getJavaMarkAndDot() {
10961096
return new int[] { Math.min(x, y), Math.max(x, y) };
10971097
}
10981098

1099-
private String stemp;
1099+
//private String stemp;
11001100
private int[] xyTemp;
11011101

11021102
@Override
@@ -1118,7 +1118,7 @@ protected boolean handleCtrlV(int mode) {
11181118
String s = (String) DOMNode.getAttr(domNode, "innerText");
11191119
switch (mode) {
11201120
case KeyEvent.KEY_PRESSED:
1121-
stemp = s;
1121+
//stemp = s;
11221122
xyTemp = getJavaMarkAndDot();
11231123
return false;
11241124
case KeyEvent.KEY_TYPED:
@@ -1254,13 +1254,13 @@ private static String replaceTag(String html, String tag, String rep) {
12541254
}
12551255
}
12561256

1257-
private int tabCount(String s) {
1258-
int n = 0;
1259-
for (int i = s.length(); --i >= 0;)
1260-
if (s.charAt(i) == '\t')
1261-
n++;
1262-
return n;
1263-
}
1257+
// private int tabCount(String s) {
1258+
// int n = 0;
1259+
// for (int i = s.length(); --i >= 0;)
1260+
// if (s.charAt(i) == '\t')
1261+
// n++;
1262+
// return n;
1263+
// }
12641264

12651265
@Override
12661266
void setJSText() {
@@ -1357,7 +1357,7 @@ public Dimension getMinimumSize(JComponent jc) {
13571357
public Rectangle modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException {
13581358
Rectangle alloc = getVisibleEditorRect();
13591359
Document doc = editor.getDocument();
1360-
Object[] r1 = getJSNodePt(focusNode, pos, null, 0);
1360+
//Object[] r1 = getJSNodePt(focusNode, pos, null, 0);
13611361
try {
13621362
if (alloc != null) {
13631363
rootView.setSize(alloc.width, alloc.height);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.swing.JMenuBar;
1313
import javax.swing.JPopupMenu;
1414
import javax.swing.LookAndFeel;
15+
import javax.swing.text.JTextComponent;
1516

1617
import swingjs.api.js.DOMNode;
1718

@@ -127,7 +128,7 @@ public void paint(Graphics g, JComponent c) {
127128
public Dimension getPreferredSize(JComponent jc) {
128129
c = this.jc = jc; // renderer issue
129130
updateDOMNode();
130-
return (isAWT ? getMinimumSizePeer(jc, label)
131+
return (isAWT ? getMinimumSizePeer(jc, label, false)
131132
: label == null ? super.getPreferredSize(jc)
132133
: JSGraphicsUtils.getPreferredButtonSize(((AbstractButton) jc),
133134
((AbstractButton) jc).getIconTextGap()));
@@ -136,18 +137,19 @@ public Dimension getPreferredSize(JComponent jc) {
136137
final static int[] htAdj = { 0, 7, 6, 7, 6, 6, 5, 5, 6, 7, 7, 7, 6, 6, 5, 5, 5, 5, 6, 6, 4, 4, 4, 4, 3, 3, 5, 5,
137138
3, 3, 4, 3, 2, 3, 3, 3, 2, 2, 2, 2, 0, };
138139

139-
static Dimension getMinimumSizePeer(JComponent jc, Object label) {
140+
static Dimension getMinimumSizePeer(JComponent jc, Object label, boolean preferredWidth) {
140141
Font f = jc.getFont();
141142
String s = null;
142143
if (f == null)
143144
return new Dimension(14, 8);
144145
FontMetrics fm = f.getFontMetrics();
145-
s = ((JLabel) label).getText();
146+
s = (label == null ? ((JTextComponent) jc).getText()
147+
:((JLabel) label).getText());
146148
if (s == null)
147149
s = "";
148150
int sz = f.getSize();
149151
int adj = (sz <= 40 ? htAdj[sz] : 0);
150-
return new Dimension(fm.stringWidth(s) + 14, fm.getHeight() + adj);
152+
return new Dimension(preferredWidth ? fm.stringWidth(s) + 14 : 4, fm.getHeight() + adj);
151153
}
152154

153155
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected String getSizingWidth() {
110110

111111
@Override
112112
public Dimension getMinimumSize(JComponent jc) {
113-
return (isAWT ? JSLabelUI.getMinimumSizePeer(jc, editor) : super.getMinimumSize(jc));
113+
return JSLabelUI.getMinimumSizePeer(jc, editor, false);
114114
}
115115

116116
@Override

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.awt.Rectangle;
4141
import java.awt.Shape;
4242
import java.awt.event.ActionEvent;
43+
import java.awt.event.InputEvent;
4344
import java.awt.event.KeyEvent;
4445
import java.awt.geom.Point2D.Double;
4546
import java.awt.geom.Rectangle2D;
@@ -280,7 +281,9 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
280281
return HANDLED;
281282
}
282283
if (!ignore && eventType == KeyEvent.KEY_PRESSED
283-
&& (keyEvent.getModifiersEx() & (KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)) != 0) {
284+
&& (keyEvent.getModifiersEx()
285+
& (InputEvent.CTRL_DOWN_MASK
286+
| InputEvent.ALT_DOWN_MASK)) != 0) {
284287
// dispatch a missing KeyTyped event.
285288
int code = keyEvent.getKeyCode();
286289
if (code >= 65 && code <= 90) {

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

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

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10+
// BH 2024.11.23 implementing java.awt.Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval")
1011
// BH 2024.06.22 adds Integer.getIngeger(String, int) (returning null)
1112
// BH 2024.03.03 removes unnecessary loadClass("xxxx") on exceptionOf(e,"xxxx") call
1213
// BH 2024.02.23 fixes missing Long.signum
@@ -3339,6 +3340,13 @@ C$.getProperty$S=function (key) {
33393340
return Clazz._isHeadless;
33403341
C$.checkKey$S(key);
33413342
var p = (C$.props == null ? sysprops[key] : C$.props.getProperty$S(key))
3343+
if (p == null) {
3344+
switch (key) {
3345+
case "DeskTop_awt.multiClickInterval":
3346+
// from java.awt.Toolkit.getDesktopProperty(name)
3347+
return Integer.valueOf$I(500);
3348+
}
3349+
}
33423350
return (p == null ? null : p);
33433351
}
33443352

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14131,6 +14131,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
1413114131

1413214132
// Google closure compiler cannot handle Clazz.new or Clazz.super
1413314133

14134+
// BH 2024.11.23 implementing java.awt.Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval")
1413414135
// BH 2024.06.22 adds Integer.getIngeger(String, int) (returning null)
1413514136
// BH 2024.03.03 removes unnecessary loadClass("xxxx") on exceptionOf(e,"xxxx") call
1413614137
// BH 2024.02.23 fixes missing Long.signum
@@ -17463,6 +17464,13 @@ C$.getProperty$S=function (key) {
1746317464
return Clazz._isHeadless;
1746417465
C$.checkKey$S(key);
1746517466
var p = (C$.props == null ? sysprops[key] : C$.props.getProperty$S(key))
17467+
if (p == null) {
17468+
switch (key) {
17469+
case "DeskTop_awt.multiClickInterval":
17470+
// from java.awt.Toolkit.getDesktopProperty(name)
17471+
return Integer.valueOf$I(500);
17472+
}
17473+
}
1746617474
return (p == null ? null : p);
1746717475
}
1746817476

0 commit comments

Comments
 (0)