summaryrefslogblamecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
blob: c31f4f8298ab454d732a6c9f939c5e90ad90f2c8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                             
 








                                   
                           








                                       
                               
                                  
                                              
 
                                                         
 

                                                                                       
                                                      
                                          


                                  
 
                                    
 
                                                  
                                     
                 
         
 

                                                          
 
 
                                                              
                                                                                       
 

                                       
           
                           
                                                     
           


                                    

                                    
                                                       











































































                                                                                                         
                       
         
 
                                       
                     
                                                                                             
                                                                                                                                             

                                                                                               





                                                     

                                                                                                                                                                   
                                       
                                                            
                 
                            
         
 
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.JDialog;
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.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.util.ResourceLoader;

public abstract class LoginWindowLayout extends JDialog {

	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),
		TEST_ACCOUNT(1),
		DIRECT_CONNECT(2);

		public final int id;

		private LOGIN_TYPE(final int id) {
			this.id = id;
		}
	}

	// authentication method to use for login attempts
	protected LOGIN_TYPE loginType = null;


	private static final String title = "bwSuite - Login";
	private static final String authenticationGroupLabel = "Authentifizierungsart";

	/**
	 * Create a new login composite
	 * 
	 * @param mainShell
	 *            The shell it should be added to
	 */
	public LoginWindowLayout() {
		super();
    	setTitle("Simple example");
    	setLocationRelativeTo(null);
    	setResizable(false);
    	setDefaultCloseOperation(JFrame.HIDE_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);
		pack();
	}

	private ImageIcon loadImage() {
		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();
			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));
			return image;
		} catch (Exception e) {
			LOGGER.warn("Cannot load image", e);
		}
		return null;
	}
}