package gui.image;
import gui.intro.About_GUI;
import gui.intro.MainMenue_GUI;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import models.Image;
import models.Links;
import models.person;
import util.GuiOrganizer;
import util.OpenLinks;
import javax.swing.JScrollPane;
import org.apache.log4j.Logger;
@SuppressWarnings("serial")
public class CreateImageAllgemein_GUI extends JFrame {
/**
* Logger instance for this class.
*/
private final static Logger LOGGER = Logger.getLogger(CreateImageAllgemein_GUI.class);
private final JPanel contentPanel = new JPanel();
String[] result;
private JTextField Vorname;
private JTextField Nachname;
private JTextField Hochschule;
private JTextField EMail;
private JTextField imagename;
private JTextArea textAreadesc;
private final int MAX_DESCRIPTION_LENGTH = 254;
private JTextArea txtrGebenSieBitte_1;
Component c = null;
private static final String HELP_MESSAGE = "
" +
"Hier legen Sie zunächst ein Image an.
" +
"Dieses stellt die Grundlage Ihres Labors dar. Das Image ist der \"PC\", mit dem die Studenten arbeiten.
" +
"Installieren Sie alle benötigte Software und laden Sie am Ende dieses Prozesses die .vmdk-Datei hoch, um sie zu verwenden.
" +
"Um das Image richtig zuordnen zu können, werden hier einige grundlegende Informationen benötigt.
" +
"Geben Sie daher bitte einen allgemeinen Namen, sowie eine genauere Beschreibung ihres Images (Labors) an.
" +
"
";
/**
* Create the dialog.
*/
public CreateImageAllgemein_GUI(Component formerGUI) {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
// Beendet das Fenster auf X
System.exit(0);
}
@Override
public void windowOpened(WindowEvent arg0) {
imagename.requestFocusInWindow();
}
});
// Verhindert das Vergroessern des Fensters
setResizable(false);
try {
// setzt das Look & Feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException e) {
LOGGER.error("Setting look and feel from system failed.");
e.printStackTrace();
JOptionPane.showMessageDialog(c,
"Konnte das Farbschema des Systems nicht übernehmen.", "Debug-Message",
JOptionPane.ERROR_MESSAGE);
}
// Setzt den Titel
setTitle("bwLehrpool Suite - Image erzeugen");
// Zentriert das Fenster
setBounds(0, 0, 603, 722);
setLocationRelativeTo(formerGUI);
getContentPane().setLayout(null);
{
JPanel panel = new JPanel();
panel.setBackground(SystemColor.menu);
panel.setBounds(10, 11, 577, 57);
getContentPane().add(panel);
panel.setLayout(null);
{
JLabel lblNewLabel = new JLabel("Eingabe Ihrer Daten");
lblNewLabel.setBounds(10, 11, 509, 22);
panel.add(lblNewLabel);
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 18));
}
JTextPane txtpnBitteWhlenSie = new JTextPane();
txtpnBitteWhlenSie.setEditable(false);
txtpnBitteWhlenSie.setBackground(SystemColor.menu);
txtpnBitteWhlenSie
.setText("Geben Sie hier bitte einen sprechenden Imagenamen sowie Ihre Kontaktdaten an");
txtpnBitteWhlenSie.setBounds(10, 36, 509, 32);
panel.add(txtpnBitteWhlenSie);
}
contentPanel.setBounds(10, 85, 577, 493);
contentPanel.setBackground(SystemColor.menu);
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel);
contentPanel.setLayout(null);
JPanel panel_1 = new JPanel();
panel_1.setBackground(SystemColor.menu);
panel_1.setBorder(new TitledBorder(null, "Informationen zum Besitzer",
TitledBorder.LEADING, TitledBorder.TOP, null, null));
panel_1.setBounds(10, 66, 557, 369);
contentPanel.add(panel_1);
panel_1.setLayout(null);
JLabel label = new JLabel("Vorname: *");
label.setBackground(SystemColor.menu);
label.setBounds(10, 245, 125, 20);
panel_1.add(label);
Vorname = new JTextField();
Vorname.setEnabled(false);
Vorname.setEditable(false);
Vorname.setBackground(Color.WHITE);
Vorname.setText(person.verantwortlicher.getVorname());
Vorname.setColumns(10);
Vorname.setBounds(145, 245, 350, 20);
panel_1.add(Vorname);
JLabel label_7 = new JLabel("Nachname: *");
label_7.setBackground(SystemColor.menu);
label_7.setBounds(10, 276, 125, 20);
panel_1.add(label_7);
Nachname = new JTextField();
Nachname.setEnabled(false);
Nachname.setEditable(false);
Nachname.setBackground(Color.WHITE);
Nachname.setText(person.verantwortlicher.getName());
Nachname.setColumns(10);
Nachname.setBounds(145, 276, 350, 20);
panel_1.add(Nachname);
JLabel label_8 = new JLabel("Hochschule: *");
label_8.setBackground(SystemColor.menu);
label_8.setBounds(10, 307, 125, 20);
panel_1.add(label_8);
Hochschule = new JTextField();
Hochschule.setEnabled(false);
Hochschule.setEditable(false);
Hochschule.setBackground(Color.WHITE);
Hochschule.setText(person.verantwortlicher.getHochschule());
Hochschule.setColumns(10);
Hochschule.setBounds(145, 307, 350, 20);
panel_1.add(Hochschule);
JLabel label_9 = new JLabel("E-Mail: *");
label_9.setBackground(SystemColor.menu);
label_9.setBounds(10, 338, 125, 20);
panel_1.add(label_9);
EMail = new JTextField();
EMail.setEnabled(false);
EMail.setEditable(false);
EMail.setBackground(Color.WHITE);
EMail.setText(person.verantwortlicher.getEMail());
EMail.setColumns(10);
EMail.setBounds(145, 338, 350, 20);
panel_1.add(EMail);
JLabel lblImagename = new JLabel("Imagename: *");
lblImagename.setBackground(SystemColor.menu);
lblImagename.setBounds(10, 23, 125, 20);
panel_1.add(lblImagename);
imagename = new JTextField();
imagename.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textAreadesc.requestFocusInWindow();
}
});
imagename.setBackground(Color.WHITE);
imagename.setText((String) null);
imagename.setColumns(10);
imagename.setBounds(145, 23, 350, 20);
imagename.setText(Image.image.getImagename()); // null am Anfang, aber
// speichert die
// Eingabe, wenn man
// zurueck kommt zur
// Seite
panel_1.add(imagename);
JTextArea txtrGebenSieBitte = new JTextArea();
txtrGebenSieBitte.setEditable(false);
txtrGebenSieBitte.setBackground(SystemColor.menu);
txtrGebenSieBitte.setLineWrap(true);
txtrGebenSieBitte.setFont(new Font("Tahoma", Font.PLAIN, 12));
txtrGebenSieBitte
.setText("Geben Sie bitte einen sprechenden Namen für das Image an.\r\nDieser soll jedoch recht allgemein gehalten werden.\r\nBeispiel: \"Programmieren\", nicht \"Java Wintersemester bei...\"");
txtrGebenSieBitte.setBounds(145, 48, 350, 49);
panel_1.add(txtrGebenSieBitte);
JLabel lblBeschreibung = new JLabel("Beschreibung: *");
lblBeschreibung.setBackground(SystemColor.menu);
lblBeschreibung.setBounds(10, 110, 125, 20);
panel_1.add(lblBeschreibung);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(145, 110, 350, 60);
panel_1.add(scrollPane);
textAreadesc = new JTextArea();
textAreadesc.setFont(new Font("Tahoma", Font.PLAIN, 11));
textAreadesc.setLineWrap(true);
textAreadesc.setText((String) null);
textAreadesc.setText(Image.image.getDesc());// null am Anfang, aber
// speichert die Eingabe,
// wenn man zurueck kommt
// zur Seite
scrollPane.setViewportView(textAreadesc);
txtrGebenSieBitte_1 = new JTextArea();
txtrGebenSieBitte_1
.setText("Geben Sie bitte eine Beschreibung für das Image an.\r\nDiese soll jedoch recht spezifisch gehalten werden.\r\nBeispiel: \"Java-Entwicklung mit Eclipse und MySQL\"");
txtrGebenSieBitte_1.setLineWrap(true);
txtrGebenSieBitte_1.setFont(new Font("Tahoma", Font.PLAIN, 12));
txtrGebenSieBitte_1.setEditable(false);
txtrGebenSieBitte_1.setBackground(SystemColor.menu);
txtrGebenSieBitte_1.setBounds(145, 177, 350, 49);
panel_1.add(txtrGebenSieBitte_1);
JPanel panel = new JPanel();
panel.setBounds(10, 402, 577, 33);
contentPanel.add(panel);
panel.setLayout(null);
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
panel.setBackground(SystemColor.menu);
JLabel lblPflichtfelder = new JLabel("* Pflichtfelder");
lblPflichtfelder.setBounds(10, 442, 136, 14);
contentPanel.add(lblPflichtfelder);
JLabel lblHauptmen = new JLabel("Hauptmenü");
lblHauptmen.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
// oeffnet das Hauptmenue
CreateImageAllgemein_GUI.this.setVisible(false);
MainMenue_GUI main = new MainMenue_GUI(c);
main.setVisible(true);
}
});
lblHauptmen.setForeground(Color.BLUE);
lblHauptmen.setBounds(10, 11, 61, 14);
contentPanel.add(lblHauptmen);
JLabel label_1 = new JLabel(">");
label_1.setBounds(69, 11, 13, 14);
contentPanel.add(label_1);
JLabel lblVlimage = new JLabel("Image");
lblVlimage.setForeground(Color.BLUE);
lblVlimage.setBounds(81, 11, 45, 14);
contentPanel.add(lblVlimage);
JLabel label_2 = new JLabel(">");
label_2.setBounds(133, 11, 13, 14);
contentPanel.add(label_2);
JLabel lblNewLabel_1 = new JLabel("Neu");
lblNewLabel_1.setBounds(146, 11, 155, 14);
contentPanel.add(lblNewLabel_1);
{
JPanel buttonPane = new JPanel();
buttonPane.setBounds(0, 640, 597, 33);
buttonPane.setBackground(SystemColor.menu);
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane);
{
JButton backButton = new JButton("Zurück");
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Image.image.setImagename(imagename.getText());
Image.image.setDesc(textAreadesc.getText());
MainMenue_GUI sr = new MainMenue_GUI(c);
sr.setVisible(true);
dispose();
}
});
backButton.setActionCommand("Cancel");
buttonPane.add(backButton);
}
{
JButton continueButton = new JButton("Weiter");
continueButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Prüfe Eingabe
if (validateContent()) {
// Schreibt die Daten in das Model
Image.image.setImagename(imagename.getText());
Image.image.setDesc(textAreadesc.getText());
LOGGER.info("Alle Eingaben in Ordnung. Imagename= \""
+ Image.image.getImagename()
+ "\", Imagebeschreibung=\""
+ Image.image.getDesc()+"\"");
// Zeige nächsten Schritt an
CreateImageTechnisch_GUI ea = new CreateImageTechnisch_GUI(c);
ea.setVisible(true);
dispose();
}
}
});
continueButton.setActionCommand("OK");
buttonPane.add(continueButton);
getRootPane().setDefaultButton(continueButton);
}
}
JSeparator separator = new JSeparator();
separator.setBounds(0, 78, 597, 2);
getContentPane().add(separator);
JSeparator separator_1 = new JSeparator();
separator_1.setBounds(0, 627, 597, 2);
getContentPane().add(separator_1);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu mnNewMenu_1 = new JMenu("Hilfe");
menuBar.add(mnNewMenu_1);
JMenuItem mntmFaq = new JMenuItem("FAQ");
mntmFaq.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
URI windows;
try {
windows = new URI(Links.getFAQ());
OpenLinks.openWebpage(windows);
} catch (URISyntaxException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(c,
"Konnte die URL '" + Links.getFAQ() + "' nicht öffnen!",
"Fehler",
JOptionPane.ERROR_MESSAGE);
}
}
});
mnNewMenu_1.add(mntmFaq);
JMenuItem mntmOtrs = new JMenuItem("OTRS");
mntmOtrs.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
URI windows;
try {
windows = new URI(Links.getOTRS());
OpenLinks.openWebpage(windows);
} catch (URISyntaxException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(c,
"Konnte die URL '" + Links.getOTRS() + "' nicht öffnen!",
"Fehler",
JOptionPane.ERROR_MESSAGE);
}
}
});
mnNewMenu_1.add(mntmOtrs);
JMenuItem menuItem = new JMenuItem("About");
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
About_GUI ab = new About_GUI();
ab.setVisible(true);
}
});
mnNewMenu_1.add(menuItem);
JMenu mnNewMenu_Info = new JMenu("Info");
mnNewMenu_Info.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
JOptionPane.showMessageDialog(c, HELP_MESSAGE, "Hilfe zu dieser Oberfläche", JOptionPane.INFORMATION_MESSAGE);
}
});
menuBar.add(mnNewMenu_Info);
c = this;
}// end main
/**
* 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(c,
"Bitte geben Sie alle notwendigen Daten an!",
"Daten unvollständig",
JOptionPane.ERROR_MESSAGE);
return false;
}
// only allow letter from alphabet and numbers for the image name and certain special chars
// x2B= "+" x2C="-" x3A=":" x5F="_"
//
if (!imagename.getText().trim().matches("[a-zA-Z0-9\\x2B\\x2D\\x3A\\x5F]+")) {
LOGGER.info("Image name not alpha-numerical, warn user.");
JOptionPane.showMessageDialog(
c,
"Der Imagename darf nur aus Buchstaben, Zahlen und den Zeichen + - _ : bestehen.",
"Unerlaubte Zeichen",
JOptionPane.ERROR_MESSAGE);
return false;
}
// max length for image description is 254 chars
if (textAreadesc.getText().length() >= MAX_DESCRIPTION_LENGTH) {
JOptionPane.showMessageDialog(c,
"Die Beschreibung darf max 254 Zeichen enthalten. Aktuell enthält sie "+textAreadesc.getText().length()+".",
"Beschreibung zu umfangreich",
JOptionPane.ERROR_MESSAGE);
return false;
}
// we passed all tests, return true!
return true;
}
}// end Class