3232import javax .swing .AbstractButton ;
3333import javax .swing .Icon ;
3434import javax .swing .ImageIcon ;
35+ import javax .swing .JButton ;
3536import javax .swing .JComponent ;
37+ import javax .swing .JLabel ;
3638import javax .swing .JTable ;
39+ import javax .swing .JToggleButton ;
3740import javax .swing .SwingConstants ;
3841import javax .swing .UIManager ;
3942import 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 , "<" , "<" );
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 , "<" , "<" );
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 ) {
0 commit comments