diff options
author | Jonathan Bauer | 2015-09-01 13:32:09 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-09-01 13:32:09 +0200 |
commit | 0d8bcfac534fdc932fdfbd2090c723f2a39f8156 (patch) | |
tree | 2f124a1b4ae281da08cc769df5ddb8a043054f69 /dozentenmodul | |
parent | [server] Add missing loop to maintenance worker (diff) | |
download | tutor-module-0d8bcfac534fdc932fdfbd2090c723f2a39f8156.tar.gz tutor-module-0d8bcfac534fdc932fdfbd2090c723f2a39f8156.tar.xz tutor-module-0d8bcfac534fdc932fdfbd2090c723f2a39f8156.zip |
[client] ConfigWindow can now be closed with ESC. Added reactToInput() stuff to enable the save button only when needed
Diffstat (limited to 'dozentenmodul')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java | 142 | ||||
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java | 4 |
2 files changed, 128 insertions, 18 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java index ddcf6539..cc9a8965 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java @@ -3,20 +3,37 @@ package org.openslx.dozmod.gui.window; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.Enumeration; + +import javax.swing.AbstractButton; +import javax.swing.ButtonModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.SatelliteUserConfig; import org.openslx.dozmod.Config; import org.openslx.dozmod.Config.ProxyMode; +import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.MainWindow; +import org.openslx.dozmod.gui.helper.MessageType; +import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.layout.ConfigWindowLayout; +import org.openslx.dozmod.thrift.Session; +import org.openslx.dozmod.thrift.ThriftError; +import org.openslx.thrifthelper.ThriftManager; -public class ConfigWindow extends ConfigWindowLayout { +public class ConfigWindow extends ConfigWindowLayout implements UiFeedback { private final static Logger LOGGER = Logger.getLogger(ConfigWindow.class); - + private SatelliteUserConfig userConfig = null; + public ConfigWindow(Frame modalParent) { super(modalParent); + btnSave.setEnabled(false); + // -- PROXY -- // set proxy mode as saved in config switch(Config.getProxyMode()) { case NONE: @@ -30,27 +47,42 @@ public class ConfigWindow extends ConfigWindowLayout { default: break; } - // set mail me stuff as saved in config - btnSendMeMail.setSelected(Config.getMailMe()); + final ActionListener reactiveListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + reactToInput(); + } + }; + btnProxyNone.addActionListener(reactiveListener); + btnProxyAuto.addActionListener(reactiveListener); + // -- END PROXY -- + + // -- SAT USER CONFIG -- + // get the satellite user config and set the checkbox accordingly + userConfig = getSatUserConfig(); + if (userConfig != null) { + btnSendMeMail.setSelected(userConfig.isEmailNotifications()); + } else { + btnSendMeMail.setSelected(false); + } + btnSendMeMail.addActionListener(reactiveListener); + // -- END USER CONFIG -- + + // -- FONT CONFIG -- // set font scaling as saved in config btnFontSize.setValue(Config.getFontScaling()); + btnFontSize.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + reactToInput(); + } + }); + // -- BOTTOM BUTTONS -- btnSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - // save proxy mode to config - ProxyMode selectedMode = null; - if (btnProxyAuto.isSelected()) - selectedMode = ProxyMode.AUTO; - if (btnProxyNone.isSelected()) - selectedMode = ProxyMode.NONE; - if (selectedMode != null) { - Config.setProxyMode(selectedMode); - } - // save mail stuff - Config.setMailMe(btnSendMeMail.isSelected()); - // save font scaling - Config.setFontScaling(btnFontSize.getValue()); + saveOptions(); } }); @@ -60,8 +92,71 @@ public class ConfigWindow extends ConfigWindowLayout { dispose(); } }); + // -- END BOTTOM BUTTONS -- } + private void reactToInput() { + // our flag to en/disable the save button + boolean changed = false; + // first check our initial state + ProxyMode initMode = Config.getProxyMode(); + SatelliteUserConfig userConfig = getSatUserConfig(); + int fontScaling = Config.getFontScaling(); + + // now check if the buttons represent another state + if (btnProxyNone.isSelected() && initMode != ProxyMode.NONE) + changed = true; + else if (btnProxyAuto.isSelected() && initMode != ProxyMode.AUTO) + changed = true; + else if (btnSendMeMail.isSelected() != userConfig.emailNotifications) + changed = true; + else if (btnFontSize.getValue() != fontScaling) + changed = true; + // en/disable the save button + btnSave.setEnabled(changed); + } + private SatelliteUserConfig getSatUserConfig() { + SatelliteUserConfig userConfig = null; + // set mail me stuff as saved on the sat + try { + userConfig = ThriftManager.getSatClient().getUserConfig(Session.getSatelliteToken()); + } catch (TException e) { + ThriftError.showMessage(this, LOGGER, e, "Konnte die benutzerspeizifische Konfiguration nicht vom Satelliten holen!"); + } + return userConfig; + } + private boolean setSatUserConfig(SatelliteUserConfig config) { + if (config == null) + return false; + // set mail me stuff as saved on the sat + try { + ThriftManager.getSatClient().setUserConfig(Session.getSatelliteToken(), config); + } catch (TException e) { + ThriftError.showMessage(this, LOGGER, e, "Konnte die benutzerspeizifische Konfiguration nicht vom Satelliten holen!"); + return false; + } + return true; + } + private void saveOptions() { + btnSave.setEnabled(false); + // save proxy mode to config + ProxyMode selectedMode = null; + if (btnProxyAuto.isSelected()) + selectedMode = ProxyMode.AUTO; + if (btnProxyNone.isSelected()) + selectedMode = ProxyMode.NONE; + if (selectedMode != null) { + Config.setProxyMode(selectedMode); + } + // save mail notification stuff to sat + if (!setSatUserConfig(new SatelliteUserConfig(btnSendMeMail.isSelected()))) { + Gui.showMessageBox(this, "Konnte die Ă„nderung nicht am Satelliten speichern!", MessageType.ERROR, LOGGER, null); + btnSave.setEnabled(true); + return; + } + // save font scaling to config + Config.setFontScaling(btnFontSize.getValue()); + } public static boolean shouldBeShown() { // TODO query Config return true; @@ -72,4 +167,17 @@ public class ConfigWindow extends ConfigWindowLayout { MainWindow.centerShell(win); win.setVisible(true); } + + /* + * UIFeedback Implementation + */ + @Override + public boolean wantConfirmQuit() { + return false; + } + + @Override + public void escapePressed() { + dispose(); + } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java index e52deb69..21838ca0 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java @@ -33,6 +33,8 @@ public class ConfigWindowLayout extends JDialog { protected JButton btnSave; protected JButton btnClose; + protected ButtonGroup radioGroup; + public ConfigWindowLayout(Frame modalParent) { super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); @@ -56,7 +58,7 @@ public class ConfigWindowLayout extends JDialog { // radio button for proxy mode JPanel radioGroupPanel = new JPanel(); - ButtonGroup radioGroup = new ButtonGroup(); + radioGroup = new ButtonGroup(); btnProxyNone = new JRadioButton("Keine"); btnProxyAuto = new JRadioButton("Automatisch"); radioGroup.add(btnProxyNone); |