Vaadin: Images in Grid with IndexedContainer - vaadin

So I'm trying to add Images to my Grid using an IndexedContainer with the following code:
//picture
String imgURL = (String)ds.child(PHOTO).getValue();//gets the image URL from the DB
System.out.println(imgURL);
ExternalResource picture = new ExternalResource(imgURL);
System.out.println(picture.getURL());
Image image = new Image(PICTURE, picture);
image.setHeight("5px");
item.getItemProperty(PICTURE).setValue(image);
Instead of getting the picture, I'm getting the toString() of the Image object. Both println print the correct URL. Also note that this works with Table but not with Grid. Any idea why?

If you want to display an image in a Vaadin Grid column, you need to set the ImageRenderer, see here paragraph ImageRenderer.
Example: Define your column like
grid.addColumn("picture", Resource.class).setRenderer(new ImageRenderer());
then add a resource as column value
grid.addRow(new ThemeResource("img/copernicus-128px.jpg"), "Nicolaus Copernicus", 1543);
In your case it is the ExternalResource. No need for the Image component.

Related

How can I automatically populate a cell in Google Sheets with an image from a Pinterest page?

Let's say I have a Google Sheet with URLs to individual pins on Pinterest in column B. For example: https://www.pinterest.com/pin/146578162860144581/
I'd like to populate cells in column C with the main image from the URL in column B.
Currently I have to do this manually by clicking through to the URL in column B, copy the image URL, and insert image into the cell in column C.
Is there a way to automate this?
Solution
Yes, you can achieve this using the sheet's Google's Apps Script. Below the following piece of code you can find a brief explanation on how this works.
The code
function populateImage() {
var sheet = SpreadsheetApp.getActiveSheet();
// Get cell values of your link column
var values = sheet.getRange('B1:B5').getValues();
// Range where we want to insert the images
var imgrange = sheet.getRange('C1:C5');
for (i=0;i<5;i++){
// Cell we want to insert the image
var cell = imgrange.getCell(i+1, 1);
// Pin Id which is at the end of each url provided, in this case 146578162860144581
var number = values[i][0].substring(29,values[i][0].length-1);
// Url to make the fetch request to access the json of that pin
var url = 'https://widgets.pinterest.com/v3/pidgets/pins/info/?pin_ids='+number;
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
// Url of the image of the pin
var imgurl =data.data[0].images["237x"].url;
// Insert image from url
cell.setFormula('=image("'+imgurl+'")');
}
}
Result
Explanation
To insert an image in a website in your sheet you will need the image url. This is the most tricky part in this issue. Pinterest does not provide a good way to get this image url by just fetching to the pin url as this request will return HTML data and not json. To achieve this you will need to make a fetch request to this url https://widgets.pinterest.com/v3/pidgets/pins/info/?pin_ids=PINIDNUMBER. You can find more information about this in this Stack Overflow question, credit goes to #SambhavSharma .
When you fetch following this url you will get the pin's json from which you can retrieve your desired image url (apart from many other data about this pin). With it you can simply insert it in the next column.
I hope this has helped you, let me know if you need anything else or if you did not understand something.

Unable to select image from gallery in appium android

I am using "java-client-5.0.4" version, I am unable to select image from gallery.
Here is my code
List<AndroidElement> galleryElements = driver.findElementsByClassName("android.widget.ImageView");
TouchAction t = new TouchAction(driver);
t.tap(galleryElements.get(0)).perform();
In this case you can use the resource-id
By selectPhoto = By.id("imageView");
driver.findElement(selectPhoto).click();
but here is a problem, it will always select the first image, for specific image selection you should use xpath with index
Use ArrayList and get all image list in that list. After that provide index of the arraylist you can select the any image:
ArrayList<WebElement> listImage=(ArrayList<WebElement>) driver.findElements(By.id("com.euradvance.classstars:id/image"));
System.out.println(listImage.size());
listImage.get(5).click();

How to select the type of file when using SaveImage()

I have realize that the SaveImage() command uses the last the last type of format that has been selected during normal DM operation. I assume that this option is selected somewhere in the GobalInfo tags. Please, could someone tell me which tag I have to modify to select dm4 format when I use SaveImage()?
'SaveImage()' is just a convenience wrapper. It is generally not the
Image which is saved to file, but an ImageDocument which can contain one ore more images. The latest DigitalMicograph help
documentation is more detailed about loading/saving than previous
ones, so I'm just copy-pasting the according passages below:
For example to store the front-most displayed image(document) as DM images, you may use:
string name = "C:\\TempImg"
string handler = "Gatan 3 Format"
ImageDocument doc = GetFrontImageDocument()
doc.ImageDocumentSaveToFile( handler, name )
And you can always get the ImageDocument from any image, using:
string handler = "Gatan 3 Format"
image img := RealImage("Test - not yet shown", 4, 100, 100 )
string name = "C:\\" + img.GetName()
ImageDocument doc = img.ImageGetOrCreateImageDocument()
doc.ImageDocumentSaveToFile( handler, name )

Can two item renderers be used for a grid column in Adobe flex?

I have a data grid with multiple columns among which one is for stock date. Based on the data i am getting from the backend,when a flag is disabled,i want the date to be displayed as a label,otherwise i want the start date to be editable date field. How can this be done? I have tried this below code but its takes the last rendered item as item renderer. Cause as i loop in,the condition for different records change and rendering it this way doesnt seem to work. Please help.
private function resultHandler_tbd(event:ResultEvent):void{
var myAC: ArrayCollection= event.result as ArrayCollection; //data from backend
myDataGridId.dataprovider= myAC;
for(var i:int=0;i<myAC.length;i++){
mylist=myAc[i];
if(mylist.tbdType=="Plan" && flag==true){
plnStartDate.itemrenderer= new ClassFactory(CustomCalenderRenderer);
}else
plnStartDate.itemrenderer = new ClassFactory(CustomLabelRenderer);
}
}
}
Have the "flag" property set in data for item renderer
Create a custom itemrenderer which will have both component, CustomCalenderRenderer and CustomLabelRenderer and binded with data.flag for includedInLayout or not
Thanks

imagej get current image from imagestack

i need to get the current image opened after importing an image sequence to ImageJ.
As i need to save the overlay information to a text file bearing the name of the image
int number = imp.getImageStackSize();
if(number > 1)
{
ImagePlus check = imp.duplicate();
gd.removeAll();
gd.addMessage(check.getTitle());
gd.showDialog();
}
imp.gettitle returns the folder name the images were loaded from.
couldn't find any solution so far :(
Any way to find the text in the status bar would be appreciated..
it was a simple issue..
the name of the current image can be retrieved by the following piece of code..
fileName = imp.getImageStack().getShortSliceLabel(imp.getCurrentSlice());
Thanks everyone..

Resources