diff options
author | Jonathan Bauer | 2015-09-15 17:06:20 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-09-15 17:06:20 +0200 |
commit | 28f84e5923208b3ff32dcd332a1212caf132cf89 (patch) | |
tree | e71ac6d8ca11b1e890493da7bfbbf09cc9401ee2 | |
parent | [client] reworked german text (diff) | |
parent | [client] Shift key for forcing satellite selection now works. (diff) | |
download | tutor-module-28f84e5923208b3ff32dcd332a1212caf132cf89.tar.gz tutor-module-28f84e5923208b3ff32dcd332a1212caf132cf89.tar.xz tutor-module-28f84e5923208b3ff32dcd332a1212caf132cf89.zip |
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
6 files changed, 96 insertions, 42 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index a2e4e859..cee3a587 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -27,6 +27,7 @@ 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.util.ClientVersion; import org.openslx.dozmod.util.ProxyConfigurator; import org.openslx.thrifthelper.ThriftManager; import org.openslx.util.Util; @@ -112,6 +113,10 @@ public class App { } public static void main(final String[] args) { + if (args.length >= 2 && args[0].equals("--json")) { + writeJsonUpdateFile(args[1]); + return; + } try { Config.init(); } catch (Exception e) { @@ -200,6 +205,14 @@ public class App { Util.sleep(1000); } + private static void writeJsonUpdateFile(String destination) { + try { + ClientVersion.createJson(destination); + } catch (IOException e) { + e.printStackTrace(); + } + } + private static void adjustFontSize(int percent) { if (percent == 100 || percent <= 0 || percent > 1000) return; 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 ee3727ab..7a0c1b56 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 877b8fc0..a097ec55 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; } } - - - - + } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java index 8818d558..a3fcee4b 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ClientVersion.java @@ -1,13 +1,19 @@ package org.openslx.dozmod.util; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.jar.Attributes; import java.util.jar.Manifest; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.log4j.Logger; +import org.openslx.sat.thrift.version.Version; import org.openslx.util.Json; // ClientVersion is a bad name, TODO find better suited one :) @@ -29,7 +35,7 @@ public class ClientVersion { localRevision = "???"; } if (remoteRevision == null) { - loadRemoteVersion("http://132.230.4.25/dozmod.version"); + loadRemoteVersion("https://bwlp-masterserver.ruf.uni-freiburg.de/dozmod/" + Version.VERSION + "/version.json"); } if (remoteRevision == null) { remoteRevision = "???"; @@ -190,4 +196,31 @@ public class ClientVersion { String revision; String changelog; } + + public static void createJson(String name) throws IOException { + loadLocalVersion(); + if (localRevisionTime == 0) + throw new RuntimeException("Missing manifest/data in jar: No revision time found"); + if (localRevision == null || localRevision.isEmpty()) + throw new RuntimeException("Missing manifest/data in jar: No commit hash found"); + System.out.println("Please enter change log. To finish, put a '.' on a single line"); + StringBuilder sb = new StringBuilder(); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + for (String line; (line = br.readLine()) != null;) { + if (line.equals(".")) + break; + sb.append(line); + sb.append('\n'); + } + VersionQuery vq = new VersionQuery(); + vq.timestamp = localRevisionTime; + vq.revision = localRevision; + vq.changelog = sb.toString(); + String data = Json.serialize(vq); + FileUtils.writeStringToFile(new File(name), data, StandardCharsets.UTF_8); + System.out.println(); + System.out.println("Created json file at " + name); + System.out.println("This build is using Thrift RPC interface version >> " + Version.VERSION + " <<"); + System.out.println(); + } } |