package Other; import Editor.APScripts; import Editor.Editor; import Main.L; import Main.PPM; import javax.microedition.content.ActionNameMap; import javax.microedition.content.ContentHandler; import javax.microedition.content.ContentHandlerException; import javax.microedition.content.ContentHandlerServer; import javax.microedition.content.Invocation; import javax.microedition.content.Registry; import javax.microedition.content.RequestListener; import javax.microedition.lcdui.*; /** * Класс регистрации Content Handler API * @author Malcolm */ public class Responder implements RequestListener { private String[] SUPPORTED_FILE_EXTS, TYPES, ACTIONS, ACTION_NAMES; private ActionNameMap[] mapArr; public Responder() { String appName = PPM.midlet.getClass().getName(); init(); Registry reg = Registry.getRegistry(appName); ContentHandlerServer chs = null; try { chs = Registry.getServer(appName); } catch (ContentHandlerException ex) { try { chs = reg.register(appName, TYPES, SUPPORTED_FILE_EXTS, ACTIONS, mapArr, null, ACTION_NAMES); } catch (ClassNotFoundException ex1) { ex1.printStackTrace(); } catch (ContentHandlerException ex1) { ex1.printStackTrace(); } } chs.setListener(this); } public void invocationRequestNotify(ContentHandlerServer chs) { Invocation inv = chs.getRequest(true); String url = inv.getURL(); openImage(url); } private void init() { SUPPORTED_FILE_EXTS = new String[]{ ".gif", ".jpg", ".bmp", ".ppm", ".psd", ".jpeg", ".png", ".aps" }; TYPES = new String[]{ "image/gif", "image/jpeg", "image/bmp", "image/x-portable-pixmap", "image/psd", "image/jpeg", "image/png", "text/aps" }; ACTIONS = new String[] { ContentHandler.ACTION_OPEN }; ACTION_NAMES = new String[]{ L.str[L.Open]+" PPM" }; ActionNameMap m1 = new ActionNameMap(ACTIONS, ACTION_NAMES, PPM.midlet.lang); mapArr = new ActionNameMap[]{ m1 }; } private void openImage(String url) { Image image1 = null; if (url.toLowerCase().endsWith(".aps")) { APScripts aps = new APScripts(JSR75.getInputStream(url)); image1 = aps.drawAPS(); } else { image1 = JSR75.getImage(url, ""); } PPM.midlet.imgname = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.')); if (Editor.I == null) { PPM.midlet.ed.create(image1.getWidth(), image1.getHeight()); } Editor.openImage(image1); PPM.dsp.setCurrent(PPM.midlet.ed); } /*private String normalize(String text) { String sr =""; StringBuffer sb = new StringBuffer(); for(int i=0; i=text.length()-1) { sr = text.substring(i, i+1); } } if(sr.toUpperCase().startsWith("%D")) { sr = text.substring(i+=4, i+2); sb.append((char) (Integer.parseInt(sr, 16)+896)); i++; }else{ sb.append(sr);i++; } } return sb.toString(); }*/ }