package GUI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import model.Person;
import java.text.DecimalFormat; //<--- habe ich manuell eingefügt...
public class PersonVerwaltenGui extends JFrame
{
DefaultListModel listModel = null;
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JPanel eastPanel = null;
private JPanel southPanel = null;
private JButton btListeFuellen = null;
private JButton btListeLeeren = null;
private JButton btNeu = null;
private JButton btAendern = null;
private JButton btLoeschen = null;
private JButton btEnde = null;
private JScrollPane JSrollPane = null;
private JList ListView = null;
/**
* This is the default constructor
*/
public PersonVerwaltenGui()
{
super();
initialize();
this.listModel = new DefaultListModel();
this.ListView.setModel(listModel);
}
/**
* This method initializes this
*
* @return void
*/
private void initialize()
{
this.setSize(500, 600);
this.setContentPane(getJContentPane());
this.setTitle("Person Verwalten");
this.addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent e)
{
System.out.println("windowClosing()"); // TODO Auto-generated
// Event stub
// windowClosing()
}
public void windowActivated(java.awt.event.WindowEvent e)
{
System.out.println("windowActivated()"); // TODO Auto-generated
// Event stub
// windowActivated()
}
});
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane()
{
if (jContentPane == null)
{
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getEastPanel(), BorderLayout.EAST);
jContentPane.add(getSouthPanel(), BorderLayout.SOUTH);
jContentPane.add(getJSrollPane(), BorderLayout.CENTER);
}
return jContentPane;
}
/**
* This method initializes eastPanel
*
* @return javax.swing.JPanel
*/
private JPanel getEastPanel()
{
if (eastPanel == null)
{
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.insets = new Insets(5, 5, 5, 5);
gridBagConstraints5.gridy = 5;
gridBagConstraints5.ipadx = 0;
gridBagConstraints5.ipady = 0;
gridBagConstraints5.fill = GridBagConstraints.BOTH;
gridBagConstraints5.gridx = 0;
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.insets = new Insets(5, 5, 5, 5);
gridBagConstraints4.gridy = 4;
gridBagConstraints4.ipadx = 0;
gridBagConstraints4.ipady = 0;
gridBagConstraints4.fill = GridBagConstraints.BOTH;
gridBagConstraints4.gridx = 0;
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.insets = new Insets(5, 5, 5, 5);
gridBagConstraints3.gridy = 3;
gridBagConstraints3.ipadx = 0;
gridBagConstraints3.ipady = 0;
gridBagConstraints3.fill = GridBagConstraints.BOTH;
gridBagConstraints3.gridx = 0;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.ipadx = 0;
gridBagConstraints2.ipady = 0;
gridBagConstraints2.fill = GridBagConstraints.BOTH;
gridBagConstraints2.insets = new Insets(5, 5, 5, 5);
gridBagConstraints2.gridy = 2;
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.ipady = 0;
gridBagConstraints1.fill = GridBagConstraints.BOTH;
gridBagConstraints1.insets = new Insets(5, 5, 5, 5);
gridBagConstraints1.gridy = 1;
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.ipadx = 0;
gridBagConstraints.ipady = 0;
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.insets = new Insets(5, 5, 5, 5);
gridBagConstraints.gridy = 0;
eastPanel = new JPanel();
eastPanel.setLayout(new GridBagLayout());
eastPanel.setBackground(new Color(255, 255, 51));
eastPanel.add(getBtListeFuellen(), gridBagConstraints);
eastPanel.add(getBtListeLeeren(), gridBagConstraints1);
eastPanel.add(getBtNeu(), gridBagConstraints2);
eastPanel.add(getBtAendern(), gridBagConstraints3);
eastPanel.add(getBtLoeschen(), gridBagConstraints4);
eastPanel.add(getBtEnde(), gridBagConstraints5);
}
return eastPanel;
}
/**
* This method initializes southPanel
*
* @return javax.swing.JPanel
*/
private JPanel getSouthPanel()
{
if (southPanel == null)
{
southPanel = new JPanel();
southPanel.setLayout(new FlowLayout());
southPanel.setBackground(Color.red);
southPanel.setName("Statusleiste");
}
return southPanel;
}
/**
* This method initializes btListeFuellen
*
* @return javax.swing.JButton
*/
private JButton getBtListeFuellen()
{
if (btListeFuellen == null)
{
btListeFuellen = new JButton();
btListeFuellen.setText("Liste füllen");
btListeFuellen
.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
ListeFuellen();
}
});
}
return btListeFuellen;
}
/**
* This method initializes btListeLeeren
*
* @return javax.swing.JButton
*/
private JButton getBtListeLeeren()
{
if (btListeLeeren == null)
{
btListeLeeren = new JButton();
btListeLeeren.setText("Liste leeren");
btListeLeeren.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
ListeLeeren();
}
});
}
return btListeLeeren;
}
/**
* This method initializes btNeu
*
* @return javax.swing.JButton
*/
private JButton getBtNeu()
{
if (btNeu == null)
{
btNeu = new JButton();
btNeu.setText("Neu");
btNeu.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
neu();
}
});
}
return btNeu;
}
/**
* This method initializes btAendern
*
* @return javax.swing.JButton
*/
private JButton getBtAendern()
{
if (btAendern == null)
{
btAendern = new JButton();
btAendern.setText("Ändern");
btAendern.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
aendern();
}
});
}
return btAendern;
}
/**
* This method initializes btLoeschen
*
* @return javax.swing.JButton
*/
private JButton getBtLoeschen()
{
if (btLoeschen == null)
{
btLoeschen = new JButton();
btLoeschen.setText("Löschen");
btLoeschen.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
loeschen();
}
});
}
return btLoeschen;
}
/**
* This method initializes btEnde
*
* @return javax.swing.JButton
*/
private JButton getBtEnde()
{
if (btEnde == null)
{
btEnde = new JButton();
btEnde.setText("Ende");
btEnde.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
ende();
}
});
}
return btEnde;
}
/**
* This method initializes JSrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJSrollPane()
{
if (JSrollPane == null)
{
JSrollPane = new JScrollPane();
JSrollPane.setViewportView(getListView());
}
return JSrollPane;
}
/**
* This method initializes ListView
*
* @return javax.swing.JList
*/
private JList getListView()
{
if (ListView == null)
{
ListView = new JList();
ListView.setFont(new Font("Courier New", Font.BOLD, 12));
}
return ListView;
}
private void ListeFuellen()
{
this.ListeLeeren();
List<Person> tList;
tList = new Person().suchen();
for (Person tPerson : tList)
{
this.listModel.addElement(tPerson);
}
}
private void ListeLeeren()
{
listModel.removeAllElements();
}
private void neu()
{
}
private void aendern()
{
Integer tSelektion = this.ListView.getSelectedIndex();
if (tSelektion < 0)
{
// Fehlermeldung
}
else
{
Person tPerson;
tPerson = (Person) this.listModel.getElementAt(tSelektion);
PersonBearbeitenGui tGui = new PersonBearbeitenGui(this);
tGui.setPerson(tPerson);
tGui.setVisible(true);
}
}
private void loeschen()
{
Integer tSelektion = this.ListView.getSelectedIndex();
if (tSelektion < 0)
{
}
else
{
Person tPerson;
tPerson = (Person) this.listModel.getElementAt(tSelektion);
tPerson.loeschen();
this.ListeFuellen();
}
}
private void ende()
{
System.exit(0);
}
}