package ch.iso.m322.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.util.Iterator;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
import ch.iso.m322.controller.AddressLoaderLeftList;
import ch.iso.m322.controller.AddressLoaderRightList;
import ch.iso.m322.controller.AddressLoaderTable;
import ch.iso.m322.controller.DeleteOneItemListLeftListener;
import ch.iso.m322.controller.DeleteOneItemListRightListener;
import ch.iso.m322.controller.DeleteOneItemTableListener;
import ch.iso.m322.controller.LeftToRightListener;
import ch.iso.m322.controller.SayWelcomeToPatientsListener;
import ch.iso.m322.model.AddressTable;
import ch.iso.m322.resource.FrameConstants;
public class MyFrame extends JFrame {
private static final long serialVersionUID = 2438104279704561527L;
// own menu bar
private MyMenu myMenuBar;
// references
private JList<String> myJListLeft;
private JList<String> myJListNextToLeft;
private JTable myJTableRight;
private JComboBox<String> salutation;
private JTextField eintrag;
private JButton focusElement;
// constructor
public MyFrame() {
super(FrameConstants.FRAME_TITLE);
this.myMenuBar = new MyMenu();
this.setJMenuBar(this.myMenuBar);
myMenuBar.setBackground(new Color(187, 140, 209));
this.add(createContent());
}
// main panel
private JPanel createContent() {
final JPanel content = new JPanel(new GridLayout(1, 3, 2, 0));
content.setBackground(new Color(255, 255, 255));
content.add(createContentNavigation());
content.add(createContentLeft());
content.add(createContentMiddle());
content.add(createContentRight());
return content;
}
// navigation panel
private Component createContentNavigation() {
final JPanel contentNavigation = new JPanel(new BorderLayout(4, 4));
contentNavigation.setBackground(new Color(222, 159, 245));
final JPanel contentNavigationMiddle = new JPanel(new GridLayout(9, 1, 5, 10));
contentNavigationMiddle.setBackground(new Color(222, 159, 245));
// manage patients button
final JButton bManagePatients = new JButton(FrameConstants.FRAME_BUTTON_MANAGE_PATIENTS);
bManagePatients.setFont(new Font("", Font.BOLD, 15));
// patient documentation button
final JButton bPatientDocumentation = new JButton(FrameConstants.FRAME_BUTTON_PATIENT_DOCUMENTATION);
bPatientDocumentation.setFont(new Font("", Font.BOLD, 15));
// patient information button
final JButton bPatientInformation = new JButton(FrameConstants.FRAME_BUTTON_PATIENT_INFORMATION);
bPatientInformation.setFont(new Font("", Font.BOLD, 15));
// create medical certificate for patient button
final JButton bCreateMedicalCertificate = new JButton(FrameConstants.FRAME_BUTTON_CREATE_MEDICAL_CERTIFICATE);
bCreateMedicalCertificate.setFont(new Font("", Font.BOLD, 15));
// perscribe medication for patient button
final JButton bPerscribeMedication = new JButton(FrameConstants.FRAME_BUTTON_PERSCRIBE_MEDICATION);
bPerscribeMedication.setFont(new Font("", Font.BOLD, 15));
// set focus element
setFocusElement(bManagePatients);
setFocusElement(bPatientDocumentation);
setFocusElement(bPatientInformation);
setFocusElement(bCreateMedicalCertificate);
setFocusElement(bPerscribeMedication);
contentNavigationMiddle.add(new JLabel());
contentNavigationMiddle.add(new JLabel());
contentNavigationMiddle.add(bManagePatients);
contentNavigationMiddle.add(bPatientDocumentation);
contentNavigationMiddle.add(bPatientInformation);
contentNavigationMiddle.add(bCreateMedicalCertificate);
contentNavigationMiddle.add(bPerscribeMedication);
contentNavigation.add(contentNavigationMiddle, BorderLayout.CENTER);
return contentNavigation;
}
// left panel
private Component createContentLeft() {
final JPanel contentLeft = new JPanel(new BorderLayout(4, 4));
contentLeft.setBackground(new Color(222, 159, 245));
final JPanel contentLeftTop = new JPanel(new GridLayout(4, 2, 5, 10));
contentLeftTop.setBackground(new Color(222, 159, 245));
final JPanel contentLeftCenter = new JPanel(new GridLayout(1, 2, 5, 50));
contentLeftCenter.setBackground(new Color(222, 159, 245));
final JPanel contentLeftUnder = new JPanel(new GridLayout(1, 2));
contentLeftCenter.setBackground(new Color(222, 159, 245));
// add firstname button
final JButton bAddFirstname = new JButton(FrameConstants.FRAME_BUTTON_ADD_FIRSTNAME);
bAddFirstname.setFont(new Font("", Font.BOLD, 12));
// delete one firstname button
final JButton bDeleteFirstname = new JButton(FrameConstants.FRAME_BUTTON_DELETE_FIRSTNAME);
bDeleteFirstname.addActionListener(new DeleteOneItemListLeftListener());
bDeleteFirstname.setFont(new Font("", Font.BOLD, 12));
// delete one lastname button
final JButton bAddLastname = new JButton(FrameConstants.FRAME_BUTTON_ADD_LASTNAME);
bAddLastname.setFont(new Font("", Font.BOLD, 12));
// delete one lastname button
final JButton bDeleteLastname = new JButton(FrameConstants.FRAME_BUTTON_DELETE_LASTNAME);
bDeleteLastname.addActionListener(new DeleteOneItemListRightListener());
bDeleteLastname.setFont(new Font("", Font.BOLD, 12));
// firstname title
final JLabel firstname = new JLabel();
firstname.setText(FrameConstants.FRAME_LIST_FIRSTNAME);
// lastname title
final JLabel lastname = new JLabel();
lastname.setText(FrameConstants.FRAME_LIST_LASTNAME);
// elements
final JLabel lSalutation = new JLabel();
lSalutation.setText(FrameConstants.FRAME_FIELD_SALUTATION);
final JComboBox<String> cSalutation = new JComboBox<String>();
cSalutation.addItem(FrameConstants.FRAME_SALUATION_FEMALE);
cSalutation.addItem(FrameConstants.FRAME_SALUATION_MALE);
this.setSalutation(cSalutation);
// define list left
final JList<String> list = new JList<String>(new DefaultListModel<String>());
// define list right
final JList<String> list2 = new JList<String>(new DefaultListModel<String>());
// set reference
setMyJListLeft(list);
setMyJListNextToLeft(list2);
// add data to left list
final DefaultListModel<String> listModel = (DefaultListModel<String>) list.getModel();
// add data to right list
final DefaultListModel<String> listModel2 = (DefaultListModel<String>) list2.getModel();
Iterator<String> data = new AddressLoaderLeftList();
while (data.hasNext()) {
listModel.addElement(data.next());
}
Iterator<String> data2 = new AddressLoaderRightList();
while (data2.hasNext()) {
listModel2.addElement(data2.next());
}
list.setPreferredSize(new Dimension(300, 200));
list.setBackground(new Color(238, 238, 238));
list2.setPreferredSize(new Dimension(300, 200));
list2.setBackground(new Color(238, 238, 238));
// scroll pane
final JScrollPane contentLeftScroller = new JScrollPane(list);
contentLeftScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
contentLeftScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
// scroll pane for list2
final JScrollPane contentLeftScroller2 = new JScrollPane(list2);
contentLeftScroller2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
contentLeftScroller2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
// set focus element
setFocusElement(bAddFirstname);
setFocusElement(bAddLastname);
setFocusElement(bDeleteFirstname);
setFocusElement(bDeleteLastname);
contentLeftTop.add(bAddFirstname);
contentLeftTop.add(bAddLastname);
contentLeftTop.add(bDeleteFirstname);
contentLeftTop.add(bDeleteLastname);
contentLeftTop.add(new JLabel());
contentLeftTop.add(new JLabel());
contentLeftTop.add(firstname);
contentLeftTop.add(lastname);
contentLeftCenter.add(lSalutation);
contentLeftCenter.add(cSalutation);
contentLeftUnder.add(contentLeftScroller);
contentLeftUnder.add(contentLeftScroller2);
contentLeft.add(contentLeftTop, BorderLayout.NORTH);
contentLeft.add(contentLeftCenter, BorderLayout.SOUTH);
contentLeft.add(contentLeftUnder, BorderLayout.CENTER);
return contentLeft;
}
// middle panel
private Component createContentMiddle() {
final JPanel contentMiddle = new JPanel(new BorderLayout(5, 5));
contentMiddle.setBackground(new Color(194, 233, 255));
final JPanel contentMiddleInner = new JPanel(new GridLayout(8, 1, 5, 5));
contentMiddleInner.setBackground(new Color(194, 233, 255));
final JPanel contentMiddleUnder = new JPanel(new GridLayout(2, 1, 5, 5));
contentMiddleUnder.setBackground(new Color(194, 233, 255));
// create buttons
final JButton bLeftToRight = new JButton(FrameConstants.FRAME_BUTTON_TO_RIGHT);
bLeftToRight.addActionListener(new LeftToRightListener());
final JButton bSayWelcomeToPatients = new JButton(FrameConstants.FRAME_BUTTON_WELCOME_TO_PATIENT);
bSayWelcomeToPatients.addActionListener(new SayWelcomeToPatientsListener());
// set focus element
setFocusElement(bLeftToRight);
setFocusElement(bSayWelcomeToPatients);
contentMiddleInner.add(new JLabel());
contentMiddleInner.add(bLeftToRight);
contentMiddleUnder.add(bSayWelcomeToPatients);
contentMiddle.add(contentMiddleInner, BorderLayout.NORTH);
contentMiddle.add(contentMiddleUnder, BorderLayout.SOUTH);
return contentMiddle;
}
// right panel
private Component createContentRight() {
final JPanel contentRight = new JPanel(new BorderLayout(5, 5));
contentRight.setBackground(new Color(255, 255, 255));
final JPanel contentRightTop = new JPanel(new GridLayout(2, 2, 5, 10));
contentRightTop.setBackground(new Color(255, 255, 255));
final JPanel contentRightCenter = new JPanel(new GridLayout(1, 2, 5, 50));
contentRightCenter.setBackground(new Color(222, 159, 245));
// elements
final JLabel tableTitle = new JLabel();
tableTitle.setFont(new Font("", Font.BOLD, 14));
tableTitle.setText(FrameConstants.FRAME_FIELD_CREATED_PATIENTS);
// delete one patient button
final JButton bDeletePatient = new JButton(FrameConstants.FRAME_BUTTON_DELETE_PATIENT);
bDeletePatient.addActionListener(new DeleteOneItemTableListener());
// print patients button
final JButton bPrintPatients = new JButton(FrameConstants.FRAME_BUTTON_PRINT_PATIENTS);
bPrintPatients.setFont(new Font("", Font.BOLD, 12));
// create table
String[] title = { FrameConstants.FRAME_TABLE_SALUATION, FrameConstants.FRAME_TABLE_FIRSTNAME,
FrameConstants.FRAME_TABLE_LASTNAME };
final JTable tableRight = new JTable(new DefaultTableModel(title, 0)); // 0 = no rows
tableRight.setBackground(new Color(238, 238, 238));
// add data
final DefaultTableModel tableModelRight = (DefaultTableModel) tableRight.getModel();
Iterator<AddressTable> data = new AddressLoaderTable();
while (data.hasNext()) {
tableModelRight.addRow(data.next().toStringArray());
}
tableRight.setPreferredSize(new Dimension(200, 490));
// set reference
setMyJTableRight(tableRight);
// scroll pane
final JScrollPane contentLeftScrollerTable = new JScrollPane(tableRight);
contentLeftScrollerTable.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
contentLeftScrollerTable.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
contentRightTop.add(tableTitle);
contentRightTop.add(new JLabel());
contentRightTop.add(bDeletePatient);
contentRightTop.add(bPrintPatients);
contentRightCenter.add(contentLeftScrollerTable, BorderLayout.CENTER);
contentRight.add(contentRightTop, BorderLayout.NORTH);
contentRight.add(contentRightCenter);
return contentRight;
}
public JList<String> getMyJListLeft() { // left list
return myJListLeft;
}
public void setMyJListLeft(JList<String> myJListLeft) {
this.myJListLeft = myJListLeft;
}
public JList<String> getMyJListNextToLeft() { // right list next to left
return myJListNextToLeft;
}
public void setMyJListNextToLeft(JList<String> myJListNextToLeft) {
this.myJListNextToLeft = myJListNextToLeft;
}
public JTable getMyJTableRight() {
return myJTableRight;
}
public void setMyJTableRight(JTable myJTableRight) {
this.myJTableRight = myJTableRight;
}
public JButton getFocusElement() {
return focusElement;
}
public void setFocusElement(JButton focusElement) {
this.focusElement = focusElement;
}
public JTextField getEintrag() {
return eintrag;
}
public void setEintrag(JTextField eintrag) {
this.eintrag = eintrag;
}
public JComboBox<String> getSalutation() {
return salutation;
}
public void setSalutation(JComboBox<String> salutation) {
this.salutation = salutation;
}
}