diff options
author | Jonathan Bauer | 2015-07-27 18:13:25 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-07-27 18:13:25 +0200 |
commit | 2eee1c291f08119d89c844f840f662cf356ca26c (patch) | |
tree | 9b8ff080894c72a8b41ed7a03cdc118321bef197 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java | |
parent | [client] ResourceLoader back to swing (diff) | |
download | tutor-module-2eee1c291f08119d89c844f840f662cf356ca26c.tar.gz tutor-module-2eee1c291f08119d89c844f840f662cf356ca26c.tar.xz tutor-module-2eee1c291f08119d89c844f840f662cf356ca26c.zip |
[client] swingified LoginWindow (no functionality yet! just commented them out for now)
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.java | 216 |
1 files changed, 109 insertions, 107 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 ae665e23..81a4ffce 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,23 +1,27 @@ package org.openslx.dozmod.gui.window.layout; +import java.awt.Color; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Image; + +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JRadioButton; +import javax.swing.JTextField; +import javax.swing.UIManager; +import javax.swing.border.TitledBorder; + 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; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -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 { +public abstract class LoginWindowLayout extends JFrame { private static final Logger LOGGER = Logger.getLogger(LoginWindowLayout.class); @@ -37,18 +41,6 @@ public abstract class LoginWindowLayout extends Composite { // authentication method to use for login attempts protected LOGIN_TYPE loginType = null; - // textfields for the username/password - protected Text usernameText; - protected Text passwordText; - - // ComboBox/label for the IDP - protected final Combo idpCombo; - protected final Label idpText; - - // buttons - protected final Button loginButton; - protected final Button saveUsernameCheck; - protected final Button[] authButtons; private static final String title = "bwSuite - Login"; private static final String authenticationGroupLabel = "Authentifizierungsart"; @@ -59,95 +51,105 @@ public abstract class LoginWindowLayout extends Composite { * @param mainShell * The shell it should be added to */ - public LoginWindowLayout(final Shell mainShell) { - super(mainShell, SWT.NONE); - - // title for composite - mainShell.setText(title); - - // left authentication selection and right loginmask - GridLayout gridLayout = new GridLayout(2, true); - this.setLayout(gridLayout); - - Label titlePicture = new Label(this, SWT.NONE); - titlePicture.setImage(loadImage()); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); - gridData.horizontalAlignment = SWT.CENTER; - titlePicture.setLayoutData(gridData); - - // group for the authentication method. - // groups have borders and a title - Group authGroup = new Group(this, SWT.NONE); - authGroup.setText(authenticationGroupLabel); - gridLayout = new GridLayout(); - gridLayout.numColumns = 1; - authGroup.setLayout(gridLayout); - gridData = new GridData(GridData.FILL, GridData.FILL, false, false); - gridData.heightHint = 150; - authGroup.setLayoutData(gridData); - - // add the authentication method selection buttons - authButtons = new Button[3]; - authButtons[LOGIN_TYPE.ECP.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.ECP.id].setText("Authentifizierung über bwIDM"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.ECP.id].setLayoutData(gridData); - - authButtons[LOGIN_TYPE.TEST_ACCOUNT.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.TEST_ACCOUNT.id].setText("Test-Zugang mit festem Benutzernamen"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.TEST_ACCOUNT.id].setLayoutData(gridData); - - authButtons[LOGIN_TYPE.DIRECT_CONNECT.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.DIRECT_CONNECT.id].setText("Direkte Verbindung zum Satelliten"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.DIRECT_CONNECT.id].setLayoutData(gridData); - - // group for the login mask - final Group loginGroup = new Group(this, SWT.NONE); - loginGroup.setText("Zugangsdaten"); - gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - loginGroup.setLayout(gridLayout); - gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); - gridData.heightHint = 150; - loginGroup.setLayoutData(gridData); - - idpText = new Label(loginGroup, SWT.NONE); - idpText.setText("IdP:"); - - idpCombo = new Combo(loginGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - idpCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - - new Label(loginGroup, SWT.NONE).setText("Benutzername:"); - usernameText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER); - usernameText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - - new Label(loginGroup, SWT.NONE).setText("Passwort:"); - passwordText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD); - passwordText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - // login button - loginButton = new Button(loginGroup, SWT.PUSH); - loginButton.setText("Login"); - saveUsernameCheck = new Button(loginGroup, SWT.CHECK); - saveUsernameCheck.setText("Benutzername speichern"); - + public LoginWindowLayout() { + super(); + setTitle("Simple example"); + setSize(600, 300); + setLocationRelativeTo(null); + setResizable(false); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + GridBagLayout bag = new GridBagLayout(); + GridBagConstraints con = new GridBagConstraints(); + setLayout(bag); + con.fill = GridBagConstraints.BOTH; + con.gridwidth = GridBagConstraints.REMAINDER; + con.weightx = 1; + con.weighty = 1; + JLabel pic = new JLabel(loadImage()); + bag.setConstraints(pic, con); + add(pic); + + // login type panel + JPanel loginTypePanel = new JPanel(); + loginTypePanel.setLayout(new BoxLayout(loginTypePanel, BoxLayout.PAGE_AXIS)); + loginTypePanel.setBorder(new TitledBorder(UIManager + .getBorder("TitledBorder.border"), "Authentifizierungsart", + TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); + // radio button group for login type + ButtonGroup bg = new ButtonGroup(); + JRadioButton radioButtonTest = new JRadioButton("Test-Zugang mit festem Benutzer"); + JRadioButton radioButtonECP = new JRadioButton("Authentifizierung über bwIDM"); + JRadioButton radioButtonSat = new JRadioButton("Direkter Zugang zum Satelliten"); + bg.add(radioButtonTest); + bg.add(radioButtonECP); + bg.add(radioButtonSat); + loginTypePanel.add(radioButtonTest); + loginTypePanel.add(radioButtonECP); + loginTypePanel.add(radioButtonSat); + con.gridwidth = 1; + bag.setConstraints(loginTypePanel, con); + add(loginTypePanel); + + // login form panel + JPanel loginFormPanel = new JPanel(); + GridBagLayout formBag = new GridBagLayout(); + GridBagConstraints formCon = new GridBagConstraints(); + formCon.fill = GridBagConstraints.BOTH; + formCon.gridwidth = 1; + loginFormPanel.setLayout(new BoxLayout(loginFormPanel, BoxLayout.PAGE_AXIS)); + loginFormPanel.setBorder(new TitledBorder(UIManager + .getBorder("TitledBorder.border"), "Authentifizierungsart", + TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); + // label + field for username + JLabel labelUsername = new JLabel("Benutzername:"); + JTextField loginUsernameField = new JTextField(); + loginUsernameField + .setToolTipText("Bitte geben Sie Ihren Benutzernamen ein."); + loginUsernameField.setColumns(10); + formBag.setConstraints(labelUsername, formCon); + formCon.gridwidth = GridBagConstraints.REMAINDER; + formBag.setConstraints(loginUsernameField, formCon); + loginFormPanel.add(labelUsername); + loginFormPanel.add(loginUsernameField); + + loginFormPanel.setLayout(formBag); + // label + field for password + JLabel labelPassword = new JLabel("Passwort:"); + JPasswordField loginPasswordField = new JPasswordField(); + loginPasswordField + .setToolTipText("Bitte geben Sie Ihren Passwort ein."); + loginPasswordField.setColumns(10); + formCon.gridwidth = 1; + formBag.setConstraints(labelPassword, formCon); + loginFormPanel.add(labelPassword); + formCon.gridwidth = GridBagConstraints.REMAINDER; + formBag.setConstraints(loginPasswordField, formCon); + loginFormPanel.add(loginPasswordField); + JButton loginButton = new JButton("Login"); + formCon.gridwidth = 1; + formCon.gridx = 1; + formBag.setConstraints(loginButton, formCon); + loginFormPanel.add(loginButton); + + con.gridwidth = GridBagConstraints.REMAINDER; + bag.setConstraints(loginFormPanel, con); + add(loginFormPanel); } - private Image loadImage() { + private ImageIcon loadImage() { try { - ImageData image = ResourceLoader.getImage("/img/Logo_bwLehrpool.png"); - Rectangle screenSize = Gui.getMonitorFromRectangle(getShell().getBounds(), true).getBounds(); - float scaleX = (float)screenSize.width / (float)image.width; - float scaleY = (float)screenSize.height / (float)image.height; + ImageIcon image = ResourceLoader.getIcon("/img/Logo_bwLehrpool.png"); + java.awt.Rectangle screenSize = getBounds(); + float scaleX = (float)screenSize.width / (float)image.getIconWidth(); + float scaleY = (float)screenSize.height / (float)image.getIconHeight(); 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); + image = new ImageIcon(image.getImage().getScaledInstance((int)(image.getIconWidth() * scaling), (int)(image.getIconHeight()* scaling), 0)); + return image; } catch (Exception e) { LOGGER.warn("Cannot load image", e); } |