Search in sources :

Example 1 with IconSpec

use of org.eclipse.scout.rt.client.services.common.icon.IconSpec in project scout.rt by eclipse.

the class IconLoader method loadResource.

@Override
public BinaryResource loadResource(String pathInfo) throws IOException {
    final String imageId = pathInfo.substring(pathInfo.lastIndexOf('/') + 1);
    IconSpec iconSpec = IconLocator.instance().getIconSpec(imageId);
    if (iconSpec == null) {
        return null;
    }
    // cache: use max-age caching for at most 4 hours
    return BinaryResources.create().withFilename(iconSpec.getName()).withContent(iconSpec.getContent()).withLastModified(System.currentTimeMillis()).withCachingAllowed(true).withCacheMaxAge(HttpCacheControl.MAX_AGE_4_HOURS).build();
}
Also used : IconSpec(org.eclipse.scout.rt.client.services.common.icon.IconSpec)

Example 2 with IconSpec

use of org.eclipse.scout.rt.client.services.common.icon.IconSpec in project scout.rt by eclipse.

the class DefaultWizardStatusHtmlProvider method loadIcon.

/**
 * To load an icon into the given attachments live list
 */
protected void loadIcon(List<BinaryResource> attachments, String iconName) {
    if (attachments == null || iconName == null) {
        return;
    }
    String tempIconName = iconName;
    try {
        int index;
        // determine file format
        index = tempIconName.lastIndexOf('.');
        if (index > 0) {
            tempIconName = tempIconName.substring(0, index);
        }
        // determine icon base name
        String baseIconName = tempIconName;
        index = tempIconName.lastIndexOf('_');
        if (index > 0) {
            baseIconName = tempIconName.substring(0, index);
        }
        // load icon
        IconSpec iconSpec = IconLocator.instance().getIconSpec(tempIconName);
        if (iconSpec == null && !tempIconName.equals(baseIconName)) {
            iconSpec = IconLocator.instance().getIconSpec(baseIconName);
        }
        if (iconSpec != null) {
            attachments.add(new BinaryResource(iconSpec.getName(), iconSpec.getContent()));
        }
    } catch (Exception t) {
        LOG.warn("Failed to load icon '{}'", tempIconName, t);
    }
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HTML.imgByBinaryResource(org.eclipse.scout.rt.platform.html.HTML.imgByBinaryResource) IconSpec(org.eclipse.scout.rt.client.services.common.icon.IconSpec) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 3 with IconSpec

use of org.eclipse.scout.rt.client.services.common.icon.IconSpec in project scout.rt by eclipse.

the class BinaryResourceUrlUtility method createIconUrl.

/**
 * @return a relative URL for a configured logical icon-name or a font-based icon. For instance:
 *         <ul>
 *         <li>input: <code>"bookmark"</code>, output: <code>"icon/bookmark.png"</code> (the file extension is
 *         included to support auto-detection of the MIME type without looking at the file contents)</li>
 *         <li>input: <code>"font:X"</code>, output: <code>"font:X"</code></li>
 *         </ul>
 *         The file extension is included to be able to auto-detect the MIME type based on it.
 *         <p>
 *         Use this method for image-files located in the /resource/icons directories of all jars on the classpath.
 */
public static String createIconUrl(String iconId) {
    if (!StringUtility.hasText(iconId) || AbstractIcons.Null.equals(iconId)) {
        return null;
    }
    if (iconId.startsWith("font:")) {
        return iconId;
    }
    IconSpec iconSpec = IconLocator.instance().getIconSpec(iconId);
    if (iconSpec != null) {
        // includes file extension
        return "icon/" + iconSpec.getName();
    }
    LOG.warn("iconId '{}' could not be resolved", iconId);
    // may happen, when no icon is available for the requested iconName
    return null;
}
Also used : IconSpec(org.eclipse.scout.rt.client.services.common.icon.IconSpec)

Aggregations

IconSpec (org.eclipse.scout.rt.client.services.common.icon.IconSpec)3 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 HTML.imgByBinaryResource (org.eclipse.scout.rt.platform.html.HTML.imgByBinaryResource)1 BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)1