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

46
LINES

< > BotCompany Repo | #1034207 // JFilePathLabel - JLabel showing file path and allowing to open in file exporer

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (13444L) is out of date.

1  
srecord noeq JFilePathLabel(File file) is Swingable {
2  
  transient JLabel label;
3  
  transient JFilePathButton button;
4  
  transient JPanel buttons = jline();
5  
  bool nameOnly;
6  
  settable bool iconOnTheLeft;
7  
  settable bool minWidth; // allow file path to be shortened if layout requires it
8  
  
9  
  cachedVisualize {
10  
    label = jlabel();
11  
    if (minWidth) jnarrowLabel(label);
12  
    makeButtons();
13  
    update();
14  
    ret layout();
15  
  }
16  
  
17  
  void makeButtons {
18  
    button = new JFilePathButton(file);
19  
    buttons.add(button.visualize());
20  
  }
21  
  
22  
  void setFile(File file) {
23  
    this.file = file;
24  
    update();
25  
  }
26  
  
27  
  File file aka get() { ret file; }
28  
29  
  void update {  
30  
    setText(label, file == null ? "-" : nameOnly ? fileName(file) : f2s(file));
31  
    if (nameOnly) toolTip(file == null ? "No file" : f2s(file), label);
32  
    button.setFile(file);
33  
  }
34  
  
35  
  JComponent layout() {
36  
    var a = buttons;
37  
    var b = label;
38  
    ret iconOnTheLeft
39  
      ? minWidth ? westAndCenterWithMargin(a, b) : jline(a, b)
40  
      : minWidth ? centerAndEastWithMargin(b, a) : jline(b, a);
41  
  }
42  
    
43  
  void showInExplorer { button.showInExplorer(); }
44  
  
45  
  selfType nameOnly() { set nameOnly; this; }
46  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034207
Snippet name: JFilePathLabel - JLabel showing file path and allowing to open in file exporer
Eternal ID of this version: #1034207/24
Text MD5: b42a46299c6aa15b2e73747f30161045
Author: stefan
Category: javax / screen recognition
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-01 22:16:27
Source code size: 1211 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 149 / 354
Version history: 23 change(s)
Referenced in: [show references]