Coverage Report - uk.co.javagear.KeyFrame
 
Classes in this File Line Coverage Branch Coverage Complexity
KeyFrame
0% 
0% 
1.5
 
 1  
 /*
 2  
  * KeyFrame.java
 3  
  *
 4  
  * This file is part of JavaGear.
 5  
  *
 6  
  * JavaGear is free software; you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation; either version 2 of the License, or
 9  
  * (at your option) any later version.
 10  
  *
 11  
  * JavaGear is distributed in the hope that it will be useful,
 12  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14  
  * GNU General Public License for more details.
 15  
  *
 16  
  * You should have received a copy of the GNU General Public License
 17  
  * along with JavaGear; if not, write to the Free Software
 18  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19  
  */
 20  
 
 21  
 package uk.co.javagear;
 22  
 
 23  
 import java.awt.Dimension;
 24  
 import java.awt.Graphics;
 25  
 import java.awt.GridLayout;
 26  
 import java.awt.Toolkit;
 27  
 import java.awt.event.ActionEvent;
 28  
 import java.awt.event.ActionListener;
 29  
 import java.awt.event.WindowAdapter;
 30  
 import java.awt.event.WindowEvent;
 31  
 import javax.swing.JButton;
 32  
 import javax.swing.JFrame;
 33  
 import javax.swing.JPanel;
 34  
 
 35  
 /**
 36  
  * Create the frame to define controller configuration.
 37  
  *
 38  
  * @author Copyright (C) 2002 Chris White
 39  
  * @version 16th March 2002
 40  
  * @see "JavaGear Final Project Report"
 41  
  */
 42  0
 public final class KeyFrame extends JFrame implements ActionListener {
 43  
     
 44  
     /**
 45  
      * Pointer to Controller Emulation.
 46  
      */
 47  
     private Controllers controllers;
 48  
     
 49  
     /**
 50  
      * Pointer to keyConfig Panel.
 51  
      */
 52  
     private KeyConfig keyConfig;
 53  
     
 54  
     private JPanel buttons;
 55  
     
 56  
     private JButton ok;
 57  
     
 58  
     private JButton cancel;
 59  
     
 60  
     
 61  
     /**
 62  
      * KeyFrame Constructor.
 63  
      *
 64  
      * @param c Controllers
 65  
      */
 66  0
     public KeyFrame(Controllers c) {
 67  0
         this.controllers = c;
 68  0
         setTitle("Key Configuration");
 69  
         
 70  
         // Get screen sizes
 71  0
         Toolkit tk = Toolkit.getDefaultToolkit();
 72  0
         Dimension d = tk.getScreenSize();
 73  
         // Set Window in middle
 74  0
         setLocation(d.width / 4, d.height / 4);
 75  
         
 76  0
         keyConfig = new KeyConfig();
 77  0
         getContentPane().add(keyConfig);
 78  
         
 79  0
         keyConfig.setKeys(controllers.getKeys());
 80  
         
 81  0
         addWindowListener(new WindowAdapter() {
 82  
             public void windowClosing(WindowEvent e) {
 83  0
                 keyConfig.setKeys(controllers.getKeys()); // reload original settings
 84  0
                 setVisible(false);
 85  0
             }
 86  
         });
 87  
         
 88  0
         buttons = new JPanel(new GridLayout(1, 2));
 89  
         
 90  0
         ok = new JButton("OK");
 91  0
         cancel = new JButton("Cancel");
 92  0
         buttons.add(ok);
 93  0
         buttons.add(cancel);
 94  
         
 95  0
         getContentPane().add(buttons, "South");
 96  
         
 97  0
         ok.addActionListener(this);
 98  0
         cancel.addActionListener(this);
 99  
         
 100  0
         setResizable(false);
 101  0
         pack();
 102  0
     }
 103  
     
 104  
     public void actionPerformed(ActionEvent evt) {
 105  0
         if (evt.getSource() == ok) {
 106  0
             controllers.setKeys(keyConfig.getKeys());
 107  0
             this.setVisible(false);
 108  0
         } else if (evt.getSource() == cancel) {
 109  0
             keyConfig.setKeys(controllers.getKeys()); // reload original settings
 110  0
             this.setVisible(false);
 111  
         }
 112  0
     }
 113  
     
 114  
     public void paint(Graphics g) {
 115  0
         keyConfig.refresh();
 116  0
         buttons.repaint();
 117  0
     }
 118  
     
 119  
 }