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 #1823070] Thu, 19 March 2020 06:58 Go to next message
Chandra Kyama is currently offline Chandra KyamaFriend
Messages: 8
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 #1823158 is a reply to message #1823070] Fri, 20 March 2020 13:11 Go to previous messageGo to next message
Chandra Kyama is currently offline Chandra KyamaFriend
Messages: 8
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
Re: Painting and drawing problem using GC in RAP. [message #1831768 is a reply to message #1823070] Fri, 28 August 2020 12:58 Go to previous messageGo to next message
Frank.K Mising name is currently offline Frank.K Mising nameFriend
Messages: 15
Registered: January 2013
Junior Member
Chandra Kyama wrote on Thu, 19 March 2020 07:58
Painting and drawing problem using GC in RAP.

[..]
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);


Since 3.14 Images implement the Drawable interface. This was a wanted change according to this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=318900

Anyways I just wanted to write a new thread about the GC(Drawable) constructor.
The problem is when you pass an Image - which is now possible -, then the internal "delegate" will not be filled in "determineDelegate( drawable )". The reason is simple: Image is neither an instance of Control nor Display and therefore the delegate stays empty:

private static GCDelegate determineDelegate( Drawable drawable ) {
    GCDelegate result = null;
    // Assume that Drawable is either a Control or a Device
    if( drawable instanceof Control ) {
      result = new ControlGC( ( Control )drawable );
    } else if( drawable instanceof Device ) {
      result = new DeviceGC( ( Device )drawable );
    }
    return result;
  }


Maybe someone can fix this. :)
Re: Painting and drawing problem using GC in RAP. [message #1831869 is a reply to message #1823070] Tue, 01 September 2020 12:20 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2427
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,

drawing directly on Image is currently not possible in RAP.

Regards,
Ivan
Previous Topic:Installing Eclipse IDE 2020-06 on iPad Pro
Next Topic:Scrolling problem in custom table
Goto Forum:
  


Current Time: Tue Sep 24 00:37:04 GMT 2024

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

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

Back to the top