
com.asprise.ocr.sample.DemoUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-ocr-api Show documentation
Show all versions of java-ocr-api Show documentation
A Java OCR SDK Library API allows you to perform OCR and bar code recognition on images (JPEG, PNG, TIFF, PDF, etc.) and output as plain text, xml with full coordinate, searchable PDF or editable RTF.
/**********************************************************************************************
*
* Asprise OCR Java API
* Copyright (C) 1998-2015. Asprise Inc.
*
* This file is licensed under the GNU Affero General Public License version 3 as published by
* the Free Software Foundation.
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*
* You should have received a copy of the GNU Affero General Public License. If not, please
* visit .
*
**********************************************************************************************/
package com.asprise.ocr.sample;
import com.asprise.ocr.sample.util.prefs.FileSystemPreferencesFactory;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JPopupMenu;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.JTextComponent;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.prefs.Preferences;
public class DemoUtils {
static final String DELIMITER = "`";
public static void setPreferencesWithXmlBackstoreOnWindows() {
if(isWindows()) {
System.setProperty("java.util.prefs.PreferencesFactory", FileSystemPreferencesFactory.class.getName());
}
}
public static void loadPrefs(Preferences prefs, String prefKey, JComboBox combo) {
DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
String recents = prefs.get(prefKey, null);
if (recents != null) {
StringTokenizer st = new StringTokenizer(recents, DELIMITER);
while (st.hasMoreTokens()) {
comboModel.addElement(st.nextToken());
}
}
combo.setModel(comboModel);
}
public static void savePrefs(Preferences prefs, String prefKey, JComboBox combo, String newValidValue) {
if (newValidValue == null) {
return;
}
DefaultComboBoxModel comboModel = (DefaultComboBoxModel) combo.getModel();
int existingIndex = comboModel.getIndexOf(newValidValue);
if (existingIndex >= 0) {
comboModel.removeElementAt(existingIndex);
}
comboModel.insertElementAt(newValidValue, 0);
combo.setSelectedIndex(0);
StringBuilder entries = new StringBuilder();
int size = Math.min(comboModel.getSize(), 20);
for (int i = 0; i < size; i++) {
entries.append(comboModel.getElementAt(i));
if (i != size - 1) {
entries.append(DELIMITER);
}
}
while (entries.length() > Preferences.MAX_VALUE_LENGTH) {
int lastIndex = entries.lastIndexOf(DELIMITER);
if (lastIndex == -1) {
break;
} else {
entries.delete(lastIndex, entries.length());
}
}
prefs.put(prefKey, entries.toString());
try {
prefs.flush();
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void autoAwesomeLookAndFeel(String fontName, Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy