summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-15 12:36:39 +0200
committerSimon Rettberg2015-07-15 12:36:39 +0200
commitf252e675d84ec171f0d4e1267db2776d4705debc (patch)
treeec20bf0a9afba55bdf088c5100e6742f1380f575 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
parent[client] Clean up SWT resources when exiting (diff)
downloadtutor-module-f252e675d84ec171f0d4e1267db2776d4705debc.tar.gz
tutor-module-f252e675d84ec171f0d4e1267db2776d4705debc.tar.xz
tutor-module-f252e675d84ec171f0d4e1267db2776d4705debc.zip
[client] Fix getImage from ResourceLoader; use it in LoginWindow
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java38
1 files changed, 21 insertions, 17 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
index 544e84bb..cc6f57b9 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
@@ -1,8 +1,10 @@
package org.openslx.dozmod.gui.window.layout;
+import org.apache.log4j.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -13,9 +15,12 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.util.ResourceLoader;
public abstract class LoginWindowLayout extends Composite {
+ private static final Logger LOGGER = Logger.getLogger(LoginWindowLayout.class);
+
// TODO This has nothing to to with the layout
protected static enum LOGIN_TYPE {
ECP(0),
@@ -32,8 +37,6 @@ public abstract class LoginWindowLayout extends Composite {
// authentication method to use for login attempts
protected LOGIN_TYPE loginType = null;
- private Image titleImage;
-
// textfields for the username/password
protected Text usernameText;
protected Text passwordText;
@@ -66,11 +69,8 @@ public abstract class LoginWindowLayout extends Composite {
GridLayout gridLayout = new GridLayout(2, true);
this.setLayout(gridLayout);
- // load the needed Picture
- loadImage();
-
Label titlePicture = new Label(this, SWT.NONE);
- titlePicture.setImage(titleImage);
+ titlePicture.setImage(loadImage());
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = SWT.CENTER;
@@ -135,19 +135,23 @@ public abstract class LoginWindowLayout extends Composite {
}
- private void loadImage() {
+ private Image loadImage() {
try {
- // TODO use the ResourceLoader class to load the logo
- // this way, we can be sure to get an image
- // (since the ResourceLoader always returns an image,
- // even if it cannot load the specified one).
- titleImage = new Image(Gui.display, getClass().getResourceAsStream("/img/Logo_bwLehrpool.png"));
- ImageData imgData = titleImage.getImageData();
- imgData = imgData.scaledTo(imgData.width / 5, imgData.height / 5);
- titleImage = new Image(Gui.display, imgData);
+ ImageData image = ResourceLoader.getImage("/img/Logo_bwLehrpool.png");
+ Rectangle screenSize = Gui.getMonitorFromRectangle(getShell().getBounds(), true).getClientArea();
+ float scaleX = (float)screenSize.width / (float)image.width;
+ float scaleY = (float)screenSize.height / (float)image.height;
+ final float scaling;
+ if (scaleX < scaleY) {
+ scaling = scaleX / 2;
+ } else {
+ scaling = scaleY / 2;
+ }
+ image = image.scaledTo((int)(image.width * scaling), (int)(image.height * scaling));
+ return new Image(Gui.display, image);
} catch (Exception e) {
- System.out.println("Cannot load image");
- System.out.println(e.getMessage());
+ LOGGER.warn("Cannot load image", e);
}
+ return null;
}
}