package inventorysystem;
import inventorysystem.gui.login;
import java.awt.Dimension;
import java.util.Vector;
import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import interfaces.Switchable;
import inventorysystem.gui.Products;
import inventorysystem.gui.Supplier;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
/**
*
* @author Epic
*/
public class InventorySystem {
private static GroupLayout panelHolder = null;
private static Vector panelStack
;
static Switchable[] switchables;
public InventorySystem() {
}
public InventorySystem
(String title
) {
/*
* Step 1: Create a vector that will hold all the panels this application will use.
* Reason : this is done so we can swap between panels when we need to.
* Step 2: Create a JLayeredPane this pane will hold the current panel in view
* our initial panel is obviously the login panel. after which we create the JFrame to
* hold our application together.
*/
login login = new login();
pane.add(login);
panelStack.add(0,login);
panelHolder = new javax.swing.GroupLayout(pane);
pane.setLayout(panelHolder);
panelHolder.setHorizontalGroup(
panelHolder.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(login, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
1200,
Short.
MAX_VALUE)
);
panelHolder.setVerticalGroup(
panelHolder.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(login, javax.
swing.
GroupLayout.
Alignment.
TRAILING, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
420,
Short.
MAX_VALUE)
);
applicationFrame();
}
private JFrame applicationFrame
(){
frame.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.add(pane);
frame.setJMenuBar(topMenu());
frame.setVisible(true);
frame.show(true);
return frame;
}
//Action menu
productItem.addActionListener(this::addNewProduct);
navigateMenu.add(productItem);
supplerItem.addActionListener(this::addNewSuppler);
navigateMenu.add(supplerItem);
topMenu.add(fileMenu);
topMenu.add(navigateMenu);
return topMenu;
}
/**
* @param args the command line arguments
*/
public static void main
(String[] args
) {
InventorySystem is = new InventorySystem("");
}
/**
* switch between panels on the jframe as a means to show different parts of the application
* in one frame.
* This is a static method because other classes would use the static vector, which is
* used as an instance variable will throw a NULL-POINTER-EXCEPTION
* @param panel
* @param isLoggedIn to determine if user is logged in
*/
{
// STEP1: get the current panel ontop the panel stack
// Step 2: if the stack is not empty and if we are not trying to replace a panel with itself
// STep 3: then switch the panel with the one we want to see
// Precaution: only a loggedin user can change panel or enter application.
if(isLoggedIn)
{
if(!panelStack.isEmpty())
{
currentPanel
= (JPanel) panelStack.
get(0);
if(currentPanel instanceof Switchable && panel instanceof Switchable)
{
if(currentPanel != panel){
panelHolder.replace(currentPanel, panel);
panelStack.add(0,panel);
}
}
}
}else{
JOptionPane.
showMessageDialog(null,
"Login to visit "+panel.
getName()+" panel.");
}
}
//<editor-fold defaultstate="collapsed" desc="Action listener methods">
/**
* Action to call new product panel
* @param evt
*/
private void addNewProduct
(java.
awt.
event.
ActionEvent evt
){
switchPanel(new Products(),login.isLoggedIn());
}
private void addNewSuppler
(java.
awt.
event.
ActionEvent evt
)
{
switchPanel(new Supplier(), login.isLoggedIn());
}
//</editor-fold>
}