From 844ea49ed48f95f26234075206b5b2b15c9468fe Mon Sep 17 00:00:00 2001 From: mandlm Date: Tue, 29 Dec 2015 19:18:38 +0100 Subject: [PATCH] Image scaling works now --- .../com.google.appengine.eclipse.core.prefs | 2 + .../mandlm/fotostream/FotoStream.gwt.xml | 2 +- .../mandlm/fotostream/client/FotoStream.java | 41 ++++++------------ .../server/CurrentImageURLServiceImpl.java | 5 +++ war/FotoStream.css | 11 ++++- war/FotoStream.html | 5 +-- war/img/no_image.png | Bin 0 -> 859 bytes 7 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 .settings/com.google.appengine.eclipse.core.prefs create mode 100644 war/img/no_image.png diff --git a/.settings/com.google.appengine.eclipse.core.prefs b/.settings/com.google.appengine.eclipse.core.prefs new file mode 100644 index 0000000..82c36af --- /dev/null +++ b/.settings/com.google.appengine.eclipse.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +filesCopiedToWebInfLib= diff --git a/src/net/molez/mandlm/fotostream/FotoStream.gwt.xml b/src/net/molez/mandlm/fotostream/FotoStream.gwt.xml index 2fa540a..b61e79e 100644 --- a/src/net/molez/mandlm/fotostream/FotoStream.gwt.xml +++ b/src/net/molez/mandlm/fotostream/FotoStream.gwt.xml @@ -12,7 +12,7 @@ - + diff --git a/src/net/molez/mandlm/fotostream/client/FotoStream.java b/src/net/molez/mandlm/fotostream/client/FotoStream.java index 6aa59cd..45cd3a5 100644 --- a/src/net/molez/mandlm/fotostream/client/FotoStream.java +++ b/src/net/molez/mandlm/fotostream/client/FotoStream.java @@ -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 imageHeight = image.getHeight(); - int imageWidth = image.getWidth(); - - double heightScale = (double)clientHeight / (double)imageHeight; - double widthScale = (double)clientWidth / (double)imageWidth; - - double scale = Math.min(heightScale, widthScale); + int clientHeight = Window.getClientHeight(); - int targetWidth = (int) (scale * (double)imageWidth); - int targetHeight = (int) (scale * (double)imageHeight); + double clientAspect = (double)clientWidth / (double)clientHeight; - label.setText( - "Client: " + clientWidth + "x" + clientHeight + " " + - "Image: " + imageWidth + "x" + imageHeight + " " + - "Target: " + targetWidth + "x" + targetHeight); + int imageWidth = image.getOffsetWidth(); + int imageHeight = image.getOffsetHeight(); + double imageAspect = (double)imageWidth / (double)imageHeight; + + 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 diff --git a/src/net/molez/mandlm/fotostream/server/CurrentImageURLServiceImpl.java b/src/net/molez/mandlm/fotostream/server/CurrentImageURLServiceImpl.java index eb06a90..db85f5a 100644 --- a/src/net/molez/mandlm/fotostream/server/CurrentImageURLServiceImpl.java +++ b/src/net/molez/mandlm/fotostream/server/CurrentImageURLServiceImpl.java @@ -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()); diff --git a/war/FotoStream.css b/war/FotoStream.css index 092d347..0e85f4a 100644 --- a/war/FotoStream.css +++ b/war/FotoStream.css @@ -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; } \ No newline at end of file diff --git a/war/FotoStream.html b/war/FotoStream.html index f063b66..49c6e2c 100644 --- a/war/FotoStream.html +++ b/war/FotoStream.html @@ -23,7 +23,7 @@ - + @@ -40,7 +40,6 @@ -
-
+
diff --git a/war/img/no_image.png b/war/img/no_image.png new file mode 100644 index 0000000000000000000000000000000000000000..c812cc8d6f8d3a5f0d06825bcf8f77a162da6b35 GIT binary patch literal 859 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRdwrjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qt-3``$9T^vIy;@;lMF1qC)z>s+EXrl%H@`pxt zJ-Ump_nA!c5S<1DK~@Z04IYw!yJYJ>M^!5e%KM)mDitGsS^_y zYg?|%6r*?j_w|COGa0rq3ejM^p(3!rN%O!le#^&C#rH9v`=EQr#KFrT{$545&s28P=*JA4 z2OH1d(5z#7ngRz>k;KTbL-)2LCi=9E_ z^!fYu+HxPiFTQ+q(Vy!dIX}Hx@M-Gl=Ew7YM818_#t9DVpTu~5#t z^2G+Jcg8(dd;RZN&X+XvUz5+rHsfE^%b57t4tspV_ZK^BSsLr)n#q5>c8+tytjY{= zg`ImDV)dDImYK>G7+kBYIyv)Z?!V}C<`c)I!j3y1etTT{sD1D@