// create and show, with some data present public void testShow() throws Exception { StatusFrame f = new StatusFrame(); f.initComponents(); f.setVisible(true); f.setSource( new DataSource() { void sendBytes(byte[] bytes) {} }); f.asciiFormattedMessage(PocketTesterTest.version); f.asciiFormattedMessage(PocketTesterTest.speed0003A); f.asciiFormattedMessage(PocketTesterTest.idlePacket); f.asciiFormattedMessage(PocketTesterTest.status1); f.asciiFormattedMessage(PocketTesterTest.status2); f.asciiFormattedMessage(PocketTesterTest.status3); f.asciiFormattedMessage(PocketTesterTest.status4); f.asciiFormattedMessage(PocketTesterTest.status5); f.dispose(); }
public GuiWithWatch() { watchFolder = prefs.get("WatchFolder", System.getProperty("user.home")); outputFolder = prefs.get("OutputFolder", System.getProperty("user.home")); watchEnabled = prefs.getBoolean("WatchEnabled", false); statusFrame = new StatusFrame(); statusFrame.setTitle(bundle.getString("statusFrame.Title")); // watch for new image files final Queue<File> queue = new LinkedList<File>(); watcher = new Watcher(queue, new File(watchFolder)); watcher.setEnabled(watchEnabled); Thread t = new Thread(watcher); t.start(); // autoOCR if there are files in the queue Action autoOcrAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final File imageFile = queue.poll(); if (imageFile != null) { if (!statusFrame.isVisible()) { statusFrame.setVisible(true); } statusFrame.getTextArea().append(imageFile.getPath() + "\n"); final ArrayList<IIOImage> iioImageList = ImageIOHelper.getIIOImageList(imageFile); if (iioImageList == null) { statusFrame .getTextArea() .append( " ** " + bundle.getString("Cannotprocess") + " " + imageFile.getName() + " **\n"); return; } if (curLangCode == null) { statusFrame .getTextArea() .append(" ** " + bundle.getString("Please_select_a_language.") + " **\n"); // queue.clear(); return; } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { try { OCR ocrEngine = new OCR(tessPath); String result = ocrEngine.recognizeText(iioImageList, -1, curLangCode); // postprocess to correct common OCR errors result = Processor.postProcess(result, curLangCode); BufferedWriter out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( new File(outputFolder, imageFile.getName() + ".txt")), UTF8)); out.write(result); out.close(); } catch (Exception e) { statusFrame .getTextArea() .append( " ** " + bundle.getString("Cannotprocess") + " " + imageFile.getName() + " **\n"); e.printStackTrace(); } } }); } } }; new Timer(5000, autoOcrAction).start(); }