This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

setPreserveAspectRatio

General questions regarding the development with JVx.

setPreserveAspectRatio

Postby lucdep » Thu Nov 15, 2018 1:47 pm

Hi,

I'm trying to set the aspect ratio of ImageViewer with this code:

editWorkpicsWrkpImage.setDataRow(rdbWorkpics);
editWorkpicsWrkpImage.setColumnName("WRKP_IMAGE");
editWorkpicsWrkpImage.setBackground(new UIColor(0xb8cce4));
((IImageViewer<UIImageViewer>)editWorkpicsWrkpImage.getCurrentCellEditor()).setPreserveAspectRatio(true);

but Eclipse always give me a type safety warning: Unchecked cast from ICellEditor to IImageViewer<UIImageViewer>

Can't find where my error comes from.
lucdep
 
Posts: 31
Joined: Wed Oct 10, 2018 12:01 pm

Re: setPreserveAspectRatio

Postby rzenz » Thu Nov 15, 2018 2:25 pm

The error message in this case says that the cast cannot be verified at runtime. An example:

We have a List which holds custom objects.

Code: Select all
List<CustomObject> list = new ArrayList<>();
list.add(new CustomObject());
list.add(new CustomObject());
list.add(new CustomObject());


Now, the List interface itself is rather typesafe, but assuming that we have a method which returns Object and our list:


Code: Select all
public Object getList()
{
    List<CustomObject> list = new ArrayList<>();
    list.add(new CustomObject());
    list.add(new CustomObject());
    list.add(new CustomObject());
    return list;
}


We'de need to cast the list to the appropriate type when calling that function:

Code: Select all
List<CustomObject> castedList = (List<CustomObject>)getList();

CustomObject item = castedList.get(1);


However, information about generic types is only available in source-code form. The Java generics system is a compile-time only system, at runtime there is no information on the type of a generic variable. Keeping that in mind, the actual code during runtime would look like this:

Code: Select all
List castedList = (List)getList();

CustomObject item = (CustomObject)castedList.get(1);


As we can see, we only get a non-specific List anymore. Now in our case that is not a problem, but it is possible that during runtime an item of a different class has ended up in the list, so the content of our list is this:

Code: Select all
[0]: CustomObject
[1]: String
[2]: CustomObject
[3]: CustomObject


So our code from above, which is compiling fine and also looks sound:

Code: Select all
List<CustomObject> castedList = (List<CustomObject>)getList();

CustomObject item = castedList.get(1);


Is actually throwing a ClassCastException during runtime. And that is what that error message is trying to tell you, that you can cast this object to another object with a generic type, but in no way can this cast be verified during compiletime or during runtime (and so should be avoided, if possible).
User avatar
rzenz
 
Posts: 36
Joined: Mon Dec 12, 2016 1:40 pm
Location: Vienna, Austria

Re: setPreserveAspectRatio

Postby johnit » Thu Nov 15, 2018 3:36 pm

johnit
 
Posts: 34
Joined: Fri Nov 16, 2012 5:58 pm

Re: setPreserveAspectRatio

Postby lucdep » Thu Nov 15, 2018 3:49 pm

Is my formulation wrong? Should I formulate it in another way? There must certainly be a safe way to use the Method setPreserveAspectRatio.
lucdep
 
Posts: 31
Joined: Wed Oct 10, 2018 12:01 pm

Re: setPreserveAspectRatio

Postby Development@SIB » Thu Nov 15, 2018 4:08 pm

Simply use a field:

Syntax: [ Download ] [ Hide ]
IImageViewer<UIImageViewer> viewer = editor.getCurrentCellEditor();
viewer.setPreserveAspectRatio(true);
User avatar
Development@SIB
 
Posts: 323
Joined: Mon Sep 28, 2009 1:54 pm

Re: setPreserveAspectRatio

Postby rzenz » Thu Nov 15, 2018 4:10 pm

Yes, you could set a UIImageView with the appropriate property on the model.

Code: Select all

private static final UIImageViewer IMAGEVIEWER_WITH_ASPECT_RATIO;

static
{
    IMAGEVIEWER_WITH_ASPECT_RATIO = new UIImageViewer();
    IMAGEVIEWER_WITH_ASPECT_RATIO.setPreserveAspectRatio(true);
}

// Some time later.
rdbWorkpics
    .getRowDefinition()
    .getColumnDefinition("WRKP_IMAGE")
    .getDataType()
    .setCellEditor(IMAGEVIEWER_WITH_ASPECT_RATIO);
User avatar
rzenz
 
Posts: 36
Joined: Mon Dec 12, 2016 1:40 pm
Location: Vienna, Austria

Re: setPreserveAspectRatio

Postby lucdep » Mon Nov 19, 2018 4:02 pm

OK, thanks it works like this!
lucdep
 
Posts: 31
Joined: Wed Oct 10, 2018 12:01 pm

Re: setPreserveAspectRatio

Postby lucdep » Tue Apr 16, 2019 4:43 pm

Hi,

This was working OK in JavaFX, but when running the code in the browser, if get these errors in Vaadin:

Code: Select all
java.lang.NullPointerException
   at com.sibvisions.rad.ui.vaadin.impl.component.VaadinIcon.fixImageSize(VaadinIcon.java:635)
   at com.sibvisions.rad.ui.vaadin.impl.component.VaadinIcon.setImageWidth(VaadinIcon.java:615)
   at com.sibvisions.rad.ui.vaadin.impl.component.VaadinIcon.setWidthFull(VaadinIcon.java:360)
   at com.sibvisions.rad.ui.vaadin.impl.celleditor.VaadinImageViewer$CellEditorHandler.setWidth(VaadinImageViewer.java:439)
   at com.sibvisions.rad.ui.vaadin.impl.control.VaadinEditor.setWidth(VaadinEditor.java:924)
   at com.sibvisions.rad.ui.vaadin.impl.control.VaadinEditor.setWidthFull(VaadinEditor.java:685)
   at com.sibvisions.rad.ui.vaadin.impl.VaadinComponentBase.setSizeFull(VaadinComponentBase.java:1322)
   at com.sibvisions.rad.ui.vaadin.impl.layout.AbstractVaadinClientLayout.repaintLayout(AbstractVaadinClientLayout.java:181)
   at com.sibvisions.rad.ui.vaadin.impl.layout.AbstractVaadinLayout.run(AbstractVaadinLayout.java:99)
   at com.sibvisions.rad.ui.vaadin.impl.VaadinFactory$UIRunnable.run(VaadinFactory.java:1879)
   at com.sibvisions.rad.ui.vaadin.impl.VaadinFactory.performInvokeLater(VaadinFactory.java:1112)
   at com.sibvisions.rad.ui.vaadin.impl.VaadinFactory.performInvokeLater(VaadinFactory.java:1039)
   at com.sibvisions.rad.ui.vaadin.impl.VaadinUI$InternalConnectorTracker.getDirtyConnectors(VaadinUI.java:3046)
   at com.vaadin.ui.ConnectorTracker.getDirtyVisibleConnectors(ConnectorTracker.java:651)
   at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:94)
   at com.vaadin.server.communication.AtmospherePushConnection.push(AtmospherePushConnection.java:168)
   at com.vaadin.server.communication.PushHandler.lambda$new$1(PushHandler.java:146)
   at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:235)
   at com.vaadin.server.communication.PushHandler.onMessage(PushHandler.java:520)
   at com.vaadin.server.communication.PushAtmosphereHandler.onMessage(PushAtmosphereHandler.java:87)
   at com.vaadin.server.communication.PushAtmosphereHandler.onRequest(PushAtmosphereHandler.java:77)
   at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:223)
   at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:115)
   at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:67)
   at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2284)
   at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:593)
   at org.atmosphere.websocket.DefaultWebSocketProcessor$3.run(DefaultWebSocketProcessor.java:345)
   at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
   at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:340)
   at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:447)
   at org.atmosphere.container.JSR356Endpoint$3.onMessage(JSR356Endpoint.java:272)
   at org.atmosphere.container.JSR356Endpoint$3.onMessage(JSR356Endpoint.java:269)
   at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:395)
   at org.apache.tomcat.websocket.server.WsFrameServer.sendMessageText(WsFrameServer.java:119)
   at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:495)
   at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:294)
   at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133)
   at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:82)
   at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171)
   at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151)
   at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148)
   at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54)
   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53)
   at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
   at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Thread.java:745)


I have been trying several options:

Code: Select all
editAdmiAdministrationAdmiLogoHeadImg.setDataRow(rdbAdmiAdministration);
editAdmiAdministrationAdmiLogoHeadImg.setColumnName("ADMI_LOGO_HEAD_IMG");
editAdmiAdministrationAdmiLogoHeadImg.setBackground(UIColor.lightGray);
      
IImageViewer<UIImageViewer> LOGOHEAD = editAdmiAdministrationAdmiLogoHeadImg.getCurrentCellEditor();
LOGOHEAD.setPreserveAspectRatio(true);


but also

Code: Select all
final UIImageViewer IMAGEVIEWER_ASPECT;
      
      IMAGEVIEWER_ASPECT = new UIImageViewer();
      IMAGEVIEWER_ASPECT.setPreserveAspectRatio(true);
      IMAGEVIEWER_ASPECT.setHorizontalAlignment(UIImageViewer.ALIGN_STRETCH);
      IMAGEVIEWER_ASPECT.setVerticalAlignment(UIImageViewer.ALIGN_STRETCH);
...
      rdbAdmiAdministration.getRowDefinition().getColumnDefinition("ADMI_LOGO_HEAD_IMG").getDataType().setCellEditor(IMAGEVIEWER_ASPECT);




but the NullPointerException always came back when running in the browser (and as I said, everything worked OK in JavaFX). After clicking away the error message, however, everythings works like expected in Vaadin as well, it's only when opening the workscreen that the error pops up.

I need some enlightment here...
lucdep
 
Posts: 31
Joined: Wed Oct 10, 2018 12:01 pm

Re: setPreserveAspectRatio

Postby Support@SIB » Tue Apr 16, 2019 6:31 pm

Please file a bug: https://oss.sibvisions.com with a simple test case.
User avatar
Support@SIB
 
Posts: 286
Joined: Mon Sep 28, 2009 1:56 pm

Re: setPreserveAspectRatio

Postby lucdep » Mon Apr 29, 2019 10:22 am

Hi,

I have no authorisation to file a case in OSS.

regards,

Luc
lucdep
 
Posts: 31
Joined: Wed Oct 10, 2018 12:01 pm

Re: setPreserveAspectRatio

Postby Support@SIB » Mon Apr 29, 2019 10:28 am

Authorization needs a while, please check again.
User avatar
Support@SIB
 
Posts: 286
Joined: Mon Sep 28, 2009 1:56 pm


Return to Development