diff options
author | Jonathan Bauer | 2016-09-07 17:09:16 +0200 |
---|---|---|
committer | Jonathan Bauer | 2016-09-07 17:09:16 +0200 |
commit | 54c0a813587a33a41da49e320548f2ce5bdd8b0c (patch) | |
tree | f862a7ad71c810d64a25766654d7c62971ff5a4d /dozentenmodul/src/main/java/org/openslx/dozmod/gui/control | |
parent | [client] reformulate "interpreter" to "extension" (diff) | |
download | tutor-module-54c0a813587a33a41da49e320548f2ce5bdd8b0c.tar.gz tutor-module-54c0a813587a33a41da49e320548f2ce5bdd8b0c.tar.xz tutor-module-54c0a813587a33a41da49e320548f2ce5bdd8b0c.zip |
[client] fix the save button for the first time ever!!!
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/control')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RunscriptConfigurator.java | 94 |
1 files changed, 50 insertions, 44 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RunscriptConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RunscriptConfigurator.java index ac0f282a..d3935b62 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RunscriptConfigurator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/RunscriptConfigurator.java @@ -1,5 +1,6 @@ package org.openslx.dozmod.gui.control; +import java.awt.Color; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -11,7 +12,7 @@ import java.io.StringReader; import java.util.EventListener; import java.util.EventObject; -import javax.swing.BorderFactory; +import javax.swing.Box; import javax.swing.DefaultComboBoxModel; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -75,31 +76,38 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { }); } + private void setError(final String msg) { + lblError.setText(msg); + } /** * Gets the runscript as String. The chosen interpreter will get encoded as * the first line of the script. * - * @return runscript as String. If not text was entered, returns a empty + * @return runscript as String. If no text was entered, returns a empty * string. */ public String getState() { - String input = taRunScript.getText(); - if (input == null) - return ""; - + setError(""); // fill remove any prior errors, we'll reset them if needed // handle user input, this is tricky since // * either an item has been selected -> editorContent will be of our enum type // * user typed its own interpreter into the box -> editorContent will be a castable String - String interpreter = ""; - Object editorContent = cboRunscriptType.getEditor().getItem(); - if (editorContent instanceof RunscriptType) - interpreter = ((RunscriptType) editorContent).extension; - else if (input instanceof String) - interpreter = (String) editorContent; - else + String extension = null; + Object cboContent = cboRunscriptType.getEditor().getItem(); + if (cboContent instanceof RunscriptType) { + extension = ((RunscriptType) cboContent).extension; + } else if (cboContent instanceof String) { + extension = (String) cboContent; + } + String taInputText = taRunScript.getText(); + if (taInputText.isEmpty()) return ""; - - return "ext=" + interpreter + "\n" + input; + if (extension == null || extension.isEmpty()) { + // this should never happen, so return null to report this invalid state + setError("Fehlende Dateinamenerweiterung!"); + return null; + } + setError(""); + return "ext=" + extension + "\n" + taInputText; } /** @@ -111,33 +119,34 @@ public class RunscriptConfigurator extends RunscriptConfiguratorLayout { * AdvancedConfiguration to set the state to */ public void setState(final String config) { - String shebang = null; - if (config == null) { + if (config == null || config.isEmpty()) { cboRunscriptType.setSelectedItem(null); taRunScript.setText(""); + return; } + String extensionHeader = null; try { BufferedReader reader = new BufferedReader(new StringReader(config)); - shebang = reader.readLine(); + extensionHeader = reader.readLine(); reader.close(); } catch (IOException e) { // swallow ... } - if (shebang != null) { + if (extensionHeader != null) { // we should have following format: ext=<interpreter> // e.g. ext=sh - shebang = shebang.replace("ext=", ""); + extensionHeader = extensionHeader.replace("ext=", ""); for (RunscriptType type : RunscriptType.values()) { - if (type.extension.equals(shebang)) { + if (type.extension.equals(extensionHeader)) { cboRunscriptType.setSelectedItem(type); // mark that we found it by nulling the shebang... - shebang = null; + extensionHeader = null; continue; } } - if (shebang != null) { + if (extensionHeader != null) { // user specific shebang, so just write the text to the cbo - cboRunscriptType.getEditor().setItem(shebang); + cboRunscriptType.getEditor().setItem(extensionHeader); } } // finished with the interpreter, remove that line from the given config @@ -197,31 +206,23 @@ class RunscriptConfiguratorLayout extends JPanel { private static final long serialVersionUID = 648729071828404053L; - private final static String txtRunScriptTitle = "Startskript"; private final static String txtRunScriptDesc = "Ein hier eingetragenes Skript wird nach dem Start dieser VM automatisch ausgeführt."; - + protected final QLabel lblError; protected final JTextArea taRunScript; protected final ComboBox<RunscriptType> cboRunscriptType; public RunscriptConfiguratorLayout() { - GridManager grid = new GridManager(this, 1, true, - new Insets(5, 5, 5, 5)); - JPanel pnlRunScript = new JPanel(); + GridManager grid = new GridManager(this, 2, true, new Insets(5, 5, 5, 5)); taRunScript = new JTextArea("", 5, 20); JScrollPane scpRunScript = new JScrollPane(taRunScript, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - pnlRunScript.setBorder(BorderFactory - .createTitledBorder(txtRunScriptTitle)); - - GridManager gridRunScript = new GridManager(pnlRunScript, 2, true, - new Insets(2, 2, 2, 2)); taRunScript.setLineWrap(true); taRunScript.setWrapStyleWord(true); - gridRunScript.add(new WordWrapLabel(txtRunScriptDesc, false, true), 2) + grid.add(new WordWrapLabel(txtRunScriptDesc, false, true), 2) .fill(true, false).expand(true, false); - gridRunScript.nextRow(); + grid.nextRow(); cboRunscriptType = new ComboBox<RunscriptType>( new ComboBoxRenderer<RunscriptType>() { @Override @@ -235,16 +236,21 @@ class RunscriptConfiguratorLayout extends JPanel { RunscriptType.values())); ; cboRunscriptType.setEditable(true); - gridRunScript.add(new QLabel("Dateinamenserweiterung: ")).fill(false, false) + grid.add(new QLabel("Dateinamenserweiterung: ")).fill(false, false) .expand(false, false); - gridRunScript.add(cboRunscriptType).fill(true, false) + grid.add(cboRunscriptType).fill(true, false) .expand(true, false); - gridRunScript.nextRow(); - gridRunScript.add(scpRunScript, 2).fill(true, true).expand(true, true); - gridRunScript.finish(false); - - // build the final grid - grid.add(pnlRunScript).fill(true, true).expand(true, true); + grid.nextRow(); + grid.add(scpRunScript, 2).fill(true, true).expand(true, true); + grid.nextRow(); + lblError = new QLabel(""); + lblError.setForeground(Color.RED); + JPanel pnlError = new JPanel(); + pnlError.add(Box.createGlue()); + pnlError.add(lblError); + pnlError.add(Box.createGlue()); + grid.add(pnlError, 2).fill(true, false).expand(true, false); grid.finish(false); + } } |