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.gui;
16
17 import java.awt.Component;
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import javax.swing.JLabel;
21 import javax.swing.JPanel;
22
23 import net.curre.prefcount.util.LocaleExt;
24
25 /**
26 * This interface represents a set of common
27 * methods for player dialog main/inner panel.
28 * <p/>
29 * Created date: May 17, 2007
30 *
31 * @author Yevgeny Nyden
32 */
33 public abstract class DialogInnerPanel extends JPanel {
34
35 /** Enumeration for inner panel relative position. */
36 public static enum PanelPosition {
37
38 /** Indicates that this is the first panel. */
39 FIRST,
40 /** Indicates that this panel is in the middle. */
41 MIDDLE,
42 /** Indicates that this is the last panel. */
43 LAST
44 }
45
46 /** Panel relative position (first, middle, last). */
47 private PanelPosition panelPosition;
48
49 /** Header message resource key. */
50 private String headerMessageKey;
51
52 /** Reference to the locale sensitive components. */
53 protected Collection<Component> localeSensitiveComps;
54
55 /**
56 * Constructor.
57 *
58 * @param headerKey Panel header message resource key.
59 * @param position Panel relative position.
60 */
61 public DialogInnerPanel(String headerKey, PanelPosition position) {
62 this.panelPosition = position;
63 this.headerMessageKey = headerKey;
64 this.localeSensitiveComps = new ArrayList<Component>();
65 super.setOpaque(false);
66 }
67
68 /**
69 * Transfers focus to the next input field or
70 * to the first field that failed validation
71 * if there was such a field.
72 */
73 public abstract void focusFirstInputField();
74
75 /**
76 * Validates input fields of the panel and returns
77 * true if all fields are valid; returns false if
78 * at least one field is invalid.
79 *
80 * @return True if all input fields are valid; false
81 * if at least one field is invalid.
82 */
83 public abstract boolean validateFields();
84
85 /**
86 * Performs necessary activity (if there is any)
87 * when switching to this panel (entering it).
88 */
89 public abstract void doOnEntry();
90
91 /**
92 * Performs necessary activity (if there is any)
93 * when switching from this panel (leaving it) -
94 * i.e. when user presses the Next button.
95 */
96 public abstract void doOnLeave();
97
98 /**
99 * Returns true if this panel is the last panel
100 * (in the stack of panels/cards in the card layout).
101 *
102 * @return True if this panel is the last panel; false otherwise.
103 */
104 public boolean isLastPanel() {
105 return this.panelPosition == PanelPosition.LAST;
106 }
107
108 /**
109 * Returns true if this panel is the first panel
110 * (in the stack of panels/cards in the card layout).
111 *
112 * @return True if this panel is the first panel; false otherwise.
113 */
114 public boolean isFirstPanel() {
115 return this.panelPosition == PanelPosition.FIRST;
116 }
117
118 /** Unregisters locale sensitive components with the LocaleExt bean. */
119 public void unregisterLocaleSensitiveComponents() {
120 LocaleExt.unregisterComponents(this.localeSensitiveComps);
121 }
122
123 /**
124 * Sets the header message text on the passed
125 * dialog frame header message label object.
126 *
127 * @param messageLabel reference to the header message label object.
128 */
129 public void setHeaderMessage(JLabel messageLabel) {
130 messageLabel.setText(LocaleExt.getString(this.headerMessageKey));
131 LocaleExt.reregisterComponent(messageLabel, this.headerMessageKey);
132 }
133
134 }