Search in sources :

Example 1 with FrameUIModel

use of edu.cmu.cs.hcii.cogtool.uimodel.FrameUIModel in project cogtool by cogtool.

the class DesignExportToHTML method buildFrameImage.

/**
	 * Builds the actual image object from the frame.
	 * Does this by creating an image object the size of the frame, and
	 * passes it as the canvas for drawing by the FrameDemoUI.
	 *
	 * Needs to pass it through a few SWT layers for it to work nicely though.
	 *
	 * NOTE: User of this class must dispose of the image themselves
	 * @param frame
	 * @return
	 */
protected static Image buildFrameImage(Frame frame) {
    // Need the View of the frame before I can build an image for it
    FrameUIModel frameUI = new FrameUIModel(frame, false, WindowUtil.SELECT_CURSOR, 1.0, false, // Don't display color overlays
    0, 0, // No attribute override
    null);
    DoubleSize size = frameUI.getPreferredSize();
    // from DesignUImodel.. but not sure how to take advantage of that
    if (size.height < 100) {
        size.height = 100;
    }
    if (size.width < 100) {
        size.width = 100;
    }
    byte[] bgImg = frame.getBackgroundImage();
    Image image;
    if (bgImg == null) {
        image = new Image(null, PrecisionUtilities.ceiling(size.width), PrecisionUtilities.ceiling(size.height));
    } else {
        image = new Image(null, new ByteArrayInputStream(bgImg));
    }
    return image;
}
Also used : FrameUIModel(edu.cmu.cs.hcii.cogtool.uimodel.FrameUIModel) ByteArrayInputStream(java.io.ByteArrayInputStream) Image(org.eclipse.swt.graphics.Image) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Aggregations

DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)1 FrameUIModel (edu.cmu.cs.hcii.cogtool.uimodel.FrameUIModel)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Image (org.eclipse.swt.graphics.Image)1