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

80
LINES

< > BotCompany Repo | #1034484 // G22AnalysisPanel

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

Uses 2164K of libraries. Click here for Pure Java version (52167L/272K).

1  
sclass G22AnalysisPanel > MetaWithChangeListeners is Swingable, AutoCloseable {
2  
  // This is actually persistable
3  
  // TODO: use Ref pointer so it's cleaned when target is deleted
4  
  settableWithVar G22Analyzer analyzer;
5  
  
6  
  transient settable G22Utils g22utils;
7  
  
8  
  // where to show recognized boxes
9  
  transient settable ImageSurface imageSurface;
10  
  
11  
  transient SingleComponentPanel scp;
12  
  transient ReliableSingleThread rstStartAnalysis = new(r _startAnalysis);
13  
  
14  
  transient gettable BufferedImage image;
15  
  transient G22RunSingleAnalyzerPanel analyzerPanel;
16  
  
17  
  public void setImage(File image) {
18  
    setImage(loadImage2(image));
19  
  }
20  
  
21  
  // we may be getting the same instance again but it still means
22  
  // there was a change in the image
23  
  public void setImage(BufferedImage image) {
24  
    this.image = image;
25  
    analyzerPanel?.setImage(image);
26  
  }
27  
  
28  
  cachedVisualize {
29  
    scp = singleComponentPanel();
30  
    varAnalyzer().onChangeAndNow(rstStartAnalysis);
31  
    ret northAndCenterWithMargins(
32  
      centerAndEastWithMargin(
33  
        withLabel("Analyzer",
34  
          bindComboBoxToVar(varAnalyzer(),
35  
            swing(-> new ConceptsComboBox(g22utils.concepts(), G22Analyzer).allowNull(true))
36  
        )),
37  
        jline(
38  
          jimageButton(#1101440, "Re-run analyzer", l0 remakeAnalyzerPanel),
39  
          jimageButtonScaledToWidth(16, #1103068, "Edit analyzer", -> editAnalyzer(analyzer))
40  
        )
41  
      ),
42  
      scp
43  
    );
44  
  }
45  
  
46  
  void _startAnalysis {
47  
    var panel = optCast G22RunSingleAnalyzerPanel(analyzerPanel);
48  
    if (panel == null || panel.analyzer != analyzer) {
49  
      analyzerPanel = new G22RunSingleAnalyzerPanel(g22utils, image, analyzer);
50  
      if (imageSurface != null) {
51  
        analyzerPanel.onAnalyzerResult((analyzer, result) -> {
52  
          imageSurface.clearOverlays();
53  
          analyzerResultToOverlays(result);
54  
        });
55  
        analyzerPanel.onAnalyzerError((analyzer, error) ->
56  
          imageSurface.clearOverlays());
57  
      }
58  
      scp.set(analyzerPanel);
59  
    }
60  
  }
61  
  
62  
  void analyzerResultToOverlays(O result) {
63  
    if (result cast Rect) {
64  
      imageSurface.addOverlay(new RenderRecognizedBox(RectAsRecognizedBox(result)));
65  
    } else if (result cast IImageRegion) {
66  
      imageSurface.addOverlay(new RenderRecognizedBox/*Region*/(RecognizedRegion(result)));
67  
    }
68  
  }
69  
  
70  
  void remakeAnalyzerPanel {
71  
    analyzerPanel = null;
72  
    thread {
73  
      _startAnalysis();
74  
    }
75  
  }
76  
  
77  
  close {}
78  
  
79  
  swappable void editAnalyzer(G22Analyzer analyzer) {}
80  
}

Author comment

Began life as a copy of #1034472

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1034484
Snippet name: G22AnalysisPanel
Eternal ID of this version: #1034484/31
Text MD5: f0d67301ed9df43f1b10fb043e2fbf5d
Transpilation MD5: 5a61d26f686833acbd6717e988791df7
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-28 21:47:40
Source code size: 2567 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 263 / 498
Version history: 30 change(s)
Referenced in: [show references]