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