/** * This formats a double which would be displayed as scientific values * * @param value * @param dp the decimal places * @return */ protected String formatScientificNumber(double value, int dp) { // first get the scientific notation format String sn = Double.toString(value); // now split into two parts String[] sa = Util.split(sn, "E"); String part1 = "" + round(Double.parseDouble(sa[0]), dp); String part2 = ""; if (sa.length == 2) { part2 = "E" + sa[1]; } return part1 + part2; }
public void actionPerformed(ActionEvent evt) { if (adapter != null) { try { byte[] d; InputStream is; if (storageFile != null) { d = new byte[Storage.getInstance().entrySize(storageFile + IMAGE_SUFFIX)]; is = Storage.getInstance().createInputStream(storageFile + IMAGE_SUFFIX); } else { d = new byte [(int) FileSystemStorage.getInstance().getLength(fileSystemFile + IMAGE_SUFFIX)]; is = FileSystemStorage.getInstance().openInputStream(fileSystemFile + IMAGE_SUFFIX); } Util.readFully(is, d); EncodedImage img = EncodedImage.create(d); EncodedImage adapted; if (adapter.isAsyncAdapter()) { adapt = img; Display.getInstance().invokeAndBlock(this); adapted = adaptedIns; adaptedIns = null; adapt = null; } else { adapted = adapter.adaptImage(img, placeholder); } if (storageFile != null) { OutputStream o = Storage.getInstance().createOutputStream(storageFile); o.write(adapted.getImageData()); o.close(); Storage.getInstance().deleteStorageFile(storageFile + IMAGE_SUFFIX); } else { OutputStream o = FileSystemStorage.getInstance().openOutputStream(fileSystemFile); o.write(adapted.getImageData()); o.close(); FileSystemStorage.getInstance().delete(fileSystemFile + IMAGE_SUFFIX); } } catch (IOException ex) { ex.printStackTrace(); return; } } fetching = false; // invoke fetch again to load the local files fetch(); }
public static void register( String callback, ServiceProvider provider, final String consumerKey, final String consumerSecret) { if (credentials == null) { credentials = new Hashtable(); // Initialize serialization Util.register(AccessToken.OBJECT_ID, AccessToken.class); // Initialize the HTMLComponent browser with defaults NetworkManager.getInstance().addDefaultHeader("Accept-Language", "en-us"); DocumentInfo.setDefaultEncoding("UTF-8"); } Hashtable credential = new Hashtable(); credential.put("key", consumerKey); credential.put("secret", consumerSecret); credential.put("provider", provider); credentials.put(callback.replace('/', '_'), credential); }
/** * Images are normally fetched from storage or network only as needed, however if the download * must start before the image is drawn this method can be invoked. */ public void fetch() { if (fetching || imageData != null) { return; } fetching = true; try { locked = super.isLocked(); if (storageFile != null) { if (Storage.getInstance().exists(storageFile)) { unlock(); imageData = new byte[Storage.getInstance().entrySize(storageFile)]; InputStream is = Storage.getInstance().createInputStream(storageFile); Util.readFully(is, imageData); resetCache(); fetching = false; repaintImage = true; return; } if (adapter != null) { Util.downloadUrlToStorageInBackground( url, storageFile + IMAGE_SUFFIX, new DownloadCompleted()); } else { Util.downloadUrlToStorageInBackground(url, storageFile, new DownloadCompleted()); } } else { if (FileSystemStorage.getInstance().exists(fileSystemFile)) { unlock(); imageData = new byte[(int) FileSystemStorage.getInstance().getLength(fileSystemFile)]; InputStream is = FileSystemStorage.getInstance().openInputStream(fileSystemFile); Util.readFully(is, imageData); resetCache(); fetching = false; repaintImage = true; return; } if (adapter != null) { Util.downloadUrlToFileSystemInBackground( url, fileSystemFile + IMAGE_SUFFIX, new DownloadCompleted()); } else { Util.downloadUrlToFileSystemInBackground( url, fileSystemFile + IMAGE_SUFFIX, new DownloadCompleted()); } } } catch (IOException ioErr) { throw new RuntimeException(ioErr.toString()); } }