diff options
author | Simon Rettberg | 2015-08-13 18:18:12 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-13 18:18:12 +0200 |
commit | d4c2981bee1e826d0a0ab49340433988018f66e0 (patch) | |
tree | 71393ac15ceaee72691b0346d9c33a0639ec9243 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java | |
parent | [server] Set updaterid and updatetime when changing owner of image (diff) | |
download | tutor-module-d4c2981bee1e826d0a0ab49340433988018f66e0.tar.gz tutor-module-d4c2981bee1e826d0a0ab49340433988018f66e0.tar.xz tutor-module-d4c2981bee1e826d0a0ab49340433988018f66e0.zip |
[client] More layout tweaks, cleanups, GridManager usage
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 | 192 |
1 files changed, 74 insertions, 118 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 3fa8d55a..8c0b5605 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,10 +1,11 @@ package org.openslx.dozmod.gui.window.layout; -import java.awt.Color; +import java.awt.BorderLayout; import java.awt.Component; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.Rectangle; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; @@ -14,21 +15,21 @@ import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; 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.openslx.bwlp.thrift.iface.Organization; import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.util.ResourceLoader; +@SuppressWarnings("serial") public abstract class LoginWindowLayout extends JDialog { private static final Logger LOGGER = Logger.getLogger(LoginWindowLayout.class); @@ -49,27 +50,19 @@ public abstract class LoginWindowLayout extends JDialog { // authentication method to use for login attempts protected LOGIN_TYPE loginType = null; - private static final String TITLE = "bwSuite - Login"; private static final String AUTH_TYPE_LABEL = "Authentifizierungsart"; private static final String LOGIN_FORM_LABEL = "Zugangsdaten"; // login type panel - protected JPanel loginTypePanel; - protected ButtonGroup loginTypeButtonGroup; protected JRadioButton[] loginTypes = new JRadioButton[3]; - // login form panel - protected JLabel idpLabel; - protected JComboBox<Organization> idpCombo; - protected JTextField usernameField; - protected JPasswordField passwordField; - protected JCheckBox saveUsernameCheck; - protected JButton loginButton; - - - + protected final JComboBox<Organization> idpCombo; + protected final JTextField usernameField; + protected final JPasswordField passwordField; + protected final JCheckBox saveUsernameCheck; + protected final JButton loginButton; /** * Create a new login composite @@ -77,130 +70,93 @@ public abstract class LoginWindowLayout extends JDialog { * @param mainShell * The shell it should be added to */ - @SuppressWarnings("serial") public LoginWindowLayout(Frame modalParent) { super(modalParent, TITLE, ModalityType.APPLICATION_MODAL); - setResizable(false); - 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(getScaledLogo()); - bag.setConstraints(pic, con); - add(pic); - - loginTypePanel = new JPanel(); - loginTypePanel.setLayout(new BoxLayout(loginTypePanel, BoxLayout.PAGE_AXIS)); - loginTypePanel.setBorder(new TitledBorder(UIManager - .getBorder("TitledBorder.border"), AUTH_TYPE_LABEL, - TitledBorder.LEADING, TitledBorder.TOP, null, Color.WHITE)); - loginTypeButtonGroup = new ButtonGroup() { - - }; - - loginTypes[0] = new JRadioButton("Authentifizierung über bwIDM"); - loginTypes[1] = new JRadioButton("Test-Zugang mit festem Benutzer"); - loginTypes[2] = new JRadioButton("Direkter Zugang zum Satelliten"); - for (int i = 0; i < loginTypes.length; i++) { - loginTypeButtonGroup.add(loginTypes[i]); - loginTypePanel.add(loginTypes[i]); - } - - con.gridwidth = 1; - bag.setConstraints(loginTypePanel, con); - add(loginTypePanel); + setResizable(false); + + GridManager grid = new GridManager(this, 2); + + grid.add(new JLabel(getScaledLogo()), 2); + grid.nextRow(); + + loginTypes[0] = new JRadioButton("Authentifizierung über bwIDM"); + loginTypes[1] = new JRadioButton("Test-Zugang mit festem Benutzer"); + loginTypes[2] = new JRadioButton("Direkter Zugang zum Satelliten"); + + idpCombo = new JComboBox<Organization>(); + usernameField = new JTextField(); + passwordField = new JPasswordField(); + loginButton = new JButton("Login"); + saveUsernameCheck = new JCheckBox("Benutzername speichern"); + + grid.add(makeLoginTypePanel()).expand(0.25, 1).fill(true, true); + grid.add(makeLoginFormPanel()).expand(0.75, 1).fill(true, true); + grid.nextRow(); + + grid.finish(true); + + } + + private JPanel makeLoginFormPanel() { // 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"), LOGIN_FORM_LABEL, - TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 255, 255))); - idpLabel = new JLabel("Identity Provider:"); - formBag.setConstraints(idpLabel, formCon); - loginFormPanel.add(idpLabel); - idpCombo = new JComboBox<Organization>(); - idpCombo.setRenderer(new DefaultListCellRenderer() { - @Override - public Component getListCellRendererComponent(JList<?> list, - Object value, int index, boolean isSelected, - boolean cellHasFocus) { - super.getListCellRendererComponent(list, value, index, - isSelected, cellHasFocus); - setText("Initialisiere..."); - return this; - } - }); - formCon.gridwidth = GridBagConstraints.REMAINDER; - formBag.setConstraints(idpCombo, formCon); - loginFormPanel.add(idpCombo); + loginFormPanel.setBorder(new TitledBorder(LOGIN_FORM_LABEL)); + GridManager grid = new GridManager(loginFormPanel, 2); + + grid.add(new JLabel("Identity Provider")); + grid.add(idpCombo).expand(true, false).fill(true, false); + grid.nextRow(); // label + field for username - JLabel labelUsername = new JLabel("Benutzername:"); - usernameField = new JTextField(); - usernameField.setToolTipText("Bitte geben Sie Ihren Benutzernamen ein."); - usernameField.setColumns(10); - formCon.gridwidth = 1; - formBag.setConstraints(labelUsername, formCon); - formCon.gridwidth = GridBagConstraints.REMAINDER; - formBag.setConstraints(usernameField, formCon); - loginFormPanel.add(labelUsername); - loginFormPanel.add(usernameField); - loginFormPanel.setLayout(formBag); + grid.add(new JLabel("Benutzername")); + grid.add(usernameField).expand(true, false).fill(true, false); + grid.nextRow(); // label + field for password - JLabel labelPassword = new JLabel("Passwort:"); - passwordField = new JPasswordField(); - passwordField.setToolTipText("Bitte geben Sie Ihren Passwort ein."); - passwordField.setColumns(10); - formCon.gridwidth = 1; - formBag.setConstraints(labelPassword, formCon); - loginFormPanel.add(labelPassword); - formCon.gridwidth = GridBagConstraints.REMAINDER; - formBag.setConstraints(passwordField, formCon); - loginFormPanel.add(passwordField); - loginButton = new JButton("Login"); - formCon.gridwidth = 1; - formCon.gridx = 1; - formBag.setConstraints(loginButton, formCon); - loginFormPanel.add(loginButton); - saveUsernameCheck = new JCheckBox("Benutzername speichern"); - formCon.gridwidth = 1; - formCon.gridx = 2; - formBag.setConstraints(saveUsernameCheck, formCon); - loginFormPanel.add(saveUsernameCheck); - - // finally add the form itself to the main panel - con.gridwidth = GridBagConstraints.REMAINDER; - bag.setConstraints(loginFormPanel, con); - add(loginFormPanel); - pack(); - validate(); + grid.add(new JLabel("Passwort")); + grid.add(passwordField).expand(true, false).fill(true, false); + grid.nextRow(); + + grid.add(loginButton); + grid.add(saveUsernameCheck); + grid.nextRow(); + grid.finish(true); + return loginFormPanel; + } + + private JPanel makeLoginTypePanel() { + JPanel loginTypePanel = new JPanel(); + loginTypePanel.setLayout(new BoxLayout(loginTypePanel, BoxLayout.PAGE_AXIS)); + loginTypePanel.setBorder(new TitledBorder(AUTH_TYPE_LABEL)); + ButtonGroup loginTypeButtonGroup = new ButtonGroup(); + for (int i = 0; i < loginTypes.length; i++) { + loginTypeButtonGroup.add(loginTypes[i]); + loginTypePanel.add(loginTypes[i]); + } + return loginTypePanel; } /** - * @return ImageIcon of the standard bwLehrpool logo scaled to the login window size + * @return ImageIcon of the standard bwLehrpool logo scaled to the login + * window size */ private ImageIcon getScaledLogo() { try { ImageIcon image = ResourceLoader.getIcon("/img/Logo_bwLehrpool.png"); - java.awt.Rectangle screenSize = Gui.getMonitorFromRectangle(getBounds(), true).getDefaultConfiguration().getBounds(); - float scaleX = (float)screenSize.width / (float)image.getIconWidth(); - float scaleY = (float)screenSize.height / (float)image.getIconHeight(); + Rectangle screenSize = Gui.getMonitorFromRectangle(getBounds(), true) + .getDefaultConfiguration() + .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 = new ImageIcon(image.getImage().getScaledInstance((int)(image.getIconWidth() * scaling), (int)(image.getIconHeight()* scaling), 0)); + 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); |