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 | |
| 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')
5 files changed, 156 insertions, 181 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java index b5ef87d6..4ddec86c 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java @@ -3,11 +3,11 @@ package org.openslx.dozmod.gui.control; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; -import java.awt.SystemColor; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JLabel; +import javax.swing.UIManager; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.util.FormatHelper; @@ -29,9 +29,7 @@ public class PersonLabel extends JLabel { } public PersonLabel(PersonLabelClickEvent cb) { - setForeground(linkColor()); this.callback = cb; - this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -47,7 +45,7 @@ public class PersonLabel extends JLabel { private Color linkColor() { // Create color for links - SystemColor tc = SystemColor.windowText; + Color tc = UIManager.getColor("Label.foreground"); int r = tc.getRed() * tc.getRed(); int g = tc.getGreen() * tc.getGreen(); int b = tc.getBlue() * tc.getBlue(); @@ -79,11 +77,22 @@ public class PersonLabel extends JLabel { */ public void setUser(UserInfo user) { this.user = user; + // Text if (user == null) { - setText(""); + setText(null); } else { setText(FormatHelper.userName(user)); } + // Tooltip, color, cursor + if (user == null || user.eMail == null || user.eMail.isEmpty()) { + setToolTipText(null); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + setForeground(UIManager.getColor("Label.foreground")); + } else { + setToolTipText("Klicken, um eine Mail an diesen Benutzer zu senden"); + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + setForeground(linkColor()); + } } /** diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java index ef0bedef..aa5a679f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java @@ -303,20 +303,30 @@ public class GridManager { /** * Set the expand properties of the element being added. * If multiple components are set to expand, they'll distribute the - * excess space among them. + * excess space among them. This call is equal to {@link #expand(1, 1)} * * @param expandX Assign any remaining horizontal space to this cell * @param expandY Assign any remaining vertical space to this cell * @return This instance, so calls can be chained */ public GBC expand(boolean expandX, boolean expandY) { + return expand(1, 1); + } + + /** + * Set the expand properties of the element being added. + * If multiple components are set to expand, they'll distribute the + * excess space among them, using the given weights. Setting one of the + * values to 0 will disable expanding for that axis. + * + * @param expandX Weight for distribution of remaining horizontal space + * @param expandY Weight for distribution of remaining vertical space + * @return This instance, so calls can be chained + */ + public GBC expand(double expandX, double expandY) { checkValid(); - if (expandX) { - mainConstraints.weightx = 1; - } - if (expandY) { - mainConstraints.weighty = 1; - } + mainConstraints.weightx = expandX; + mainConstraints.weighty = expandY; return this; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index 64060de1..21ee98da 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -106,7 +106,6 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe final PopupMenu pop = new PopupMenu(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource().equals(popupItemNew)) { - // TODO new lecture wizard with this image preset LOGGER.debug("New lecture clicked"); ImageVersionDetails selected = versionTable.getSelectedItem(); if (selected == null) @@ -319,6 +318,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe setVisible(true); } + @SuppressWarnings("deprecation") @Override public void show() { if (!isVisible()) { @@ -358,47 +358,30 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe /** * Checks whether the user changed any fields of the image details and * enables the save button if so. - * */ private void reactToChange() { boolean changed = false; - // Image name: + OperatingSystem newOs = cboOperatingSystem.getItemAt(cboOperatingSystem.getSelectedIndex()); + ShareMode newShareMode = cboShareMode.getItemAt(cboShareMode.getSelectedIndex()); + if (!txtTitle.getText().equals(image.getImageName())) { - LOGGER.debug("Title changed to: " + txtTitle.getText()); changed = true; - } - // Image description: - if (!txtDescription.getText().equals(image.getDescription())) { - LOGGER.debug("Description changed to: " + txtDescription.getText()); + } else if (!txtDescription.getText().equals(image.getDescription())) { changed = true; - } - // OS: - OperatingSystem newOs = cboOperatingSystem.getItemAt(cboOperatingSystem.getSelectedIndex()); - if (newOs != null && newOs.getOsId() != image.getOsId()) { - LOGGER.debug("OS changed to: " + newOs.getOsName()); + } else if (newOs != null && newOs.getOsId() != image.getOsId()) { changed = true; - } - // TODO TAGS - // ShareMode: - ShareMode newShareMode = cboShareMode.getItemAt(cboShareMode.getSelectedIndex()); - if (newShareMode != null && !newShareMode.equals(image.shareMode)) { - LOGGER.debug("ShareMode changed to: " + newShareMode); + } else if (newShareMode != null && !newShareMode.equals(image.shareMode)) { changed = true; - } - // Template: - if (btnIsTemplate.isSelected() != image.isTemplate) { - LOGGER.debug("Template changed to: " + btnIsTemplate.isSelected()); + } else if (btnIsTemplate.isSelected() != image.isTemplate) { changed = true; } + // TODO TAGS btnSaveChanges.setEnabled(changed); - } @Override public boolean wantConfirmQuit() { - // Maybe return true if the user changed one of the fields, but not - // really a priority - return false; + return btnSaveChanges.isEnabled(); } @Override diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java index 60c901b2..16359b32 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java @@ -44,6 +44,7 @@ import org.openslx.dozmod.thrift.Session; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; +import org.openslx.util.Util; import edu.kit.scc.dei.ecplean.ECPAuthenticationException; @@ -57,20 +58,20 @@ public class LoginWindow extends LoginWindowLayout { private final static Logger LOGGER = Logger.getLogger(LoginWindow.class); // TODO This has nothing to to with the layout - public static enum LOGIN_TYPE { + public static enum LoginType { ECP(0), TEST_ACCOUNT(1), DIRECT_CONNECT(2); public final int id; - private LOGIN_TYPE(final int id) { + private LoginType(final int id) { this.id = id; } } // authentication method to use for login attempts - protected LOGIN_TYPE loginType = null; + protected LoginType loginType = null; // text constants private final String NO_USERNAME = "Kein Benutzername angegeben!"; private final String NO_PASSWORD = "Kein Passwort angegeben!"; @@ -86,14 +87,13 @@ public class LoginWindow extends LoginWindowLayout { } }); // first do all listeners stuff - for (final LOGIN_TYPE type : LOGIN_TYPE.values()) { + for (final LoginType type : LoginType.values()) { loginTypes[type.id].setActionCommand(type.toString()); loginTypes[type.id].addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { - idpLabel.setVisible(type == LOGIN_TYPE.ECP); - idpCombo.setVisible(type == LOGIN_TYPE.ECP); + idpCombo.setEnabled(idpCombo.getModel().getSize() != 0 && type == LoginType.ECP); loginType = type; } } @@ -102,18 +102,22 @@ public class LoginWindow extends LoginWindowLayout { // check if we had saved an authentication method String savedAuthMethod = Config.getAuthenticationMethod(); - LOGIN_TYPE savedLoginType; + LoginType savedLoginType; try { - savedLoginType = LOGIN_TYPE.valueOf(savedAuthMethod); + savedLoginType = LoginType.valueOf(savedAuthMethod); } catch (Exception e) { // if no valid LOGIN_TYPE was saved, just enable the BWIDM button - savedLoginType = LOGIN_TYPE.ECP; + savedLoginType = LoginType.ECP; } - if (savedLoginType == LOGIN_TYPE.ECP) { + if (savedLoginType == LoginType.ECP) { // disable login button til the idp list is here loginButton.setEnabled(false); } + // While filling, disable + idpCombo.setEnabled(false); + // Not yet implemented, disable + loginTypes[LoginType.DIRECT_CONNECT.id].setEnabled(false); // enable the corresponding button loginTypes[savedLoginType.id].setSelected(true); loginType = savedLoginType; @@ -123,6 +127,7 @@ public class LoginWindow extends LoginWindowLayout { @Override public void fire() { + Util.sleep(2000); try { // Wait for proxy server init App.waitForInit(); @@ -184,6 +189,21 @@ public class LoginWindow extends LoginWindowLayout { } else { usernameField.requestFocus(); } + + idpCombo.setRenderer(new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList<?> list, Object value, int index, + boolean isSelected, boolean cellHasFocus) { + if (idpCombo.getModel().getSize() == 0) { + value = "Inizialisiere..."; + } else if (value instanceof Organization) { + value = ((Organization) value).getDisplayName(); + } + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + this.setEnabled(idpCombo.isEnabled()); + return this; + } + }); } /** @@ -200,22 +220,10 @@ public class LoginWindow extends LoginWindowLayout { } idpCombo.setModel(new DefaultComboBoxModel<Organization>(orgs.toArray(new Organization[orgs.size()]))); - 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); - if (value instanceof Organization) { - Organization org = (Organization) value; - setText(org.getDisplayName()); - } - return this; - } - }); // now check if we had a saved identity provider String savedOrganizationId = Config.getIdentityProvider(); idpCombo.setSelectedItem(OrganizationCache.find(savedOrganizationId)); - + idpCombo.setEnabled(idpCombo.getModel().getSize() != 0 && loginType == LoginType.ECP); } /** @@ -389,13 +397,22 @@ public class LoginWindow extends LoginWindowLayout { MessageType.ERROR, LOGGER, e); } + @SuppressWarnings("deprecation") + @Override + public void show() { + if (!isVisible()) { + pack(); + MainWindow.centerShell(this); + } + super.show(); + } + /** * Opens the login window */ public static void open(Frame modalParent) { LoginWindow win = new LoginWindow(modalParent); - MainWindow.centerShell(win); win.setVisible(true); } } 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); |
