-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/armameeldoparti/utils/common/custom/graphical/ui/CustomToolTipUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package armameeldoparti.utils.common.custom.graphical.ui; | ||
|
||
import java.awt.AlphaComposite; | ||
import java.awt.Color; | ||
import java.awt.Dimension; | ||
import java.awt.FontMetrics; | ||
import java.awt.Graphics; | ||
import java.awt.Graphics2D; | ||
import java.awt.geom.RoundRectangle2D; | ||
import javax.swing.JComponent; | ||
import javax.swing.JToolTip; | ||
import javax.swing.plaf.ToolTipUI; | ||
|
||
import armameeldoparti.utils.common.Constants; | ||
|
||
public class CustomToolTipUI extends ToolTipUI { | ||
|
||
// ---------- Public methods --------------------------------------------------------------------------------------------------------------------- | ||
|
||
@Override | ||
public void paint(Graphics g, JComponent c) { | ||
Graphics2D g2 = (Graphics2D) g.create(); | ||
|
||
RoundRectangle2D roundedRect = new RoundRectangle2D.Float(0, 0, c.getWidth(), c.getHeight(), | ||
Constants.ROUNDED_BORDER_ARC_TOOLTIP, | ||
Constants.ROUNDED_BORDER_ARC_TOOLTIP); | ||
|
||
// Round rectangle configuration | ||
g2.setRenderingHints(Constants.MAP_RENDERING_HINTS); | ||
g2.setComposite(AlphaComposite.Clear); | ||
g2.fill(roundedRect); | ||
|
||
// Background painting | ||
g2.setComposite(AlphaComposite.Src); | ||
g2.setColor(Constants.COLOR_GREEN_DARK_MEDIUM); | ||
g2.fill(roundedRect); | ||
|
||
// Text painting | ||
FontMetrics fm = g2.getFontMetrics(); | ||
|
||
String text = ((JToolTip) c).getTipText(); | ||
|
||
g2.setColor(Color.WHITE); | ||
g2.drawString(text, (c.getWidth() - fm.stringWidth(text)) / 2, (c.getHeight() - fm.getHeight()) / 2 + fm.getAscent()); | ||
g2.dispose(); | ||
} | ||
|
||
@Override | ||
public Dimension getPreferredSize(JComponent c) { | ||
FontMetrics fm = c.getFontMetrics(c.getFont()); | ||
|
||
return new Dimension(fm.stringWidth(((JToolTip) c).getTipText()) + c.getInsets().left + c.getInsets().right, | ||
fm.getHeight() + c.getInsets().top + c.getInsets().bottom); | ||
} | ||
} |