Package de.achim.turnier.endrunde

Source Code of de.achim.turnier.endrunde.EndrundenPaarungsPanel

package de.achim.turnier.endrunde;

import info.clearthought.layout.TableLayout;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Vector;

import javax.sound.sampled.ReverbType;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import de.achim.turnier.spielplan.SpielPlanPanel;
import de.achim.turnier.tabellen.TabellenPanel;
import de.achim.turnier.utility.Begegnung;
import de.achim.turnier.utility.IPaarungPanels;
import de.achim.turnier.utility.ITabellen;

public class EndrundenPaarungsPanel extends JPanel implements IPaarungPanels{

  private SpielPlanPanel spp;
  private JPanel anlegen;
  private JLabel title;
 
  private Vector<String> vGruppe1 = new Vector<String>();
  private Vector<String> vGruppe2 = new Vector<String>();
  private Vector<String[]> vPaarungen = new Vector<String[]>();
  private Vector<HashMap<String, JComponent>> vComboPaarungen = new Vector<HashMap<String,JComponent>>();
  private Vector<Begegnung> begegnungsListe = new Vector<Begegnung>();
  private EndrundenTabelle endTab ;
 
  private JPanel motherPanel;
  private TableLayout tabLayout;
  private int rows;
  private int columns;
 
  private int gruppe;
 
  public EndrundenPaarungsPanel(){
       
    anlegen = new JPanel();
   
    title = new JLabel();
    Font font = new Font( Font.SANS_SERIF, Font.PLAIN, 20 );
    title.setFont(font);
    title.setHorizontalAlignment(title.CENTER);
   
  //  setGridDimensions(1, 7);
  //  setTitle("Paarungen anlegen", "0,0,6,0");
   
  //  okButton = new JButton("OK");
  //  ActionListener al = new MakePaarung(this);
  //  okButton.addActionListener(al);
   
    add(anlegen, BorderLayout.CENTER);
  }
 
  public Vector<String> getvGruppe1() {
    return vGruppe1;
  }

  public void setvGruppe1(Vector<String> vGruppe1) {
    this.vGruppe1 = vGruppe1;
  }

  public Vector<String> getvGruppe2() {
    return vGruppe2;
  }

  public void setvGruppe2(Vector<String> vGruppe2) {
    this.vGruppe2 = vGruppe2;
  }
 
  private void setTitle(String title, String constraint) {
    if(this.title.getText().length() <= 0){
      this.title.setText(title);
      anlegen.add(this.title, constraint);
      revalidate();
    }
  }
 
  public JPanel getMotherPanel() {
    return this.motherPanel;
  }

  public void setMotherPanel(JPanel motherPanel) {
    this.motherPanel = motherPanel;
  }
 
  public Vector<Begegnung> getBegegnungsListe() {
    return this.begegnungsListe;
  }
 
  public void fillPanel(){
   
    int index = vGruppe1.size(); //entsp. anzahl der reihen im tablayout
    setGridDimensions(index +3, 7);
   
    setTitle("Paarungen anlegen", "0,0,6,0");
   
    JLabel lbspielUm = new JLabel("Spiel um ");
    lbspielUm.setSize(20, 20);
    JLabel lbUhrzeit = new JLabel("Uhrzeit");
    JLabel lbGruppe1 = new JLabel("Gruppe 1");
    JLabel lbGruppe2 = new JLabel("Gruppe 2");
    JLabel lbTore1 = new JLabel("Tore 1");
    JLabel lbTore2 = new JLabel("Tore 2");
   
    anlegen.add(lbspielUm, "0,1");
    anlegen.add(lbUhrzeit, "1,1");
    anlegen.add(lbGruppe1, "2,1" );
    anlegen.add(lbGruppe2, "3,1");
    anlegen.add(lbTore1, "4,1");
    anlegen.add(lbTore2, "5,1");
    int spielum = 1;
   
    for(int i =0; i < index; i++){
      //HashMap<String, JComponent> hm = new HashMap<String, JComponent>();
      EndrundenPanel ep = new EndrundenPanel();
      ep.setEndTab(endTab);
     
      //JComboBox jcGroup1 = new JComboBox();
      fillComboBox(ep.getJcGroup1(), vGruppe1);
      //JComboBox jcGroup2 = new JComboBox();
      fillComboBox(ep.getJcGroup2(), vGruppe2);
      //JTextField uhrzeit = new JTextField("12:00");
      String zeile = String.valueOf(i+2);
      ep.setSpielum(String.valueOf(i+1));
      ep.setMotherPanel(this);
      //JTextField jtTore1 = new JTextField("0");
      //JTextField jtTore2 = new JTextField("0");
      //JButton btnOk = new JButton("OK");
      anlegen.add(ep, "0, " + zeile + ", 6, " + zeile);
/*      anlegen.add(new JLabel("Platz " + spielum), "0, "+zeile);
      anlegen.add(uhrzeit, "1, "+zeile);
      anlegen.add(jcGroup1, "2, "+zeile);
      anlegen.add(jcGroup2, "3, "+zeile);
      anlegen.add(jtTore1, "4, "+zeile);
      anlegen.add(jtTore2, "5, "+zeile);
      anlegen.add(btnOk, "6, "+zeile);
     
      hm.put("g1", jcGroup1);
      hm.put("g2", jcGroup2);
      hm.put("u1", uhrzeit);
      vComboPaarungen.add(hm);
      System.out.println("----" + i);*/
      spielum = spielum +2;
    }
   
    /*JPanel btnPanel = new JPanel();
    btnPanel.add(okButton);
    String btnPos = "0,"+ String.valueOf(index+2) + ", 3, 0";
    anlegen.add(btnPanel,  btnPos);*/
    revalidate();
  }
 
  public Vector<HashMap<String, JComponent>> getvComboPaarungen() {
    return this.vComboPaarungen;
  }

  public void setSpp(SpielPlanPanel spp) {
    this.spp = spp;
  }

  public SpielPlanPanel getSpp() {
    return this.spp;
  }
 
 
  private 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);

    anlegen.setLayout(tabLayout);
  }
 
  /**
   * @param endTab the endTab to set
   */
  public void setEndTab(EndrundenTabelle endTab) {
    this.endTab = endTab;
  }

  /**
   * @return the endTab
   */
  public EndrundenTabelle getEndTab() {
    return this.endTab;
  }

  private void fillComboBox(JComboBox combo, Vector<String> vstring){
   
    Iterator<String> iter = vstring.iterator();
    while(iter.hasNext()){
      String s = iter.next();
      System.out.println(s);
      combo.addItem(s);
    }

  }
 
  private double[] makeSize(int count){
    double [] arr = new double[count];
    for(int i = 0;i < count; i++){
      arr[i] = TableLayout.FILL;
    }
    return arr; 
  }

  @Override
  public void initFromLine(String line) {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void setTabellenPanel(ITabellen tabelle) {
    setEndTab((EndrundenTabelle)tabelle);   
  }

  /**
   * @param gruppe the gruppe to set
   */
  public void setGruppe(int gruppe) {
    this.gruppe = gruppe;
  }

  /**
   * @return the gruppe
   */
  public int getGruppe() {
    return this.gruppe;
  }
 
} //end of EndrundenPaarungsPanel


class MakePaarung implements ActionListener{
 
  private EndrundenPaarungsPanel epp;
  private SpielPlanPanel spp;
  public MakePaarung(EndrundenPaarungsPanel epp){
    this.epp = epp;
  }

  @Override
  public void actionPerformed(ActionEvent e) {
    System.out.println(epp.getvComboPaarungen().size());
    Iterator<HashMap<String, JComponent>> iter = epp.getvComboPaarungen().iterator();
    while(iter.hasNext()){
      HashMap<String, JComponent> hm = iter.next();
      JComboBox combo1 =(JComboBox) hm.get("g1");
      JComboBox combo2 = (JComboBox)hm.get("g2");
      JTextField uhrzeit = (JTextField)hm.get("u1");
      String mannschaft1 = combo1.getSelectedItem().toString();
      String mannschaft2 = combo2.getSelectedItem().toString();
      System.out.println("g1: " + mannschaft1);
      System.out.println("g2: " + mannschaft2);
      spp = epp.getSpp();
     
      long jetzt = new Date().getTime();
      DateFormat df = DateFormat.getDateInstance();
      Date langesDate = new Date(jetzt)
      df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMANY);
      String datum = df.format(langesDate);
      df = DateFormat.getTimeInstance(DateFormat.SHORT);
      //String uhrzeit = df.format(langesDate);
     
      spp.addSpielPaarung(mannschaft1, mannschaft2, datum + " " + uhrzeit.getText());
    }
    JButton btn = (JButton)e.getSource();
    btn.setEnabled(false);
    epp.repaint();
  }
 
}
TOP

Related Classes of de.achim.turnier.endrunde.EndrundenPaarungsPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.