rendered paste bodypackage gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import applicationLogicAccess.ApplicationLogicAccess;
public class GUI implements WindowListener {
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
ApplicationLogicAccess.getInstance().exit();
mainFrame.dispose();
}
/**
* @param args
*/
public static void main(String[] args) {
GUI gui = new GUI();
gui.run();
}
private void updateList() {
switch (filterMode) {
case 0:
list.setText(ApplicationLogicAccess.getInstance().getList());
break;
case 1:
list.setText(ApplicationLogicAccess.getInstance()
.getListFilteredByName(nameField.getText()));
break;
case 2:
if (typeCombo.getSelectedItem().equals("Punkt"))
list.setText(ApplicationLogicAccess.getInstance()
.getListFilteredByType("Point"));
if (typeCombo.getSelectedItem().equals("Dreieck"))
list.setText(ApplicationLogicAccess.getInstance()
.getListFilteredByType("Triangle"));
if (typeCombo.getSelectedItem().equals("Linie"))
list.setText(ApplicationLogicAccess.getInstance()
.getListFilteredByType("Line"));
if (typeCombo.getSelectedItem().equals("Kugel"))
list.setText(ApplicationLogicAccess.getInstance()
.getListFilteredByType("Sphere"));
break;
}
}
private int filterMode;
private JFrame mainFrame;
private JTextArea list;
private JComboBox typeCombo;
private JTextField nameField;
public void run() {
filterMode = 0;
mainFrame = new JFrame("Verwaltung grafischer Objekte");
// mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
mainFrame.addWindowListener(this);
Container p = mainFrame.getContentPane();
p.setLayout(new GridLayout(4, 2));
list = new JTextArea();
list.setEditable(false);
updateList();
JButton addButton = new JButton("Hinzufügen...");
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AddDialog dialog = new AddDialog();
dialog.run(mainFrame);
updateList();
}
});
JButton deleteButton = new JButton("Löschen...");
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DeleteDialog dialog = new DeleteDialog();
dialog.run(mainFrame);
updateList();
}
});
ButtonGroup filterGroup = new ButtonGroup();
JRadioButton filterNoneButton = new JRadioButton("Keine Filterung",
true);
JRadioButton filterNameButton = new JRadioButton("Filtern nach Name",
true);
JRadioButton filterTypeButton = new JRadioButton("Filter nach Typ",
true);
filterGroup.add(filterNoneButton);
filterGroup.add(filterNameButton);
filterGroup.add(filterTypeButton);
filterNoneButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
filterMode = 0;
updateList();
}
});
filterNameButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
filterMode = 1;
updateList();
}
});
filterTypeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
filterMode = 2;
updateList();
}
});
nameField = new JTextField();
nameField.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
updateList();
}
});
typeCombo = new JComboBox(new Object[] { "Dreieck", "Punkt", "Linie",
"Kugel" });
typeCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateList();
}
});
p.add(addButton);
p.add(deleteButton);
p.add(list);
p.add(filterNoneButton);
p.add(filterNameButton);
p.add(nameField);
p.add(filterTypeButton);
p.add(typeCombo);
mainFrame.setSize(500, 200);
mainFrame.setVisible(true);
}
}