public ResourceSource getRelativeSource(final String name) { try { final URL srcURL = UrlUtils.resolveRelativeURL(_url, "./" + name); if (srcURL != null) { // check if the URL can be opened // just force it to try to grab info srcURL.openStream().close(); // Ok satisfied... return return new URLResourceSource(srcURL); } } catch (final MalformedURLException ex) { } catch (final IOException ex) { } if (logger.isLoggable(Level.FINEST)) { logger.logp(Level.FINEST, getClass().getName(), "getRelativeSource(String)", "Unable to find relative file {0} from {1}.", new Object[] { name, _url }); } return null; }
/** * Construct a new URLResourceSource from a specific URL and type. * * @param sourceUrl * The url to load the resource from. Must not be null. * @param type * our type. Usually a file extension such as .png. Required for generic loading when multiple resource * handlers could be used. */ public URLResourceSource(final URL sourceUrl, final String type) { assert (sourceUrl != null) : "sourceUrl must not be null"; setURL(sourceUrl); _type = type; }
if (tex.getTextureKey() != null && tex.getTextureKey().getSource() != null) { _imageLabel .setIcon(new ImageIcon(((URLResourceSource) tex.getTextureKey().getSource()).getURL()));
/** * Creates the font. Font must exist in this bundle in images/fonts. * * @param fontName * @return */ public static BMFont newFont(final String fontName) { BMFont font = null; final URLResourceSource rs = new URLResourceSource(BMFontManager.class.getResource(fontName + ".fnt")); try { font = new BMFont(rs, false); } catch (final IOException e) { if (logger.isLoggable(Level.WARNING)) { logger.logp(Level.WARNING, "BMFontManager", "getFont(String)", "Unable to load font.", new Object[] { fontName }); } } return font; }
/** * Construct a new URLResourceSource from a specific URL and type. * * @param sourceUrl * The url to load the resource from. Must not be null. * @param type * our type. Usually a file extension such as .png. Required for generic loading when multiple resource * handlers could be used. */ public URLResourceSource(final URL sourceUrl, final String type) { assert (sourceUrl != null) : "sourceUrl must not be null"; setURL(sourceUrl); _type = type; }
public ResourceSource getRelativeSource(final String name) { try { final URL srcURL = UrlUtils.resolveRelativeURL(_url, "./" + name); if (srcURL != null) { // check if the URL can be opened // just force it to try to grab info srcURL.openStream().close(); // Ok satisfied... return return new URLResourceSource(srcURL); } } catch (final MalformedURLException ex) { } catch (final IOException ex) { } if (logger.isLoggable(Level.FINEST)) { logger.logp(Level.FINEST, getClass().getName(), "getRelativeSource(String)", "Unable to find relative file {0} from {1}.", new Object[] { name, _url }); } return null; }
/** * Construct a new URLResourceSource from a specific URL. * * @param sourceUrl * The url to load the resource from. Must not be null. If the URL has a valid URL filename (see * {@link URL#getFile()}) and an extension (eg. http://url/myFile.png) then the extension (.png in this * case) is used as the type. */ public URLResourceSource(final URL sourceUrl) { assert (sourceUrl != null) : "sourceUrl must not be null"; setURL(sourceUrl); // add type, if present final String fileName = _url.getFile(); if (fileName != null) { final int dot = fileName.lastIndexOf('.'); if (dot >= 0) { _type = fileName.substring(dot); } else { _type = UNKNOWN_TYPE; } } }
return new URLResourceSource(rVal); } catch (final IOException e) { return new URLResourceSource(rVal); } catch (final IOException e) {
/** * Construct a new URLResourceSource from a specific URL. * * @param sourceUrl * The url to load the resource from. Must not be null. If the URL has a valid URL filename (see * {@link URL#getFile()}) and an extension (eg. http://url/myFile.png) then the extension (.png in this * case) is used as the type. */ public URLResourceSource(final URL sourceUrl) { assert (sourceUrl != null) : "sourceUrl must not be null"; setURL(sourceUrl); // add type, if present final String fileName = _url.getFile(); if (fileName != null) { final int dot = fileName.lastIndexOf('.'); if (dot >= 0) { _type = fileName.substring(dot); } else { _type = UNKNOWN_TYPE; } } }
final URL u = ResourceLocatorTool.getClassPathResource(ResourceLocatorTool.class, resourceName); if (u != null) { return new URLResourceSource(u);
public void read(final InputCapsule capsule) throws IOException { final String protocol = capsule.readString("protocol", null); final String host = capsule.readString("host", null); final String file = capsule.readString("file", null); if (file != null) { // see if we would like to divert this to a new location. final ResourceSource src = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, URLDecoder.decode(file, "UTF-8")); if (src instanceof URLResourceSource) { setURL(((URLResourceSource) src)._url); _type = ((URLResourceSource) src)._type; return; } } if (protocol != null && host != null && file != null) { setURL(new URL(protocol, host, file)); } _type = capsule.readString("type", null); }
protected ResourceSource doRecursiveLocate(String resourceName) { // Trim off any prepended local dir. while (resourceName.startsWith("./") && resourceName.length() > 2) { resourceName = resourceName.substring(2); } while (resourceName.startsWith(".\\") && resourceName.length() > 2) { resourceName = resourceName.substring(2); } // Try to locate using resourceName as is. try { String spec = URLEncoder.encode(resourceName, "UTF-8"); // this fixes a bug in JRE1.5 (file handler does not decode "+" to spaces) spec = spec.replaceAll("\\+", "%20"); final URL rVal = new URL(_baseDir.toURL(), spec); // open a stream to see if this is a valid resource // XXX: Perhaps this is wasteful? Also, what info will determine validity? rVal.openStream().close(); return new URLResourceSource(rVal); } catch (final IOException e) { // URL wasn't valid in some way, so try up a path. } catch (final IllegalArgumentException e) { // URL wasn't valid in some way, so try up a path. } resourceName = trimResourceName(resourceName); if (resourceName == null) { return null; } else { return doRecursiveLocate(resourceName); } }
public void read(final InputCapsule capsule) throws IOException { final String protocol = capsule.readString("protocol", null); final String host = capsule.readString("host", null); final String file = capsule.readString("file", null); if (file != null) { // see if we would like to divert this to a new location. final ResourceSource src = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, URLDecoder.decode(file, "UTF-8")); if (src instanceof URLResourceSource) { setURL(((URLResourceSource) src)._url); _type = ((URLResourceSource) src)._type; return; } } if (protocol != null && host != null && file != null) { setURL(new URL(protocol, host, file)); } _type = capsule.readString("type", null); }
final URL u = ResourceLocatorTool.getClassPathResource(ResourceLocatorTool.class, resourceName); if (u != null) { return new URLResourceSource(u);
closest.bmFont = new BMFont(new URLResourceSource(url), false);
private void loadApplyTexture() throws MalformedURLException { final TextureState ts = (TextureState) getEdittedParticles().getLocalRenderState(StateType.Texture); // XXX: Needed? // TextureManager.clearCache(); ts.setTexture(TextureManager.load(new URLResourceSource(_newTexture.toURI().toURL()), Texture.MinificationFilter.BilinearNearestMipMap, TextureStoreFormat.GuessCompressedFormat, true)); ts.getTexture().setWrap(WrapMode.BorderClamp); ts.setEnabled(true); getEdittedParticles().setRenderState(ts); _newTexture = null; }
closest.bmFont = new BMFont(new URLResourceSource(url), false);