156 return formattedText; 157 } 158 return SwingUtilities.layoutCompoundLabel( 159 ss.getComponent(), fm, text, icon, vAlign, hAlign, 160 vTextPosition, hTextPosition, viewR, iconR, textR, 161 iconTextGap); 162 } 163 164 /** 165 * Returns the size of the passed in string. 166 * 167 * @param ss SynthContext 168 * @param font Font to use 169 * @param metrics FontMetrics, may be ignored 170 * @param text Text to get size of. 171 * 172 * @return the size of the passed in string. 173 */ 174 public int computeStringWidth(SynthContext ss, Font font, 175 FontMetrics metrics, String text) { 176 return SwingUtilities2.stringWidth(ss.getComponent(), metrics, 177 text); 178 } 179 180 /** 181 * Returns the minimum size needed to properly render an icon and text. 182 * 183 * @param ss SynthContext 184 * @param font Font to use 185 * @param text Text to layout 186 * @param icon Icon to layout 187 * @param hAlign horizontal alignment 188 * @param vAlign vertical alignment 189 * @param hTextPosition horizontal text position 190 * @param vTextPosition vertical text position 191 * @param iconTextGap gap between icon and text 192 * @param mnemonicIndex Index into text to render the mnemonic at, -1 193 * indicates no mnemonic. 194 * 195 * @return the minimum size needed to properly render an icon and text. 196 */ 197 public Dimension getMinimumSize(SynthContext ss, Font font, String text, 330 } 331 332 /** 333 * Paints text at the specified location. This will not attempt to 334 * render the text as html nor will it offset by the insets of the 335 * component. 336 * 337 * @param ss SynthContext 338 * @param g Graphics used to render string in. 339 * @param text Text to render 340 * @param x X location to draw text at. 341 * @param y Upper left corner to draw text at. 342 * @param mnemonicIndex Index to draw string at. 343 */ 344 public void paintText(SynthContext ss, Graphics g, String text, 345 int x, int y, int mnemonicIndex) { 346 if (text != null) { 347 JComponent c = ss.getComponent(); 348 FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); 349 y += fm.getAscent(); 350 SwingUtilities2.drawStringUnderlineCharAt(c, g, text, 351 mnemonicIndex, x, y); 352 } 353 } 354 355 /** 356 * Paints an icon and text. This will render the text as html, if 357 * necessary, and offset the location by the insets of the component. 358 * 359 * @param ss SynthContext 360 * @param g Graphics to render string and icon into 361 * @param text Text to layout 362 * @param icon Icon to layout 363 * @param hAlign horizontal alignment 364 * @param vAlign vertical alignment 365 * @param hTextPosition horizontal text position 366 * @param vTextPosition vertical text position 367 * @param iconTextGap gap between icon and text 368 * @param mnemonicIndex Index into text to render the mnemonic at, -1 369 * indicates no mnemonic. 370 * @param textOffset Amount to offset the text when painting 371 */ | 156 return formattedText; 157 } 158 return SwingUtilities.layoutCompoundLabel( 159 ss.getComponent(), fm, text, icon, vAlign, hAlign, 160 vTextPosition, hTextPosition, viewR, iconR, textR, 161 iconTextGap); 162 } 163 164 /** 165 * Returns the size of the passed in string. 166 * 167 * @param ss SynthContext 168 * @param font Font to use 169 * @param metrics FontMetrics, may be ignored 170 * @param text Text to get size of. 171 * 172 * @return the size of the passed in string. 173 */ 174 public int computeStringWidth(SynthContext ss, Font font, 175 FontMetrics metrics, String text) { 176 JComponent comp = ss.getComponent(); 177 return SwingUtilities2.getTextUIDrawing(comp) 178 .getStringWidth(comp, metrics, text); 179 } 180 181 /** 182 * Returns the minimum size needed to properly render an icon and text. 183 * 184 * @param ss SynthContext 185 * @param font Font to use 186 * @param text Text to layout 187 * @param icon Icon to layout 188 * @param hAlign horizontal alignment 189 * @param vAlign vertical alignment 190 * @param hTextPosition horizontal text position 191 * @param vTextPosition vertical text position 192 * @param iconTextGap gap between icon and text 193 * @param mnemonicIndex Index into text to render the mnemonic at, -1 194 * indicates no mnemonic. 195 * 196 * @return the minimum size needed to properly render an icon and text. 197 */ 198 public Dimension getMinimumSize(SynthContext ss, Font font, String text, 331 } 332 333 /** 334 * Paints text at the specified location. This will not attempt to 335 * render the text as html nor will it offset by the insets of the 336 * component. 337 * 338 * @param ss SynthContext 339 * @param g Graphics used to render string in. 340 * @param text Text to render 341 * @param x X location to draw text at. 342 * @param y Upper left corner to draw text at. 343 * @param mnemonicIndex Index to draw string at. 344 */ 345 public void paintText(SynthContext ss, Graphics g, String text, 346 int x, int y, int mnemonicIndex) { 347 if (text != null) { 348 JComponent c = ss.getComponent(); 349 FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); 350 y += fm.getAscent(); 351 SwingUtilities2.getTextUIDrawing(c) 352 .drawStringUnderlineCharAt(c, g, text, mnemonicIndex, x, y); 353 } 354 } 355 356 /** 357 * Paints an icon and text. This will render the text as html, if 358 * necessary, and offset the location by the insets of the component. 359 * 360 * @param ss SynthContext 361 * @param g Graphics to render string and icon into 362 * @param text Text to layout 363 * @param icon Icon to layout 364 * @param hAlign horizontal alignment 365 * @param vAlign vertical alignment 366 * @param hTextPosition horizontal text position 367 * @param vTextPosition vertical text position 368 * @param iconTextGap gap between icon and text 369 * @param mnemonicIndex Index into text to render the mnemonic at, -1 370 * indicates no mnemonic. 371 * @param textOffset Amount to offset the text when painting 372 */ |