Image scaling works now

This commit is contained in:
mandlm 2015-12-29 19:18:38 +01:00
parent b3dbcc2588
commit 844ea49ed4
7 changed files with 34 additions and 32 deletions

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
filesCopiedToWebInfLib=

View File

@ -12,7 +12,7 @@
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- <inherits name='com.google.gwt.user.theme.clean.Clean'/> -->
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->

View File

@ -7,9 +7,7 @@ import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class FotoStream implements EntryPoint
@ -18,10 +16,6 @@ public class FotoStream implements EntryPoint
public void onModuleLoad()
{
final Label label = new Label();
RootPanel.get("textContainer").add(label);
final Image image = new Image();
image.setVisible(false);
image.addLoadHandler(new LoadHandler()
@ -29,27 +23,24 @@ public class FotoStream implements EntryPoint
@Override
public void onLoad(LoadEvent event)
{
int clientHeight = Window.getClientHeight();
int clientWidth = Window.getClientWidth();
int clientHeight = Window.getClientHeight();
int imageHeight = image.getHeight();
int imageWidth = image.getWidth();
double clientAspect = (double)clientWidth / (double)clientHeight;
double heightScale = (double)clientHeight / (double)imageHeight;
double widthScale = (double)clientWidth / (double)imageWidth;
int imageWidth = image.getOffsetWidth();
int imageHeight = image.getOffsetHeight();
double scale = Math.min(heightScale, widthScale);
double imageAspect = (double)imageWidth / (double)imageHeight;
int targetWidth = (int) (scale * (double)imageWidth);
int targetHeight = (int) (scale * (double)imageHeight);
label.setText(
"Client: " + clientWidth + "x" + clientHeight + " " +
"Image: " + imageWidth + "x" + imageHeight + " " +
"Target: " + targetWidth + "x" + targetHeight);
int widthScalePercent = 100;
if (imageAspect > 0 && clientAspect > 0 && imageAspect < clientAspect)
{
widthScalePercent = (int)(((double)imageAspect / (double)clientAspect) * 100.0);
}
image.setVisible(true);
image.setWidth("50%");
image.setWidth(widthScalePercent + "%");
}
});
@ -63,11 +54,7 @@ public class FotoStream implements EntryPoint
@Override
public void onFailure(Throwable caught)
{
DialogBox errorMsg = new DialogBox();
errorMsg.setTitle("Error loading image");
errorMsg.setHTML(caught.getMessage());
errorMsg.show();
image.setUrl("img/no_image.png");
}
@Override

View File

@ -50,6 +50,11 @@ public class CurrentImageURLServiceImpl extends RemoteServiceServlet implements
readImageFiles();
if (imageFiles.isEmpty())
{
return "img/no_image.png";
}
File latestFile = imageFiles.get(imageFiles.size() - 1);
Date latestFileDate = new Date(latestFile.lastModified());

View File

@ -1,7 +1,16 @@
body
{
margin: 0;
padding: 0;
background-color: black;
overflow: hidden;
}
div
{
padding: 20px;
margin: 0;
padding: 10px;
background-color: black;
color: green;
}

View File

@ -23,7 +23,7 @@
<!-- If you add any GWT meta tags, they must -->
<!-- be added before this line. -->
<!-- -->
<script type="text/javascript" language="javascript" src="fotostream/fotostream.nocache.js"></script>
<script src="fotostream/fotostream.nocache.js"></script>
</head>
<!-- -->
@ -40,7 +40,6 @@
</div>
</noscript>
<div id="imageContainer"></div>
<div id="textContainer"></div>
<div id="imageContainer" align="center"></div>
</body>
</html>

BIN
war/img/no_image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B