Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

49
LINES

< > BotCompany Repo | #1001425 // ShowBigText class

JavaX fragment (include)

1  
static class ShowBigText {
2  
  S fontID = "#1000993";  // Brother Deluxe Font
3  
  Color background = Color.white;
4  
  Color foreground = Color.black;
5  
  S text = "test";
6  
  ImageSurface is;
7  
  Font font;
8  
  S title = "JavaX";
9  
10  
  // thread-safe
11  
  void showText(final S text) {
12  
    swing {
13  
      ShowBigText.this.text = text;
14  
      if (is == null) {
15  
        font = loadFont(fontID);
16  
        
17  
        BufferedImage img = makeImage();
18  
        is = showImage_centered(img, title);
19  
        moveToTopRightCorner(getFrame(is));
20  
      }
21  
  
22  
      getFrame(is).setTitle(title);
23  
      is.setImage(makeImage());
24  
    }
25  
  }
26  
27  
  BufferedImage makeImage() {  
28  
    // TODO: dispose old image?
29  
    BufferedImage img = new BufferedImage(200, 60, BufferedImage.TYPE_INT_RGB);
30  
    
31  
    Graphics g = img.getGraphics();
32  
    int w = img.getWidth(), h = img.getHeight();
33  
    g.setColor(background);
34  
    g.fillRect(0, 0, w, h);
35  
    g.setColor(foreground);
36  
    g.setFont(font.deriveFont(30f));
37  
    FontMetrics fm = g.getFontMetrics();
38  
    int y = fm.getAscent() + (h-fm.getHeight())/2;
39  
    int x = (w-fm.stringWidth(text))/2;
40  
    g.drawString(text, x, y);
41  
    g.dispose();
42  
    
43  
    return img;
44  
  }
45  
  
46  
  void setToolTip(S text) {
47  
    if (is != null) is.setToolTipText(text);
48  
  }
49  
}

Author comment

Began life as a copy of #1001424

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001425
Snippet name: ShowBigText class
Eternal ID of this version: #1001425/5
Text MD5: 511d19266f0918d247b7dac5d9110ae6
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-13 16:09:51
Source code size: 1288 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 671 / 2774
Version history: 4 change(s)
Referenced in: [show references]