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.beans.PropertyChangeListener;
025 import java.beans.PropertyChangeSupport;
026 import java.util.HashMap;
027
028 /**
029 * The model for the Wizard component, which tracks the text, icons, and enabled state
030 * of each of the buttons, as well as the current panel that is displayed. Note that
031 * the model, in its current form, is not intended to be subclassed.
032 * @author Lorenz Buehmann
033 */
034
035
036 public class WizardModel {
037
038 /**
039 * Identification string for the current panel.
040 */
041 public static final String CURRENT_PANEL_DESCRIPTOR_PROPERTY = "currentPanelDescriptorProperty";
042
043 /**
044 * Property identification String for the Back button's text.
045 */
046 public static final String BACK_BUTTON_TEXT_PROPERTY = "backButtonTextProperty";
047
048 /**
049 * Property identification String for the Back button's enabled state.
050 */
051 public static final String BACK_BUTTON_ENABLED_PROPERTY = "backButtonEnabledProperty";
052
053 /**
054 * Property identification String for the Next button's text.
055 */
056 public static final String NEXT_FINISH_BUTTON_TEXT_PROPERTY = "nextButtonTextProperty";
057
058 /**
059 * Property identification String for the Next button's enabled state.
060 */
061 public static final String NEXT_FINISH_BUTTON_ENABLED_PROPERTY = "nextButtonEnabledProperty";
062
063 /**
064 * Property identification String for the Cancel button's text.
065 */
066 public static final String CANCEL_BUTTON_TEXT_PROPERTY = "cancelButtonTextProperty";
067
068 /**
069 * Property identification String for the Cancel button's enabled state.
070 */
071 public static final String CANCEL_BUTTON_ENABLED_PROPERTY = "cancelButtonEnabledProperty";
072
073 private WizardPanelDescriptor currentPanel;
074
075 private HashMap<Object, WizardPanelDescriptor> panelHashmap;
076
077 private HashMap<String, Object> buttonTextHashmap;
078 private HashMap<String, Boolean> buttonEnabledHashmap;
079
080 private PropertyChangeSupport propertyChangeSupport;
081
082 private ORE ore;
083
084 /**
085 * Default constructor.
086 */
087 public WizardModel() {
088
089 panelHashmap = new HashMap<Object, WizardPanelDescriptor>();
090
091 buttonTextHashmap = new HashMap<String, Object>();
092 buttonEnabledHashmap = new HashMap<String, Boolean>();
093
094 propertyChangeSupport = new PropertyChangeSupport(this);
095 ore = new ORE();
096
097 }
098
099 /**
100 * Returns the currently displayed WizardPanelDescriptor.
101 * @return The currently displayed WizardPanelDescriptor
102 */
103 WizardPanelDescriptor getCurrentPanelDescriptor() {
104 return currentPanel;
105 }
106
107 /**
108 * Registers the WizardPanelDescriptor in the model using the Object-identifier specified.
109 * @param id Object-based identifier
110 * @param descriptor WizardPanelDescriptor that describes the panel
111 */
112 void registerPanel(Object id, WizardPanelDescriptor descriptor) {
113
114 // Place a reference to it in a hashtable so we can access it later
115 // when it is about to be displayed.
116
117 panelHashmap.put(id, descriptor);
118
119 }
120
121 /**
122 * Sets the current panel to that identified by the Object passed in.
123 * @param id Object-based panel identifier
124 * @return boolean indicating success or failure
125 */
126 boolean setCurrentPanel(Object id) {
127
128 // First, get the hashtable reference to the panel that should
129 // be displayed.
130
131 WizardPanelDescriptor nextPanel = panelHashmap.get(id);
132
133 // If we couldn't find the panel that should be displayed, return
134 // false.
135
136 if (nextPanel == null){
137 throw new WizardPanelNotFoundException();
138 }
139 WizardPanelDescriptor oldPanel = currentPanel;
140 currentPanel = nextPanel;
141
142 if (oldPanel != currentPanel){
143 firePropertyChange(CURRENT_PANEL_DESCRIPTOR_PROPERTY, oldPanel, currentPanel);
144 }
145
146 return true;
147
148 }
149
150 private Object getBackButtonText() {
151 return buttonTextHashmap.get(BACK_BUTTON_TEXT_PROPERTY);
152 }
153
154 void setBackButtonText(Object newText) {
155
156 Object oldText = getBackButtonText();
157 if (!newText.equals(oldText)) {
158 buttonTextHashmap.put(BACK_BUTTON_TEXT_PROPERTY, newText);
159 firePropertyChange(BACK_BUTTON_TEXT_PROPERTY, oldText, newText);
160 }
161 }
162
163 private Object getNextFinishButtonText() {
164 return buttonTextHashmap.get(NEXT_FINISH_BUTTON_TEXT_PROPERTY);
165 }
166
167 void setNextFinishButtonText(Object newText) {
168
169 Object oldText = getNextFinishButtonText();
170 if (!newText.equals(oldText)) {
171 buttonTextHashmap.put(NEXT_FINISH_BUTTON_TEXT_PROPERTY, newText);
172 firePropertyChange(NEXT_FINISH_BUTTON_TEXT_PROPERTY, oldText, newText);
173 }
174 }
175
176 private Object getCancelButtonText() {
177 return buttonTextHashmap.get(CANCEL_BUTTON_TEXT_PROPERTY);
178 }
179
180 void setCancelButtonText(Object newText) {
181
182 Object oldText = getCancelButtonText();
183 if (!newText.equals(oldText)) {
184 buttonTextHashmap.put(CANCEL_BUTTON_TEXT_PROPERTY, newText);
185 firePropertyChange(CANCEL_BUTTON_TEXT_PROPERTY, oldText, newText);
186 }
187 }
188
189
190
191 Boolean getBackButtonEnabled() {
192 return buttonEnabledHashmap.get(BACK_BUTTON_ENABLED_PROPERTY);
193 }
194
195 void setBackButtonEnabled(Boolean newValue) {
196
197 Boolean oldValue = getBackButtonEnabled();
198 if (newValue != oldValue) {
199 buttonEnabledHashmap.put(BACK_BUTTON_ENABLED_PROPERTY, newValue);
200 firePropertyChange(BACK_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
201 }
202 }
203
204 Boolean getNextFinishButtonEnabled() {
205 return buttonEnabledHashmap.get(NEXT_FINISH_BUTTON_ENABLED_PROPERTY);
206 }
207
208 void setNextFinishButtonEnabled(Boolean newValue) {
209
210 Boolean oldValue = getNextFinishButtonEnabled();
211 if (newValue != oldValue) {
212 buttonEnabledHashmap.put(NEXT_FINISH_BUTTON_ENABLED_PROPERTY, newValue);
213 firePropertyChange(NEXT_FINISH_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
214 }
215 }
216
217 Boolean getCancelButtonEnabled() {
218 return buttonEnabledHashmap.get(CANCEL_BUTTON_ENABLED_PROPERTY);
219 }
220
221 void setCancelButtonEnabled(Boolean newValue) {
222
223 Boolean oldValue = getCancelButtonEnabled();
224 if (newValue != oldValue) {
225 buttonEnabledHashmap.put(CANCEL_BUTTON_ENABLED_PROPERTY, newValue);
226 firePropertyChange(CANCEL_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
227 }
228 }
229
230
231
232 public void addPropertyChangeListener(PropertyChangeListener p) {
233 propertyChangeSupport.addPropertyChangeListener(p);
234 }
235
236 public void removePropertyChangeListener(PropertyChangeListener p) {
237 propertyChangeSupport.removePropertyChangeListener(p);
238 }
239
240 protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
241 propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
242 }
243
244 public ORE getOre() {
245 return ore;
246 }
247
248 public void setOre(ORE ore) {
249 this.ore = ore;
250 }
251
252 public HashMap<Object, WizardPanelDescriptor> getPanelHashMap(){
253 return panelHashmap;
254 }
255
256 }