Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Painting and drawing problem using GC in RAP.(RAP Compatabity issue)
Painting and drawing problem using GC in RAP. [message #1823071] Thu, 19 March 2020 06:59 Go to next message
Chandra Kyama is currently offline Chandra KyamaFriend
Messages: 9
Registered: February 2020
Junior Member
Painting and drawing problem using GC in RAP.

We are migrating our product RCP to RAP where as Eclipse org.eclipse.swt_3.8.1.v3836 to RAP 3.11 Version.
We are unable to display or painting the image in Widget or composite.

Problem 1:
Problem with setIncrement and setPageIncrement methods of Scrollble inbuilt class not available in RAP latest versions.
These methods giving layout problem in Scrollable.
Sample Code:
ScrollBar horizontal = getHorizontalBar();
horizontal.setIncrement((int) (getClientArea().width / 100));
horizontal.setPageIncrement(getClientArea().width);

Problem 2: While creating the image object width and height values are not caluclating due to above problem 1.
Due to that we are getting ERROR_INVALID_ARGUMENT exception in Image object constuction.
which leads to further we are unable to getting to create the GC object.
Sample Code :
Image screenImage = new Image(getDisplay(), clientRect.width, clientRect.height);

Problem 3:
Problem with create GC object by passing image object as argument to the constructor.
because RAP does not allow the image object as argument to GC, it is allowing as any of Drawble object.
Sample Code :
GC newGC = new GC(screenImage);

above all 3 problems leads to painting and drawing functionality not working in our application after we migrating from SWT to RAP version.
Would you please provide me suggestions to fix the problem in RAP.

Thanks & Regards
Chandra Shaker Kyama
Re: Painting and drawing problem using GC in RAP. [message #1823157 is a reply to message #1823071] Fri, 20 March 2020 13:10 Go to previous message
Chandra Kyama is currently offline Chandra KyamaFriend
Messages: 9
Registered: February 2020
Junior Member
Solution:

Please refer below Process steps:

1. Written the customized CustomBase64Image class which maintainig the base64 image string and zoom properties.
2. Introduced the ImageViewerComposite.java which creates the custom browser composite with specified image pattern.
3. Customized methods zoomout, zoomin, rotate and updateImageViewer to update image processing in browser composite.
4. Preparing the base64Image image based on ImageData which internally uses ByteArrayOutputStream and ImageLoader.
5. No more using ImageCanvas class and its supportive methods of ImageUIUtil methods.
6. Added java docs to respective changes and please refer accordingly.


Source code:

public class CustomBase64Image {

private String imageSource = null;
private int zoom = 5;

public CustomBase64Image(String imageSource, int zoom) {
super();
this.imageSource = imageSource;
this.zoom = zoom;
}

public String getImageSource() {
return imageSource;
}

public void setImageSource(String imageSource) {
this.imageSource = imageSource;
}

public int getZoom() {
return zoom;
}

public void setZoom(int zoom) {
this.zoom = zoom;
}
}

public class ImageViewerComposite {

private static final String IMAGE_PATTERN = "<html><body><div style=\"text-align: center;\"><img src=\"data:image/png;base64,{0}\" style=zoom:{1}; ></img></div></body></html>";

private CustomBase64Image base64Image = null;

private final Browser imageViewer;

public ImageViewerComposite(final Composite parent) {
imageViewer = createViewerComposite(parent);
}

/**
* This method is displaying the base64 image into browser based on ImagePattern.
*
* @param customImage is the argument type of CustomBase64Image.
* which internally binds the image source and zoom percentage.
*
*/
public void updateImageViewer(final CustomBase64Image customImage) {
this.base64Image = customImage;
final String zoomPercentage = base64Image.getZoom() + "%";
String format = MessageFormat.format(IMAGE_PATTERN, base64Image.getImageSource(), zoomPercentage);
imageViewer.setText(format);
}

/**
* Current image page should be zoomed out and display into browser upon zoom value.
*
* @return zoom value to the caller method.
*/

public int zoomOut() {
if (base64Image.getZoom() > 5)
base64Image.setZoom(base64Image.getZoom() - 5);
updateImageViewer();
return base64Image.getZoom();
}


/**
* Current image page should be zoomed in and display into browser upon zoom value.
*
* @return zoom value to the caller method.
*/
public int zoomIn() {
if (base64Image.getZoom() >= 5)
base64Image.setZoom(base64Image.getZoom() + 5);
updateImageViewer();
return base64Image.getZoom();
}

/**
* It update the image size based on the zoom value and image source.
*/

private void updateImageViewer() {
final String zoomPercentage = base64Image.getZoom() + "%";
String format = MessageFormat.format(IMAGE_PATTERN, this.base64Image.getImageSource(), zoomPercentage);
imageViewer.setText(format);
}

/**
* It creates the browser composite and layout.
* @param parent argument is passing value of specified composite.
* @return Returns the Browser object with layout data.
*/
private Browser createViewerComposite(Composite parent) {
final Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayout(new GridLayout(1, true));
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
final Browser browser = new Browser(composite, SWT.BORDER);
browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
composite.layout();
return browser;
}
}


private void initImages() { //KEC-21690
model.getImageIndexBean().getImagePageInfoBeans();
sourceImages = model.getImageIndexBean().getSourceImages();

for (ImageData data : sourceImages) {
CustomBase64Image image = new CustomBase64Image(convertToBase64Image(data), INITIAL_ZOOM);
base64Images.add(image);
}
imageViewerComposite.updateImageViewer(base64Images.get(0));

}

/**
* This method converts image data to base64 string content.
* <p> Converting image data to byteArrayOutputStream data which internally converting byte stream data to base64 string data by using @Code ImageLoader class.
*
* @see ByteArrayOutputStream
* @see ImageLoader
* @see Base64.getEncoder()
*
* @param imageData type of ImageData.
*
*/

public String convertToBase64Image(ImageData imageData) { //KEC-21690
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[]{imageData};
loader.save(out, SWT.IMAGE_PNG);
return Base64.getEncoder().encodeToString(out.toByteArray());
}


Please refer above solution to fix display functionality in Latest RAP.

Thanks & Regards
Chandra Shaker Kyama

[Updated on: Fri, 20 March 2020 13:11]

Report message to a moderator

Previous Topic:Chrome does reuse HTTP Connection for F5 -> old session isn't destroyed
Next Topic:Do you accept contributions via github?
Goto Forum:
  


Current Time: Fri Dec 06 11:08:26 GMT 2024

Powered by FUDForum. Page generated in 0.03605 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top