Image scaling works now
This commit is contained in:
parent
b3dbcc2588
commit
844ea49ed4
7 changed files with 34 additions and 32 deletions
2
.settings/com.google.appengine.eclipse.core.prefs
Normal file
2
.settings/com.google.appengine.eclipse.core.prefs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
filesCopiedToWebInfLib=
|
|
@ -12,7 +12,7 @@
|
||||||
<!-- Inherit the default GWT style sheet. You can change -->
|
<!-- Inherit the default GWT style sheet. You can change -->
|
||||||
<!-- the theme of your GWT application by uncommenting -->
|
<!-- the theme of your GWT application by uncommenting -->
|
||||||
<!-- any one of the following lines. -->
|
<!-- 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.standard.Standard'/> -->
|
||||||
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
|
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
|
||||||
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
|
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
|
||||||
|
|
|
@ -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.Timer;
|
||||||
import com.google.gwt.user.client.Window;
|
import com.google.gwt.user.client.Window;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
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.Image;
|
||||||
import com.google.gwt.user.client.ui.Label;
|
|
||||||
import com.google.gwt.user.client.ui.RootPanel;
|
import com.google.gwt.user.client.ui.RootPanel;
|
||||||
|
|
||||||
public class FotoStream implements EntryPoint
|
public class FotoStream implements EntryPoint
|
||||||
|
@ -18,10 +16,6 @@ public class FotoStream implements EntryPoint
|
||||||
|
|
||||||
public void onModuleLoad()
|
public void onModuleLoad()
|
||||||
{
|
{
|
||||||
final Label label = new Label();
|
|
||||||
RootPanel.get("textContainer").add(label);
|
|
||||||
|
|
||||||
|
|
||||||
final Image image = new Image();
|
final Image image = new Image();
|
||||||
image.setVisible(false);
|
image.setVisible(false);
|
||||||
image.addLoadHandler(new LoadHandler()
|
image.addLoadHandler(new LoadHandler()
|
||||||
|
@ -29,27 +23,24 @@ public class FotoStream implements EntryPoint
|
||||||
@Override
|
@Override
|
||||||
public void onLoad(LoadEvent event)
|
public void onLoad(LoadEvent event)
|
||||||
{
|
{
|
||||||
int clientHeight = Window.getClientHeight();
|
|
||||||
int clientWidth = Window.getClientWidth();
|
int clientWidth = Window.getClientWidth();
|
||||||
|
int clientHeight = Window.getClientHeight();
|
||||||
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 targetWidth = (int) (scale * (double)imageWidth);
|
double clientAspect = (double)clientWidth / (double)clientHeight;
|
||||||
int targetHeight = (int) (scale * (double)imageHeight);
|
|
||||||
|
|
||||||
label.setText(
|
int imageWidth = image.getOffsetWidth();
|
||||||
"Client: " + clientWidth + "x" + clientHeight + " " +
|
int imageHeight = image.getOffsetHeight();
|
||||||
"Image: " + imageWidth + "x" + imageHeight + " " +
|
|
||||||
"Target: " + targetWidth + "x" + targetHeight);
|
|
||||||
|
|
||||||
|
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.setVisible(true);
|
||||||
image.setWidth("50%");
|
image.setWidth(widthScalePercent + "%");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -63,11 +54,7 @@ public class FotoStream implements EntryPoint
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught)
|
public void onFailure(Throwable caught)
|
||||||
{
|
{
|
||||||
DialogBox errorMsg = new DialogBox();
|
image.setUrl("img/no_image.png");
|
||||||
|
|
||||||
errorMsg.setTitle("Error loading image");
|
|
||||||
errorMsg.setHTML(caught.getMessage());
|
|
||||||
errorMsg.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -50,6 +50,11 @@ public class CurrentImageURLServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
readImageFiles();
|
readImageFiles();
|
||||||
|
|
||||||
|
if (imageFiles.isEmpty())
|
||||||
|
{
|
||||||
|
return "img/no_image.png";
|
||||||
|
}
|
||||||
|
|
||||||
File latestFile = imageFiles.get(imageFiles.size() - 1);
|
File latestFile = imageFiles.get(imageFiles.size() - 1);
|
||||||
Date latestFileDate = new Date(latestFile.lastModified());
|
Date latestFileDate = new Date(latestFile.lastModified());
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
|
|
||||||
|
body
|
||||||
|
{
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background-color: black;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
div
|
div
|
||||||
{
|
{
|
||||||
padding: 20px;
|
margin: 0;
|
||||||
|
padding: 10px;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
color: green;
|
color: green;
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@
|
||||||
<!-- If you add any GWT meta tags, they must -->
|
<!-- If you add any GWT meta tags, they must -->
|
||||||
<!-- be added before this line. -->
|
<!-- 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>
|
</head>
|
||||||
|
|
||||||
<!-- -->
|
<!-- -->
|
||||||
|
@ -40,7 +40,6 @@
|
||||||
</div>
|
</div>
|
||||||
</noscript>
|
</noscript>
|
||||||
|
|
||||||
<div id="imageContainer"></div>
|
<div id="imageContainer" align="center"></div>
|
||||||
<div id="textContainer"></div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
BIN
war/img/no_image.png
Normal file
BIN
war/img/no_image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 859 B |
Loading…
Reference in a new issue