Skip to content

Commit 72cef74

Browse files
hansonrhansonr
authored andcommitted
tooltip, frame
tooltip not activating over component toFront not engaging on frame title bar click
1 parent cd88333 commit 72cef74

File tree

17 files changed

+484
-235
lines changed

17 files changed

+484
-235
lines changed
2.35 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180821075258
1+
20180821150349
2.35 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180821075258
1+
20180821150349
2.35 KB
Binary file not shown.

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@
5555
import javax.swing.JLayeredPane;
5656
import javax.swing.JRootPane;
5757
import javax.swing.RootPaneContainer;
58+
import javax.swing.plaf.ComponentUI;
59+
5860
import sun.awt.AppContext;
5961
import swingjs.JSToolkit;
6062
//import java.util.concurrent.atomic.AtomicBoolean;
6163
//import java.util.logging.Logger;
6264
import swingjs.JSUtil;
65+
import swingjs.plaf.JSComponentUI;
6366

6467
/**
6568
*
@@ -1037,9 +1040,11 @@ void doDispose() {
10371040
public void run() {
10381041

10391042
// Though Window is not a JComponent, we still treat it as such.
1040-
((JComponent) me).getUI().uninstallUI(null);
1041-
((JComponent) me).getUI().uninstallJS();
1042-
1043+
ComponentUI ui = ((JComponent) me).getUI();
1044+
if (ui != null) {
1045+
ui.uninstallUI(null);
1046+
ui.uninstallJS();
1047+
}
10431048
// Check if this window is the fullscreen window for the
10441049
// device. Exit the fullscreen mode prior to disposing
10451050
// of the window if that's the case.

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,23 +2802,22 @@ static boolean processKeyBindingsForAllComponents(KeyEvent e,
28022802
* >How to Use Tool Tips</a> in <em>The Java Tutorial</em> for further
28032803
* documentation.
28042804
*
2805-
* @param text
2806-
* the string to display; if the text is <code>null</code>, the tool
2807-
* tip is turned off for this component
2805+
* @param text the string to display; if the text is <code>null</code>, the tool
2806+
* tip is turned off for this component
28082807
* @see #TOOL_TIP_TEXT_KEY
28092808
* @beaninfo preferred: true description: The text to display in a tool tip.
28102809
*/
28112810
public void setToolTipText(String text) {
2812-
// String oldText = getToolTipText();
2811+
String oldText = getToolTipText();
28132812
putClientProperty(TOOL_TIP_TEXT_KEY, text);
2814-
// ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
2815-
// if (text != null) {
2816-
// if (oldText == null) {
2817-
// toolTipManager.registerComponent(this);
2818-
// }
2819-
// } else {
2820-
// toolTipManager.unregisterComponent(this);
2821-
// }
2813+
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
2814+
if (text != null) {
2815+
if (oldText == null) {
2816+
toolTipManager.registerComponent(this);
2817+
}
2818+
} else {
2819+
toolTipManager.unregisterComponent(this);
2820+
}
28222821
}
28232822

28242823
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public void setLayer(Component c, int layer, int position) {
377377
layerObj = getObjectForLayer(layer);
378378

379379
if(layer == getLayer(c) && position == getPosition(c)) {
380-
repaint(c.getBounds());
380+
//SwingJS - not necessary repaint(c.getBounds());
381381
return;
382382
}
383383

@@ -388,14 +388,14 @@ public void setLayer(Component c, int layer, int position) {
388388
getComponentToLayer().put((Component)c, layerObj);
389389

390390
if(c.getParent() == null || c.getParent() != this) {
391-
repaint(c.getBounds());
391+
//SwingJS not necessary repaint(c.getBounds());
392392
return;
393393
}
394394

395395
int index = insertIndexForLayer(c, layer, position);
396396

397397
setComponentZOrder(c, index);
398-
repaint(c.getBounds());
398+
// SwingJS not necessary repaint(c.getBounds());
399399
}
400400

401401
/**

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

Lines changed: 108 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@
3232
import javax.swing.AbstractButton;
3333
import javax.swing.Icon;
3434
import javax.swing.ImageIcon;
35+
import javax.swing.JButton;
3536
import javax.swing.JComponent;
37+
import javax.swing.JLabel;
3638
import javax.swing.JTable;
39+
import javax.swing.JToggleButton;
3740
import javax.swing.SwingConstants;
3841
import javax.swing.UIManager;
3942
import javax.swing.event.ChangeEvent;
@@ -784,100 +787,6 @@ protected void propertyChangedCUI(String prop) {
784787
System.out.println("JSComponentUI: unrecognized prop: " + this.id + " " + prop);
785788
}
786789

787-
private ImageIcon getIcon(JSComponent c, Icon icon) {
788-
return (c == null || icon == null
789-
&& (icon = ((AbstractButton) c).getIcon()) == null ?
790-
null : icon.getIconWidth() <= 0 || icon.getIconHeight() <= 0 ? null : (icon instanceof ImageIcon) ? (ImageIcon) icon :
791-
JSToolkit.paintImageForIcon(jc, icon));
792-
}
793-
794-
protected void setIconAndText(String prop, Icon icon, int gap, String text) {
795-
796-
// TODO add textPosition
797-
798-
actualWidth = actualHeight = 0;
799-
currentText = text;
800-
currentGap = gap;
801-
canAlignText = false;
802-
canAlignIcon = false;
803-
currentIcon = null;
804-
imageNode = null;
805-
if (iconNode != null) {
806-
icon = currentIcon = getIcon(jc, icon);
807-
$(iconNode).empty();
808-
if (currentIcon != null) {
809-
imageNode = DOMNode.getImageNode(currentIcon.getImage());
810-
DOMNode.setStyles(imageNode, "vertical-align", "middle"); // else
811-
// this
812-
// will
813-
// be
814-
// "baseline"
815-
iconNode.appendChild(imageNode);
816-
iconHeight = icon.getIconHeight();
817-
}
818-
}
819-
boolean isHTML = false;
820-
if (text == null || text.length() == 0) {
821-
text = "";
822-
if (icon != null)
823-
canAlignIcon = true;
824-
} else {
825-
if (icon == null) {
826-
canAlignText = allowTextAlignment;
827-
} else {
828-
// vCenter(imageNode, 10); // perhaps? Not sure if this is a
829-
// good idea
830-
if (gap == Integer.MAX_VALUE)
831-
gap = getDefaultIconTextGap();
832-
if (gap != 0 && text != null)
833-
DOMNode.addHorizontalGap(iconNode, gap);
834-
}
835-
if (text.indexOf("<html>") == 0) {
836-
isHTML = true;
837-
// PhET uses <html> in labels and uses </br>
838-
text = PT.rep(text.substring(6, text.length() - 7), "</br>", "");
839-
text = PT.rep(text, "</html>", "");
840-
text = PT.rep(text, "href=", "target=_blank href=");
841-
text = PT.rep(text, "href=", "target=_blank href=");
842-
// Jalview hack
843-
text = PT.rep(text, "width: 350; text-align: justify; word-wrap: break-word;",
844-
"width: 350px; word-wrap: break-word;");
845-
}
846-
}
847-
DOMNode obj = null;
848-
if (textNode != null) {
849-
prop = "innerHTML";
850-
obj = textNode;
851-
if (!isHTML)
852-
text = PT.rep(text, "<", "&lt;");
853-
} else if (valueNode != null) {
854-
prop = "value";
855-
obj = valueNode;
856-
if (iconNode != null)
857-
DOMNode.setVisible(obj, text != null);
858-
}
859-
if (obj != null)
860-
setProp(obj, prop, text);
861-
if (centeringNode == null) {
862-
// button
863-
setBackgroundFor(valueNode, c.getBackground());
864-
} else {
865-
// label
866-
setCssFont(centeringNode, c.getFont());
867-
// added to make sure that the displayed element does not wrap with
868-
// this new text
869-
}
870-
if (!boundsSet)
871-
setHTMLSize(domNode, true);
872-
if (centeringNode != null)
873-
setAlignment();
874-
if (debugging)
875-
System.out.println("JSComponentUI: setting " + id + " " + prop);
876-
}
877-
878-
protected int getDefaultIconTextGap() {
879-
return 0;
880-
}
881790

882791
private String createMsgs = "";
883792

@@ -1659,26 +1568,123 @@ protected void setInnerComponentBounds(int width, int height) {
16591568
+ this.height + "->" + height);
16601569
}
16611570

1571+
private ImageIcon getIcon(JSComponent c, Icon icon) {
1572+
return (c == null || icon == null
1573+
&& (icon = ((AbstractButton) c).getIcon()) == null ?
1574+
null : icon.getIconWidth() <= 0 || icon.getIconHeight() <= 0 ? null : (icon instanceof ImageIcon) ? (ImageIcon) icon :
1575+
JSToolkit.paintImageForIcon(jc, icon));
1576+
}
1577+
1578+
1579+
protected void setIconAndText(String prop, Icon icon, int gap, String text) {
1580+
1581+
// TODO so, actually, icons replace the checkbox or radio button, they do not complement them
1582+
1583+
actualWidth = actualHeight = 0;
1584+
currentText = text;
1585+
currentGap = gap;
1586+
canAlignText = false;
1587+
canAlignIcon = false;
1588+
currentIcon = null;
1589+
imageNode = null;
1590+
if (iconNode != null) {
1591+
icon = currentIcon = getIcon(jc, icon);
1592+
$(iconNode).empty();
1593+
if (currentIcon != null) {
1594+
imageNode = DOMNode.getImageNode(currentIcon.getImage());
1595+
DOMNode.setStyles(imageNode, "vertical-align", "middle"); // else
1596+
// this
1597+
// will
1598+
// be
1599+
// "baseline"
1600+
iconNode.appendChild(imageNode);
1601+
iconHeight = icon.getIconHeight();
1602+
}
1603+
}
1604+
boolean isHTML = false;
1605+
if (text == null || text.length() == 0) {
1606+
text = "";
1607+
if (icon != null)
1608+
canAlignIcon = true;
1609+
} else {
1610+
if (icon == null) {
1611+
canAlignText = allowTextAlignment;
1612+
} else {
1613+
// vCenter(imageNode, 10); // perhaps? Not sure if this is a
1614+
// good idea
1615+
if (gap == Integer.MAX_VALUE)
1616+
gap = getDefaultIconTextGap();
1617+
if (gap != 0 && text != null)
1618+
DOMNode.addHorizontalGap(iconNode, gap);
1619+
}
1620+
if (text.indexOf("<html>") == 0) {
1621+
isHTML = true;
1622+
// PhET uses <html> in labels and uses </br>
1623+
text = PT.rep(text.substring(6, text.length() - 7), "</br>", "");
1624+
text = PT.rep(text, "</html>", "");
1625+
text = PT.rep(text, "href=", "target=_blank href=");
1626+
text = PT.rep(text, "href=", "target=_blank href=");
1627+
// Jalview hack
1628+
text = PT.rep(text, "width: 350; text-align: justify; word-wrap: break-word;",
1629+
"width: 350px; word-wrap: break-word;");
1630+
}
1631+
}
1632+
DOMNode obj = null;
1633+
if (textNode != null) {
1634+
prop = "innerHTML";
1635+
obj = textNode;
1636+
if (!isHTML)
1637+
text = PT.rep(text, "<", "&lt;");
1638+
} else if (valueNode != null) {
1639+
prop = "value";
1640+
obj = valueNode;
1641+
if (iconNode != null)
1642+
DOMNode.setVisible(obj, text != null);
1643+
}
1644+
if (obj != null)
1645+
setProp(obj, prop, text);
1646+
if (centeringNode == null) {
1647+
// button
1648+
setBackgroundFor(valueNode, c.getBackground());
1649+
} else {
1650+
// label
1651+
setCssFont(centeringNode, c.getFont());
1652+
// added to make sure that the displayed element does not wrap with
1653+
// this new text
1654+
}
1655+
if (!boundsSet)
1656+
setHTMLSize(domNode, true);
1657+
if (centeringNode != null)
1658+
setAlignment();
1659+
if (debugging)
1660+
System.out.println("JSComponentUI: setting " + id + " " + prop);
1661+
}
1662+
1663+
protected int getDefaultIconTextGap() {
1664+
return 0;
1665+
}
1666+
16621667
private void setAlignment() {
16631668
if (canAlignText) {
16641669
setVerticalAlignment(true);
1665-
setTextAlignment();
1670+
setOverallAlignment();
16661671
} else if (canAlignIcon) {
16671672
setVerticalAlignment(false);
1668-
setTextAlignment();
1673+
setOverallAlignment();
16691674
}
16701675
}
16711676

1672-
private void setTextAlignment() {
1677+
private void setOverallAlignment() {
16731678
if (this.c.getWidth() == 0)
16741679
return;
1680+
// OK, this is the alignment of the component, not the text
16751681
int type = ((AbstractButton) c).getHorizontalAlignment();
16761682
String prop = getCSSTextAlignment(type);
16771683
// the centeringNode is not visible. It is a div that allows us to
16781684
// position the text and icon of the image based on its preferred size
16791685
// in the
1680-
DOMNode.setStyles(domNode, "width", c.getWidth() + "px", "text-align", textAlign = prop);
1681-
if (jc.uiClassID == "LabelUI" && centeringNode != null) {
1686+
if (jc.uiClassID == "LabelUI" &&
1687+
centeringNode != null) {
16821688
int left = 0;
16831689
int w = actualWidth;
16841690
if (w == 0)
@@ -1696,8 +1702,10 @@ private void setTextAlignment() {
16961702
left = (c.getWidth() - w) / 2;
16971703
break;
16981704
default:
1705+
DOMNode.setStyles(domNode, "width", c.getWidth() + "px", "text-align", textAlign = prop);
16991706
return;
17001707
}
1708+
DOMNode.setStyles(domNode, "width", c.getWidth() + "px", "text-align", textAlign = prop);
17011709
// Problem:
17021710
// edu_northwestern_physics_groups_atomic_applet_Mirror_applet.html
17031711
// an initial paint shows checkboxes lower than they should be.
@@ -1710,6 +1718,7 @@ private void setTextAlignment() {
17101718
}
17111719
}
17121720

1721+
17131722
protected String getCSSTextAlignment(int type) {
17141723
String prop = null;
17151724
switch (type) {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ public DOMNode updateDOMNode() {
119119

120120
JSFunction fGetFrameParent = null;
121121
/**
122-
* @j2sNative var me = this; fGetFrameParent =
123-
*
124-
* function(x, y) {
125-
* if (arguments.length == 0) {
126-
* return $(fnode).parent();
122+
* @j2sNative var me = this; fGetFrameParent = function(x, y) {
123+
*
124+
* if (arguments.length == 1) {
125+
* if (x == 501)
126+
* me.jc.toFront$();
127+
* return $(fnode).parent();
127128
* }
128129
* var xy = me.getMoveCoords$I$I(x, y);
129130
* $($(fnode).parent()).css({ top: xy[1] + 'px', left: xy[0] + 'px' });

0 commit comments

Comments
 (0)