Skip to content

Commit 3c51477

Browse files
committed
minor fixes
better handling of resources by Class.java, smoother tooltip, better HTMLDocument in JSEditorPaneUI fix for JSLabel with icon but no image additional minor changes
1 parent 4423b2e commit 3c51477

File tree

11 files changed

+265
-244
lines changed

11 files changed

+265
-244
lines changed

sources/net.sf.j2s.java.core/src/java/lang/Class.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,14 +2424,14 @@ public InputStream getResourceAsStream(String name) {
24242424
String clazzName = /** @j2sNative this.$clazz$ && (this.$clazz$.__CLASS_NAME$__ || this.$clazz$.__CLASS_NAME__)||*/ "";
24252425
if (clazzName == "" && !name.startsWith("/"))
24262426
name = "/" + name;
2427-
Object data = null, fname = null;
2427+
Object data = null;
2428+
if (name == null || URL.class == null)
2429+
return null;
2430+
name = name.replace('\\','/');
2431+
String baseFolder = null;
2432+
String fname= name;
24282433
/**
24292434
* @j2sNative
2430-
if (!name)
2431-
return null;
2432-
name = name.replace (/\\/g, '/');
2433-
var baseFolder = null;
2434-
fname = name;
24352435
if (arguments.length == 2 && name.indexOf ('/') != 0) { // additional argument
24362436
name = "/" + name;
24372437
}
@@ -2464,13 +2464,13 @@ public InputStream getResourceAsStream(String name) {
24642464
var url = null;
24652465
var javapath = fname;
24662466
try {
2467-
if (fname.indexOf(":/") < 0) {
2468-
var d = document.location.href.split("#")[0].split("?")[0].split("/");
2469-
d[d.length - 1] = fname;
2470-
fname = d.join("/");
2471-
}
2467+
// if (fname.indexOf(":/") < 0) {
2468+
// var d = document.location.href.split("#")[0].split("?")[0].split("/");
2469+
// d[d.length - 1] = fname;
2470+
// fname = d.join("/");
2471+
// }
24722472
Clazz.load("java.net.URL");
2473-
url = Clazz.new_(java.net.URL.c$$S,[fname]);
2473+
url = Clazz.new_(java.net.URL.c$$S,["file:/" + fname]);
24742474
} catch (e) {
24752475
return null;
24762476
}

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
package javax.swing;
3131

3232
/**
33+
* SwingJS note -- JToopTip extends JLabel; was JComponent
34+
*
3335
* Used to display a "Tip" for a Component. Typically components provide api
3436
* to automate the process of using <code>ToolTip</code>s.
3537
* For example, any Swing component can use the <code>JComponent</code>
@@ -62,10 +64,8 @@
6264
* @author Dave Moore
6365
* @author Rich Shiavi
6466
*/
65-
public class JToolTip extends JComponent {
67+
public class JToolTip extends JLabel {
6668

67-
68-
String tipText;
6969
JComponent component;
7070

7171
/** Creates a tool tip. */
@@ -91,8 +91,8 @@ public String getUIClassID() {
9191
* description: Sets the text of the tooltip
9292
*/
9393
public void setTipText(String tipText) {
94-
String oldValue = this.tipText;
95-
this.tipText = tipText;
94+
String oldValue = getText();
95+
super.setText(tipText);
9696
firePropertyChange("tiptext", oldValue, tipText);
9797
}
9898

@@ -103,7 +103,7 @@ public void setTipText(String tipText) {
103103
* @return the <code>String</code> that is displayed
104104
*/
105105
public String getTipText() {
106-
return tipText;
106+
return getText();
107107
}
108108

109109
/**
@@ -148,24 +148,19 @@ boolean alwaysOnTop() {
148148
return true;
149149
}
150150

151-
/**
152-
* Returns a string representation of this <code>JToolTip</code>.
153-
* This method
154-
* is intended to be used only for debugging purposes, and the
155-
* content and format of the returned string may vary between
156-
* implementations. The returned string may be empty but may not
157-
* be <code>null</code>.
158-
*
159-
* @return a string representation of this <code>JToolTip</code>
160-
*/
161-
@Override
162-
protected String paramString() {
163-
String tipTextString = (tipText != null ?
164-
tipText : "");
165-
166-
return super.paramString() +
167-
",tipText=" + tipTextString;
168-
}
151+
/**
152+
* Returns a string representation of this <code>JToolTip</code>. This method is
153+
* intended to be used only for debugging purposes, and the content and format
154+
* of the returned string may vary between implementations. The returned string
155+
* may be empty but may not be <code>null</code>.
156+
*
157+
* @return a string representation of this <code>JToolTip</code>
158+
*/
159+
@Override
160+
protected String paramString() {
161+
String tipText = getText();
162+
return super.paramString() + ",tipText=" +(tipText != null ? tipText : "");
163+
}
169164

170165

171166
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ public void windowClosed(WindowEvent e) {
497497
//
498498
@Override
499499
public void hide() {
500-
super.hide();
500+
// was super.hide(), but this also disposes of contents BH 2020.04.10
501+
getComponent().hide();
501502
recycleHeavyWeightPopup(this);
502503
}
503504

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

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ public void actionPerformed(ActionEvent e) {
141141
@Override
142142
public void actionPerformed(ActionEvent e) {
143143
hideTipWindow();
144+
//System.out.println("ttm stop enter");
145+
144146
enterTimer.stop();
145147
showImmediately = false;
146148
insideComponent = null;
@@ -270,8 +272,14 @@ public int getReshowDelay() {
270272
}
271273

272274
void showTipWindow() {
275+
276+
277+
//System.out.println("ttm showtipwindow1");
278+
273279
if (insideComponent == null || !insideComponent.isShowing())
274280
return;
281+
282+
//System.out.println("ttm showtipwindow2");
275283
Component win = insideComponent.getTopLevelAncestor();
276284
// will be null for some menu items
277285
if (win != null && win.isWindowOrJSApplet()) {
@@ -359,13 +367,14 @@ void showTipWindow() {
359367
// }
360368
// }
361369
// else
362-
{
363-
popupFactory.setPopupType(PopupFactory.HEAVY_WEIGHT_POPUP);// PopupFactory.MEDIUM_WEIGHT_POPUP);
364-
}
370+
// {
371+
popupFactory.setPopupType(PopupFactory.HEAVY_WEIGHT_POPUP);// PopupFactory.MEDIUM_WEIGHT_POPUP);/
372+
// }
365373
JToolTip t = tip;
366374
hideTipWindow();
367375
tip = t;
368376
tipWindow = popupFactory.getPopup(insideComponent, tip, location.x, location.y);
377+
// Yes, we do this again...
369378
popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
370379
tipWindow.show();
371380
hasFired = true;
@@ -378,6 +387,9 @@ void showTipWindow() {
378387
} else {
379388
window = null;
380389
}
390+
//System.out.println("ttm stop inside");
391+
//System.out.println("ttm start inside");
392+
381393
insideTimer.stop();
382394
insideTimer.start();
383395
tipShowing = true;
@@ -390,14 +402,24 @@ void hideTipWindow() {
390402
window.removeMouseListener(this);
391403
window = null;
392404
}
393-
@SuppressWarnings("unused")
394405
Popup win = this.tipWindow;
395406
// give this a few milliseconds, for continuity
396-
JSToolkit.dispatch(/** @j2sNative function() {win.hide$()} || */null, 10, 0);
397-
// tipWindow.hide();
407+
Runnable r = new Runnable() {
408+
409+
@Override
410+
public void run() {
411+
win.hide();
412+
}
413+
414+
};
415+
JSToolkit.dispatch(r, 10, 0);
398416
tipWindow = null;
399417
tipShowing = false;
400418
tip = null;
419+
//System.out.println("ttm stop inside");
420+
//System.out.println("ttm stop enter");
421+
//System.out.println("ttm stop exit");
422+
401423
insideTimer.stop();
402424
enterTimer.stop();
403425
exitTimer.stop();
@@ -480,6 +502,7 @@ private void initiateToolTip(MouseEvent event) {
480502
}
481503

482504
if (insideComponent != null) {
505+
//System.out.println("ttm stop enter");
483506
enterTimer.stop();
484507
}
485508
// A component in an unactive internal frame is sent two
@@ -506,6 +529,8 @@ private void initiateToolTip(MouseEvent event) {
506529
}
507530
} else {
508531
// useCurrentMenu = true;
532+
//System.out.println("ttm start enter");
533+
509534
enterTimer.start();
510535
}
511536
}
@@ -569,7 +594,9 @@ public void mouseExited(MouseEvent event) {
569594
}
570595
}
571596

572-
if (shouldHide) {
597+
if (shouldHide)
598+
// System.out.println("ttm stop enter");
599+
{
573600
enterTimer.stop();
574601
if (insideComponent != null) {
575602
insideComponent.removeMouseMotionListener(this);
@@ -578,6 +605,8 @@ public void mouseExited(MouseEvent event) {
578605
toolTipText = null;
579606
mouseEvent = null;
580607
hideTipWindow();
608+
// System.out.println("ttm restart exit");
609+
581610
exitTimer.restart();
582611
}
583612
}
@@ -591,6 +620,10 @@ public void mouseExited(MouseEvent event) {
591620
@Override
592621
public void mousePressed(MouseEvent event) {
593622
hideTipWindow();
623+
//System.out.println("ttm stop inside");
624+
//System.out.println("ttm stop enter");
625+
//System.out.println("ttm stop exit");
626+
594627
insideTimer.stop();
595628
exitTimer.stop();
596629
enterTimer.stop();
@@ -618,6 +651,7 @@ public void mouseDragged(MouseEvent event) {
618651
*/
619652
@Override
620653
public void mouseMoved(MouseEvent event) {
654+
621655
if (tipShowing) {
622656
checkForTipChange(event);
623657
} else if (showImmediately) {
@@ -627,17 +661,25 @@ public void mouseMoved(MouseEvent event) {
627661
preferredLocation = component.getToolTipLocation(event);
628662
mouseEvent = event;
629663
insideComponent = component;
664+
//System.out.println("ttm stop exit");
665+
630666
exitTimer.stop();
631667
showTipWindow();
632668
}
633669
} else {
670+
671+
634672
hideTipWindow();
635-
if (hasFired)
636-
return;
673+
674+
//System.out.println("ttm component mouse moved showing " + tipShowing + " " + showImmediately + " " + hasFired);
675+
676+
// if (hasFired)
677+
// return;
637678
// Lazily lookup the values from within insideTimerAction
638679
insideComponent = (JComponent) event.getSource();
639680
mouseEvent = event;
640681
toolTipText = null;
682+
//System.out.println("ttm restart enter");
641683
enterTimer.restart();
642684
}
643685
}
@@ -661,6 +703,7 @@ private void checkForTipChange(MouseEvent event) {
661703

662704

663705
if (newText != null) {
706+
//System.out.println("ttm restart enter");
664707
enterTimer.restart();
665708
return;
666709
}
@@ -672,8 +715,10 @@ private void checkForTipChange(MouseEvent event) {
672715
if (showImmediately) {
673716
hideTipWindow();
674717
showTipWindow();
718+
//System.out.println("ttm stop exit");
675719
exitTimer.stop();
676720
} else {
721+
//System.out.println("ttm restart enter");
677722
enterTimer.restart();
678723
}
679724
return;
@@ -683,6 +728,11 @@ private void checkForTipChange(MouseEvent event) {
683728
mouseEvent = null;
684729
insideComponent = null;
685730
hideTipWindow();
731+
732+
//System.out.println("ttm stop inside");
733+
//System.out.println("ttm stop enter");
734+
//System.out.println("ttm restart exit");
735+
686736
enterTimer.stop();
687737
insideTimer.stop();
688738
exitTimer.restart();
@@ -701,6 +751,7 @@ private void checkForTipChange(MouseEvent event) {
701751
private class MoveBeforeEnterListener extends MouseMotionAdapter {
702752
@Override
703753
public void mouseMoved(MouseEvent e) {
754+
//System.out.println("TTM mousemoved");
704755
initiateToolTip(e);
705756
}
706757
}

0 commit comments

Comments
 (0)