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

49
LINES

< > BotCompany Repo | #1001425 // ShowBigText class

JavaX fragment (include)

static class ShowBigText {
  S fontID = "#1000993";  // Brother Deluxe Font
  Color background = Color.white;
  Color foreground = Color.black;
  S text = "test";
  ImageSurface is;
  Font font;
  S title = "JavaX";

  // thread-safe
  void showText(final S text) {
    swing {
      ShowBigText.this.text = text;
      if (is == null) {
        font = loadFont(fontID);
        
        BufferedImage img = makeImage();
        is = showImage_centered(img, title);
        moveToTopRightCorner(getFrame(is));
      }
  
      getFrame(is).setTitle(title);
      is.setImage(makeImage());
    }
  }

  BufferedImage makeImage() {  
    // TODO: dispose old image?
    BufferedImage img = new BufferedImage(200, 60, BufferedImage.TYPE_INT_RGB);
    
    Graphics g = img.getGraphics();
    int w = img.getWidth(), h = img.getHeight();
    g.setColor(background);
    g.fillRect(0, 0, w, h);
    g.setColor(foreground);
    g.setFont(font.deriveFont(30f));
    FontMetrics fm = g.getFontMetrics();
    int y = fm.getAscent() + (h-fm.getHeight())/2;
    int x = (w-fm.stringWidth(text))/2;
    g.drawString(text, x, y);
    g.dispose();
    
    return img;
  }
  
  void setToolTip(S text) {
    if (is != null) is.setToolTipText(text);
  }
}

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: 728 / 2836
Version history: 4 change(s)
Referenced in: #1001426 - Test ShowBigText
#1001441 - Jumping Heart (jumps between two machines) with window
#1001464 - OS Sensor
#1001468 - OS Sensor 2: OS Sensor with Memory
#1001492 - Self-moving OS Sensor
#1001652 - Remote Bots Up?
#1001655 - Central Server Up?
#1001669 - File size watcher (big text)
#1003872 - Integrating #759 in One Program
#1003874 - Backup of #759 Before Integration
#1004091 - 759 with new loadClasses (spike)
#1004566 - renderText - renders text line from loaded font (e.g. TTF)
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)
#3000189 - Answer for stefanreich(>> t bla)
#3000190 - Answer for stefanreich(>> t 20 questions)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)