Newer
Older
POS_for_GUI_tests / src / frames / MainFrame.java
package frames;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;

import panels.MainPanel;
import panels.ShowHistoryPanel;
import resources.CustomersModel;

//-------------------------------------------------------------------------
// 
public class MainFrame extends JFrame implements IMainFrame {
	
	// model
	private CustomersModel model;

	// cache
	private MainPanel mainPanel;
	private ShowHistoryPanel historyPanel;

	// -------------------------------------------------------------------------
	// -------------------------------------------------------------------------
	// constructor
	// -------------------------------------------------------------------------
	//
	public MainFrame() {
		super("POS");

		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// initialize model
		model = new CustomersModel();
		
		// initialize Panels
		mainPanel = new MainPanel(this, model);
		historyPanel = new ShowHistoryPanel(this, model);

		// set visible
		historyPanel.setVisible(false);
		this.add(historyPanel, BorderLayout.CENTER);

		mainPanel.setVisible(true);
		this.add(mainPanel, BorderLayout.CENTER);
		
		// adjust window size
		this.pack();
	}

	// -------------------------------------------------------------------------
	// 
	public void showMainPanel() {
		getContentPane().removeAll();
		
		mainPanel.updateTableByTransition();
		
		add(mainPanel);
		validate();
		repaint();
	}

	// -------------------------------------------------------------------------
	//
	public void showHistoryPanel(int index) {
		getContentPane().removeAll();
		
		historyPanel.setVisible(true);
		historyPanel.updateListModelByIndex(index);		
		
		add(historyPanel);
		validate();
		repaint();
	}

	public CustomersModel getModel() {
		return model;
	}

	public MainPanel getMainPanel() {
		return mainPanel;
	}

	public ShowHistoryPanel getHistoryPanel() {
		return historyPanel;
	}
}