package de.achim.turnier.spielplan;
import info.clearthought.layout.TableLayout;
import java.awt.Font;
import java.util.HashMap;
import java.util.Vector;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import de.achim.turnier.Turniervewaltung2;
import de.achim.turnier.endrunde.EndrundenPaarungsPanel;
import lib.SGLayout;
public class SpielPlanContainer extends JPanel {
private JLabel title;
private Turniervewaltung2 motherFrame;
private Vector<SpielPlanPanel> vSPP = new Vector<SpielPlanPanel>();
private HashMap<String, SpielPlanPanel> hmSPP = new HashMap<String, SpielPlanPanel>();
private int rows;
private int columns;
private TableLayout tabLayout;
private int index = 0;
private EndrundenPaarungsPanel epp;
public SpielPlanContainer(){
title = new JLabel();
Font font = new Font( Font.SANS_SERIF, Font.PLAIN, 20 );
title.setFont(font);
title.setHorizontalAlignment(title.CENTER);
}
public void addSpielPlanPanel(SpielPlanPanel spp, String constraint){
vSPP.add(spp);
hmSPP.put(spp.getName(), spp);
add(spp, constraint); //das tablayout brauch den constraint
}
public Vector<SpielPlanPanel> getSpielPlanPanels(){
return vSPP;
}
public void setGridDimensions(int r, int c){
this.rows = r;
this.columns = c;
tabLayout = new TableLayout();
double[] row = makeSize(r);
double[] col = makeSize(c);
tabLayout.setRow(row);
tabLayout.setColumn(col);
setLayout(tabLayout);
}
public void addComponent(JComponent comp, String constraint){//, int index){
add(comp, constraint);
if(comp instanceof EndrundenPaarungsPanel){
this.epp = (EndrundenPaarungsPanel)comp;
}
revalidate();
}
public JLabel getTitle() {
return title;
}
public void setTitle(String title, String constraint) {
if(this.title.getText().length() <= 0){
this.title.setText(title);
add(this.title, constraint);//, index);
index ++;
revalidate();
}
}
public void setMotherFrame(JFrame mother){
this.motherFrame = (Turniervewaltung2)mother;
motherFrame.registerComponent(this);
}
public JFrame getMotherFrame(){
return this.motherFrame;
}
public void updateData(JComponent comp){
if(comp.getName().equals("spielpanel")){
Turniervewaltung2 tv2 = ((Turniervewaltung2)getMotherFrame());
tv2.updateData(comp);
}
}
private double[] makeSize(int count){
double [] arr = new double[count];
for(int i = 0;i < count; i++){
arr[i] = TableLayout.FILL;
}
return arr;
}
public Vector<SpielPlanPanel> getvSPP() {
return vSPP;
}
public void setHmSPP(HashMap<String, SpielPlanPanel> hmSPP) {
this.hmSPP = hmSPP;
}
public HashMap<String, SpielPlanPanel> getHmSPP() {
return hmSPP;
}
public EndrundenPaarungsPanel getEpp() {
return epp;
}
}