110 tipText = ""; 111 } 112 113 String accelString = getAcceleratorString(tip); 114 FontMetrics accelMetrics = SwingUtilities2.getFontMetrics(c, g, smallFont); 115 int accelSpacing = calcAccelSpacing(c, accelMetrics, accelString); 116 117 Insets insets = tip.getInsets(); 118 Rectangle paintTextR = new Rectangle( 119 insets.left + 3, 120 insets.top, 121 size.width - (insets.left + insets.right) - 6 - accelSpacing, 122 size.height - (insets.top + insets.bottom)); 123 View v = (View) c.getClientProperty(BasicHTML.propertyKey); 124 if (v != null) { 125 v.paint(g, paintTextR); 126 accelBL = BasicHTML.getHTMLBaseline(v, paintTextR.width, 127 paintTextR.height); 128 } else { 129 g.setFont(font); 130 SwingUtilities2.drawString(tip, g, tipText, paintTextR.x, 131 paintTextR.y + metrics.getAscent()); 132 accelBL = metrics.getAscent(); 133 } 134 135 if (!accelString.equals("")) { 136 g.setFont(smallFont); 137 g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); 138 SwingUtilities2.drawString(tip, g, accelString, 139 tip.getWidth() - 1 - insets.right 140 - accelSpacing 141 + padSpaceBetweenStrings 142 - 3, 143 paintTextR.y + accelBL); 144 } 145 } 146 147 private int calcAccelSpacing(JComponent c, FontMetrics fm, String accel) { 148 return accel.equals("") 149 ? 0 150 : padSpaceBetweenStrings + 151 SwingUtilities2.stringWidth(c, fm, accel); 152 } 153 154 public Dimension getPreferredSize(JComponent c) { 155 Dimension d = super.getPreferredSize(c); 156 157 String key = getAcceleratorString((JToolTip)c); 158 if (!(key.equals(""))) { 159 d.width += calcAccelSpacing(c, c.getFontMetrics(smallFont), key); 160 } 161 return d; 162 } 163 164 /** 165 * If the accelerator is hidden, the method returns {@code true}, 166 * otherwise, returns {@code false}. 167 * 168 * @return {@code true} if the accelerator is hidden. 169 */ 170 protected boolean isAcceleratorHidden() { 171 Boolean b = (Boolean)UIManager.get("ToolTip.hideAccelerator"); | 110 tipText = ""; 111 } 112 113 String accelString = getAcceleratorString(tip); 114 FontMetrics accelMetrics = SwingUtilities2.getFontMetrics(c, g, smallFont); 115 int accelSpacing = calcAccelSpacing(c, accelMetrics, accelString); 116 117 Insets insets = tip.getInsets(); 118 Rectangle paintTextR = new Rectangle( 119 insets.left + 3, 120 insets.top, 121 size.width - (insets.left + insets.right) - 6 - accelSpacing, 122 size.height - (insets.top + insets.bottom)); 123 View v = (View) c.getClientProperty(BasicHTML.propertyKey); 124 if (v != null) { 125 v.paint(g, paintTextR); 126 accelBL = BasicHTML.getHTMLBaseline(v, paintTextR.width, 127 paintTextR.height); 128 } else { 129 g.setFont(font); 130 getTextUIDrawing().drawString(tip, g, tipText, paintTextR.x, 131 paintTextR.y + metrics.getAscent()); 132 accelBL = metrics.getAscent(); 133 } 134 135 if (!accelString.equals("")) { 136 g.setFont(smallFont); 137 g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); 138 getTextUIDrawing().drawString(tip, g, accelString, 139 tip.getWidth() - 1 - insets.right 140 - accelSpacing 141 + padSpaceBetweenStrings 142 - 3, 143 paintTextR.y + accelBL); 144 } 145 } 146 147 private int calcAccelSpacing(JComponent c, FontMetrics fm, String accel) { 148 return accel.equals("") 149 ? 0 150 : padSpaceBetweenStrings + 151 getTextUIDrawing().getStringWidth(c, fm, accel); 152 } 153 154 public Dimension getPreferredSize(JComponent c) { 155 Dimension d = super.getPreferredSize(c); 156 157 String key = getAcceleratorString((JToolTip)c); 158 if (!(key.equals(""))) { 159 d.width += calcAccelSpacing(c, c.getFontMetrics(smallFont), key); 160 } 161 return d; 162 } 163 164 /** 165 * If the accelerator is hidden, the method returns {@code true}, 166 * otherwise, returns {@code false}. 167 * 168 * @return {@code true} if the accelerator is hidden. 169 */ 170 protected boolean isAcceleratorHidden() { 171 Boolean b = (Boolean)UIManager.get("ToolTip.hideAccelerator"); |