Package Interface

Source Code of Interface.BestelTable

package Interface;

import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;

import Logica.rekeningItem;
import Logica.DecimalPlaces;

public class BestelTable extends AbstractTableModel {
  private String[] fColumnName = {"Product", "Prijs", "Hoeveelheid", "Bijbestellen", "Totaal", "#Al betaald", "Subtotaal"};
  private Vector<rekeningItem> fData;
  private JLabel fTotaal;
  private JLabel fAlbetaald;
  private JLabel fSubTotaal;

  public BestelTable(Vector<rekeningItem> rek, JLabel totaal, JLabel alBetaald, JLabel subTotaal) {
    fTotaal = totaal;
    fAlbetaald = alBetaald;
    fSubTotaal = subTotaal;
    fData = rek;
   
    calculateTotaal();
  }
 
  @Override
  public int getColumnCount() {
    return fColumnName.length;
  }
 
  @Override
  public String getColumnName(int col) {
         return fColumnName[col].toString();
  }

  @Override
  public int getRowCount() {
    return fData.size();
  }
 
  @Override
  public void fireTableDataChanged(){
    System.out.println(fData.get(0).getToevoegen());
    super.fireTableDataChanged();
    fireTableRowsUpdated(0, getRowCount());
    calculateTotaal();
  }

  @Override
  public Object getValueAt(int rowIndex, int columnIndex) {
    rekeningItem temp = fData.get(rowIndex);
    switch (columnIndex) {
    case 0:
      return temp.getProduct().getName();
    case 1:
      return "€" + DecimalPlaces.set2decimals(temp.getProduct().getPrijs());
    case 2:
      return temp.getHoeveelheid();
    case 3:
      return temp.getToevoegen();
    case 4:
      return "€" + DecimalPlaces.set2decimals(temp.getTotaal());
    case 5:
      return temp.getAfgerekend();
    case 6:
      return "€" + DecimalPlaces.set2decimals(temp.getSubTotaal());
    default:
      return null;
    }
  }
   
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        if (col != 3) {
            return false;
        } else {
            return true;
        }
    }
   
    public void setValueAt(Object value, int row, int col) {
        if(col == 3){
          String valueString = value.toString();
          if(valueString.length() == 0)valueString = "0";
          try{
            fData.get(row).setToevoegen(Integer.parseInt(valueString));
          }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Er ging iets mis met de invoer. Kijk de invoer na.\n" +
                e.getMessage());
          }
        }
        fireTableRowsUpdated(row, row);
        calculateTotaal();
    }
   
    private void calculateTotaal(){
      double Totaal = 0;
      double Sub = 0;
      for(int i = 0; i < fData.size(); i++){
        Totaal += fData.get(i).getTotaal();
        Sub += fData.get(i).getSubTotaal();
      }
      fTotaal.setText("€" + DecimalPlaces.set2decimals(Totaal));
      fAlbetaald.setText("€" + DecimalPlaces.set2decimals(Totaal-Sub));
      fSubTotaal.setText("€" + DecimalPlaces.set2decimals(Sub));
    }
   
    @SuppressWarnings("unchecked")
  @Override
  public Class getColumnClass(int c){
        switch (c) {
    case 0:
      return String.class;
    case 1:
      return String.class;
    case 2:
      return Integer.class;
    case 3:
      return Integer.class;
    case 4:
      return String.class;
    case 5:
      return Integer.class;
    case 6:
      return String.class;
    default:
      return Object.class;
    }
    }
   

}
TOP

Related Classes of Interface.BestelTable

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.