Package Interface

Source Code of Interface.ChoiseTable

package Interface;

import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JComboBox;

import com.sun.org.apache.bcel.internal.generic.FDIV;

import Logica.DecimalPlaces;
import Logica.Kassa;
import Logica.Rekening;
import javax.swing.Box;
import javax.swing.JTextField;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
import java.awt.Color;
import javax.swing.border.TitledBorder;

public class ChoiseTable extends JPanel implements ActionListener {
  private JComboBox comboBox;
  private Kassa fKassa;
  private Map<String, Rekening> fMap;
  private KassaGUI fGUI;
  private JTextField textField;
  private JLabel lblFouteInvoer;
 
  /**
   * Create the panel.
   */
  public ChoiseTable(Kassa kassa, KassaGUI gui) {
    fKassa = kassa;
    fGUI = gui;
    setLayout(new BorderLayout(0, 0));
   
    JLabel lblKiesTafel = new JLabel("Kies tafel");
    lblKiesTafel.setFont(new Font("Lucida Grande", Font.BOLD, 17));
    lblKiesTafel.setHorizontalAlignment(SwingConstants.CENTER);
    add(lblKiesTafel, BorderLayout.NORTH);
   
    JPanel panel = new JPanel();
    add(panel, BorderLayout.CENTER);
   
    JButton btnKiesTafel = new JButton("Kies Tafel");
    btnKiesTafel.addActionListener(this);
   
    comboBox = new JComboBox(getTableList());
    comboBox.addActionListener(this);
   
    Box horizontalBox = Box.createHorizontalBox();
   
    textField = new JTextField();
    textField.setToolTipText("tafelNr");
    textField.setColumns(10);
    textField.addActionListener(this);
   
    lblFouteInvoer = new JLabel("Foute invoer");
    lblFouteInvoer.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    lblFouteInvoer.setForeground(Color.RED);
    lblFouteInvoer.setVisible(false);
   
    JPanel panel_1 = new JPanel();
    panel_1.setBorder(new TitledBorder(null, "Administratie mogelijkheden", TitledBorder.LEADING, TitledBorder.TOP, null, null));
   
    GroupLayout gl_panel = new GroupLayout(panel);
    gl_panel.setHorizontalGroup(
      gl_panel.createParallelGroup(Alignment.TRAILING)
        .addGroup(gl_panel.createSequentialGroup()
          .addGap(279)
          .addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
            .addComponent(comboBox, Alignment.LEADING, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(gl_panel.createSequentialGroup()
              .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
              .addPreferredGap(ComponentPlacement.RELATED)
              .addComponent(btnKiesTafel, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE)))
          .addPreferredGap(ComponentPlacement.RELATED)
          .addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
            .addComponent(horizontalBox, GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE)
            .addComponent(lblFouteInvoer))
          .addGap(363))
        .addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
          .addContainerGap()
          .addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 790, GroupLayout.PREFERRED_SIZE)
          .addContainerGap(181, Short.MAX_VALUE))
    );
    gl_panel.setVerticalGroup(
      gl_panel.createParallelGroup(Alignment.LEADING)
        .addGroup(gl_panel.createSequentialGroup()
          .addGap(20)
          .addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
              .addComponent(btnKiesTafel)
              .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
              .addComponent(lblFouteInvoer))
            .addComponent(horizontalBox, GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE))
          .addPreferredGap(ComponentPlacement.RELATED)
          .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
          .addPreferredGap(ComponentPlacement.RELATED, 230, Short.MAX_VALUE)
          .addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 160, GroupLayout.PREFERRED_SIZE)
          .addContainerGap())
    );
    panel_1.setLayout(null);
   
    JButton btnNewButton = new JButton("Totaal omzet");
    btnNewButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        fGUI.open(new TotaalOmzet(fGUI, fKassa));
      }
    });
    btnNewButton.setBounds(31, 34, 117, 29);
    panel_1.add(btnNewButton);
   
    JButton btnBierprijs = new JButton("Bierprijs");
    btnBierprijs.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        fGUI.open(new Bierprijs(fGUI, fKassa));
      }
    });
    btnBierprijs.setBounds(31, 75, 117, 29);
    panel_1.add(btnBierprijs);
   
    JButton btnRefresh = new JButton("Refresh");
    btnRefresh.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        fGUI.open(new ChoiseTable(fKassa, fGUI));
      }
    });
    btnRefresh.setBounds(644, 34, 117, 29);
    panel_1.add(btnRefresh);
    panel.setLayout(gl_panel);
    panel.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{textField, comboBox, btnKiesTafel, horizontalBox}));
   
    SwingUtilities.invokeLater(new Runnable() {
     
      @Override
      public void run() {
        textField.requestFocus();
       
      }
    });
  }

  @Override
  public void actionPerformed(ActionEvent arg0) {
    Rekening rek;
    if(comboBox.getSelectedItem() != ""){
      rek = fMap.get(comboBox.getSelectedItem());
      fGUI.open(new BestelFrom(fKassa, fGUI, rek.getTafel()));
    }else if(isNumeric(textField.getText())){
      int tafel = Integer.parseInt(textField.getText());
      if(fKassa.existingTafel(tafel)){
        try {
          rek = Rekening.getRekeningFromTafel(tafel, fKassa.getDB());
          fGUI.open(new BestelFrom(fKassa, fGUI, rek.getTafel()));
        } catch (Exception e) {
          e.printStackTrace();
          return;
        }
      }else{
        NewTable nt = new NewTable(fKassa, fGUI, tafel);
        fGUI.open(nt);
      }
    }else{
      lblFouteInvoer.setVisible(true);
    }
   
  }
 
  public static boolean isNumeric(String str
  { 
      try 
     
        int d = Integer.parseInt(str)
     
      catch(NumberFormatException nfe
      { 
        return false
     
      return true
    }
 
  private Vector<String> getTableList(){
    fMap = new HashMap<String, Rekening>();
    Vector<String> toRet = new Vector<String>();
    toRet.add("");
    try{
      Vector<Rekening> rekeningen = fKassa.getAllOpenRekeningen();
      for(int i = 0; i < rekeningen.size(); i++){
        String tempString = rekeningen.get(i).getTafel() + ": " + rekeningen.get(i).getName() +
            " (€" + DecimalPlaces.set2decimals(rekeningen.get(i).getSubTotaal()) + ")";
        toRet.add(tempString);
        fMap.put(tempString, rekeningen.get(i));
      }
    }catch(Exception e){
      System.err.println(e.getMessage());
    }
    return toRet;
  }
}
TOP

Related Classes of Interface.ChoiseTable

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.