// =================================================================
// Restaurant Builder - Interface
// CSC - 540
// 10/22/13
// Kris Purdy, Chris Fletemier
// =================================================================
package layout.manager;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class Interface extends JFrame implements ActionListener
{
// Class variables
private static final int SCREEN_WIDTH = 1366;
private static final int SCREEN_HEIGHT = 700;
private static final int FLOORPLAN_WIDTH = 1150;
private static final int FLOORPLAN_HEIGHT = SCREEN_HEIGHT;
private static final int BUTTONS_WIDTH = SCREEN_WIDTH - FLOORPLAN_WIDTH;
private static final int BUTTONS_HEIGHT = 280;
private static final int OBJECTLIST_WIDTH = BUTTONS_WIDTH;
private static final int OBJECTLIST_HEIGHT = SCREEN_HEIGHT - BUTTONS_HEIGHT;
private static final int BTN_WIDTH = 50;
private static final int BTN_HEIGHT = 50;
private static final int LABELS_WIDTH = 180;
private static final int LABELS_HEIGHT = 50;
private static final int OBJECT_WIDTH = 180;
private static final int OBJECT_HEIGHT = 225;
private final Floorplan floorplan;
private Estimate estimate;
private final ImageIcon leftRotateImg;
private final ImageIcon rightRotateImg;
private final ImageIcon upImg;
private final ImageIcon downImg;
private final ImageIcon leftImg;
private final ImageIcon rightImg;
private final ImageIcon costImg;
private final ImageIcon deleteImg;
private final ImageIcon selectionImg;
private final ImageIcon clearLayoutImg;
private final ImageIcon hostessPodiumImg;
private final ImageIcon roundTableImg;
private final ImageIcon squareTableImg;
private final ImageIcon rectangularTableImg;
private final ImageIcon tableForTwoImg;
private final ImageIcon boothImg;
private final ImageIcon buffettBarImg;
private final ImageIcon toiletPaperDispenserImg;
private final ImageIcon toiletImg;
private final ImageIcon towelDispenserImg;
private final ImageIcon wasteBasketImg;
private final ImageIcon bathroomSinkImg;
private final ImageIcon ovenImg;
private final ImageIcon rangeImg;
private final ImageIcon counterTopImg;
private final ImageIcon fridgeImg;
private final ImageIcon freezerImg;
private final ImageIcon kitchenSinkImg;
private final ImageIcon dishwasherImg;
private final ImageIcon kitchenImg;
private final ImageIcon diningroomImg;
private final ImageIcon bathroomImg;
private final JButton leftRotateBtn;
private final JButton rightRotateBtn;
private final JButton upBtn;
private final JButton downBtn;
private final JButton leftBtn;
private final JButton rightBtn;
private final JButton costBtn;
private final JButton deleteBtn;
private final JButton selectBtn;
private final JButton clearLayoutBtn;
private final JPanel buttons;
private final JPanel objectlist;
private final JPanel whitespace;
private final JLabel kitchenLbl;
private final JLabel diningroomLbl;
private final JLabel bathroomLbl;
private final RLabel hostessPodiumLbl;
private final RLabel roundTableLbl;
private final RLabel squareTableLbl;
private final RLabel rectangularTableLbl;
private final RLabel tableForTwoLbl;
private final RLabel boothLbl;
private final RLabel buffettBarLbl;
private final RLabel toiletPaperDispenserLbl;
private final RLabel toiletLbl;
private final RLabel towelDispenserLbl;
private final RLabel wasteBasketLbl;
private final RLabel bathroomSinkLbl;
private final RLabel ovenLbl;
private final RLabel rangeLbl;
private final RLabel counterTopLbl;
private final RLabel fridgeLbl;
private final RLabel freezerLbl;
private final RLabel kitchenSinkLbl;
private final RLabel dishwasherLbl;
private final JLabel recttabLbl; // Can remove later
private final JScrollPane scroll;
private final RestaurantObject recttab;
private ArrayList<RestaurantObject> list;
// Default Constructor
public Interface() throws IOException
{
//---------------------------------------------------------------MAIN WINDOW
// Create and set up the main window
setTitle("Restaurant Builder");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
//------------------------------------------------------------MOUSE LISTENER
MouseListener ml = new MouseListener() {
@Override
public void mouseReleased(MouseEvent e)
{
// Empty
}
@Override
public void mousePressed(MouseEvent e)
{
// Empty
}
@Override
public void mouseExited(MouseEvent e)
{
// Empty
}
@Override
public void mouseEntered(MouseEvent e)
{
// Empty
}
@Override
public void mouseClicked(MouseEvent e)
{
removeFocus();
((RLabel)e.getSource()).setBorder(BorderFactory.createLineBorder(Color.black, 3));
((RLabel)e.getSource()).setFocus(true);
}
};
//-----------------------------------------------------------FLOORPLAN PANEL
// Create the floorplan panel
floorplan = new Floorplan("resources/floorplanPic.png",
FLOORPLAN_WIDTH, FLOORPLAN_HEIGHT);
floorplan.setBounds(0, 0, FLOORPLAN_WIDTH, FLOORPLAN_HEIGHT);
floorplan.setLayout(null);
// ---------------------------------------------------------------------TEST
recttab = new RestaurantObject("RectangularTable");
recttabLbl = new JLabel();
ImageIcon testImg = new ImageIcon(recttab.getImgPath());
recttabLbl.setIcon(testImg);
recttabLbl.setBounds(500, 200, recttab.getImgWidth(), recttab.getImgHeight());
recttabLbl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
//recttabLbl.setFocusable(true);
//recttabLbl.setRequestFocusEnabled(true);
//recttabLbl.grabFocus();
floorplan.add(recttabLbl);
ComponentMover cm = new ComponentMover();
cm.registerComponent(recttabLbl);
recttabLbl.addMouseListener(ml);
// recttabLbl.addMouseListener(new MouseAdapter(){
// @Override
// public void mousePressed(MouseEvent arg0) {
// recttabLbl.setBorder(BorderFactory.createLineBorder(Color.black));
// }
// @Override
// public void mouseReleased(MouseEvent arg0) {
// recttabLbl.setBorder(null);
// }
// });
// -----------------------------------------------------------------END TEST
//-------------------------------------------------------------BUTTONS PANEL
// Create the buttons panel
buttons = new JPanel();
buttons.setLayout(null);
buttons.setBackground(Color.LIGHT_GRAY);
buttons.setBounds(FLOORPLAN_WIDTH, 0, BUTTONS_WIDTH, BUTTONS_HEIGHT);
// Create images for the buttons
leftRotateImg = new ImageIcon("RotateLeft.png");
rightRotateImg = new ImageIcon("RotateRight.png");
upImg = new ImageIcon("Up.png");
downImg = new ImageIcon("Down.png");
leftImg = new ImageIcon("Left.png");
rightImg = new ImageIcon("Right.png");
costImg = new ImageIcon("Cost.png");
deleteImg = new ImageIcon("Delete.png");
selectionImg = new ImageIcon("Selection.png");
clearLayoutImg = new ImageIcon("ClearLayout.png");
// Create the buttons
leftRotateBtn = new JButton(leftRotateImg);
leftRotateBtn.setToolTipText("Rotate to the left.");
leftRotateBtn.addActionListener(this);
rightRotateBtn = new JButton(rightRotateImg);
rightRotateBtn.setToolTipText("Rotate to the Right.");
rightRotateBtn.addActionListener(this);
upBtn = new JButton(upImg);
upBtn.setToolTipText("Move the object up.");
upBtn.addActionListener(this);
downBtn = new JButton(downImg);
downBtn.setToolTipText("Move the object down.");
downBtn.addActionListener(this);
leftBtn = new JButton(leftImg);
leftBtn.setToolTipText("Move the object to the left.");
leftBtn.addActionListener(this);
rightBtn = new JButton(rightImg);
rightBtn.setToolTipText("Move the object to the right.");
rightBtn.addActionListener(this);
costBtn = new JButton(costImg);
costBtn.setToolTipText("Show the current costs for the materials "
+ "and labor.");
costBtn.addActionListener(this);
deleteBtn = new JButton(deleteImg);
deleteBtn.setToolTipText("Delete the object.");
deleteBtn.addActionListener(this);
selectBtn = new JButton(selectionImg);
selectBtn.setToolTipText("Deselects and changes to the select cursor.");
selectBtn.addActionListener(this);
clearLayoutBtn = new JButton(clearLayoutImg);
clearLayoutBtn.setToolTipText("Removes all objects from the layout.");
clearLayoutBtn.addActionListener(this);
// Set the location and size of the buttons
leftRotateBtn.setBounds(25, 25, BTN_WIDTH, BTN_HEIGHT);
upBtn.setBounds(85, 25, BTN_WIDTH, BTN_HEIGHT);
rightRotateBtn.setBounds(145, 25, BTN_WIDTH, BTN_HEIGHT);
leftBtn.setBounds(25, 85, BTN_WIDTH, BTN_HEIGHT);
costBtn.setBounds(85, 85, BTN_WIDTH, BTN_HEIGHT);
rightBtn.setBounds(145, 85, BTN_WIDTH, BTN_HEIGHT);
selectBtn.setBounds(25, 145, BTN_WIDTH, BTN_HEIGHT);
downBtn.setBounds(85, 145, BTN_WIDTH, BTN_HEIGHT);
deleteBtn.setBounds(145, 145, BTN_WIDTH, BTN_HEIGHT);
clearLayoutBtn.setBounds(25, 205, BTN_WIDTH * 3 + 20, BTN_HEIGHT);
// Add the buttons to the panel
buttons.add(leftRotateBtn);
buttons.add(upBtn);
buttons.add(rightRotateBtn);
buttons.add(leftBtn);
buttons.add(costBtn);
buttons.add(rightBtn);
buttons.add(selectBtn);
buttons.add(downBtn);
buttons.add(deleteBtn);
buttons.add(clearLayoutBtn);
//----------------------------------------------------------OBJECTLIST PANEL
// Create objectlist panel
objectlist = new JPanel();
objectlist.setBackground(Color.WHITE);
objectlist.setLayout(new BoxLayout(objectlist, BoxLayout.Y_AXIS));
// Create labels to store images of the objects
hostessPodiumLbl = new RLabel();
hostessPodiumLbl.addMouseListener(ml);
hostessPodiumLbl.setName("hostessPodiumLbl");
roundTableLbl = new RLabel();
roundTableLbl.addMouseListener(ml);
roundTableLbl.setName("roundTableLbl");
squareTableLbl = new RLabel();
squareTableLbl.addMouseListener(ml);
squareTableLbl.setName("squareTableLbl");
rectangularTableLbl = new RLabel();
rectangularTableLbl.addMouseListener(ml);
rectangularTableLbl.setName("rectangularTableLbl");
tableForTwoLbl = new RLabel();
tableForTwoLbl.addMouseListener(ml);
tableForTwoLbl.setName("tableForTwoLbl");
boothLbl = new RLabel();
boothLbl.addMouseListener(ml);
boothLbl.setName("boothLbl");
buffettBarLbl = new RLabel();
buffettBarLbl.addMouseListener(ml);
buffettBarLbl.setName("buffettBarLbl");
toiletPaperDispenserLbl = new RLabel();
toiletPaperDispenserLbl.addMouseListener(ml);
toiletPaperDispenserLbl.setName("toiletPaperDispenserLbl");
toiletLbl = new RLabel();
toiletLbl.addMouseListener(ml);
toiletLbl.setName("toiletLbl");
towelDispenserLbl = new RLabel();
towelDispenserLbl.addMouseListener(ml);
towelDispenserLbl.setName("towelDispenserLbl");
wasteBasketLbl = new RLabel();
wasteBasketLbl.addMouseListener(ml);
wasteBasketLbl.setName("wasteBasketLbl");
bathroomSinkLbl = new RLabel();
bathroomSinkLbl.addMouseListener(ml);
bathroomSinkLbl.setName("bathroomSinkLbl");
ovenLbl = new RLabel();
ovenLbl.addMouseListener(ml);
ovenLbl.setName("ovenLbl");
rangeLbl = new RLabel();
rangeLbl.addMouseListener(ml);
rangeLbl.setName("rangeLbl");
counterTopLbl = new RLabel();
counterTopLbl.addMouseListener(ml);
counterTopLbl.setName("counterTopLbl");
fridgeLbl = new RLabel();
fridgeLbl.addMouseListener(ml);
fridgeLbl.setName("fridgeLbl");
freezerLbl = new RLabel();
freezerLbl.addMouseListener(ml);
freezerLbl.setName("freezerLbl");
kitchenSinkLbl = new RLabel();
kitchenSinkLbl.addMouseListener(ml);
kitchenSinkLbl.setName("kitchenSinkLbl");
dishwasherLbl = new RLabel();
dishwasherLbl.addMouseListener(ml);
dishwasherLbl.setName("dishwasherLbl");
kitchenLbl = new JLabel();
diningroomLbl = new JLabel();
bathroomLbl = new JLabel();
// Load the images for the objects
hostessPodiumImg = new ImageIcon("scrlHostessPodium.png");
roundTableImg = new ImageIcon("scrlRoundTable.png");
squareTableImg = new ImageIcon("scrlSquareTable.png");
rectangularTableImg = new ImageIcon("scrlRectangularTable.png");
tableForTwoImg = new ImageIcon("scrlTableForTwo.png");
boothImg = new ImageIcon("scrlBooth.png");
buffettBarImg = new ImageIcon("scrlBuffettBar.png");
toiletPaperDispenserImg = new ImageIcon("scrlToiletPaper.png");
toiletImg = new ImageIcon("scrlToilet.png");
towelDispenserImg = new ImageIcon("scrlTowelDispenser.png");
wasteBasketImg = new ImageIcon("scrlWasteBasket.png");
bathroomSinkImg = new ImageIcon("scrlBathroomSink.png");
ovenImg = new ImageIcon("scrlOven.png");
rangeImg = new ImageIcon("scrlRange.png");
counterTopImg = new ImageIcon("scrlCountertop.png");
fridgeImg = new ImageIcon("scrlFridge.png");
freezerImg = new ImageIcon("scrlFreezer.png");
kitchenSinkImg = new ImageIcon("scrlKitchenSink.png");
dishwasherImg = new ImageIcon("scrlDishwasher.png");
kitchenImg = new ImageIcon("Kitchen.png");
diningroomImg = new ImageIcon("DiningRoom.png");
bathroomImg = new ImageIcon("Bathroom.png");
// Attach the images to the labels
hostessPodiumLbl.setIcon(hostessPodiumImg);
roundTableLbl.setIcon(roundTableImg);
squareTableLbl.setIcon(squareTableImg);
rectangularTableLbl.setIcon(rectangularTableImg);
tableForTwoLbl.setIcon(tableForTwoImg);
boothLbl.setIcon(boothImg);
buffettBarLbl.setIcon(buffettBarImg);
toiletPaperDispenserLbl.setIcon(toiletPaperDispenserImg);
toiletLbl.setIcon(toiletImg);
towelDispenserLbl.setIcon(towelDispenserImg);
wasteBasketLbl.setIcon(wasteBasketImg);
bathroomSinkLbl.setIcon(bathroomSinkImg);
ovenLbl.setIcon(ovenImg);
rangeLbl.setIcon(rangeImg);
counterTopLbl.setIcon(counterTopImg);
fridgeLbl.setIcon(fridgeImg);
freezerLbl.setIcon(freezerImg);
kitchenSinkLbl.setIcon(kitchenSinkImg);
dishwasherLbl.setIcon(dishwasherImg);
kitchenLbl.setIcon(kitchenImg);
diningroomLbl.setIcon(diningroomImg);
bathroomLbl.setIcon(bathroomImg);
// Add all the images to the panel
objectlist.add(diningroomLbl);
objectlist.add(hostessPodiumLbl);
objectlist.add(roundTableLbl);
objectlist.add(squareTableLbl);
objectlist.add(rectangularTableLbl);
objectlist.add(boothLbl);
objectlist.add(bathroomLbl);
objectlist.add(toiletPaperDispenserLbl);
objectlist.add(toiletLbl);
objectlist.add(towelDispenserLbl);
objectlist.add(wasteBasketLbl);
objectlist.add(bathroomSinkLbl);
objectlist.add(kitchenLbl);
objectlist.add(ovenLbl);
objectlist.add(rangeLbl);
objectlist.add(counterTopLbl);
objectlist.add(fridgeLbl);
objectlist.add(freezerLbl);
objectlist.add(kitchenSinkLbl);
objectlist.add(dishwasherLbl);
// Create a scroll bar for the objectlist panel
scroll = new JScrollPane(objectlist);
scroll.setBackground(Color.WHITE);
scroll.setBorder(null);
scroll.getVerticalScrollBar().setUnitIncrement(16);
scroll.setBounds(FLOORPLAN_WIDTH + 25, BUTTONS_HEIGHT,
OBJECTLIST_WIDTH - 25, OBJECTLIST_HEIGHT);
//----------------------------------------------------------WHITESPACE PANEL
// Create a panel to add some white space
whitespace = new JPanel();
whitespace.setBounds(FLOORPLAN_WIDTH, BUTTONS_HEIGHT, 25, OBJECTLIST_HEIGHT);
whitespace.setBackground(Color.WHITE);
//---------------------------------------------------------------MAIN WINDOW
// Display the main window
add(floorplan);
add(buttons);
add(scroll);
add(whitespace);
setExtendedState(Frame.MAXIMIZED_BOTH);
setVisible(true);
setResizable(false);
}
//-----------------------------------------------------------ACTION LISTENER
@Override
public void actionPerformed(ActionEvent e)
{
int x, y, imgW, imgH;
x = recttab.getX();
y = recttab.getY();
imgW = recttab.getImgWidth();
imgH = recttab.getImgHeight();
if (e.getSource() == leftRotateBtn)
{
System.out.println("leftRotateBtn");
}
else if (e.getSource() == upBtn)
{
if (y > 5)
{
y -= 5;
recttab.setY(y);
recttabLbl.setBounds(x, y, imgW, imgH);
}
}
else if (e.getSource() == rightRotateBtn)
{
System.out.println("rightRotateBtn");
}
else if (e.getSource() == leftBtn)
{
if (x > 5)
{
x -= 5;
recttab.setX(x);
recttabLbl.setBounds(x, y, imgW, imgH);
}
}
else if (e.getSource() == costBtn)
{
estimate = new Estimate();
}
else if (e.getSource() == rightBtn)
{
if (x < (FLOORPLAN_WIDTH - recttab.getImgWidth() - 5))
{
x += 5;
recttab.setX(x);
recttabLbl.setBounds(x, y, imgW, imgH);
}
}
else if (e.getSource() == selectBtn)
{
removeFocus();
}
else if (e.getSource() == downBtn)
{
if (y < (SCREEN_HEIGHT - recttab.getImgHeight() - 5))
{
y += 5;
recttab.setY(y);
recttabLbl.setBounds(x, y, imgW, imgH);
}
}
else if (e.getSource() == deleteBtn)
{
System.out.println("deleteBtn");
}
else if (e.getSource() == clearLayoutBtn)
{
System.out.println("clearLayoutBtn");
}
}
// New label class to allow lables to have focus
private class RLabel extends JLabel
{
private boolean focus;
private String name;
// Does the object have focus
@Override
public boolean hasFocus()
{
return this.focus;
}
// Set the focus
public void setFocus(boolean f)
{
this.focus = f;
}
// Get the labels name
@Override
public String getName()
{
return this.name;
}
// Set the labels name
@Override
public void setName(String n)
{
this.name = n;
}
}
// Removes focus from all labels
private void removeFocus()
{
hostessPodiumLbl.setBorder(null);
hostessPodiumLbl.setFocus(false);
roundTableLbl.setBorder(null);
roundTableLbl.setFocus(false);
squareTableLbl.setBorder(null);
squareTableLbl.setFocus(false);
rectangularTableLbl.setBorder(null);
rectangularTableLbl.setFocus(false);
tableForTwoLbl.setBorder(null);
tableForTwoLbl.setFocus(false);
boothLbl.setBorder(null);
boothLbl.setFocus(false);
buffettBarLbl.setBorder(null);
buffettBarLbl.setFocus(false);
toiletPaperDispenserLbl.setBorder(null);
toiletPaperDispenserLbl.setFocus(false);
toiletLbl.setBorder(null);
toiletLbl.setFocus(false);
towelDispenserLbl.setBorder(null);
towelDispenserLbl.setFocus(false);
wasteBasketLbl.setBorder(null);
wasteBasketLbl.setFocus(false);
bathroomSinkLbl.setBorder(null);
bathroomSinkLbl.setFocus(false);
ovenLbl.setBorder(null);
ovenLbl.setFocus(false);
rangeLbl.setBorder(null);
rangeLbl.setFocus(false);
counterTopLbl.setBorder(null);
counterTopLbl.setFocus(false);
fridgeLbl.setBorder(null);
fridgeLbl.setFocus(false);
freezerLbl.setBorder(null);
freezerLbl.setFocus(false);
kitchenSinkLbl.setBorder(null);
kitchenSinkLbl.setFocus(false);
dishwasherLbl.setBorder(null);
dishwasherLbl.setFocus(false);
}
}