diff options
author | Jonathan Bauer | 2014-09-23 18:37:39 +0200 |
---|---|---|
committer | Jonathan Bauer | 2014-09-23 18:37:39 +0200 |
commit | bb0846427f84804d14e388a07f48dea4d7c3b07e (patch) | |
tree | e769fe089dfed2f68256250411f951715fa5d55c /dozentenmodul/src/main/java | |
parent | [client] few javadoc comments (diff) | |
download | tutor-module-bb0846427f84804d14e388a07f48dea4d7c3b07e.tar.gz tutor-module-bb0846427f84804d14e388a07f48dea4d7c3b07e.tar.xz tutor-module-bb0846427f84804d14e388a07f48dea4d7c3b07e.zip |
[client] merge all 3 content checking function into validateContent()
better error messages
removed unused imports/vars
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r-- | dozentenmodul/src/main/java/gui/image/CreateImageAllgemein_GUI.java | 132 |
1 files changed, 57 insertions, 75 deletions
diff --git a/dozentenmodul/src/main/java/gui/image/CreateImageAllgemein_GUI.java b/dozentenmodul/src/main/java/gui/image/CreateImageAllgemein_GUI.java index cf5345fb..30d3bd25 100644 --- a/dozentenmodul/src/main/java/gui/image/CreateImageAllgemein_GUI.java +++ b/dozentenmodul/src/main/java/gui/image/CreateImageAllgemein_GUI.java @@ -1,7 +1,6 @@ package gui.image; import gui.intro.About_GUI; -import gui.intro.Login_GUI; import gui.intro.MainMenue_GUI; import java.awt.Color; @@ -44,10 +43,6 @@ import javax.swing.JScrollPane; import org.apache.log4j.Logger; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; - - @SuppressWarnings("serial") public class CreateImageAllgemein_GUI extends JFrame { @@ -64,9 +59,6 @@ public class CreateImageAllgemein_GUI extends JFrame { private JTextField EMail; private JTextField imagename; private JTextArea textAreadesc; - private boolean textfieldsHaveContent = false; // no textfield is empty - private boolean descriptionLengthOK = false; //description may not be longer than 254 chars - private boolean nameIsOK = false; // imagename only contains letters private final int MAX_DESCRIPTION_LENGTH = 254; private JTextArea txtrGebenSieBitte_1; @@ -94,10 +86,10 @@ public class CreateImageAllgemein_GUI extends JFrame { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { - // TODO Auto-generated catch block + LOGGER.error("Setting look and feel from system failed."); e.printStackTrace(); JOptionPane.showMessageDialog(null, - e.getCause() + "\n" + e.getStackTrace(), "Debug-Message", + "Konnte das Farbschema des Systems nicht übernehmen.", "Debug-Message", JOptionPane.ERROR_MESSAGE); } // Setzt den Titel @@ -325,23 +317,21 @@ public class CreateImageAllgemein_GUI extends JFrame { JButton continueButton = new JButton("Weiter"); continueButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - // Prueft die Eingabe und leitet weiter zur naechsten - // Seite - if (checkContent() == true - && checkNameIsLettersOrNumbers() == true && descriptionLenghtOK() == true) { - // Schreibt die Daten in das Model - Image.image.setImagename(imagename.getText()); - Image.image.setDesc(textAreadesc.getText()); - // Info + // Prüfe Eingabe + if (validateContent()) { LOGGER.info("Alle Eingaben in Ordnung. Imagename= \"" + Image.image.getImagename() + "\", Imagebeschreibung=\"" + Image.image.getDesc()+"\""); + + // Schreibt die Daten in das Model + Image.image.setImagename(imagename.getText()); + Image.image.setDesc(textAreadesc.getText()); + + // Zeige nächsten Schritt an CreateImageTechnisch_GUI ea = new CreateImageTechnisch_GUI(); ea.setVisible(true); dispose(); - } else { - } } }); @@ -369,14 +359,16 @@ public class CreateImageAllgemein_GUI extends JFrame { mntmFaq.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent arg0) { - OpenLinks open = new OpenLinks(); URI windows; try { windows = new URI(Links.getFAQ()); - open.openWebpage(windows); + OpenLinks.openWebpage(windows); } catch (URISyntaxException e) { - // TODO Auto-generated catch block e.printStackTrace(); + JOptionPane.showMessageDialog(null, + "Konnte die URL '" + Links.getFAQ() + "' nicht öffnen!", + "Fehler", + JOptionPane.ERROR_MESSAGE); } } }); @@ -386,14 +378,16 @@ public class CreateImageAllgemein_GUI extends JFrame { mntmOtrs.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent arg0) { - OpenLinks open = new OpenLinks(); URI windows; try { windows = new URI(Links.getOTRS()); - open.openWebpage(windows); + OpenLinks.openWebpage(windows); } catch (URISyntaxException e) { - // TODO Auto-generated catch block e.printStackTrace(); + JOptionPane.showMessageDialog(null, + "Konnte die URL '" + Links.getOTRS() + "' nicht öffnen!", + "Fehler", + JOptionPane.ERROR_MESSAGE); } } @@ -411,63 +405,51 @@ public class CreateImageAllgemein_GUI extends JFrame { }// end main - public boolean checkNameIsLettersOrNumbers() { - nameIsOK = false; + /** + * Checks if the fields of the form have content, + * if the image name has only alpha-numerical characters and + * if the image description has less than 254 characters. + * + * @return true if all fields are set, false otherwise. + */ + private boolean validateContent() { + // check if any text field is empty + if (imagename.getText().isEmpty() + || textAreadesc.getText().isEmpty() + || Vorname.getText().isEmpty() + || Nachname.getText().isEmpty() + || Hochschule.getText().isEmpty() + || EMail.getText().isEmpty()) { + // missing some fields + LOGGER.info("Form has missing fields, warning user."); + JOptionPane.showMessageDialog(null, + "Bitte geben Sie alle notwendigen Daten an!", + "Daten unvollständig", + JOptionPane.ERROR_MESSAGE); + return false; + } - // only allow letter from alphabet and numbers - if (imagename.getText().matches("[a-zA-Z0-9]+")) { - nameIsOK = true; - } else { - JOptionPane - .showMessageDialog( + // only allow letter from alphabet and numbers for the image name + if (!imagename.getText().matches("[a-zA-Z0-9]+")) { + LOGGER.info("Image name not alpha-numerical, warning user."); + JOptionPane.showMessageDialog( null, "Der Imagename darf keine Leer- oder Sonderzeichen enthalten.", "Unerlaubte Zeichen", - JOptionPane.INFORMATION_MESSAGE); - }// if - - return nameIsOK; - }// end nameIsOK - - public boolean checkContent() { - textfieldsHaveContent = false; - - // check if any textfield is empty - if (imagename.getText().isEmpty() == false - && textAreadesc.getText().isEmpty() == false - && Vorname.getText().isEmpty() == false - && Nachname.getText().isEmpty() == false - && Hochschule.getText().isEmpty() == false - && EMail.getText().isEmpty() == false) { - // all textfields have content - textfieldsHaveContent = true; - } else { - JOptionPane - .showMessageDialog(null, - "Bitte geben Sie alle notwendigen Daten an!", - "Daten unvollständig", - JOptionPane.INFORMATION_MESSAGE); - }// end if + JOptionPane.ERROR_MESSAGE); + return false; + } - return textfieldsHaveContent; - }// end checkContent - - public boolean descriptionLenghtOK(){ - descriptionLengthOK=false; - - //max length is 254 chars + // max length for image description is 254 chars if (textAreadesc.getText().length() >= MAX_DESCRIPTION_LENGTH) { - descriptionLengthOK=false; - JOptionPane - .showMessageDialog(null, + JOptionPane.showMessageDialog(null, "Die Beschreibung darf max 254 Zeichen enthalten. Aktuell enthält sie "+textAreadesc.getText().length()+".", "Beschreibung zu umfangreich", - JOptionPane.INFORMATION_MESSAGE); - }else { - descriptionLengthOK=true; - + JOptionPane.ERROR_MESSAGE); + return false; } - return descriptionLengthOK; - }// enddescriptionLenghtOK() + // we passed all tests, return true! + return true; + } }// end Class |