Search in sources :

Example 16 with Media

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

the class JSSolutionModel method getMedia.

/**
 * Gets the specified media object; can be assigned to a button/label.
 *
 * @sample
 * var myMedia = solutionModel.getMedia('button01.gif')
 * //now set the imageMedia property of your label or button
 * //myButton.imageMedia = myMedia
 * // OR
 * //myLabel.imageMedia = myMedia
 *
 * @param name the specified name of the media object
 *
 * @return a JSMedia element
 */
@JSFunction
public JSMedia getMedia(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Media media = fs.getMedia(name);
    if (media != null) {
        return new JSMedia(media, application.getFlattenedSolution(), false);
    }
    return null;
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 17 with Media

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

the class JSSolutionModel method removeMedia.

/**
 * Removes the media item specified by name.
 *
 * @sample
 * var bytes1 = plugins.file.readFile('D:/Imgs/image1.png');
 * var image1 = solutionModel.newMedia('image1.png', bytes1);
 * var bytes2 = plugins.file.readFile('D:/Imgs/image2.jpg');
 * var image2 = solutionModel.newMedia('image2.jpg',bytes2);
 * var bytes3 = plugins.file.readFile('D:/Imgs/image3.jpg');
 * var image3 = solutionModel.newMedia('image3.jpg',bytes3);
 *
 * var f = solutionModel.newForm("newForm",databaseManager.getDataSource('example_data', 'orders'),null,false,500,350);
 * var l = f.newLabel('', 20, 70, 300, 200);
 * l.imageMedia = image1;
 * l.borderType =  solutionModel.createLineBorder(4,'#ff0000');
 * forms["newForm"].controller.show();
 *
 * var status = solutionModel.removeMedia('image1.jpg');
 * if (status) application.output("image1.png has been removed");
 * else application.output("image1.png has not been removed");
 *
 * var mediaList = solutionModel.getMediaList();
 * for (var i = 0; i < mediaList.length; i++) {
 * 	application.output(mediaList[i].getName() + ":" + mediaList[i].mimeType);
 * }
 *
 * @param name the name of the media item to be removed
 *
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeMedia(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Media mediaItem = fs.getMedia(name);
    if (mediaItem != null) {
        fs.deletePersistCopy(mediaItem, false);
        return true;
    }
    return false;
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 18 with Media

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

the class JSSolutionModel method getMediaList.

/**
 * Gets the list of all media objects.
 *
 * @sample
 * var mediaList = solutionModel.getMediaList();
 * if (mediaList.length != 0 && mediaList != null) {
 * 	for (var x in mediaList) {
 * 		application.output(mediaList[x]);
 * 	}
 * }
 *
 * 	@return a list with all the media objects.
 */
@JSFunction
public JSMedia[] getMediaList() {
    FlattenedSolution fs = application.getFlattenedSolution();
    ArrayList<JSMedia> lst = new ArrayList<JSMedia>();
    Iterator<Media> media = fs.getMedias(true);
    while (media.hasNext()) {
        lst.add(new JSMedia(media.next(), application.getFlattenedSolution(), false));
    }
    return lst.toArray(new JSMedia[lst.size()]);
}
Also used : ArrayList(java.util.ArrayList) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 19 with Media

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

the class JSSolutionModel method newMedia.

/**
 * Creates a new media object that can be assigned to a label or a button.
 *
 * @sample
 * var myMedia = solutionModel.newMedia('button01.gif',bytes)
 * //now set the imageMedia property of your label or button
 * //myButton.imageMedia = myMedia
 * // OR
 * //myLabel.imageMedia = myMedia
 *
 * @param name The name of the new media
 *
 * @param bytes The content
 *
 * @return a JSMedia object
 */
@JSFunction
public JSMedia newMedia(String name, byte[] bytes) {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        Media media = fs.getSolutionCopy().createNewMedia(new ScriptNameValidator(fs), name);
        media.setPermMediaData(bytes);
        media.setMimeType(MimeTypes.getContentType(bytes));
        return new JSMedia(media, application.getFlattenedSolution(), true);
    } catch (RepositoryException e) {
        throw new RuntimeException("error createing new media with name " + name, e);
    }
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 20 with Media

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

the class PersistHelper method getOrderedStyleSheets.

public static List<String> getOrderedStyleSheets(FlattenedSolution fs) {
    List<String> styleSheets = new ArrayList<String>();
    List<Solution> orderedModules = new ArrayList<Solution>();
    orderedModules.add(fs.getSolution());
    if (fs.getModules() != null) {
        buildOrderedModulesList(fs.getSolution(), orderedModules, new ArrayList<Solution>(Arrays.asList(fs.getModules())));
    }
    for (Solution solution : orderedModules) {
        if (solution.getStyleSheetID() > 0) {
            Media media = fs.getMedia(solution.getStyleSheetID());
            if (media != null) {
                if (!styleSheets.contains(media.getName())) {
                    styleSheets.add(media.getName());
                }
            } else {
                // $NON-NLS-1$ //$NON-NLS-2$
                Debug.warn("Stylesheet set for solution '" + solution.getName() + "' cannot be found");
            }
        }
    }
    return styleSheets;
}
Also used : ArrayList(java.util.ArrayList) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

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