Skip to content

Commit 5ee0a5f

Browse files
hansonrhansonr
authored andcommitted
JSSplitPaneUI correction for setDividerSize(0)
1 parent 471297e commit 5ee0a5f

File tree

3 files changed

+89
-57
lines changed

3 files changed

+89
-57
lines changed

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

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -631,88 +631,116 @@ protected String getPropertyPrefix() {
631631
*/
632632
private Object[] lastRange;
633633

634+
class Node {
635+
Node[] childNodes;
636+
String tagName;
637+
Node parentNode;
638+
String innerText;
639+
int length;
640+
String textContent;
641+
}
642+
634643
/**
635644
* Find the HTML node and offset for this Java caret position.
636645
*
637646
* @param node domNode or one of its descendants
638647
* @param off document offset to start of this node
639648
* @param pt target caret position
640-
* @return range information or length: [textNode,charOffset] or [nontextNode,charNodesOffset] or [null, nlen]
649+
* @return range information or length: [textNode,charOffset] or
650+
* [nontextNode,charNodesOffset] or [null, nlen]
641651
*/
642652
@SuppressWarnings("unused")
643653
@Override
644-
protected Object[] getJSNodePt(DOMNode node, int pt, boolean isRoot) {
654+
protected Object[] getJSNodePt(DOMNode dnode, int pt, Object[] lastRange, int level) {
645655
// JavaScript below will call this method iteratively with off >= 0.
656+
Node node = /** @j2sNative dnode || */
657+
null;
658+
boolean isRoot = (lastRange == null);
646659
pt = Math.max(0, pt);
647-
if (isRoot) {
648-
//System.out.println("JSEPUI getJSNodePt " + editor.getText().replace('\n', '.').replace('\t', '^'));
649-
lastRange = null;
650-
}
651-
652-
boolean isTAB = isJSTAB(node);
653-
654-
//System.out.println("getting JSNodePt for " + isTAB + " " + pt + " " + (/** @j2sNative node.data||node.outerHTML ||*/""));
655-
660+
// if (isRoot) {
661+
// System.out.println("JSEPUI getJSNodePt " + editor.getText().replace('\n', '.').replace('\t', '^'));
662+
// }
663+
664+
boolean isTAB = isJSTAB(dnode);
665+
666+
// System.out.println("getting JSNodePt for " + isTAB + " " + pt + " " + (/**
667+
// @j2sNative node.data||node.outerHTML ||*/""));
668+
656669
// Must consider several cases for BR and DIV:
657670
// <br>
658671
// <div><br><div> where br counts as 1 character --> [div, 0] or [null, 1]
659-
// <div>.....<br><div> where childNodes[i] is br, counts as 0 charactors --> [div, i] or [null, 0]
672+
// <div>.....<br><div> where childNodes[i] is br, counts as 0 charactors -->
673+
// [div, i] or [null, 0]
660674
// as well as "raw" text in the root domNode:
661-
// text....<br>...text...<br>.... where br counts as 1 character --> [node.parentNode, i] or [null, 1]
675+
// text....<br>...text...<br>.... where br counts as 1 character -->
676+
// [node.parentNode, i] or [null, 1]
662677
//
663-
// also note that range can point to a character position only if the node is #text
664-
// otherwise, it must point to a childNodes index in the parent node. So <br> must
665-
// be indicated this second way.
678+
// also note that range can point to a character position only if the node is
679+
// #text
680+
// otherwise, it must point to a childNode index in the parent node. So <br>
681+
// must be indicated this second way.
666682
//
667683
// TAB will be indicated as a JSTAB string (see above).
668-
669-
/**
670-
* @j2sNative
671-
*
672-
673-
674-
this.lastRange = [node, 0];
675-
if (isTAB) {
676-
return (pt == 0 ? this.lastRange : [null, pt - 1]);
677-
}
678-
var nodes = node.childNodes;
679-
var tag = node.tagName;
680-
var n = nodes.length;
684+
//
685+
Object[] r = /** @j2sNative 1?[]: */
686+
null;
687+
try {
688+
lastRange = setNode(null, node, 0);
689+
if (isTAB) {
690+
return (pt == 0 ? r = lastRange : setNode(r, null, pt - 1));
691+
}
692+
Node[] nodes = node.childNodes;
693+
String tag = node.tagName;
694+
int n = nodes.length;
681695
if (tag == "BR" || n == 1 && nodes[0].tagName == "BR") {
682-
return (pt == 0 ? [node, 0] : [null, pt - 1]);
683-
}
684-
var nlen = 0;
685-
var i1 = (tag == "DIV" || tag == "P" ? 1 : 0);
686-
for (var i = 0; i < n; i++) {
696+
return (pt == 0 ? setNode(r, node, 0) : setNode(r, null, pt - 1));
697+
}
698+
int nlen = 0;
699+
int i1 = (tag == "DIV" || tag == "P" ? 1 : 0);
700+
for (int i = 0; i < n; i++) {
687701
node = nodes[i];
688-
if (node.innerText) {
689-
var ret=this.getJSNodePt$swingjs_api_js_DOMNode$I$Z(node, pt, false);
690-
if (ret[0] != null)
691-
return ret;
692-
pt = ret[1];
702+
if (node.innerText != null) {
703+
r = getJSNodePt((DOMNode) (Object) node, pt, lastRange, ++level);
704+
if (r[0] != null) {
705+
return r;
706+
}
707+
pt = /** @j2sNative 1?r[1] : */
708+
0;
693709
} else if (node.tagName == "BR") {
694710
if (pt == 0)
695-
return [node.parentNode, i];
711+
return setNode(r, node.parentNode, i);
696712
pt -= (isRoot ? 1 : 0);
697713
} else {
698714
nlen = node.length;
699715
if (nlen >= pt)
700-
return this.lastRange = [node, pt];
701-
this.lastRange = [node, nlen];
716+
return r = setNode(lastRange, node, pt);
717+
lastRange = setNode(lastRange, node, nlen);
702718
pt -= nlen;
703719
}
704720
}
705721
if (!isRoot)
706-
return [null, Math.max(0, pt - i1)];
707-
var r = this.lastRange;
708-
this.lastRange = null;
709-
return r;
710-
*/
711-
{
712-
return null;
722+
return setNode(r, null, Math.max(0, pt - i1));
723+
return r = lastRange;
724+
} finally {
725+
// System.out.println("level " + level
726+
// + " pt = " + r[1]
727+
// + " text=" + (r[0] == null ? "<null>" : (((Node) r[0]).parentNode == null ? "NULL" : ((Node) r[0]).parentNode.tagName) + " "
728+
// + ((Node) r[0]).textContent.replace('\n','.').replace('\t','^').replace(' ','_')));
713729
}
714730
}
715731

732+
private Object[] setNode(Object[] r, Node node, int i) {
733+
/**
734+
@j2sNative if (r) {
735+
r[0] = node;
736+
r[1] = i;
737+
return r;
738+
}
739+
r = [node, i];
740+
*/
741+
return r;
742+
}
743+
716744
@Override
717745
public String getJSTextValue() {
718746
String s = getInnerTextSafely(domNode, false, null).toString().replaceAll("\u00A0"," "); // &nbsp;
@@ -777,7 +805,6 @@ protected void jsSelect(Object[] r1, Object[] r2, boolean andScroll) {
777805

778806
andScroll |= (jc.秘keyAction != null);
779807

780-
781808

782809
// System.out.println("jsSelect " + r1 + r2 + " " + andScroll);
783810
// range index may be NaN

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,16 +2218,21 @@ private class SplitPaneDivider extends JLabel {
22182218
/**
22192219
* Returns dividerSize x dividerSize
22202220
*/
2221+
@Override
2222+
public Dimension getMinimumSize() {
2223+
return getPreferredSize();
2224+
}
2225+
/**
2226+
* Returns dividerSize x dividerSize
2227+
*/
22212228
@Override
22222229
public Dimension getPreferredSize() {
22232230
// Ideally this would return the size from the layout manager,
22242231
// but that could result in the layed out size being different from
22252232
// the dividerSize, which may break developers as well as
22262233
// BasicSplitPaneUI.
2227-
if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
2228-
return new Dimension(paneui.splitPane.getDividerSize(), 1);
2229-
}
2230-
return new Dimension(1, paneui.splitPane.getDividerSize());
2234+
int d = paneui.splitPane.getDividerSize();
2235+
return (orientation == JSplitPane.HORIZONTAL_SPLIT ? new Dimension(d, 1) : new Dimension(1, d));
22312236
}
22322237

22332238
SplitPaneDivider(JSSplitPaneUI ui) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,8 @@ public void updateJSCursor(String why) {
11891189
protected void setJSSelection(int mark, int dot, boolean andScroll) {
11901190
// overridden by JSEditorPaneUI
11911191
//System.out.println(id + " seJSSelection " + mark + " " + dot + " " +andScroll);
1192-
Object[] r1 = getJSNodePt(focusNode, mark, true);
1193-
Object[] r2 = (r1 == null || dot == mark ? r1 : getJSNodePt(focusNode, dot, true));
1192+
Object[] r1 = getJSNodePt(focusNode, mark, null, 0);
1193+
Object[] r2 = (r1 == null || dot == mark ? r1 : getJSNodePt(focusNode, dot, null, 0));
11941194

11951195
//System.out.println(id + " setJSSelection " + r1 + " " + r2);
11961196

@@ -1209,7 +1209,7 @@ protected void setJSSelection(int mark, int dot, boolean andScroll) {
12091209
* @param pt
12101210
* @return
12111211
*/
1212-
protected Object[] getJSNodePt(DOMNode node, int pt, boolean isRoot) {
1212+
protected Object[] getJSNodePt(DOMNode node, int pt, Object[] lastRange, int level) {
12131213
/**
12141214
* @j2sNative return [null, pt];
12151215
*/

0 commit comments

Comments
 (0)