001 /**
002 * Copyright (C) 2007-2008, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program. If not, see <http://www.gnu.org/licenses/>.
018 *
019 */
020
021 package org.dllearner.tools.ore;
022
023
024 import java.awt.Component;
025
026 import javax.swing.JPanel;
027
028
029 /**
030 * A base descriptor class used to reference a Component panel for the Wizard, as
031 * well as provide general rules as to how the panel should behave.
032 * @author Lorenz Buehmann
033 */
034 public class WizardPanelDescriptor {
035
036 private static final String DEFAULT_PANEL_IDENTIFIER = "defaultPanelIdentifier";
037
038
039 /**
040 * Identifier returned by getNextPanelDescriptor() to indicate that this is the
041 * last panel and the text of the 'Next' button should change to 'Finish'.
042 */
043 public static final FinishIdentifier FINISH = new FinishIdentifier();
044
045 private Wizard wizard;
046 private Component targetPanel;
047 private Object panelIdentifier;
048
049 /**
050 * Default constructor. The id and the Component panel must be set separately.
051 */
052 public WizardPanelDescriptor() {
053 panelIdentifier = DEFAULT_PANEL_IDENTIFIER;
054 targetPanel = new JPanel();
055
056 }
057
058 /**
059 * Constructor which accepts both the Object-based identifier and a reference to
060 * the Component class which makes up the panel.
061 * @param id Object-based identifier
062 * @param panel A class which extends java.awt.Component that will be inserted as a
063 * panel into the wizard dialog.
064 */
065 public WizardPanelDescriptor(Object id, Component panel) {
066 panelIdentifier = id;
067 targetPanel = panel;
068 }
069
070 /**
071 * Returns to java.awt.Component that serves as the actual panel.
072 * @return A reference to the java.awt.Component that serves as the panel
073 */
074 public final Component getPanelComponent() {
075 return targetPanel;
076 }
077
078 /**
079 * Sets the panel's component as a class that extends java.awt.Component.
080 * @param panel java.awt.Component which serves as the wizard panel
081 */
082 public final void setPanelComponent(Component panel) {
083 targetPanel = panel;
084 }
085
086 /**
087 * Returns the unique Object-based identifier for this panel descriptor.
088 * @return The Object-based identifier
089 */
090 public final Object getPanelDescriptorIdentifier() {
091 return panelIdentifier;
092 }
093
094 /**
095 * Sets the Object-based identifier for this panel. The identifier must be unique
096 * from all the other identifiers in the panel.
097 * @param id Object-based identifier for this panel.
098 */
099 public final void setPanelDescriptorIdentifier(Object id) {
100 panelIdentifier = id;
101 }
102
103 final void setWizard(Wizard w) {
104 wizard = w;
105
106 }
107
108 /**
109 * Returns a reference to the Wizard component.
110 * @return The Wizard class hosting this descriptor.
111 */
112 public final Wizard getWizard() {
113 return wizard;
114 }
115
116 /**
117 * Returns a reference to the current WizardModel for this Wizard component.
118 * @return The current WizardModel for this Wizard component.
119 */
120 public WizardModel getWizardModel() {
121 return wizard.getModel();
122 }
123
124 // Override this method to provide an Object-based identifier
125 // for the next panel.
126
127 /**
128 * Override this class to provide the Object-based identifier of the panel that the
129 * user should traverse to when the Next button is pressed. Note that this method
130 * is only called when the button is actually pressed, so that the panel can change
131 * the next panel's identifier dynamically at runtime if necessary. Return null if
132 * the button should be disabled. Return FinishIdentfier if the button text
133 * should change to 'Finish' and the dialog should end.
134 * @return Object-based identifier.
135 */
136 public Object getNextPanelDescriptor() {
137 return null;
138 }
139
140 // Override this method to provide an Object-based identifier
141 // for the previous panel.
142
143 /**
144 * Override this class to provide the Object-based identifier of the panel that the
145 * user should traverse to when the Back button is pressed. Note that this method
146 * is only called when the button is actually pressed, so that the panel can change
147 * the previous panel's identifier dynamically at runtime if necessary. Return null if
148 * the button should be disabled.
149 * @return Object-based identifier
150 */
151 public Object getBackPanelDescriptor() {
152 return null;
153 }
154
155 // Override this method in the subclass if you wish it to be called
156 // just before the panel is displayed.
157
158 /**
159 * Override this method to provide functionality that will be performed just before
160 * the panel is to be displayed.
161 */
162 public void aboutToDisplayPanel() {
163
164 }
165
166 // Override this method in the subclass if you wish to do something
167 // while the panel is displaying.
168
169 /**
170 * Override this method to perform functionality when the panel itself is displayed.
171 */
172 public void displayingPanel() {
173
174 }
175
176 // Override this method in the subclass if you wish it to be called
177 // just before the panel is switched to another or finished.
178
179 /**
180 * Override this method to perform functionality just before the panel is to be
181 * hidden.
182 */
183 public void aboutToHidePanel() {
184
185 }
186
187
188
189 static class FinishIdentifier {
190 public static final String ID = "FINISH";
191 }
192
193
194 }