org.jdesktop.swingx.util.OS Java Examples

The following examples show how to use org.jdesktop.swingx.util.OS. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginSettingsConfigurable.java    From IDEA-Native-Terminal-Plugin with MIT License 6 votes vote down vote up
public PluginSettingsConfigurable() {
    // Set 'chooseFolders' depend on OS, because macOS application represents a directory.
    terminalChooserDescriptor = new FileChooserDescriptor(true, OS.isMacOSX(), false, false, false, false);

    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    if (openProjects.length > 0) {
        project = openProjects[0];
    } else {
        project = ProjectManager.getInstance().getDefaultProject();
    }
    pluginSettingsForm = new PluginSettingsForm();
    pluginSettings = PluginSettings.getInstance();

    // FileChooserDialog support  -longforus
    String favoriteTerminal = "";
    if (pluginSettings.getState() != null) {
        favoriteTerminal = pluginSettings.getState().getFavoriteTerminal();
    }
    if (!TextUtils.isEmpty(favoriteTerminal)) {
        selectedTerminal = VirtualFileManager.getInstance().findFileByUrl(getFileUrl(favoriteTerminal));
    }

    pluginSettingsForm.getTerminalFileChooserButton().addActionListener(e -> {
        VirtualFile[] chosenTerminals = new FileChooserDialogImpl(terminalChooserDescriptor, project)
                .choose(project, selectedTerminal);

        if (chosenTerminals.length > 0) {
            VirtualFile file = chosenTerminals[0];
            if (file != null) {
                String canonicalPath = file.getCanonicalPath();
                Terminal terminal = Terminal.fromString(canonicalPath);
                if (terminal == Terminal.GENERIC) {
                    Messages.showWarningDialog(warningMessage, "Warning");
                }
                selectedTerminal = file;
                pluginSettingsForm.getFavoriteTerminalField().setText(canonicalPath);
            }
        }
    });
}
 
Example #2
Source File: OCR.java    From JewelCrawler with GNU General Public License v3.0 4 votes vote down vote up
public String recognizeText(File imageFile, String imageFormat)
		throws Exception {
	File tempImage = ImageIOHelper.createImage(imageFile, imageFormat);
	File outputFile = new File(imageFile.getParentFile(), "output");
	StringBuffer strB = new StringBuffer();
	List<String> cmd = new ArrayList<String>();
	if (OS.isWindowsXP()) {
		cmd.add(tessPath + "\\tesseract");
		// cmd.add(tessPath + "\\Tesseract-OCR");
	} else if (OS.isLinux()) {
		cmd.add("tesseract");
	} else {
		// cmd.add(tessPath + "\\Tesseract-OCR");
		cmd.add(tessPath + "\\tesseract");
	}
	cmd.add("");
	cmd.add(outputFile.getName());
	cmd.add(LANG_OPTION);
	// cmd.add("chi_sim");
	cmd.add("eng");

	ProcessBuilder pb = new ProcessBuilder();
	pb.directory(imageFile.getParentFile());

	cmd.set(1, tempImage.getName());
	System.out
			.println(Arrays.toString(cmd.toArray(new String[cmd.size()])));
	pb.command(cmd);
	pb.redirectErrorStream(true);
	Process process = pb.start();
	// tesseract.exe 1.jpg 1 -l chi_sim
	int w = process.waitFor();

	// delete temp working files
	tempImage.delete();
	System.out.println(w);
	if (w == 0) {
		BufferedReader in = new BufferedReader(new InputStreamReader(
				new FileInputStream(outputFile.getAbsolutePath() + ".txt"),
				"UTF-8"));

		String str;

		while ((str = in.readLine()) != null) {
			strB.append(str).append(EOL);
		}
		in.close();
	} else {
		String msg;
		switch (w) {
		case 1:
			msg = "Errors accessing files. There may be spaces in your image's filename.";
			break;
		case 29:
			msg = "Cannot recognize the image or its selected region.";
			break;
		case 31:
			msg = "Unsupported image format.";
			break;
		default:
			msg = "Errors occurred.";
		}
		tempImage.delete();
		throw new RuntimeException(msg);
	}
	new File(outputFile.getAbsolutePath() + ".txt").delete();
	return strB.toString();
}