@Nullable private LookupFile getClosestParent(final String typed) { if (typed == null) return null; LookupFile lastFound = myFinder.find(typed); if (lastFound == null) return null; if (lastFound.exists()) { if (typed.charAt(typed.length() - 1) != File.separatorChar) return lastFound.getParent(); return lastFound; } final String[] splits = myFinder.normalize(typed).split(myFileSpitRegExp); StringBuilder fullPath = new StringBuilder(); for (int i = 0; i < splits.length; i++) { String each = splits[i]; fullPath.append(each); if (i < splits.length - 1) { fullPath.append(myFinder.getSeparator()); } final LookupFile file = myFinder.find(fullPath.toString()); if (file == null || !file.exists()) return lastFound; lastFound = file; } return lastFound; }
private void addMacroPaths(final CompletionResult result, final String typedText) { result.myMacros = new ArrayList<LookupFile>(); final Iterator<String> macros = myMacroMap.keySet().iterator(); while (macros.hasNext()) { String eachMacro = macros.next(); if (eachMacro.toUpperCase().startsWith(typedText.toUpperCase())) { final String eachPath = myMacroMap.get(eachMacro); if (eachPath != null) { final LookupFile macroFile = myFinder.find(eachPath); if (macroFile != null && macroFile.exists()) { result.myMacros.add(macroFile); result.myToComplete.add(macroFile); macroFile.setMacro(eachMacro); } } } } }
@Nullable public LookupFile getFile() { String text = getTextFieldText(); if (text == null) return null; return myFinder.find(text); }
private void checkPatterns(ScreenImage simg) { Finder finder = null; if (Settings.UseImageFinder) { finder = new ImageFinder(_region); ((ImageFinder) finder).setIsMultiFinder(); } else { finder = new Finder(simg, _region); } String imgOK; Debug.log( 3, "observe: checkPatterns entry: sthgLeft: %s isObserving: %s", sthgLeft, _region.isObserving()); for (Object ptn : _state.keySet()) { if (_state.get(ptn) != State.FIRST && _state.get(ptn) != State.UNKNOWN && _state.get(ptn) != State.REPEAT) { continue; } imgOK = null; if (ptn instanceof String) { imgOK = finder.find((String) ptn); Image img = Image.create((String) ptn); if (img.isValid()) { imgOK = finder.find(img); } else if (img.isText()) { imgOK = finder.findText((String) ptn); } } else if (ptn instanceof Pattern) { imgOK = finder.find((Pattern) ptn); } else if (ptn instanceof Image) { imgOK = finder.find((Image) ptn); } if (null == imgOK) { Debug.error("EventMgr: checkPatterns: Image not valid", ptn); _state.put(ptn, State.MISSING); continue; } if (_state.get(ptn) == State.REPEAT) { Debug.log(3, "repeat: checking"); if (_lastMatch.get(ptn).exists(ptn) != null) { if ((new Date()).getTime() > _wait.get(ptn)) { _state.put(ptn, State.APPEARED); Debug.log(3, "repeat: vanish timeout"); // time out } else { sthgLeft = true; } continue; // not vanished within given time or still there } else { _state.put(ptn, State.UNKNOWN); sthgLeft = true; Debug.log(3, "repeat: has vanished"); continue; // has vanished, repeat } } Match m = null; boolean hasMatch = false; if (finder.hasNext()) { m = finder.next(); if (m.getScore() >= getSimiliarity(ptn)) { hasMatch = true; _lastMatch.put(ptn, m); } } if (hasMatch) { Debug.log( 2, "EventMgr: checkPatterns: " + ptn.toString() + " match: " + m.toStringShort() + " in " + _region.toStringShort()); } else if (_state.get(ptn) == State.FIRST) { Debug.log( 2, "EventMgr: checkPatterns: " + ptn.toString() + " match: " + "NO" + " in " + _region.toStringShort()); _state.put(ptn, State.UNKNOWN); } if (_appearOb.containsKey(ptn)) { if (_state.get(ptn) != State.APPEARED) { if (hasMatch) { _state.put(ptn, State.APPEARED); _count.put(ptn, _count.get(ptn) + 1); callAppearObserver(ptn, m); } else { sthgLeft = true; } } } else if (_vanishOb.containsKey(ptn)) { if (_state.get(ptn) != State.VANISHED) { if (!hasMatch) { _state.put(ptn, State.VANISHED); _count.put(ptn, _count.get(ptn) + 1); callVanishObserver(ptn, _lastMatch.get(ptn)); } else { sthgLeft = true; } } } if (!_region.isObserving()) { break; } } Debug.log( 3, "observe: checkPatterns exit: sthgLeft: %s isObserving: %s", sthgLeft, _region.isObserving()); }