< prev index next >

src/java.desktop/share/classes/javax/swing/SwingUtilities.java

Print this page




1073             textR.width = textR.height = 0;
1074             text = "";
1075             gap = 0;
1076         }
1077         else {
1078             int availTextWidth;
1079             gap = (icon == null) ? 0 : textIconGap;
1080 
1081             if (horizontalTextPosition == CENTER) {
1082                 availTextWidth = viewR.width;
1083             }
1084             else {
1085                 availTextWidth = viewR.width - (iconR.width + gap);
1086             }
1087             v = (c != null) ? (View) c.getClientProperty("html") : null;
1088             if (v != null) {
1089                 textR.width = Math.min(availTextWidth,
1090                                        (int) v.getPreferredSpan(View.X_AXIS));
1091                 textR.height = (int) v.getPreferredSpan(View.Y_AXIS);
1092             } else {
1093                 textR.width = SwingUtilities2.stringWidth(c, fm, text);

1094                 lsb = SwingUtilities2.getLeftSideBearing(c, fm, text);
1095                 if (lsb < 0) {
1096                     // If lsb is negative, add it to the width and later
1097                     // adjust the x location. This gives more space than is
1098                     // actually needed.
1099                     // This is done like this for two reasons:
1100                     // 1. If we set the width to the actual bounds all
1101                     //    callers would have to account for negative lsb
1102                     //    (pref size calculations ONLY look at width of
1103                     //    textR)
1104                     // 2. You can do a drawString at the returned location
1105                     //    and the text won't be clipped.
1106                     textR.width -= lsb;
1107                 }
1108                 if (textR.width > availTextWidth) {
1109                     text = SwingUtilities2.clipString(c, fm, text,
1110                                                       availTextWidth);
1111                     textR.width = SwingUtilities2.stringWidth(c, fm, text);

1112                 }
1113                 textR.height = fm.getHeight();
1114             }
1115         }
1116 
1117 
1118         /* Compute textR.x,y given the verticalTextPosition and
1119          * horizontalTextPosition properties
1120          */
1121 
1122         if (verticalTextPosition == TOP) {
1123             if (horizontalTextPosition != CENTER) {
1124                 textR.y = 0;
1125             }
1126             else {
1127                 textR.y = -(textR.height + gap);
1128             }
1129         }
1130         else if (verticalTextPosition == CENTER) {
1131             textR.y = (iconR.height / 2) - (textR.height / 2);




1073             textR.width = textR.height = 0;
1074             text = "";
1075             gap = 0;
1076         }
1077         else {
1078             int availTextWidth;
1079             gap = (icon == null) ? 0 : textIconGap;
1080 
1081             if (horizontalTextPosition == CENTER) {
1082                 availTextWidth = viewR.width;
1083             }
1084             else {
1085                 availTextWidth = viewR.width - (iconR.width + gap);
1086             }
1087             v = (c != null) ? (View) c.getClientProperty("html") : null;
1088             if (v != null) {
1089                 textR.width = Math.min(availTextWidth,
1090                                        (int) v.getPreferredSpan(View.X_AXIS));
1091                 textR.height = (int) v.getPreferredSpan(View.Y_AXIS);
1092             } else {
1093                 textR.width = SwingUtilities2.getTextUIDrawing(c)
1094                         .getStringWidth(c, fm, text);
1095                 lsb = SwingUtilities2.getLeftSideBearing(c, fm, text);
1096                 if (lsb < 0) {
1097                     // If lsb is negative, add it to the width and later
1098                     // adjust the x location. This gives more space than is
1099                     // actually needed.
1100                     // This is done like this for two reasons:
1101                     // 1. If we set the width to the actual bounds all
1102                     //    callers would have to account for negative lsb
1103                     //    (pref size calculations ONLY look at width of
1104                     //    textR)
1105                     // 2. You can do a drawString at the returned location
1106                     //    and the text won't be clipped.
1107                     textR.width -= lsb;
1108                 }
1109                 if (textR.width > availTextWidth) {
1110                     text = SwingUtilities2.clipString(c, fm, text,
1111                                                       availTextWidth);
1112                     textR.width = SwingUtilities2.getTextUIDrawing(c)
1113                             .getStringWidth(c, fm, text);
1114                 }
1115                 textR.height = fm.getHeight();
1116             }
1117         }
1118 
1119 
1120         /* Compute textR.x,y given the verticalTextPosition and
1121          * horizontalTextPosition properties
1122          */
1123 
1124         if (verticalTextPosition == TOP) {
1125             if (horizontalTextPosition != CENTER) {
1126                 textR.y = 0;
1127             }
1128             else {
1129                 textR.y = -(textR.height + gap);
1130             }
1131         }
1132         else if (verticalTextPosition == CENTER) {
1133             textR.y = (iconR.height / 2) - (textR.height / 2);


< prev index next >