Search in sources :

Example 11 with Media

use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.

the class AbstractScriptButton method setMediaIcon.

public void setMediaIcon(int mediaId) {
    this.mediaId = mediaId;
    try {
        setIcon(ComponentFactory.loadIcon(application.getFlattenedSolution(), new Integer(mediaId)));
        Media media = application.getFlattenedSolution().getMedia(mediaId);
        if (media != null)
            text_url = MediaURLStreamHandler.MEDIA_URL_DEF + media.getName();
    } catch (Exception ex) {
        Debug.error(ex);
    }
}
Also used : Media(com.servoy.j2db.persistence.Media)

Example 12 with Media

use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.

the class AbstractScriptLabel method setMediaIcon.

public void setMediaIcon(int mediaId) {
    this.mediaId = mediaId;
    try {
        setIcon(ComponentFactory.loadIcon(application.getFlattenedSolution(), new Integer(mediaId)));
        Media media = application.getFlattenedSolution().getMedia(mediaId);
        if (media != null)
            text_url = MediaURLStreamHandler.MEDIA_URL_DEF + media.getName();
    } catch (Exception ex) {
        Debug.error(ex);
    }
}
Also used : Media(com.servoy.j2db.persistence.Media)

Example 13 with Media

use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.

the class FlattenedSolutionLessFileManager method readLess.

@Override
public Object readLess(String path, String encoding) {
    if (fs != null) {
        Media media = getMedia(path);
        if (media != null) {
            imports.add(media);
            if (encoding != null) {
                try {
                    return new String(media.getMediaData(), encoding);
                } catch (UnsupportedEncodingException e) {
                    return new String(media.getMediaData());
                }
            } else
                return media.getMediaData();
        }
    }
    Object content = super.readLess(path, encoding);
    if (content != null)
        return content;
    Debug.error("Couldn't resolve the media for " + startFolder + path + " when parsing the @import statement of the less file: " + lessFile);
    return "";
}
Also used : Media(com.servoy.j2db.persistence.Media) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 14 with Media

use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.

the class WebTabPanel method addTab.

public boolean addTab(IForm formController, String formName, String tabname, String tabText, String tabtooltip, String iconURL, String fg, String bg, String relationName, RelatedFoundSet relatedFs, int idx) {
    if (formController != null) {
        // to make sure we don't have recursion on adding a tab, to a tabpanel, that is based
        // on the form that the tabpanel is placed on
        WebForm webForm = findParent(WebForm.class);
        if (webForm != null) {
            FormController parentFormController = webForm.getController();
            if (parentFormController != null && parentFormController.equals(formController)) {
                return false;
            }
        }
    }
    WebTabFormLookup flp = (WebTabFormLookup) createFormLookupPanel(tabname, relationName, formName);
    if (formController != null)
        flp.setReadOnly(formController.isReadOnly());
    FlattenedSolution fl = application.getFlattenedSolution();
    int mediaId = -1;
    if (iconURL != null && !"".equals(iconURL)) {
        Media media = fl.getMedia(iconURL.replaceAll("media:///", ""));
        if (media != null)
            mediaId = media.getID();
        if (mediaId == -1) {
            Debug.warn("Form '" + formController.getName() + "' with tabpanel  '" + this.name + "' has tabicon  for tab '" + tabname + "'in with icon media url : " + iconURL + " not found");
        }
    }
    byte[] iconData = (mediaId == -1 ? null : ComponentFactory.loadIcon(fl, new Integer(mediaId)));
    int count = allTabs.size();
    int tabIndex = idx;
    if (tabIndex == -1 || tabIndex >= count) {
        tabIndex = count;
    }
    insertTab(application.getI18NMessageIfPrefixed(tabText), iconData, flp, application.getI18NMessageIfPrefixed(tabtooltip), tabIndex, true);
    if (fg != null)
        setTabForegroundAt(tabIndex, PersistHelper.createColor(fg));
    if (bg != null)
        setTabBackgroundAt(tabIndex, PersistHelper.createColor(bg));
    // from the relatedFs - which is already in the relationName param
    if (relatedFs != null && currentForm == flp) {
        FormController fp = flp.getWebForm().getController();
        if (fp != null && flp.getRelationName() != null && flp.getRelationName().equals(relationName)) {
            fp.loadData(relatedFs, null);
        }
    }
    return true;
}
Also used : FormController(com.servoy.j2db.FormController) WebForm(com.servoy.j2db.server.headlessclient.WebForm) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Point(java.awt.Point)

Example 15 with Media

use of com.servoy.j2db.persistence.Media in project servoy-client by Servoy.

the class MediaResourcesServlet method findAndSendMediaData.

protected boolean findAndSendMediaData(HttpServletRequest request, HttpServletResponse response, String mediaName, FlattenedSolution fs) throws IOException {
    Media media = fs.getMedia(mediaName);
    if (media == null && mediaName.endsWith(".css")) {
        media = fs.getMedia(mediaName.replace(".css", ".less"));
        Solution sc = fs.getSolutionCopy(false);
        if (media != null && media.getParent() != sc) {
            // is a less file, try to load the compiled version
            URL url = getServletConfig().getServletContext().getResource('/' + SERVOY_SOLUTION_CSS + '/' + mediaName);
            if (url != null) {
                setHeaders(request, response);
                // cache resources on client until changed
                if (HTTPUtils.checkAndSetUnmodified(request, response, media.getLastModifiedTime() != -1 ? media.getLastModifiedTime() : fs.getLastModifiedTime()))
                    return true;
                response.setContentType("text/css");
                URLConnection con = url.openConnection();
                long lenght = con.getContentLengthLong();
                if (lenght > 0)
                    response.setContentLengthLong(lenght);
                try (InputStream is = con.getInputStream()) {
                    IOUtils.copy(is, response.getOutputStream());
                }
                return true;
            }
        }
    }
    if (media != null) {
        return sendMediaData(request, response, fs, media);
    }
    return false;
}
Also used : InputStream(java.io.InputStream) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

Media (com.servoy.j2db.persistence.Media)29 FlattenedSolution (com.servoy.j2db.FlattenedSolution)10 IOException (java.io.IOException)8 Point (java.awt.Point)7 Solution (com.servoy.j2db.persistence.Solution)4 JSFunction (org.mozilla.javascript.annotations.JSFunction)3 FormController (com.servoy.j2db.FormController)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 ByteArrayResource (com.servoy.j2db.server.headlessclient.ByteArrayResource)2 Image (java.awt.Image)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 URLConnection (java.net.URLConnection)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)1 IForm (com.servoy.j2db.IForm)1 IFormController (com.servoy.j2db.IFormController)1 IScriptExecuter (com.servoy.j2db.IScriptExecuter)1 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)1