Coverage Report - org.homeunix.thecave.buddi.view.ScheduledTransactionListFrame
 
Classes in this File Line Coverage Branch Coverage Complexity
ScheduledTransactionListFrame
79%
66/83
44%
8/18
2.5
ScheduledTransactionListFrame$1
25%
1/4
0%
0/2
2.5
ScheduledTransactionListFrame$2
20%
1/5
0%
0/2
2.5
 
 1  
 /*
 2  
  * Created on May 6, 2006 by wyatt
 3  
  */
 4  
 package org.homeunix.thecave.buddi.view;
 5  
 
 6  
 import java.awt.BorderLayout;
 7  
 import java.awt.FlowLayout;
 8  
 import java.awt.event.ActionEvent;
 9  
 import java.awt.event.ActionListener;
 10  
 import java.awt.event.MouseAdapter;
 11  
 import java.awt.event.MouseEvent;
 12  
 
 13  
 import javax.swing.JButton;
 14  
 import javax.swing.JPanel;
 15  
 import javax.swing.JScrollPane;
 16  
 import javax.swing.ListSelectionModel;
 17  
 import javax.swing.event.ListSelectionEvent;
 18  
 import javax.swing.event.ListSelectionListener;
 19  
 
 20  
 import org.homeunix.thecave.buddi.Const;
 21  
 import org.homeunix.thecave.buddi.i18n.BuddiKeys;
 22  
 import org.homeunix.thecave.buddi.i18n.keys.ButtonKeys;
 23  
 import org.homeunix.thecave.buddi.i18n.keys.MenuKeys;
 24  
 import org.homeunix.thecave.buddi.model.Document;
 25  
 import org.homeunix.thecave.buddi.model.ScheduledTransaction;
 26  
 import org.homeunix.thecave.buddi.model.prefs.PrefsModel;
 27  
 import org.homeunix.thecave.buddi.plugin.api.exception.ModelException;
 28  
 import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter;
 29  
 import org.homeunix.thecave.buddi.util.InternalFormatter;
 30  
 import org.homeunix.thecave.buddi.view.dialogs.ScheduledTransactionEditorDialog;
 31  
 import org.homeunix.thecave.buddi.view.menu.bars.BuddiMenuBar;
 32  
 import org.homeunix.thecave.buddi.view.swing.ScheduledTransactionListCellRenderer;
 33  
 import org.jdesktop.swingx.JXList;
 34  
 import org.jdesktop.swingx.decorator.HighlighterFactory;
 35  
 
 36  
 import ca.digitalcave.moss.common.ClassLoaderFunctions;
 37  
 import ca.digitalcave.moss.common.OperatingSystemUtil;
 38  
 import ca.digitalcave.moss.swing.MossAssociatedDocumentFrame;
 39  
 import ca.digitalcave.moss.swing.MossDocumentFrame;
 40  
 import ca.digitalcave.moss.swing.exception.WindowOpenException;
 41  
 import ca.digitalcave.moss.swing.model.BackedListModel;
 42  
 
 43  0
 public class ScheduledTransactionListFrame extends MossAssociatedDocumentFrame implements ActionListener {
 44  
         public static final long serialVersionUID = 0;
 45  
 
 46  
         private final JButton doneButton;
 47  
 //        private final JButton cancelButton;
 48  
         private final JButton newButton;
 49  
         private final JButton editButton;
 50  
         private final JButton deleteButton;
 51  
 
 52  
 //        private final ScheduleEditorDialog scheduleEditor;
 53  
 
 54  
         private final JXList list;
 55  
         private final BackedListModel<ScheduledTransaction> listModel;
 56  
         private final Document model;
 57  
 
 58  
         public ScheduledTransactionListFrame(MossDocumentFrame parent){
 59  1845
                 super(parent, ScheduledTransactionListFrame.class.getName() + ((Document) parent.getDocument()).getUid() + "_" + parent.getDocument().getFile());
 60  1845
                 this.setIconImage(ClassLoaderFunctions.getImageFromClasspath("img/BuddiFrameIcon.gif"));
 61  
 
 62  1845
                 this.model = (Document) parent.getDocument();
 63  
                 
 64  
 //                scheduleEditor = new ScheduleEditorDialog(frame);
 65  
 
 66  1845
                 doneButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_DONE));
 67  
 //                cancelButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_CANCEL));
 68  1845
                 newButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_NEW));
 69  1845
                 editButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_EDIT));
 70  1845
                 deleteButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_DELETE));
 71  
 
 72  1845
                 listModel = new BackedListModel<ScheduledTransaction>(model.getScheduledTransactions());
 73  1845
                 list = new JXList();
 74  1845
         }
 75  
 
 76  
         @Override
 77  
         public void updateButtons() {                
 78  3690
                 super.updateButtons();
 79  
 
 80  3690
                 editButton.setEnabled(list.getSelectedIndices().length > 0);
 81  3690
                 deleteButton.setEnabled(list.getSelectedIndices().length > 0);
 82  3690
         }
 83  
 
 84  
         @Override
 85  
         public void updateContent() {
 86  1845
                 listModel.fireListChanged();
 87  
 
 88  1845
                 super.updateContent();
 89  1845
         }
 90  
 
 91  
         public void init() {
 92  
 //                scheduleEditor.loadSchedule(null);
 93  
                 
 94  1845
                 doneButton.setPreferredSize(InternalFormatter.getButtonSize(doneButton));
 95  1845
                 newButton.setPreferredSize(InternalFormatter.getButtonSize(newButton));
 96  1845
                 editButton.setPreferredSize(InternalFormatter.getButtonSize(editButton));
 97  1845
                 deleteButton.setPreferredSize(InternalFormatter.getButtonSize(deleteButton));
 98  
 
 99  1845
                 JPanel editTransactionsButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
 100  1845
                 editTransactionsButtonPanel.add(newButton);
 101  1845
                 editTransactionsButtonPanel.add(editButton);
 102  1845
                 editTransactionsButtonPanel.add(deleteButton);
 103  
 
 104  1845
                 JScrollPane listScroller = new JScrollPane(list);                
 105  
 
 106  1845
                 JPanel scrollPanel = new JPanel(new BorderLayout());
 107  1845
                 scrollPanel.add(listScroller, BorderLayout.CENTER);
 108  1845
                 scrollPanel.add(editTransactionsButtonPanel, BorderLayout.SOUTH);
 109  
 
 110  1845
                 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
 111  
 //                buttonPanel.add(cancelButton);
 112  1845
                 buttonPanel.add(doneButton);
 113  
 
 114  1845
                 if (OperatingSystemUtil.isMac()){
 115  0
                         listScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
 116  
                 }
 117  
 
 118  1845
                 newButton.addActionListener(this);
 119  1845
                 editButton.addActionListener(this);
 120  1845
                 deleteButton.addActionListener(this);
 121  1845
                 doneButton.addActionListener(this);
 122  
 
 123  1845
                 list.addHighlighter(HighlighterFactory.createAlternateStriping(Const.COLOR_EVEN_ROW, Const.COLOR_ODD_ROW));
 124  1845
                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 125  1845
                 list.setModel(listModel);
 126  1845
                 list.setCellRenderer(new ScheduledTransactionListCellRenderer());
 127  1845
                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 128  1845
                 list.addListSelectionListener(new ListSelectionListener(){
 129  
                         public void valueChanged(ListSelectionEvent e) {
 130  0
                                 if (!e.getValueIsAdjusting()){
 131  0
                                         updateButtons();
 132  
                                 }
 133  0
                         }
 134  
                 });
 135  1845
                 list.addMouseListener(new MouseAdapter(){
 136  
                         @Override
 137  
                         public void mouseClicked(MouseEvent e) {
 138  0
                                 super.mouseClicked(e);
 139  
                                 
 140  0
                                 if (e.getClickCount() >= 2){
 141  0
                                         editButton.doClick();
 142  
                                 }
 143  0
                         }
 144  
                 });
 145  
 
 146  1845
                 this.setTitle(TextFormatter.getTranslation(MenuKeys.MENU_EDIT_EDIT_SCHEDULED_TRANSACTIONS));
 147  1845
                 this.setJMenuBar(new BuddiMenuBar(this));
 148  1845
                 this.setLayout(new BorderLayout());
 149  1845
                 this.add(scrollPanel, BorderLayout.CENTER);
 150  1845
                 this.add(buttonPanel, BorderLayout.SOUTH);
 151  1845
                 this.getRootPane().setDefaultButton(doneButton);
 152  1845
         }
 153  
 
 154  
         public void actionPerformed(ActionEvent e) {
 155  1200
                 if (e.getSource().equals(newButton)){
 156  1165
                         ScheduledTransactionEditorDialog editor = new ScheduledTransactionEditorDialog(this, null);
 157  
                         try {
 158  1165
                                 editor.openWindow();
 159  
                         }
 160  45
                         catch (WindowOpenException woe){}
 161  
                         
 162  45
                         list.setSelectedIndex(-1);
 163  45
                         listModel.fireListChanged();
 164  45
                 }
 165  35
                 else if (e.getSource().equals(editButton)){
 166  0
                         Object o = list.getSelectedValue();
 167  
 
 168  0
                         if (o instanceof ScheduledTransaction) {
 169  0
                                 ScheduledTransactionEditorDialog editor = new ScheduledTransactionEditorDialog(this, (ScheduledTransaction) o);
 170  
                                 try {
 171  0
                                         editor.openWindow();
 172  
                                 }
 173  0
                                 catch (WindowOpenException woe){}
 174  
                         }
 175  0
                 }
 176  35
                 else if (e.getSource().equals(deleteButton)){
 177  0
                         Object o = list.getSelectedValue();
 178  
 
 179  0
                         if (o instanceof ScheduledTransaction){
 180  
                                 try {
 181  0
                                         model.removeScheduledTransaction((ScheduledTransaction) o);
 182  
                                 }
 183  0
                                 catch (ModelException me){}
 184  
                         }
 185  
                         
 186  0
                         list.setSelectedIndex(-1);
 187  0
                         listModel.fireListChanged();
 188  0
                         editButton.setEnabled(false);
 189  0
                         deleteButton.setEnabled(false);
 190  0
                 }
 191  35
                 else if (e.getSource().equals(doneButton)){
 192  35
                         this.closeWindow();
 193  
                 }
 194  80
         }
 195  
         
 196  
         @Override
 197  
         public void closeWindowWithoutPrompting() {
 198  40
                 PrefsModel.getInstance().putWindowLocation(BuddiKeys.SCHEDULED_TRANSACTION.toString(), this.getLocation());
 199  40
                 PrefsModel.getInstance().save();
 200  
                 
 201  40
                 super.closeWindowWithoutPrompting();
 202  40
         }
 203  
 }