diff options
| author | Stephan Schwaer | 2015-09-15 15:26:09 +0200 |
|---|---|---|
| committer | Stephan Schwaer | 2015-09-15 15:26:09 +0200 |
| commit | d431d34a8f23edebdde097a519732cef1ac1ee02 (patch) | |
| tree | 6d8b612bac52a0c6f26dc83f2cf13d9217037cb7 /dozentenmodul/src/main/java | |
| parent | [client] Put real update url in place (diff) | |
| download | tutor-module-d431d34a8f23edebdde097a519732cef1ac1ee02.tar.gz tutor-module-d431d34a8f23edebdde097a519732cef1ac1ee02.tar.xz tutor-module-d431d34a8f23edebdde097a519732cef1ac1ee02.zip | |
[client] Shift key for forcing satellite selection now works.
Diffstat (limited to 'dozentenmodul/src/main/java')
4 files changed, 49 insertions, 41 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java index faa08038..19a8640a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -192,24 +192,7 @@ public abstract class MainWindow { } }); - KeyEventDispatcher satelliteShiftDispatcher = new KeyEventDispatcher() { - // TODO Fix to register shift key - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - int type = event.getID(); - int code = event.getKeyChar(); - LOGGER.info("SHIFT!: " + " type: " + type + " code: " + code); - if (code == KeyEvent.VK_SHIFT) { // ESC or Ctrl-W closes current window - if (type == KeyEvent.KEY_PRESSED) { - ThriftActions.forceCustomSattelite = true; - } else if ( type == KeyEvent.KEY_RELEASED) - ThriftActions.forceCustomSattelite = false; - event.consume(); - } - return event.isConsumed(); - } - }; - KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(satelliteShiftDispatcher); + // Set layout for the mainshell, items added to the shell should get a gridData mainContainer.setLayout(new BoxLayout(mainContainer, BoxLayout.PAGE_AXIS)); 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 0dfae7cf..1874a7b6 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 @@ -1,6 +1,8 @@ package org.openslx.dozmod.gui.window; import java.awt.Frame; +import java.awt.KeyEventDispatcher; +import java.awt.KeyboardFocusManager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; @@ -20,7 +22,6 @@ import javax.swing.SwingUtilities; import org.apache.log4j.Logger; import org.apache.thrift.TBaseHelper; import org.apache.thrift.TException; -import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Organization; import org.openslx.bwlp.thrift.iface.Satellite; import org.openslx.dozmod.App; @@ -41,7 +42,6 @@ import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.Sorters; import org.openslx.dozmod.thrift.ThriftActions; import org.openslx.dozmod.thrift.ThriftError; -import org.openslx.dozmod.thrift.cache.MetaDataCache; import org.openslx.dozmod.thrift.cache.OrganizationCache; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; @@ -74,6 +74,23 @@ public class LoginWindow extends LoginWindowLayout { // text constants private final String NO_USERNAME = "Kein Benutzername angegeben!"; private final String NO_PASSWORD = "Kein Passwort angegeben!"; + + public static boolean forceCustomSatellite; + private final KeyEventDispatcher satelliteShiftDispatcher = new KeyEventDispatcher() { + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + int type = event.getID(); + int code = event.getKeyCode(); + if (code == KeyEvent.VK_SHIFT) { // shift key is pressed + if (type == KeyEvent.KEY_PRESSED) { + forceCustomSatellite = true; + } else if ( type == KeyEvent.KEY_RELEASED) + forceCustomSatellite = false; + event.consume(); + } + return event.isConsumed(); + } + }; public LoginWindow(Frame modalParent) { // call the constructor of the superclass @@ -154,6 +171,8 @@ public class LoginWindow extends LoginWindowLayout { } }); + KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(satelliteShiftDispatcher); + loginButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -372,6 +391,9 @@ public class LoginWindow extends LoginWindowLayout { Config.saveCurrentSession(Session.getSatelliteAddress(), Session.getSatelliteToken(), Session.getMasterToken()); } + // Remove the listener for the shift key. (For forcing the satellite selection) + KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(satelliteShiftDispatcher); + dispose(); return; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java index ede91a12..8ab78823 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java @@ -17,6 +17,9 @@ import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.gui.window.layout.SatelliteListWindowLayout; +/** + * Window for selecting an available satellite or setting custom ip. + */ @SuppressWarnings("serial") public class SatelliteListWindow extends SatelliteListWindowLayout implements UiFeedback { @@ -28,26 +31,28 @@ public class SatelliteListWindow extends SatelliteListWindowLayout implements Ui public void userAdded(UserInfo user, SatelliteListWindow window); } + /** + * Don't use this, use the static function open instead. + */ public SatelliteListWindow(final Window modalParent, List<Satellite> satList) { super(modalParent); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - + if (satList != null && !satList.isEmpty()){ satelliteTable.setData(satList, true); radioSatelliteTable.setSelected(true); customIpField.setEnabled(false); + satelliteTable.setSelectedItem(satelliteTable.getModelRow(0)); } else { radioSatelliteTable.setEnabled(false); radioCustomIp.setSelected(true); } - - radioCustomIp.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { satelliteTable.setEnabled(false); - customIpField.setEnabled(true); + customIpField.setEnabled(true); satelliteTable.clearSelection(); } }); @@ -57,13 +62,14 @@ public class SatelliteListWindow extends SatelliteListWindowLayout implements Ui public void actionPerformed(ActionEvent arg0) { satelliteTable.setEnabled(true); customIpField.setEnabled(false); + satelliteTable.setSelectedItem(satelliteTable.getModelRow(0)); } }); exitButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if(radioSatelliteTable.isSelected()) + if(radioSatelliteTable.isSelected() && satelliteTable.getSelectedItem() != null) satellite = satelliteTable.getSelectedItem(); else { satellite = new Satellite(); @@ -94,7 +100,7 @@ public class SatelliteListWindow extends SatelliteListWindowLayout implements Ui * * @param modalParent * @param satList The list of satellites to display. - * @return satellite with adress to use. + * @return satellite with address to use. */ public static Satellite open(Window modalParent, List<Satellite> satList) { SatelliteListWindow win = new SatelliteListWindow( modalParent, satList ); @@ -111,5 +117,5 @@ public class SatelliteListWindow extends SatelliteListWindowLayout implements Ui public void escapePressed() { } - + } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java index 88dc755b..931802cb 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftActions.java @@ -46,6 +46,7 @@ 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.QFileChooser; +import org.openslx.dozmod.gui.window.LoginWindow; import org.openslx.dozmod.gui.window.SatelliteListWindow; import org.openslx.dozmod.thrift.cache.ImageCache; import org.openslx.dozmod.thrift.cache.LectureCache; @@ -63,12 +64,11 @@ import org.openslx.util.vm.DiskImage; import org.openslx.util.vm.DiskImage.UnknownImageFormatException; public class ThriftActions { - + private static final Logger LOGGER = Logger.getLogger(ThriftActions.class); private static final long SIZE_CHECK_EXTRA_DL = 50l * 1024l * 1024l; private static final long SIZE_CHECK_EXTRA_UL = 150l * 1024l * 1024l; - - public static boolean forceCustomSattelite = false; + /* ******************************************************************************* * @@ -112,12 +112,11 @@ public class ThriftActions { // TODO: Show list if > 1 // Satellite sat = data.satellites.get(0); Satellite sat = null; - LOGGER.info(forceCustomSattelite); - if (data.satellites.size() == 1 && !forceCustomSattelite) + if (data.satellites.size() == 1 && !LoginWindow.forceCustomSatellite) sat = data.satellites.get(0); else sat = SatelliteListWindow.open(window , data.satellites); - + if (sat.addressList == null || sat.addressList.isEmpty()) { // TODO: Ask for manual IP address entry Gui.asyncMessageBox( @@ -128,6 +127,7 @@ public class ThriftActions { address = sat.addressList.get(0); satToken = data.satelliteToken; masterToken = data.masterToken; + } // try to get a new client client = ThriftManager.getNewSatelliteClient(GraphicalCertHandler.getSslContext(address), address, @@ -160,7 +160,7 @@ public class ThriftActions { Gui.asyncMessageBox( "Authentifizierung erfolgreich, der Satellit verweigert jedoch die Verbindung.\n\n" + "Grund: " + e.number.toString() + " (" + e.message + ")", - MessageType.ERROR, null, null); + MessageType.ERROR, null, null); } return false; } catch (TInvocationException e) { @@ -352,7 +352,7 @@ public class ThriftActions { hashGen = new AsyncHashGenerator(transferInformation.token, diskFile); hashGen.start(); Util.sleep(50);// A little ugly... Give the hash generator a head - // start + // start } catch (FileNotFoundException | NoSuchAlgorithmException e) { Gui.showMessageBox(frame, "Kann keine Block-Hashes für den Upload berechnen, " + "automatische Fehlerkorrektur deaktiviert.", MessageType.WARNING, LOGGER, e); @@ -362,7 +362,7 @@ public class ThriftActions { uploadThread.setDaemon(true); uploadThread.start(); do { // Even more ugly - block the GUI thread so we know whether the - // upload started, and only then switch to the next page + // upload started, and only then switch to the next page Util.sleep(5); } while (uploadTask.getFailCount() == 0 && uploadTask.getTransferCount() == 0 && !uploadTask.isCanceled()); @@ -541,7 +541,7 @@ public class ThriftActions { Gui.asyncMessageBox( "Zur heruntergeladenen VM konnte keine vmx-Datei angelegt werden." + "\nSie können versuchen, das Abbild manuell in den VMWare-Player zu importieren.", - MessageType.WARNING, LOGGER, e); + MessageType.WARNING, LOGGER, e); } } }); @@ -1146,8 +1146,5 @@ public class ThriftActions { this.hasher = hasher; } } - - - - + } |
