use of com.codename1.io.URL in project CodenameOne by codenameone.
the class CN1Console method downloadGroovy.
private void downloadGroovy() throws IOException {
try {
String url = GROOVY_URL;
if (url == null) {
throw new RuntimeException("No Groovy URL found for this platform");
}
File groovyDir = new File(GROOVY_HOME);
if (groovyDir.exists()) {
delTree(groovyDir);
}
groovyDir.getParentFile().mkdirs();
File groovyZip = new File(groovyDir.getParentFile(), "groovy.zip");
downloadToFile(url, groovyZip);
File tmpDir = new File(groovyZip.getParentFile(), "groovy.tmp." + System.currentTimeMillis());
try {
new UnzipUtility().unzip(groovyZip.getAbsolutePath(), tmpDir.getAbsolutePath());
groovyDir.mkdir();
File libDirTmp = findDir(tmpDir, "lib");
File legalDirTmp = findDir(tmpDir, "licenses");
if (libDirTmp == null || !libDirTmp.exists()) {
throw new IOException("No lib dir found within Groovy zip");
}
if (legalDirTmp == null || !legalDirTmp.exists()) {
throw new IOException("No legal dir found within Groovy zip");
}
libDirTmp.renameTo(new File(groovyDir, "lib"));
legalDirTmp.renameTo(new File(groovyDir, "licenses"));
} finally {
delTree(tmpDir);
groovyZip.delete();
}
} catch (MalformedURLException ex) {
Logger.getLogger(CN1Console.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}
}
use of com.codename1.io.URL in project CodenameOne by codenameone.
the class JavaSEPort method loadSkinFile.
private void loadSkinFile(String f, JFrame frm) {
try {
File fsFile = new File(f);
if (fsFile.exists()) {
f = fsFile.toURI().toString();
}
if (f.contains("://") || f.startsWith("file:")) {
try {
// load Via URL loading
loadSkinFile(new URL(f).openStream(), frm);
} catch (FileNotFoundException ex) {
String d = System.getProperty("dskin");
loadSkinFile(d, frm);
return;
} catch (MalformedURLException ex) {
loadSkinFile(getResourceAsStream(getClass(), DEFAULT_SKIN), frm);
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
InputStream is = getResourceAsStream(getClass(), f);
if (is != null) {
loadSkinFile(is, frm);
} else {
loadSkinFile(getResourceAsStream(getClass(), DEFAULT_SKIN), frm);
}
}
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.put("skin", f);
addSkinName(f);
} catch (Throwable t) {
System.out.println("Failed loading the skin file: " + f);
t.printStackTrace();
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.remove("skin");
}
}
use of com.codename1.io.URL in project CodenameOne by codenameone.
the class ImageDownloadService method createImageToFileSystem.
/**
* Constructs an image request that will automatically populate the given Label
* when the response arrives, it will cache the file locally.
*
* @param url the image URL
* @param callback the callback that should be updated when the data arrives
* @param destFile local file to store the data into the given path
*/
public static void createImageToFileSystem(String url, ActionListener callback, String destFile) {
Image im = cacheImage(null, false, destFile, null, null, defaultMaintainAspectRatio);
if (im != null) {
callback.actionPerformed(new NetworkEvent(null, im));
return;
}
// image not found on cache go and download from the url
ImageDownloadService i = new ImageDownloadService(url, callback);
i.cacheImages = true;
i.destinationFile = destFile;
i.setFailSilently(true);
NetworkManager.getInstance().addToQueue(i);
}
use of com.codename1.io.URL in project CodenameOne by codenameone.
the class ImageDownloadService method createImageToStorage.
/**
* Constructs an image request that will automatically populate the given Label
* when the response arrives, it will cache the file locally.
*
* @param url the image URL
* @param callback the callback that should be updated when the data arrives
* @param cacheId a unique identifier to be used to store the image into storage
* @param keep if set to true keeps the file in RAM once loaded
*/
public static void createImageToStorage(String url, ActionListener callback, String cacheId, boolean keep) {
Image im = cacheImage(cacheId, keep, null, null, null, defaultMaintainAspectRatio);
if (im != null) {
callback.actionPerformed(new NetworkEvent(null, im));
return;
}
// image not found on cache go and download from the url
ImageDownloadService i = new ImageDownloadService(url, callback);
i.cacheImages = true;
i.cacheId = cacheId;
i.setFailSilently(true);
NetworkManager.getInstance().addToQueue(i);
}
use of com.codename1.io.URL in project CodenameOne by codenameone.
the class ImageDownloadService method createImageToStorage.
/**
* Constructs an image request that will automatically populate the given Label
* when the response arrives, it will cache the file locally to the Storage
*
* @param url the image URL
* @param l the Label that should be updated when the data arrives
* to just use storage and the url as the key
* @param cacheId a unique identifier to be used to store the image into storage
* @param toScale the scale dimension or null
* @param priority the priority for the task
*/
private static void createImageToStorage(final String url, final Label l, final String cacheId, final boolean keep, final Dimension toScale, final byte priority, final Image placeholder, final boolean maintainAspectRatio) {
if (Display.getInstance().isEdt()) {
Display.getInstance().scheduleBackgroundTask(new Runnable() {
public void run() {
createImageToStorage(url, l, cacheId, keep, toScale, priority, placeholder, maintainAspectRatio);
}
});
return;
}
Image im = cacheImage(cacheId, keep, null, toScale, placeholder, maintainAspectRatio);
if (im != null) {
if (!fastScale && toScale != null) {
im = scaleImage(im, toScale, defaultMaintainAspectRatio);
}
final Image i = im;
Display.getInstance().callSerially(new Runnable() {
public void run() {
l.setIcon(i);
Form f = l.getComponentForm();
if (f != null) {
f.revalidate();
}
}
});
return;
}
// image not found on cache go and download from the url
ImageDownloadService i = new ImageDownloadService(url, l);
i.maintainAspectRatio = maintainAspectRatio;
i.setDuplicateSupported(true);
i.cacheImages = true;
i.toScale = toScale;
i.cacheId = cacheId;
i.placeholder = placeholder;
i.setPriority(priority);
i.setFailSilently(true);
NetworkManager.getInstance().addToQueue(i);
}
Aggregations