Coverage Report - org.homeunix.thecave.buddi.view.swing.MyAccountTableAmountCellRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
MyAccountTableAmountCellRenderer
8%
3/36
0%
0/36
10
 
 1  
 /*
 2  
  * Created on Aug 5, 2007 by wyatt
 3  
  */
 4  
 package org.homeunix.thecave.buddi.view.swing;
 5  
 
 6  
 import java.awt.Component;
 7  
 
 8  
 import javax.swing.JTable;
 9  
 import javax.swing.table.DefaultTableCellRenderer;
 10  
 
 11  
 import org.homeunix.thecave.buddi.model.Account;
 12  
 import org.homeunix.thecave.buddi.model.AccountType;
 13  
 import org.homeunix.thecave.buddi.model.Document;
 14  
 import org.homeunix.thecave.buddi.model.impl.FilteredLists;
 15  
 import org.homeunix.thecave.buddi.model.prefs.PrefsModel;
 16  
 import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter;
 17  
 import org.homeunix.thecave.buddi.util.Formatter;
 18  
 import org.homeunix.thecave.buddi.util.InternalFormatter;
 19  
 
 20  
 public class MyAccountTableAmountCellRenderer extends DefaultTableCellRenderer {
 21  
         public static final long serialVersionUID = 0;
 22  
         
 23  
         private final Document document;
 24  
         
 25  6338
         public MyAccountTableAmountCellRenderer(Document document) {
 26  6338
                 this.document = document;
 27  6338
         }
 28  
 
 29  
         @Override
 30  
         public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
 31  0
                 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 32  
 
 33  0
                 if (value instanceof Account){
 34  0
                         Account a = (Account) value;
 35  0
                         if (column == 1){
 36  0
                                 this.setText(TextFormatter.getHtmlWrapper(
 37  
                                                 TextFormatter.getDeletedWrapper(
 38  
                                                                 TextFormatter.getFormattedCurrency(
 39  
                                                                                 a.getBalance(), 
 40  
                                                                                 InternalFormatter.isRed(a, a.getBalance()), 
 41  
                                                                                 a.getAccountType().isCredit()
 42  
                                                                 ), a)));
 43  
                         }
 44  0
                         else if (column == 2 || column == 3){
 45  0
                                 this.setText("");
 46  
 
 47  0
                                 if (column == 2 && a.getAccountType().isCredit() && PrefsModel.getInstance().isShowCreditRemaining()){
 48  0
                                         long availableFunds = (a.getBalance() + a.getOverdraftCreditLimit()) * -1;
 49  0
                                         this.setText(TextFormatter.getHtmlWrapper(
 50  
                                                         TextFormatter.getDeletedWrapper(
 51  
                                                                         TextFormatter.getFormattedCurrency(
 52  
                                                                                         availableFunds, 
 53  
                                                                                         InternalFormatter.isRed(a, availableFunds), 
 54  
                                                                                         a.getAccountType().isCredit()
 55  
                                                                         ), a)));
 56  0
                                 }
 57  0
                                 else if (column == 2 && !a.getAccountType().isCredit() && PrefsModel.getInstance().isShowOverdraft()){
 58  0
                                         long availableFunds = a.getBalance() + a.getOverdraftCreditLimit();
 59  0
                                         this.setText(TextFormatter.getHtmlWrapper(
 60  
                                                         TextFormatter.getDeletedWrapper(
 61  
                                                                         TextFormatter.getFormattedCurrency(
 62  
                                                                                         availableFunds, 
 63  
                                                                                         InternalFormatter.isRed(a, availableFunds), 
 64  
                                                                                         a.getAccountType().isCredit()
 65  
                                                                         ), a)));
 66  0
                                 }
 67  0
                                 else if (PrefsModel.getInstance().isShowInterestRates()){
 68  0
                                         long interestRate = a.getInterestRate();
 69  0
                                         if (interestRate != 0){
 70  0
                                                 this.setText(TextFormatter.getHtmlWrapper(
 71  
                                                                 TextFormatter.getDeletedWrapper(
 72  
                                                                                 Formatter.getDecimalFormat(3).format((double) interestRate / 1000.0)
 73  
                                                                                 + "%", 
 74  
                                                                                 a)));
 75  
                                         }
 76  
                                 }
 77  
                         }
 78  
                 }
 79  0
                 if (value instanceof AccountType){
 80  0
                         if (column == 1){
 81  0
                                 AccountType t = (AccountType) value;
 82  0
                                 long amount = 0;
 83  0
                                 for (Account a : new FilteredLists.AccountListFilteredByType(document, document.getAccounts(), t)) {
 84  0
                                         if (!a.isDeleted())
 85  0
                                                 amount += a.getBalance();
 86  
                                 }
 87  0
                                 this.setText(TextFormatter.getHtmlWrapper(
 88  
                                                 TextFormatter.getFormattedCurrency(
 89  
                                                                 amount, 
 90  
                                                                 InternalFormatter.isRed(t, amount), 
 91  
                                                                 t.isCredit())));
 92  0
                         }
 93  
                         else {
 94  0
                                 this.setText("");
 95  
                         }
 96  
                 }
 97  
 
 98  
 
 99  0
                 if (hasFocus && isSelected) {
 100  0
                         table.editCellAt(row,column);
 101  0
                         table.getCellEditor(row, column).getTableCellEditorComponent(table, value, isSelected, row, column).requestFocus();
 102  
                 }
 103  
 
 104  0
                 return this;
 105  
         }
 106  
 }