import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
/**
*
* BoxPanel contains all boxes that can be set out of the upper list of boxes in the frame
* @author florian
*
*/
public class BoxPanel extends JPanel{
private static final long serialVersionUID = 1L;
protected GUI gui;
private List<Box> boxList;
private Color color;
private final int standardWidth;
private final int standardHeight;
private final int fourBitWidth;
private final int eightBitWidth;
private final int sixteenBitWidth;
private final int twentyfourBitWidth;
private final int thirtytwoBitWidth;
private final int fourtyeightBitWidth;
/**
* Constructor
*
*/
public BoxPanel(GUI gui) {
this.gui = gui;
boxList = new ArrayList<Box>();
standardWidth = (int) gui.frameDim.getWidth()/15;
standardHeight = (int) gui.frameDim.getHeight()/19;
fourBitWidth = standardWidth;
eightBitWidth = (int) (fourBitWidth*1.5);
sixteenBitWidth = (int) (eightBitWidth*1.5);
twentyfourBitWidth = (int) ((sixteenBitWidth + eightBitWidth)*0.75);
thirtytwoBitWidth = (int) (sixteenBitWidth*1.5);
fourtyeightBitWidth = (int) ((thirtytwoBitWidth + sixteenBitWidth)*0.75);
}
public void fillBoxPanel(){
String[] boxText = {"Checksum","Code","Data","HdrLen","Hdr Checksum",
"FOS","Identifier","Total Length",
"Length/Type","Options","Pad","Packet ID",
"Protocol","Präambel","SeqNumr",
"SourAddr(Eth)","SourAddr(IP)","TarAddr(Eth)",
"TarAddr(IP)","TOS","TTL","Type","Vers"};
int n = 0; // horizontal gap between boxes
int m = 40; // vertical gap between boxes
int rowCount = 12; // amount of boxes in one row
int x = 45; // vertical gap for the first box (related to (0,0))
int y = 5; // horizontal gap for the first box (related to (0,0))
int width = standardWidth; // width of a normal box
int height = standardHeight; // height of a normal box
this.color = Color.WHITE; // color of a normal box
// creating boxes, setting color and text to each of the boxes
for(int i=0; i<boxText.length; i++){
if(i < rowCount){
Box box = new Box(width, height, x+n, y, boxText[i], null, color);
this.boxList.add(box);
n = width*(i+1)+(i+1)*4;
}
if(i == rowCount){
n=0;
Box box = new Box(width, height, x+n, y+m, boxText[i], null, color);
this.boxList.add(box);
n = width*(i-11)+(i)*4;
}
if(i > rowCount){
Box box = new Box(width, height, x+n, y+m, boxText[i], null, color);
this.boxList.add(box);
n = width*(i-11)+(i)*4;
}
}
}
public int getStandardHeight(){
return this.standardHeight;
}
public List<Box> getBoxList(){
return this.boxList;
}
public int getFourBitWidth(){
return this.fourBitWidth;
}
public int getEightBitWidth(){
return this.eightBitWidth;
}
public int getSixteenBitWidth(){
return this.sixteenBitWidth;
}
public int getTwentyFourBitWidth(){
return this.twentyfourBitWidth;
}
public int getThirtytwoBitWidth(){
return this.thirtytwoBitWidth;
}
public int getFourtyeightBitWidth(){
return this.fourtyeightBitWidth;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (Box box: boxList)
box.paintComponent(g);
}
}