diff options
| author | Stephan Schwaer | 2015-06-22 14:12:05 +0200 |
|---|---|---|
| committer | Stephan Schwaer | 2015-06-22 14:12:05 +0200 |
| commit | 61c822f7c39e6197b64a154ab2c6d1a484c847c4 (patch) | |
| tree | e296f6815f97ffd6eb78eb385be4609086fe0fcd /dozentenmodul/src/main/java/gui | |
| parent | Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff) | |
| download | tutor-module-61c822f7c39e6197b64a154ab2c6d1a484c847c4.tar.gz tutor-module-61c822f7c39e6197b64a154ab2c6d1a484c847c4.tar.xz tutor-module-61c822f7c39e6197b64a154ab2c6d1a484c847c4.zip | |
Added GUI for Login
Diffstat (limited to 'dozentenmodul/src/main/java/gui')
| -rw-r--r-- | dozentenmodul/src/main/java/gui/GuiManager.java | 87 | ||||
| -rw-r--r-- | dozentenmodul/src/main/java/gui/core/LoginComposite.java | 175 |
2 files changed, 245 insertions, 17 deletions
diff --git a/dozentenmodul/src/main/java/gui/GuiManager.java b/dozentenmodul/src/main/java/gui/GuiManager.java index 41d5c711..d3904238 100644 --- a/dozentenmodul/src/main/java/gui/GuiManager.java +++ b/dozentenmodul/src/main/java/gui/GuiManager.java @@ -1,31 +1,84 @@ package gui; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; public abstract class GuiManager { + static Shell mainShell; + static Composite contentComposite; + static Display display; - private static Display _display; - private static Shell _mainShell; - private static Shell _containerShell; + /** + * Add a new composite with content to the main Shell + * @param The composite to add, should be a GUI + */ + public static void addContent( Composite contentComposite ){ + removeContent(); + + GuiManager.contentComposite = contentComposite; + mainShell.layout(); + + } + + /** + * Remove the current content of the main shell + */ + private static void removeContent() { + if(contentComposite != null) { + GuiManager.contentComposite.dispose(); + + } + System.out.println(mainShell.toString()); + } + + + public static Display getDisplay(){ + return display; + } + public static void initGui() { - // init display, shell - _display = new Display(); - _mainShell = new Shell(_display); + display = new Display(); + mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER); + + Menu menuBar = new Menu(mainShell, SWT.BAR); + MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE); + cascadeFileMenu.setText("&File"); + + Menu fileMenu = new Menu(mainShell, SWT.DROP_DOWN); + cascadeFileMenu.setMenu(fileMenu); + + MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH); + exitItem.setText("&Exit"); + exitItem.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + mainShell.getDisplay().dispose(); + System.exit(0); + } + }); + + mainShell.setText("Dozmod"); + mainShell.setMenuBar(menuBar); + mainShell.setLayout(new FillLayout()); + + addContent(new gui.core.LoginComposite(mainShell)); + - // add static gui elements - _containerShell = _mainShell; + mainShell.pack(); + mainShell.open(); - // pack (aka size widgets) and open - _mainShell.pack(); - _mainShell.open(); - // main loop - while (!_mainShell.isDisposed()) { - if (!_display.readAndDispatch()) - _display.sleep(); + while (!mainShell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); } - _display.dispose(); } -}
\ No newline at end of file +} diff --git a/dozentenmodul/src/main/java/gui/core/LoginComposite.java b/dozentenmodul/src/main/java/gui/core/LoginComposite.java new file mode 100644 index 00000000..38449b2f --- /dev/null +++ b/dozentenmodul/src/main/java/gui/core/LoginComposite.java @@ -0,0 +1,175 @@ +package gui.core; +import gui.GuiManager; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +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; + + +public class LoginComposite extends Composite { + + private Image _titleImage; + private Text _usernameText; + private Text _passwordText; + /** + * Create a new login composite + * @param mainShell The shell it should be added to + + */ + public LoginComposite(final Shell mainShell) { + super(mainShell, SWT.NO_BACKGROUND); + mainShell.setText("Dozmod - Login"); + + // Left authentication selection and right loginmask + GridLayout gridLayout = new GridLayout(2, true); + this.setLayout(gridLayout); + + //Load the needed Picture + loadImage(); + + Label titlePicture = new Label(this, SWT.NONE); + titlePicture.setImage(_titleImage); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + gridData.horizontalSpan = 2; + gridData.horizontalAlignment = SWT.CENTER; + titlePicture.setLayoutData(gridData); + + // Group for the authentication method. + Group authGroup = new Group(this, SWT.NONE); + authGroup.setText("Authentifizierungsart"); + gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + authGroup.setLayout(gridLayout); + gridData = new GridData(GridData.FILL, GridData.CENTER, false, false); + gridData.heightHint = 150; + authGroup.setLayoutData(gridData); + + // Add the radio buttons + Button[] authButtons = new Button[3]; + + authButtons[0] = new Button(authGroup, SWT.RADIO); + authButtons[0].setSelection(true); + authButtons[0].setText("Authentifizierung über bwIDM"); + + authButtons[1] = new Button(authGroup, SWT.RADIO); + authButtons[1].setText("Test-Zugang mit festem Benutzernamen"); + + authButtons[2] = new Button(authGroup, SWT.RADIO); + authButtons[2].setText("Direkte Verbindung zum Satteliten"); + + + // 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); + + + final Label IdPText = new Label(loginGroup, SWT.NONE); + IdPText.setText("IdP:"); + + + final Combo IdPCombo = new Combo(loginGroup, SWT.DROP_DOWN | SWT.READ_ONLY); + + + IdPCombo.add("Ubuntu"); + IdPCombo.add("Fedora"); + IdPCombo.add("Mandriva"); + IdPCombo.add("Red Hat"); + IdPCombo.add("Mint"); + + + + 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); + _passwordText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + Button loginButton = new Button(loginGroup, SWT.PUSH); + loginButton.setText("Login"); + Button saveUsernameCheck = new Button(loginGroup, SWT.CHECK); + saveUsernameCheck.setText("Benutzername speichern"); + + // Actions of the login button + loginButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + System.out.println("BAM!"); + //loginComposite.dispose(); + mainShell.setText("Login?"); + + + } + }); + + // For save username checkbox. + saveUsernameCheck.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + System.out.println("Checkboxtoggle"); + } + }); + + // Selecting the "Authentifizierung über bwIDM" radio button + authButtons[0].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + IdPText.setVisible(true); + IdPCombo.setVisible(true); + } + }); + + // Selecting the "Test-Zugang über bwIDM" radio button + authButtons[1].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + IdPText.setVisible(false); + IdPCombo.setVisible(false); + + } + }); + + authButtons[2].setEnabled(false); + // Selecting the "Direkte Verbindung zum Satteliten" radio button + authButtons[2].addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + IdPText.setVisible(false); + IdPCombo.setVisible(false); + } + }); + } + + + + private void loadImage(){ + try { + _titleImage = new Image(GuiManager.getDisplay() , "resources/Logo_bwLehrpool.png"); + ImageData imgData = _titleImage.getImageData(); + imgData = imgData.scaledTo(imgData.width/5, imgData.height/5); + _titleImage = new Image(GuiManager.getDisplay(), imgData); + } catch (Exception e) { + System.out.println("Cannot load image"); + System.out.println(e.getMessage()); + } + } + + +} |
