Search in sources :

Example 1 with ImageLoader

use of org.eclipse.swt.graphics.ImageLoader in project cogtool by cogtool.

the class WindowsImageTransfer method nativeToJava.

protected Object nativeToJava(TransferData transferData) {
    final Object o = super.nativeToJava(transferData);
    final byte[] bytes = (byte[]) o;
    try {
        final InputStream bis = new PrependWinBMPHeaderFilterInputStream(new UncompressDibFilterInputStream(new ByteArrayInputStream(bytes)));
        final ImageData[] data = new ImageLoader().load(bis);
        if (data.length < 1) {
            return null;
        }
        return data[0];
    } catch (IOException e) {
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ImageData(org.eclipse.swt.graphics.ImageData) IOException(java.io.IOException) ImageLoader(org.eclipse.swt.graphics.ImageLoader)

Example 2 with ImageLoader

use of org.eclipse.swt.graphics.ImageLoader in project cogtool by cogtool.

the class WindowsImageTransfer method javaToNative.

protected void javaToNative(Object object, TransferData transferData) {
    final ImageData imgData = (ImageData) object;
    final ImageLoader loader = new ImageLoader();
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final byte[] bytes;
    loader.data = new ImageData[] { imgData };
    loader.save(new RemoveWinBMPHeaderFilterOutputStream(bos), SWT.IMAGE_BMP);
    bytes = bos.toByteArray();
    super.javaToNative(bytes, transferData);
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageLoader(org.eclipse.swt.graphics.ImageLoader)

Example 3 with ImageLoader

use of org.eclipse.swt.graphics.ImageLoader in project cogtool by cogtool.

the class DesignExportToHTML method exportToHTML.

public void exportToHTML(Design d, String dir, Cancelable cancelState, ProgressCallback progressState) {
    // No need to duplicate here; we're already in the child thread
    // and the design had to have been duplicated in the main thread!
    design = d;
    destDirectory = dir;
    // Performed by the child thread
    // Create a file object for DestDir and test if it is actually
    // a directory
    parentDir = new File(destDirectory);
    if (!parentDir.isDirectory()) {
        // If there is no directory specified, we should fail here.
        throw new IllegalArgumentException("Create Web pages called " + "without a directory");
    }
    Set<Frame> frameSet = design.getFrames();
    int frameCount = frameSet.size();
    // Start at 0 leaving one extra "count" for overlib copy
    // Use "double" to force proper division when setting progress below
    double progressCount = 0.0;
    // call buildFrameList to build the lookup maps.
    buildFrameList();
    Iterator<Frame> iter = frameSet.iterator();
    ImageLoader imageLoader = new ImageLoader();
    String html = null;
    Image img = null;
    //Note: Very long while loop in terms of code
    while ((!cancelState.isCanceled()) && iter.hasNext()) {
        Frame frame = iter.next();
        try {
            //below function, "buildFrameImage", takes in a frame and returns its image
            img = buildFrameImage(frame);
            imageLoader.data = new ImageData[] { img.getImageData() };
            String imageName = getFrameFileName(frame, ".jpg");
            // create new FILE handler for the new imageSaver's use
            File imageFile = new File(parentDir, imageName);
            try {
                imageLoader.save(imageFile.getCanonicalPath(), SWT.IMAGE_JPEG);
            } catch (IOException ex) {
                // We can continue even with exceptions on individual images
                throw new ImageException("Failed saving image for HTML export", ex);
            }
        } finally {
            // dispose the image, it's not needed any more.
            img.dispose();
        }
        try {
            // write HTML to destDir
            FileWriter fileOut = null;
            BufferedWriter writer = null;
            try {
                // Use the local file name, and not the complete path.
                html = buildFrameHTML(frame);
                File htmlFile = new File(parentDir, getFrameFileName(frame, ".html"));
                fileOut = new FileWriter(htmlFile);
                writer = new BufferedWriter(fileOut);
                writer.write(html);
            } finally {
                if (writer != null) {
                    writer.close();
                } else if (fileOut != null) {
                    fileOut.close();
                }
            }
        } catch (IOException ex) {
            throw new ExportIOException("Could not save HTML for export ", ex);
        }
        // Update the progress count
        progressCount += 1.0;
        progressState.updateProgress(progressCount / frameCount, SWTStringUtil.insertEllipsis(frame.getName(), 250, StringUtil.NO_FRONT, SWTStringUtil.DEFAULT_FONT));
    //end of getting frames
    }
    //make sure user did not cancel, and then create folder "build"
    if (!cancelState.isCanceled()) {
        File buildDir = new File(parentDir, "build");
        if (!buildDir.exists()) {
            if (!buildDir.mkdir()) {
                throw new ExportIOException("Could not create build directory");
            }
        }
        try {
            // Write out the index page.
            FileWriter fileOut = null;
            BufferedWriter writer = null;
            try {
                // Use the local file name, and not the complete path.
                //This creates the main page, needs a little styling
                html = buildIndexPage();
                File htmlFile = new File(parentDir, "index.html");
                fileOut = new FileWriter(htmlFile);
                writer = new BufferedWriter(fileOut);
                writer.write(html);
            } finally {
                if (writer != null) {
                    writer.close();
                } else if (fileOut != null) {
                    fileOut.close();
                }
            }
        } catch (IOException ex) {
            throw new ExportIOException("Could not save index.html for export ", ex);
        }
        //Here we import all the resources from the standard directory
        InputStream overlibStream = ClassLoader.getSystemResourceAsStream("edu/cmu/cs/hcii/cogtool/resources/ExportToHTML/overlib.js");
        if (overlibStream == null) {
            throw new ExportIOException("Could not locate overlib.js resource");
        }
        File overlibFile = new File(buildDir, "overlib.js");
        InputStream containerCoreStream = ClassLoader.getSystemResourceAsStream("edu/cmu/cs/hcii/cogtool/resources/ExportToHTML/container_core.js");
        if (containerCoreStream == null) {
            throw new ExportIOException("Could not locate container_core.js resource");
        }
        File containerCoreFile = new File(buildDir, "container_core.js");
        InputStream fontsStream = ClassLoader.getSystemResourceAsStream("edu/cmu/cs/hcii/cogtool/resources/ExportToHTML/fonts-min.css");
        if (fontsStream == null) {
            throw new ExportIOException("Could not locate fonts-min.css resource");
        }
        File fontsFile = new File(buildDir, "fonts-min.css");
        InputStream menuStyleStream = ClassLoader.getSystemResourceAsStream("edu/cmu/cs/hcii/cogtool/resources/ExportToHTML/menu.css");
        if (menuStyleStream == null) {
            throw new ExportIOException("Could not locate menu.css resource");
        }
        File menuStyleFile = new File(buildDir, "menu.css");
        InputStream menuStream = ClassLoader.getSystemResourceAsStream("edu/cmu/cs/hcii/cogtool/resources/ExportToHTML/menu.js");
        if (menuStream == null) {
            throw new ExportIOException("Could not locate menu.js resource");
        }
        File menuFile = new File(buildDir, "menu.js");
        //As you can see, lots of yahoo fancy shmancy
        InputStream eventStream = ClassLoader.getSystemResourceAsStream("edu/cmu/cs/hcii/cogtool/resources/ExportToHTML/yahoo-dom-event.js");
        if (eventStream == null) {
            throw new ExportIOException("Could not locate yahoo-dom-event.js resource");
        }
        File eventFile = new File(buildDir, "yahoo-dom-event.js");
        InputStream spriteStream = ClassLoader.getSystemResourceAsStream("edu/cmu/cs/hcii/cogtool/resources/ExportToHTML/sprite.png");
        if (spriteStream == null) {
            throw new ExportIOException("Could not locate sprite.png resource");
        }
        File spriteFile = new File(buildDir, "sprite.png");
        try {
            FileUtil.copyStreamToFile(overlibStream, overlibFile);
            FileUtil.copyStreamToFile(containerCoreStream, containerCoreFile);
            FileUtil.copyStreamToFile(fontsStream, fontsFile);
            FileUtil.copyStreamToFile(menuStyleStream, menuStyleFile);
            FileUtil.copyStreamToFile(menuStream, menuFile);
            FileUtil.copyStreamToFile(eventStream, eventFile);
            FileUtil.copyStreamToFile(spriteStream, spriteFile);
        } catch (IOException ex) {
            throw new ExportIOException("Failed to create file", ex);
        }
    }
    // clear the look up object
    frameLookUp.clear();
    frameLookUp = null;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ImageException(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil.ImageException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) BufferedWriter(java.io.BufferedWriter) ImageLoader(org.eclipse.swt.graphics.ImageLoader) File(java.io.File)

Example 4 with ImageLoader

use of org.eclipse.swt.graphics.ImageLoader in project cogtool by cogtool.

the class GraphicsUtil method convertImageType.

/**
     * newType is SWT.IMAGE_*
     */
public static byte[] convertImageType(ImageData imgData, int newType) {
    ImageLoader loader = new ImageLoader();
    loader.data = new ImageData[] { imgData };
    ByteArrayOutputStream out = new ByteArrayOutputStream(32768);
    loader.save(out, newType);
    return out.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageLoader(org.eclipse.swt.graphics.ImageLoader)

Example 5 with ImageLoader

use of org.eclipse.swt.graphics.ImageLoader in project dbeaver by serge-rider.

the class BookmarkStorage method serialize.

public ByteArrayInputStream serialize() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream(5000);
    XMLBuilder xml = new XMLBuilder(buffer, GeneralUtils.getDefaultFileEncoding());
    xml.startElement(TAG_BOOKMARK);
    xml.addAttribute(ATTR_TITLE, title);
    if (description != null) {
        xml.addAttribute(ATTR_DESCRIPTION, description);
    }
    xml.addAttribute(ATTR_DATA_SOURCE, dataSourceId);
    for (String path : dataSourcePath) {
        xml.startElement(TAG_PATH);
        xml.addText(path);
        xml.endElement();
    }
    {
        xml.startElement(TAG_IMAGE);
        Image realImage = DBeaverIcons.getImage(this.image);
        ImageLoader loader = new ImageLoader();
        loader.data = new ImageData[] { realImage.getImageData() };
        ByteArrayOutputStream imageBuffer = new ByteArrayOutputStream(5000);
        loader.save(imageBuffer, SWT.IMAGE_PNG);
        xml.addText(Base64.encode(imageBuffer.toByteArray()));
        xml.endElement();
    }
    xml.endElement();
    xml.flush();
    return new ByteArrayInputStream(buffer.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Image(org.eclipse.swt.graphics.Image) DBPImage(org.jkiss.dbeaver.model.DBPImage) ImageLoader(org.eclipse.swt.graphics.ImageLoader) XMLBuilder(org.jkiss.utils.xml.XMLBuilder)

Aggregations

ImageLoader (org.eclipse.swt.graphics.ImageLoader)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Image (org.eclipse.swt.graphics.Image)7 ImageData (org.eclipse.swt.graphics.ImageData)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 File (java.io.File)4 InputStream (java.io.InputStream)3 GC (org.eclipse.swt.graphics.GC)3 ImageException (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil.ImageException)2 FileOutputStream (java.io.FileOutputStream)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1