Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void setTooltip(Component cmp, String t) {
- cmp.putClientProperty("tooltip", t);
- }
- public static void showTooltip(Component cmp, Form f) {
- final String t = (String)cmp.getClientProperty("tooltip");
- if(t == null) {
- f.setGlassPane(null);
- } else {
- int offset = Display.getInstance().convertToPixels(2) + 10;
- final Font fnt = cmp.getUIManager().getComponentStyle("Label").getFont();
- int width = fnt.stringWidth(t);
- int height = fnt.getHeight();
- int x = cmp.getAbsoluteX();
- if(x > f.getWidth() / 2) {
- x -= (width + offset);
- } else {
- x += cmp.getWidth() + offset;
- }
- int y = cmp.getAbsoluteY();
- if(y > f.getHeight() / 2) {
- y -= (height + offset);
- } else {
- y += cmp.getHeight() + offset;
- }
- final Rectangle rect = new Rectangle(x, y, width + 10, height + 10);
- final Rectangle shadow = new Rectangle(x + 5, y + 5, width + 10, height + 10);
- final Stroke s = new Stroke(3, Stroke.CAP_ROUND, Stroke.JOIN_ROUND, 1);
- f.setGlassPane(new Painter() {
- @Override
- public void paint(Graphics g, Rectangle r) {
- g.setColor(0);
- g.setAlpha(120);
- g.fillShape(shadow);
- g.setAlpha(255);
- g.setColor(0xeeeeee);
- g.fillShape(rect);
- g.setColor(0);
- g.drawShape(rect, s);
- g.setColor(0);
- g.setFont(fnt);
- g.drawString(t, rect.getX() + 5, rect.getY() + 5);
- }
- });
- }
- }
- @Override
- public void pointerHover(int[] x, int[] y) {
- Component c = getComponentAt(x[0], y[0]);
- if(c != null) {
- GuiBuilderUtils.showTooltip(c, this);
- }
- }
Add Comment
Please, Sign In to add comment