View Javadoc

1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.event;
16  
17  import java.awt.event.ActionEvent;
18  import java.awt.event.ActionListener;
19  import java.awt.event.FocusEvent;
20  import java.awt.event.FocusListener;
21  import java.awt.event.KeyEvent;
22  import java.awt.event.KeyListener;
23  import javax.swing.*;
24  
25  import net.curre.prefcount.gui.PlayerDialogBasePanel;
26  
27  /**
28   * Object of this class represents a listener that extends
29   * <code>AbstractAction</code> class,  implements the
30   * <code>ActionListener</code>, <code>KeyListener</code>, and
31   * <code>FocusListener</code> interfaces to be used as a
32   * listener with the player navigational buttons.
33   * <p/>
34   * Created date: Jun 7, 2007
35   *
36   * @author Yevgeny Nyden
37   */
38  public class DialogButtonNavigationListener extends AbstractAction
39      implements ActionListener, KeyListener, FocusListener {
40  
41    /**
42     * If true, represents the next button;
43     * if false - back button.
44     */
45    private boolean isNextButton;
46  
47    /** Reference to the main player dialog panel. */
48    private PlayerDialogBasePanel basePanel;
49  
50    /**
51     * Constructor.
52     *
53     * @param nextButton If true, represents the next button;
54     *                   if false - back button.
55     * @param basePanel  Reference to the main player dialog panel.
56     */
57    public DialogButtonNavigationListener(boolean nextButton, PlayerDialogBasePanel basePanel) {
58      isNextButton = nextButton;
59      this.basePanel = basePanel;
60    }
61  
62    /**
63     * Performs the button action.
64     * <p/>
65     * {@inheritDoc}
66     */
67    public void actionPerformed(ActionEvent actionEvent) {
68      basePanel.nextQuestionEventHelper(isNextButton);
69    }
70  
71    /**
72     * Does nothing.
73     * <p/>
74     * {@inheritDoc}
75     */
76    public void keyTyped(KeyEvent keyEvent) {
77    }
78  
79    /**
80     * Does nothing.
81     * <p/>
82     * {@inheritDoc}
83     */
84    public void keyPressed(KeyEvent keyEvent) {
85    }
86  
87    /**
88     * Performs the button action.
89     * <p/>
90     * {@inheritDoc}
91     */
92    public void keyReleased(KeyEvent keyEvent) {
93    }
94  
95    /**
96     * Does nothing.
97     * <p/>
98     * {@inheritDoc}
99     */
100   public void focusGained(FocusEvent focusEvent) {
101   }
102 
103   /**
104    * Transfers focus from this button to
105    * the next appropriate component.
106    * <p/>
107    * {@inheritDoc}
108    */
109   public void focusLost(FocusEvent focusEvent) {
110     int ind = isNextButton ? 1 : 0;
111     basePanel.transferFocusProperly(ind);
112   }
113 
114 }