Search in sources :

Example 91 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class EditableResources method readMultiImage.

@Override
Image readMultiImage(DataInputStream input, boolean skipAll) throws IOException {
    com.codename1.ui.EncodedImage resultImage = null;
    int dpi = com.codename1.ui.Display.getInstance().getDeviceDensity();
    int dpiCount = input.readInt();
    int bestFitOffset = 0;
    int bestFitDPI = 0;
    int[] lengths = new int[dpiCount];
    dpisLoaded = new int[dpiCount];
    widthForDPI = new int[dpiCount];
    heightForDPI = new int[dpiCount];
    for (int iter = 0; iter < dpiCount; iter++) {
        int currentDPI = input.readInt();
        dpisLoaded[iter] = currentDPI;
        lengths[iter] = input.readInt();
        if (bestFitDPI != dpi && dpi >= currentDPI && currentDPI >= bestFitDPI) {
            bestFitDPI = currentDPI;
            bestFitOffset = iter;
        }
    }
    multiPending = new MultiImage();
    multiPending.setDpi(dpisLoaded);
    multiPending.setInternalImages(new EncodedImage[dpisLoaded.length]);
    for (int iter = 0; iter < lengths.length; iter++) {
        int size = lengths[iter];
        if (!skipAll && bestFitOffset == iter) {
            byte[] multiImageData = new byte[size];
            input.readFully(multiImageData, 0, size);
            resultImage = com.codename1.ui.EncodedImage.create(multiImageData);
            widthForDPI[iter] = resultImage.getWidth();
            heightForDPI[iter] = resultImage.getHeight();
            multiPending.getInternalImages()[iter] = resultImage;
        } else {
            byte[] multiImageData = new byte[size];
            input.readFully(multiImageData, 0, size);
            com.codename1.ui.EncodedImage tmp = com.codename1.ui.EncodedImage.create(multiImageData);
            widthForDPI[iter] = tmp.getWidth();
            heightForDPI[iter] = tmp.getHeight();
            multiPending.getInternalImages()[iter] = tmp;
        }
    }
    if (resultImage == null) {
        return Image.createImage(5, 5);
    }
    return resultImage;
}
Also used : EncodedImage(com.codename1.ui.EncodedImage)

Example 92 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class EditableResources method svgToMulti.

private MultiImage svgToMulti(Image image) throws IOException {
    SVG s = (SVG) image.getSVGDocument();
    MultiImage mi = new MultiImage();
    mi.dpi = s.getDpis();
    if (mi.dpi == null || mi.dpi.length == 0) {
        mi.dpi = new int[] { com.codename1.ui.Display.DENSITY_MEDIUM };
        mi.internalImages = new com.codename1.ui.EncodedImage[] { toEncodedImage(image) };
        return mi;
    }
    mi.internalImages = new com.codename1.ui.EncodedImage[mi.dpi.length];
    for (int iter = 0; iter < mi.dpi.length; iter++) {
        Image currentImage = image.scaled(s.getWidthForDPI()[iter], s.getHeightForDPI()[iter]);
        mi.internalImages[iter] = toEncodedImage(currentImage);
    }
    return mi;
}
Also used : SVG(com.codename1.impl.javase.SVG) BufferedImage(java.awt.image.BufferedImage) EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image)

Example 93 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class EditableResources method setResource.

void setResource(final String id, final byte type, final Object value) {
    /*if(!SwingUtilities.isEventDispatchThread()) {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        setResource(id, type, value);
                    }
                });
            } catch (Exception ex) {
                ex.printStackTrace();
            } 
            return;
        }*/
    if (overrideResource != null) {
        overrideResource.setResource(id, type, value);
        return;
    }
    boolean exists = false;
    int index = -1;
    if (value != null) {
        exists = getResourceObject(id) != null;
    } else {
        index = getIndexOfChild(getParent(type), id);
    }
    Object superValue = value;
    if (multiPending != null) {
        if (superValue instanceof com.codename1.ui.EncodedImage) {
            superValue = multiPending;
        }
        multiPending = null;
    }
    super.setResource(id, type, superValue);
    if (superValue != null) {
        index = getIndexOfChild(getParent(type), id);
        if (exists) {
            fireTreeNodeChanged(id, index);
        } else {
            fireTreeNodeAdded(id, index);
        }
    } else {
        fireTreeNodeRemoved(id, type, index);
    }
}
Also used : AnimationObject(com.codename1.ui.animations.AnimationObject) EncodedImage(com.codename1.ui.EncodedImage)

Example 94 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class EditableResources method saveFont.

private void saveFont(DataOutputStream output, boolean packed, String id) throws IOException {
    EditorFont f = (EditorFont) getFont(id);
    // write the system font fallback
    output.writeByte(f.getSystemFallback().getFace() | f.getSystemFallback().getSize() | f.getSystemFallback().getStyle());
    // do we have an emedded truetype font? Do we support embedded fonts?
    boolean trueTypeIncluded = f.getTruetypeFont() != null;
    output.writeBoolean(trueTypeIncluded);
    if (trueTypeIncluded) {
        output.writeInt(f.getTruetypeFont().length);
        output.write(f.getTruetypeFont());
    }
    boolean lookupIncluded = f.getLookupFont() != null;
    output.writeBoolean(lookupIncluded);
    if (lookupIncluded) {
        output.writeUTF(f.getLookupFont());
    }
    boolean bitmapIncluded = f.isIncludesBitmap();
    output.writeBoolean(bitmapIncluded);
    if (bitmapIncluded) {
        com.codename1.ui.Font bitmapFont = f.getBitmapFont();
        com.codename1.ui.Image cache = CodenameOneAccessor.getImage(bitmapFont);
        int[] imageArray = cache.getRGB();
        for (int iter = 0; iter < imageArray.length; iter++) {
            imageArray[iter] = (imageArray[iter] >> 8) & 0xff0000;
        }
        saveImage(output, com.codename1.ui.Image.createImage(imageArray, cache.getWidth(), cache.getHeight()), null, BufferedImage.TYPE_INT_RGB);
        String charset = bitmapFont.getCharset();
        int charCount = charset.length();
        output.writeShort(charCount);
        int[] cutOffsets = CodenameOneAccessor.getOffsets(bitmapFont);
        int[] charWidth = CodenameOneAccessor.getWidths(bitmapFont);
        for (int iter = 0; iter < charCount; iter++) {
            output.writeShort(cutOffsets[iter]);
        }
        for (int iter = 0; iter < charCount; iter++) {
            output.writeByte(charWidth[iter]);
        }
        output.writeUTF(charset);
        output.writeByte(f.getRenderingHint());
    }
}
Also used : Image(com.codename1.ui.Image) EditorFont(com.codename1.ui.EditorFont)

Example 95 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class EditableResources method toEncodedImage.

private com.codename1.ui.EncodedImage toEncodedImage(Image image) throws IOException {
    if (image instanceof EncodedImage) {
        return (com.codename1.ui.EncodedImage) image;
    }
    BufferedImage buffer = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    buffer.setRGB(0, 0, image.getWidth(), image.getHeight(), image.getRGB(), 0, image.getWidth());
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    ImageIO.write(buffer, "png", byteOut);
    byteOut.close();
    return com.codename1.ui.EncodedImage.create(byteOut.toByteArray());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage)

Aggregations

EncodedImage (com.codename1.ui.EncodedImage)26 Component (com.codename1.ui.Component)23 Point (java.awt.Point)23 IOException (java.io.IOException)23 AnimationObject (com.codename1.ui.animations.AnimationObject)22 ArrayList (java.util.ArrayList)22 BufferedImage (java.awt.image.BufferedImage)19 Hashtable (java.util.Hashtable)18 Form (com.codename1.ui.Form)15 Timeline (com.codename1.ui.animations.Timeline)15 Image (com.codename1.ui.Image)13 EditableResources (com.codename1.ui.util.EditableResources)13 File (java.io.File)13 Vector (java.util.Vector)13 TextArea (com.codename1.ui.TextArea)12 Border (com.codename1.ui.plaf.Border)12 Label (com.codename1.ui.Label)10 BorderLayout (com.codename1.ui.layouts.BorderLayout)10 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)10 Container (com.codename1.ui.Container)9