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

75
LINES

< > BotCompany Repo | #1006232 // Record browser's URL box

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (9072L/63K/212K).

1  
!7
2  
3  
static int sleepTimeWhenNotFound = 5000;
4  
5  
static JFrame frame;
6  
static ImageSurface imageSurface;
7  
static FindURLBox1 finder;
8  
9  
static BoxShot shot;
10  
static TimeRange timeRange;
11  
12  
concept BoxShot {
13  
  S imageMD5;
14  
  byte[] png;
15  
  new RefL<TimeRange> timeRanges;
16  
}
17  
18  
concept TimeRange {
19  
  long from, to;
20  
  
21  
  *() {}
22  
  *(long *from) { to = from; }
23  
  
24  
  void addNow() {
25  
    cset(this, to := max(to, now()));
26  
  }
27  
}
28  
29  
p {
30  
  conceptsAndBot(60*1000);
31  
  
32  
  awt {
33  
    finder = new FindURLBox1;
34  
    frame = showFrame("Find URL Box", jcenteredLabel("-"));
35  
    frameInnerSize(frame, 500, 70);
36  
    moveToBottomRightCorner(frame);
37  
    frame.setAlwaysOnTop(true);
38  
    
39  
    awtCalcRegularly(frame, 200, 0, r {
40  
      final bool b = finder.go();
41  
      awt {
42  
        if (b) {
43  
          RGBImage img = finder.bestImage();
44  
          S since = "";
45  
          if (shot != null && timeRange != null)
46  
            since = ", since " + (now()-timeRange.from)/1000 + "s, " + nth(l(shot.timeRanges)) + " appearance)";
47  
          S text = "URL box found in " + finder.recogTime + " ms (" + img.w() + "*" + img.h() + " px" + since + ")";
48  
          if (imageSurface == null) {
49  
            imageSurface = new ImageSurface(img);
50  
            setFrameContents(frame, jSection(text, new JScrollPane(imageSurface)));
51  
          } else {
52  
            imageSurface.setImage(img);
53  
            setSectionTitle(imageSurface, text);
54  
          }
55  
          
56  
          S imageMD5 = md5OfRGBImage(img);
57  
          shot = uniq(BoxShot, +imageMD5);
58  
          if (shot.png == null) shot.png = rgbImageToPNG(img);
59  
          if (shot.timeRanges.contains(timeRange))
60  
            timeRange.addNow();
61  
          else
62  
            shot.timeRanges.add(timeRange = new TimeRange(now()));
63  
          shot.change();
64  
        } else {
65  
          timeRange = null;
66  
          if (imageSurface != null) {
67  
            imageSurface = null;
68  
            setFrameContents(frame, jcenteredLabel("URL box not found (" + finder.recogTime + " ms)"));
69  
          }
70  
        }
71  
      }
72  
      if (!b) sleep(sleepTimeWhenNotFound);
73  
    });
74  
  }
75  
}

Author comment

Began life as a copy of #1006217

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006232
Snippet name: Record browser's URL box
Eternal ID of this version: #1006232/1
Text MD5: f3bc68d421ba4d09b569e4faa13daa04
Transpilation MD5: b65aa2f0dbeb55eb063eddbae0759e90
Author: stefan
Category: javax / ocr
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-25 20:26:33
Source code size: 2123 bytes / 75 lines
Pitched / IR pitched: No / No
Views / Downloads: 644 / 776
Referenced in: [show references]