Skip to content

Commit 596fd9d

Browse files
committed
JSEditorPaneUI fixes for HTMLEditorKit
1 parent 3a27bef commit 596fd9d

File tree

4 files changed

+101
-76
lines changed

4 files changed

+101
-76
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/JEditorPane.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,11 +1436,11 @@ public void setText(String t) {
14361436
try {
14371437
Document doc = getDocument();
14381438
if (doc instanceof HTMLDocument) {
1439-
if (t.indexOf("<body>")< 0)
1439+
if (t.indexOf("<body")< 0)
14401440
t = "<body>" + t + "</body>";
1441-
if (t.indexOf("<head>")< 0)
1441+
if (t.indexOf("<head")< 0)
14421442
t = "<head>" + t + "</head>";
1443-
if (t.indexOf("<html>")< 0)
1443+
if (t.indexOf("<html")< 0)
14441444
t = "<html>" + t + "</html>";
14451445
}
14461446
if (秘jsHTMLHelper != null)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,13 @@ public JSComponentUI set(JComponent target) {
733733
protected void newID(boolean forceNew) {
734734
classID = c.getUIClassID();
735735
notImplemented = (classID == "ComponentUI");
736-
boolean firstTime = (id == null);
736+
boolean firstTime = (id0 == null);
737737
if (firstTime || forceNew) {
738738
num = ++incr;
739-
id = c.getHTMLName(classID) + "_" + num;
739+
id = c.getHTMLName(classID);
740740
if (firstTime)
741741
id0 = id;
742+
id += "_" + num;
742743
}
743744
}
744745

@@ -1588,6 +1589,8 @@ public DOMNode updateDOMNode() {
15881589
protected DOMNode updateDOMNodeCUI() {
15891590
if (myCursor != getCursor())
15901591
setCursor();
1592+
if (outerNode != null)
1593+
setVisible(outerNode, jc.isVisible());
15911594
return domNode;
15921595
}
15931596

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void propertyChange(PropertyChangeEvent e) {
254254
private String currentHTML;
255255
private boolean isStyled;
256256
private String mytext;
257-
private DOMNode styleNode;
257+
private DOMNode bodyNode;
258258

259259
// private int epTimer;
260260
// @Override
@@ -339,6 +339,12 @@ private int getJSCharCount(DOMNode sib) {
339339
return n + (/** @j2sNative sib.textContent && sib.textContent.length || */ 0);
340340
}
341341

342+
@Override
343+
public void dispose() {
344+
super.dispose();
345+
mytext = currentHTML = null;
346+
}
347+
342348
// @Override
343349
public void setText(String text) {
344350
Document d = editor.getDocument();
@@ -350,19 +356,19 @@ public void setText(String text) {
350356
if (isHtmlKit) {
351357
mytext = html = text;
352358
isHTML = true;
353-
domNode.setAttribute("innerHTML", "");
359+
DOMNode.setAttr(domNode, "innerHTML", "");
354360
// we will have to figure out a way for images and base.
355361
html = (String) editor.秘jsHTMLHelper.get("html", getInner(text, "body"));
356362
DOMNode.setAttrs(domNode, "contentEditable", TRUE);
357-
styleNode = DOMNode.createElement("div", id0 + "_style");
358-
domNode.appendChild(styleNode);
363+
bodyNode = DOMNode.createElement("div", id0 + "_body");
364+
domNode.appendChild(bodyNode);
359365
String[] styles = (String[]) editor.秘jsHTMLHelper.get("styles", "body");
360366
if (styles != null)
361-
DOMNode.setStyles(styleNode, styles);
367+
DOMNode.setStyles(bodyNode, styles);
362368
String css = (String) editor.秘jsHTMLHelper.get("css", id);
363-
setStyle(id + "_style", css);
369+
setStyle(id0 + "_styles", css);
364370
} else {
365-
styleNode = domNode;
371+
bodyNode = domNode;
366372
mytext = text;
367373
isHTML = text.startsWith("<html");
368374
if (isHTML) {
@@ -389,7 +395,7 @@ public void setText(String text) {
389395
return;
390396
// had text = fixText(currentText = text) here, but result was never used
391397
currentText = text;
392-
DOMNode.setAttr(styleNode, "innerHTML", currentHTML = html);
398+
DOMNode.setAttr(bodyNode, "innerHTML", currentHTML = html);
393399
updateDataUI();
394400
JSToolkit.dispatch(updateRunnable, 10, 0);
395401
}
@@ -412,15 +418,16 @@ private void setStyle(String id, String css) {
412418
if (d == null) {
413419
$(body).append("<style id=" + id +">" + css + "</style>");
414420
} else {
415-
DOMNode.setAttr(d, "innerText", css);
421+
// If I use innerText here, then \n gets turned into <br>
422+
DOMNode.setAttr(d, "innerHTML", css);
416423
}
417424
}
418425

419426
private String getInner(String html, String tag) {
420-
int pt = html.indexOf("<" + tag);
427+
int pt = html.lastIndexOf("<" + tag);
421428
if (pt >= 0) {
422429
html = html.substring(html.indexOf(">", pt) + 1);
423-
pt = html.lastIndexOf("</" + tag + ">");
430+
pt = html.indexOf("</" + tag + ">", pt);
424431
if (pt >= 0)
425432
html = html.substring(0, pt);
426433
}

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

Lines changed: 75 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,67 +3607,82 @@ public ScrollableTabButton(int direction) {
36073607
private class Handler implements ChangeListener, ContainerListener,
36083608
FocusListener, MouseListener, MouseMotionListener,
36093609
PropertyChangeListener {
3610-
//
3611-
// PropertyChangeListener
3612-
//
3613-
@Override
3610+
//
3611+
// PropertyChangeListener
3612+
//
3613+
@Override
36143614
public void propertyChange(PropertyChangeEvent e) {
3615-
JTabbedPane pane = (JTabbedPane)e.getSource();
3616-
String name = e.getPropertyName();
3617-
boolean isScrollLayout = scrollableTabLayoutEnabled();
3618-
if (name == "mnemonicAt") {
3619-
updateMnemonics();
3620-
pane.秘repaint();
3621-
}
3622-
else if (name == "displayedMnemonicIndexAt") {
3623-
pane.秘repaint();
3624-
}
3625-
else if (name =="indexForTitle") {
3626-
calculatedBaseline = false;
3627-
updateHtmlViews((Integer)e.getNewValue());
3628-
} else if (name == "tabLayoutPolicy") {
3629-
JSTabbedPaneUI.this.uninstallUI(pane);
3630-
JSTabbedPaneUI.this.installUI(pane);
3631-
calculatedBaseline = false;
3632-
} else if (name == "tabPlacement") {
3633-
if (scrollableTabLayoutEnabled()) {
3634-
tabScroller.createButtons();
3635-
}
3636-
calculatedBaseline = false;
3637-
} else if (name == "opaque" && isScrollLayout) {
3638-
boolean newVal = ((Boolean)e.getNewValue()).booleanValue();
3639-
tabScroller.tabPanel.setOpaque(newVal);
3640-
tabScroller.viewport.setOpaque(newVal);
3641-
} else if (name == "background" && isScrollLayout) {
3642-
Color newVal = (Color)e.getNewValue();
3643-
tabScroller.tabPanel.setBackground(newVal);
3644-
tabScroller.viewport.setBackground(newVal);
3645-
Color newColor = selectedColor == null ? newVal : selectedColor;
3646-
tabScroller.scrollForwardButton.setBackground(newColor);
3647-
tabScroller.scrollBackwardButton.setBackground(newColor);
3648-
} else if (name == "indexForTabComponent") {
3649-
if (tabContainer != null) {
3650-
tabContainer.removeUnusedTabComponents();
3651-
}
3652-
Component c = tabPane.getTabComponentAt(
3653-
(Integer)e.getNewValue());
3654-
if (c != null) {
3655-
if (tabContainer == null) {
3656-
installTabContainer();
3657-
} else {
3658-
tabContainer.add(c);
3659-
}
3660-
}
3661-
tabPane.revalidate();
3662-
tabPane.秘repaint();
3663-
calculatedBaseline = false;
3664-
} else if (name == "indexForNullComponent") {
3665-
isRunsDirty = true;
3666-
updateHtmlViews((Integer)e.getNewValue());
3667-
} else if (name == "font") {
3668-
calculatedBaseline = false;
3669-
}
3670-
}
3615+
JTabbedPane pane = (JTabbedPane) e.getSource();
3616+
String name = e.getPropertyName();
3617+
boolean isScrollLayout = scrollableTabLayoutEnabled();
3618+
switch (name) {
3619+
case "mnemonicAt":
3620+
updateMnemonics();
3621+
pane.秘repaint();
3622+
break;
3623+
case "displayedMnemonicIndexAt":
3624+
pane.秘repaint();
3625+
break;
3626+
case "indexForTitle":
3627+
calculatedBaseline = false;
3628+
updateHtmlViews((Integer) e.getNewValue());
3629+
break;
3630+
case "tabLayoutPolicy":
3631+
JSTabbedPaneUI.this.uninstallUI(pane);
3632+
JSTabbedPaneUI.this.installUI(pane);
3633+
calculatedBaseline = false;
3634+
break;
3635+
case "tabPlacement":
3636+
if (scrollableTabLayoutEnabled()) {
3637+
tabScroller.createButtons();
3638+
}
3639+
calculatedBaseline = false;
3640+
break;
3641+
case "opaque":
3642+
if (isScrollLayout) {
3643+
boolean newVal = ((Boolean) e.getNewValue()).booleanValue();
3644+
tabScroller.tabPanel.setOpaque(newVal);
3645+
tabScroller.viewport.setOpaque(newVal);
3646+
}
3647+
break;
3648+
case "background":
3649+
if (isScrollLayout) {
3650+
Color newVal = (Color) e.getNewValue();
3651+
tabScroller.tabPanel.setBackground(newVal);
3652+
tabScroller.viewport.setBackground(newVal);
3653+
Color newColor = selectedColor == null ? newVal : selectedColor;
3654+
tabScroller.scrollForwardButton.setBackground(newColor);
3655+
tabScroller.scrollBackwardButton.setBackground(newColor);
3656+
}
3657+
break;
3658+
case "indexForTabComponent":
3659+
if (tabContainer != null) {
3660+
tabContainer.removeUnusedTabComponents();
3661+
}
3662+
Component c = tabPane.getTabComponentAt((Integer) e.getNewValue());
3663+
if (c != null) {
3664+
if (tabContainer == null) {
3665+
installTabContainer();
3666+
} else {
3667+
tabContainer.add(c);
3668+
}
3669+
}
3670+
tabPane.revalidate();
3671+
tabPane.秘repaint();
3672+
calculatedBaseline = false;
3673+
break;
3674+
case "indexForNullComponent":
3675+
isRunsDirty = true;
3676+
updateHtmlViews((Integer) e.getNewValue());
3677+
break;
3678+
case "font":
3679+
calculatedBaseline = false;
3680+
break;
3681+
default:
3682+
System.out.println("JSTabbedPaneUI prop changed " + name);
3683+
break;
3684+
}
3685+
}
36713686

36723687
private void updateHtmlViews(int index) {
36733688
String title = tabPane.getTitleAt(index);

0 commit comments

Comments
 (0)