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

34
LINES

< > BotCompany Repo | #1019643 // Font Plus/Minus (enlarge/shrink font size of components by clicking on them)

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (14734L/102K).

!7

module FontPlusMinus > DynPrintLog {
  transient volatile bool active, enlarging;
  double scale = 1.25;

  visualize {
    ret centerAndSouthWithMargins(super.visualize(), jhgrid(
      jbutton("Font +", r { doIt(true) }),
      jbutton("Font -", r { doIt(false) })));
  }
  
  start {
    dm_requireMouseLogger();
    ownResource(vmBus_onMessage('mouseDown, voidfunc(int x, int y, int button) {
      if (!active) ret;
      active = false;
      final JComponent c = optCast(JComponent, componentAtScreenLocation(x, y));
      print("Have component: " + c);
      if (c == null) ret;
      swing {
        Font font = scaleFont(c.getFont(), enlarging ? scale : 1/scale);
        c.setFont(font);
        print((enlarging ? "Enlarged" : "Shrunk") + " font to " + formatDouble(font.getSize2D(), 1));
      }
    }));
  }
  
  void doIt(bool enlarge) {
    enlarging = enlarge;
    print("Please click on a component to " + (enlarge ? "enlarge" : "shrink") + " its font");
    set active;
  }
}

Author comment

Began life as a copy of #1019642

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

-
Snippet ID: #1019643
Snippet name: Font Plus/Minus (enlarge/shrink font size of components by clicking on them)
Eternal ID of this version: #1019643/6
Text MD5: 798d7478d374ee17e8372956cb10aa43
Transpilation MD5: a9c29ae4df3e89ef886457d0de7e6b5c
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-17 00:51:27
Source code size: 1031 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 320 / 6675
Version history: 5 change(s)
Referenced in: